aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 10:28:42 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 10:51:01 +0200
commit451a3400b76511393c62a444f588a4ed15f4a549 (patch)
treee4f5873a863d1d3e55618eab48b83262f874719d /catalog-be/src
parent5abfe4e1fb5fae4bbd5fbc340519f52075aff3ff (diff)
Initial OpenECOMP SDC commit
Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/IAuditingManager.java31
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatConstants.java258
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatUtil.java268
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java137
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/AsdcComponentsCleanerTask.java175
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/ComponentsCleanBusinessLogic.java89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java196
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaErrorResponse.java86
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java610
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DeConfigurationStatus.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java367
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java356
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTask.java293
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java207
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionNotificationSender.java127
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java84
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotificationEnum.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/INotificationData.java102
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IResourceArtifactInfo.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IServiceArtifactInfo.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/JsonContainerResourceInstance.java108
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationDataImpl.java118
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/PublishNotificationRunnable.java156
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ResourceArtifactInfoImpl.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceArtifactInfoImpl.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java268
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/SubscriberTypeEnum.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/TestQueue.java188
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java77
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java573
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java4127
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java295
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java571
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java123
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java274
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java309
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java860
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java1661
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java285
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java313
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java265
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java255
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java214
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java1125
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java1512
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java151
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java441
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/IDeploymentArtifactTypeConfigGetter.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java722
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InformationDeployedArtifactsBusinessLogic.java117
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java526
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java124
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java130
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java887
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java59
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java391
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementsBusinessLogic.java94
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java5475
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java921
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java1768
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java72
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java209
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java409
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java119
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java141
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java160
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java572
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java42
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java50
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java119
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java170
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/CategoryTypeEnum.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/HighestFilterEnum.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ArtifactUtils.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/NodeTypeConvertUtils.java76
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java65
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java243
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/CambriaOperationStatus.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java42
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java230
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java279
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java376
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java53
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java118
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java646
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetMetadataConverter.java381
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java300
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ArtifactMetadata.java106
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/AssetMetadata.java129
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/IAssetMetadata.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductAssetMetadata.java72
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductCategoryGroupMetadata.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetDetailedMetadata.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetMetadata.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceInstanceMetadata.java89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java53
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java225
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java202
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java122
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java1461
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java166
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/WebAppContextWrapper.java35
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java159
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfo.java84
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java352
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTypesInfo.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/CreateAndAssotiateInfo.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java91
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusListResponse.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceInfo.java74
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponce.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java130
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupTemplateInfo.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java151
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceVersionInfo.java53
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ServicesWrapper.java35
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ServletJsonResponse.java44
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInfo.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInterface.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java132
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java109
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java843
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java472
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java564
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java278
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java226
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java203
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java744
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java270
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java125
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java227
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java296
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java169
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java611
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java182
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java320
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java216
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java311
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PropertyServlet.java562
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java124
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java84
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java188
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java180
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java692
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java728
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java92
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java122
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java317
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java516
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java315
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java261
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java649
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java189
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java629
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java33
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java137
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java73
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java87
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java83
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java90
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java68
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java66
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminAction.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminValidator.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java714
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java121
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java92
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanCommitHandler.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanRollbackHandler.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java87
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java107
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java98
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java313
-rw-r--r--catalog-be/src/main/resources/application-context.xml64
-rw-r--r--catalog-be/src/main/resources/config/configuration.yaml478
-rw-r--r--catalog-be/src/main/resources/config/distribution-engine-configuration.yaml46
-rw-r--r--catalog-be/src/main/resources/config/ecomp-error-configuration.yaml383
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml1694
-rw-r--r--catalog-be/src/main/resources/config/logback.xml226
-rw-r--r--catalog-be/src/main/resources/config/neo4j-errors-configuration.yaml60
-rw-r--r--catalog-be/src/main/resources/config/titan.properties10
-rw-r--r--catalog-be/src/main/resources/elasticsearch.yml393
-rw-r--r--catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.yml204
-rw-r--r--catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.zipbin0 -> 1385 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/categories/categoryTypes.yml116
-rw-r--r--catalog-be/src/main/resources/import/tosca/categories/categoryTypes.zipbin0 -> 848 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml821
-rw-r--r--catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zipbin0 -> 3456 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/group-types/groupTypes.yml30
-rw-r--r--catalog-be/src/main/resources/import/tosca/group-types/groupTypes.zipbin0 -> 523 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.yml17
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.zipbin0 -> 469 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.yml177
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.zipbin0 -> 1425 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.json17
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.yml137
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.zipbin0 -> 1017 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.json15
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.yml89
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.zipbin0 -> 781 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.yml49
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.zipbin0 -> 675 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.yml64
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.zipbin0 -> 720 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.yml35
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.zipbin0 -> 638 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.json15
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.yml59
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.zipbin0 -> 718 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.yml76
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.zipbin0 -> 764 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.yml84
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.zipbin0 -> 826 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.yml9
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.zipbin0 -> 321 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.yml97
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.zipbin0 -> 972 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.yml136
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.zipbin0 -> 1192 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.json24
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.yml249
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.zipbin0 -> 1840 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.yml42
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.zipbin0 -> 692 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.yml18
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.zipbin0 -> 355 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml11
-rw-r--r--catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zipbin0 -> 273 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.yml17
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.zipbin0 -> 382 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.yml18
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.zipbin0 -> 352 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.json24
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.yml35
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.zipbin0 -> 519 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.yml9
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.zipbin0 -> 318 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.yml9
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.zipbin0 -> 295 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/database/database.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/database/database.yml27
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/database/database.zipbin0 -> 477 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.yml20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.zipbin0 -> 428 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/network/network.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/network/network.yml45
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/network/network.zipbin0 -> 463 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.yml18
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.zipbin0 -> 346 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/port/port.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/port/port.yml31
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/port/port.zipbin0 -> 414 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/root/root.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/root/root.yml23
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/root/root.zipbin0 -> 417 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.yml17
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.zipbin0 -> 395 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.yml15
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.zipbin0 -> 358 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.json20
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.yml11
-rw-r--r--catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.zipbin0 -> 340 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.yml94
-rw-r--r--catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.zipbin0 -> 673 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/users/importUsers.yaml13
-rw-r--r--catalog-be/src/main/resources/jetty-ssl.xml51
-rw-r--r--catalog-be/src/main/resources/keystore/README.txt16
-rw-r--r--catalog-be/src/main/resources/keystore/catalogbe.jksbin0 -> 2201 bytes
-rw-r--r--catalog-be/src/main/resources/keystore/catalogbe.jks.pwd1
-rw-r--r--catalog-be/src/main/resources/portal.properties25
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py74
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importCommon.py43
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py74
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py74
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py113
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py156
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py135
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py77
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py65
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py75
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py159
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py74
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py221
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py114
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py143
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py93
-rw-r--r--catalog-be/src/main/resources/swagger/css/print.css1155
-rw-r--r--catalog-be/src/main/resources/swagger/css/reset.css125
-rw-r--r--catalog-be/src/main/resources/swagger/css/screen.css1256
-rw-r--r--catalog-be/src/main/resources/swagger/css/typography.css26
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.eotbin0 -> 22922 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.svg411
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.ttfbin0 -> 40513 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woffbin0 -> 25992 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff2bin0 -> 11480 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.eotbin0 -> 22008 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.svg403
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.ttfbin0 -> 39069 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woffbin0 -> 24868 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff2bin0 -> 11304 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/explorer_icons.pngbin0 -> 5763 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/favicon-16x16.pngbin0 -> 645 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/favicon-32x32.pngbin0 -> 1654 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/favicon.icobin0 -> 5430 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/logo_small.pngbin0 -> 770 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/pet_store_api.pngbin0 -> 824 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/throbber.gifbin0 -> 9257 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/images/wordnik_api.pngbin0 -> 980 bytes
-rw-r--r--catalog-be/src/main/resources/swagger/index.html123
-rw-r--r--catalog-be/src/main/resources/swagger/lib/backbone-min.js35
-rw-r--r--catalog-be/src/main/resources/swagger/lib/handlebars-2.0.0.js48
-rw-r--r--catalog-be/src/main/resources/swagger/lib/highlight.7.3.pack.js21
-rw-r--r--catalog-be/src/main/resources/swagger/lib/jquery-1.8.0.min.js22
-rw-r--r--catalog-be/src/main/resources/swagger/lib/jquery.ba-bbq.min.js38
-rw-r--r--catalog-be/src/main/resources/swagger/lib/jquery.slideto.min.js21
-rw-r--r--catalog-be/src/main/resources/swagger/lib/jquery.wiggle.min.js28
-rw-r--r--catalog-be/src/main/resources/swagger/lib/marked.js1292
-rw-r--r--catalog-be/src/main/resources/swagger/lib/swagger-oauth.js304
-rw-r--r--catalog-be/src/main/resources/swagger/lib/underscore-min.js26
-rw-r--r--catalog-be/src/main/resources/swagger/lib/underscore-min.map1
-rw-r--r--catalog-be/src/main/resources/swagger/o2c.html20
-rw-r--r--catalog-be/src/main/resources/swagger/swagger-ui.js21738
-rw-r--r--catalog-be/src/main/resources/swagger/swagger-ui.min.js28
-rw-r--r--catalog-be/src/main/webapp/META-INF/MANIFEST.MF9
-rw-r--r--catalog-be/src/main/webapp/WEB-INF/jetty-web.xml8
-rw-r--r--catalog-be/src/main/webapp/WEB-INF/web.xml131
-rw-r--r--catalog-be/src/main/webapp/index.html7
-rw-r--r--catalog-be/src/main/webapp/index.jsp5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/AuditingMockManager.java44
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java266
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/ErrorConfigurationTest.java77
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/TestExternalConfiguration.java63
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/ZipUtil.java132
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/AuditingManagerTest.java79
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseConfDependentTest.java48
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ComponentBusinessLogicTest.java61
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java91
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java189
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java369
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceTestUtils.java90
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceBusinessLogicTest.java931
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineConfigTest.java168
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineHealthCheckTest.java138
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTaskTest.java269
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java234
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java105
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java111
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogicTest.java155
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CsarValidationUtilsTest.java37
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java509
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java94
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java1423
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceInstanceBusinessLogicTest.java284
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransitionTest.java169
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTest.java230
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckinTest.java170
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java188
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/LifecycleTestBase.java215
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTest.java125
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogicTest.java192
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java159
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/GenerateEcompErrorFileTest.java77
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java72
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ApplicationConfig.java62
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java268
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceUploadServletTest.java189
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java154
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/UserAdminServletTest.java148
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/user/UserAdminManagerTest.java91
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java437
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/configuration.yaml427
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/distribution-engine-configuration.yaml43
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/ecomp-error-configuration.yaml383
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml1583
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/neo4j-errors-configuration.yaml60
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/users-configuration.yaml2
-rw-r--r--catalog-be/src/test/resources/config/configuration1.yaml17
-rw-r--r--catalog-be/src/test/resources/config/elasticsearch.yml387
-rw-r--r--catalog-be/src/test/resources/config/elasticsearch.yml.bak387
-rw-r--r--catalog-be/src/test/resources/config/mysql-type-empty-nodes.zipbin0 -> 1894 bytes
-rw-r--r--catalog-be/src/test/resources/config/mysql-type-no-nodes.zipbin0 -> 448 bytes
-rw-r--r--catalog-be/src/test/resources/config/mysql-type-no-version.zipbin0 -> 1142 bytes
-rw-r--r--catalog-be/src/test/resources/config/mysql-type-only-yaml.zipbin0 -> 1129 bytes
-rw-r--r--catalog-be/src/test/resources/config/mysql-type-with-scripts.zipbin0 -> 66267 bytes
-rw-r--r--catalog-be/src/test/resources/config/mysql-type.yml82
-rw-r--r--catalog-be/src/test/resources/config/mysql-type.zipbin0 -> 1129 bytes
-rw-r--r--catalog-be/src/test/resources/config/normative-types-root.zipbin0 -> 1638 bytes
-rw-r--r--catalog-be/src/test/resources/config/sample.yaml17
-rw-r--r--catalog-be/src/test/resources/config/sampleNoProtocol.yaml17
-rw-r--r--catalog-be/src/test/resources/elasticsearch.yml391
-rw-r--r--catalog-be/src/test/resources/logback-test.xml13
-rw-r--r--catalog-be/src/test/resources/mock_vf.csarbin0 -> 1316 bytes
-rw-r--r--catalog-be/src/test/resources/normativeTypes/importToscaProperties.yml452
-rw-r--r--catalog-be/src/test/resources/normativeTypes/importToscaWithAttribute.yml41
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-all-map-test.yml30
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-DBMS.yml17
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-Root.yml23
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-blockStorage.yml18
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-compute.yml35
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-database.yml27
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-port.yml31
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-softwareComponent.yml17
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-new-webServer.yml11
-rw-r--r--catalog-be/src/test/resources/normativeTypes/normative-types-string-list-test.yml29
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_duplicateNode.yml23
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_empty.yml17
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_inputs.yml103
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_nodeEmpty.yml18
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_nodeVF.yml38
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_notValidNode.yml36
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_notValidRelationNode.yml36
-rw-r--r--catalog-be/src/test/resources/normativeTypes/topology_template_sample.yml36
-rw-r--r--catalog-be/src/test/resources/types/capabilityTypes.yml148
-rw-r--r--catalog-be/src/test/resources/types/capabilityTypes.zipbin0 -> 979 bytes
-rw-r--r--catalog-be/src/test/resources/types/categoryTypes.yml74
-rw-r--r--catalog-be/src/test/resources/types/categoryTypes.zipbin0 -> 403 bytes
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeDeriveFromIntegerWithProperty.yml8
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeDerivedFromRootNoProperties.yml4
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeDuplicateProperty.yml11
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeForGroup.yml40
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part1.yml15
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part2.yml12
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part1.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part2.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part1.yml20
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part2.yml20
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part1.yml22
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part2.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part1.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part2.yml25
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypeWithPropertyTypeThisDataType.yml9
-rw-r--r--catalog-be/src/test/resources/types/datatypes/dataTypes.yml129
-rw-r--r--catalog-be/src/test/resources/types/datatypes/derived3levelDataType.yml37
-rw-r--r--catalog-be/src/test/resources/types/datatypes/derivedDataType.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/derivedDataTypeNoProperties.yml15
-rw-r--r--catalog-be/src/test/resources/types/datatypes/derivedInvalidDataType.yml15
-rw-r--r--catalog-be/src/test/resources/types/datatypes/emptyDataType.yml4
-rw-r--r--catalog-be/src/test/resources/types/datatypes/emptyDataTypeNoPropertiesTag.yml3
-rw-r--r--catalog-be/src/test/resources/types/datatypes/exitingPropertyAtAncestor.yml19
-rw-r--r--catalog-be/src/test/resources/types/datatypes/invalidDataType.yml1
-rw-r--r--catalog-be/src/test/resources/types/datatypes/oneDataType.yml9
-rw-r--r--catalog-be/src/test/resources/types/interfaceLifecycleTypes.yml11
-rw-r--r--catalog-be/src/test/resources/types/interfaceLifecycleTypes.zipbin0 -> 273 bytes
-rw-r--r--catalog-be/src/test/resources/valid_vf.csarbin0 -> 1316 bytes
500 files changed, 105254 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/IAuditingManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/IAuditingManager.java
new file mode 100644
index 0000000000..36b79c2d9c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/IAuditingManager.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.auditing.api;
+
+import java.util.EnumMap;
+
+import javax.servlet.ServletContext;
+
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+
+public interface IAuditingManager {
+ void auditEvent(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields);
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatConstants.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatConstants.java
new file mode 100644
index 0000000000..eb14b5afe7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatConstants.java
@@ -0,0 +1,258 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.auditing.impl;
+
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+
+public interface AuditingLogFormatConstants {
+
+ static AuditingFieldsKeysEnum[] DISTRIBUTION_REGISTRATION_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_API_KEY,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_NOTIFICATION_TOPIC_NAME,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TOPIC_NAME};
+
+ static AuditingFieldsKeysEnum[] DISTRIBUTION_DOWNLOAD_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] GET_UEB_CLUSTER_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] DISTRIBUTION_DEPLOY_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] DISTRIBUTION_STATUS_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TOPIC_NAME,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] DISTRIBUTION_NOTIFY_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] ADD_REMOVE_TOPIC_KEY_ACL_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ROLE,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_API_KEY,
+ AuditingFieldsKeysEnum.AUDIT_STATUS
+ };
+
+ static AuditingFieldsKeysEnum[] CREATE_TOPIC_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME,
+ AuditingFieldsKeysEnum.AUDIT_STATUS
+ };
+
+ static AuditingFieldsKeysEnum[] ACTIVATE_DISTRIBUTION_ARRAY ={
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] CHANGE_DISTRIBUTION_STATUS_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT
+ };
+
+ static AuditingFieldsKeysEnum[] CREATE_RESOURCE_TEMPLATE_SUFFIX_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] CREATE_RESOURCE_TEMPLATE_PREFIX_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE
+ };
+
+ static AuditingFieldsKeysEnum[] USER_ACCESS_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_USER_UID,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] USER_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_USER_UID,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] AUTH_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_AUTH_URL,
+ AuditingFieldsKeysEnum.AUDIT_AUTH_USER,
+ AuditingFieldsKeysEnum.AUDIT_AUTH_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_AUTH_REALM
+ };
+
+ static AuditingFieldsKeysEnum[] ECOMP_USER_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_ECOMP_USER,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] CATEGORY_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_CATEGORY_NAME,
+ AuditingFieldsKeysEnum.AUDIT_SUB_CATEGORY_NAME,
+ AuditingFieldsKeysEnum.AUDIT_GROUPING_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] GET_USERS_LIST_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_USER_DETAILS,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+
+ static AuditingFieldsKeysEnum[] GET_CATEGORY_HIERARCHY_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_DETAILS,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+ static AuditingFieldsKeysEnum[] USER_ADMIN_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_USER_BEFORE,
+ AuditingFieldsKeysEnum.AUDIT_USER_AFTER,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+ static AuditingFieldsKeysEnum[] EXTERNAL_GET_ASSET_LIST_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+ static AuditingFieldsKeysEnum[] EXTERNAL_GET_ASSET_TEMPLATE_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+ static AuditingFieldsKeysEnum[] EXTERNAL_DOWNLOAD_ARTIFACT_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+ static AuditingFieldsKeysEnum[] EXTERNAL_CRUD_API_ARTIFACT_ARRAY = {
+ AuditingFieldsKeysEnum.AUDIT_ACTION,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME,
+ AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID,
+ AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL,
+ AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID,
+ AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID,
+ AuditingFieldsKeysEnum.AUDIT_CURR_ARTIFACT_UUID,
+ AuditingFieldsKeysEnum.AUDIT_ARTIFACT_DATA,
+ AuditingFieldsKeysEnum.AUDIT_STATUS,
+ AuditingFieldsKeysEnum.AUDIT_DESC
+ };
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatUtil.java
new file mode 100644
index 0000000000..5fec39bbdb
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingLogFormatUtil.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.auditing.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.Formatter;
+import java.util.Locale;
+
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public class AuditingLogFormatUtil {
+
+ // When adding any new fields here, please keep the convention <fieldName>=
+ // <value>, with the space between them.
+ private static Logger log = LoggerFactory.getLogger(AuditingLogFormatUtil.class.getName());
+
+ // This is the key by which audit marker is recognized in logback.xml
+ private static String AUDIT_MARKER_STR = "AUDIT_MARKER";
+
+ public static Marker auditMarker = MarkerFactory.getMarker(AUDIT_MARKER_STR);
+
+ protected static void logAuditEvent(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+
+ StringBuilder sb = new StringBuilder();
+ Formatter formatter = new Formatter(sb, Locale.US);
+ log.trace("logAuditEvent - start");
+
+ try {
+
+ // Common fields
+ String modifier = getModifier((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME), (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID));
+ Object statusObj = auditingFields.get(AuditingFieldsKeysEnum.AUDIT_STATUS);
+ String status = null;
+ if (statusObj != null) {
+ status = String.valueOf(statusObj);
+ }
+ String desc = (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_DESC);
+ String action = (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_ACTION);
+
+ AuditingActionEnum auditEventType = AuditingActionEnum.getActionByName(action);
+ StringBuilder formattedEvent = getFormattedEvent(auditingFields, modifier, status, desc, action, auditEventType);
+ String formattedString = formattedEvent.toString();
+
+ // This is the only way to fix DE166225 without major refactoring,
+ // after it was previously agreed with Ella that activity type will
+ // be the method name.
+
+ if (auditEventType.equals(AuditingActionEnum.AUTH_REQUEST)) {
+ HttpRequestAuthentication(formattedString);
+ } else {
+ log.info(auditMarker, formattedString);
+ }
+ } catch (Exception e) {
+ log.debug("unexpected error occurred: {} {}", e.getMessage(), e);
+
+ } finally {
+ formatter.close();
+ log.trace("logAuditEvent - end");
+ }
+
+ }
+
+ private static void HttpRequestAuthentication(String formattedString) {
+ log.info(auditMarker, formattedString);
+ }
+
+ private static StringBuilder getFormattedEvent(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields, String modifier, String status, String desc, String action, AuditingActionEnum auditEventType) {
+
+ StringBuilder formattedString = new StringBuilder();
+
+ switch (auditEventType) {
+ case ADD_USER:
+ case DELETE_USER:
+ case UPDATE_USER:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.USER_ADMIN_TEMPLATE_ARRAY, auditingFields);
+
+ break;
+ case USER_ACCESS:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.USER_ACCESS_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_REGISTER:
+ case DISTRIBUTION_UN_REGISTER:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.DISTRIBUTION_REGISTRATION_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case UPDATE_RESOURCE_METADATA:
+ case CREATE_RESOURCE:
+ case IMPORT_RESOURCE:
+ ArrayList<AuditingFieldsKeysEnum> createResourceList = new ArrayList(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_PREFIX_ARRAY));
+ createResourceList.addAll(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_SUFFIX_ARRAY));
+ if (auditEventType == AuditingActionEnum.IMPORT_RESOURCE) {
+ createResourceList.add(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TOSCA_NODE_TYPE);
+ }
+ AuditingFieldsKeysEnum[] createResourceArray = new AuditingFieldsKeysEnum[100];
+ createResourceArray = createResourceList.toArray(createResourceArray);
+ formattedString = buildStringAccrodingToArray(createResourceArray, auditingFields);
+ break;
+ case CHECKIN_RESOURCE:
+ case CHECKOUT_RESOURCE:
+ case UNDO_CHECKOUT_RESOURCE:
+ case CERTIFICATION_REQUEST_RESOURCE:
+ case START_CERTIFICATION_RESOURCE:
+ case CERTIFICATION_SUCCESS_RESOURCE:
+ case FAIL_CERTIFICATION_RESOURCE:
+ case CANCEL_CERTIFICATION_RESOURCE:
+ ArrayList<AuditingFieldsKeysEnum> checkinFieldsList = new ArrayList(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_PREFIX_ARRAY));
+ checkinFieldsList.add(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT);
+ checkinFieldsList.addAll(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_SUFFIX_ARRAY));
+ AuditingFieldsKeysEnum[] checkinFieldsArray = new AuditingFieldsKeysEnum[100];
+ checkinFieldsArray = checkinFieldsList.toArray(checkinFieldsArray);
+ String comment = (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT);
+ if (comment == null || comment.equals(Constants.NULL_STRING)) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, Constants.EMPTY_STRING);
+ }
+ formattedString = buildStringAccrodingToArray(checkinFieldsArray, auditingFields);
+ break;
+ case ARTIFACT_UPLOAD:
+ case ARTIFACT_DELETE:
+ case ARTIFACT_METADATA_UPDATE:
+ case ARTIFACT_PAYLOAD_UPDATE:
+ case ARTIFACT_DOWNLOAD:
+ ArrayList<AuditingFieldsKeysEnum> artifactFieldsList = new ArrayList(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_PREFIX_ARRAY));
+ artifactFieldsList.add(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID);
+ artifactFieldsList.add(AuditingFieldsKeysEnum.AUDIT_CURR_ARTIFACT_UUID);
+ artifactFieldsList.add(AuditingFieldsKeysEnum.AUDIT_ARTIFACT_DATA);
+ artifactFieldsList.addAll(Arrays.asList(AuditingLogFormatConstants.CREATE_RESOURCE_TEMPLATE_SUFFIX_ARRAY));
+ artifactFieldsList.addAll(Arrays.asList(AuditingLogFormatConstants.EXTERNAL_DOWNLOAD_ARTIFACT_ARRAY));
+ AuditingFieldsKeysEnum[] artifactFieldsArray = new AuditingFieldsKeysEnum[100];
+ artifactFieldsArray = artifactFieldsList.toArray(artifactFieldsArray);
+ formattedString = buildStringAccrodingToArray(artifactFieldsArray, auditingFields);
+ break;
+ case DOWNLOAD_ARTIFACT:
+ ArrayList<AuditingFieldsKeysEnum> downloadArtifactFieldsList = new ArrayList(Arrays.asList(AuditingLogFormatConstants.EXTERNAL_DOWNLOAD_ARTIFACT_ARRAY));
+ AuditingFieldsKeysEnum[] downloadArtifactFieldsArray = new AuditingFieldsKeysEnum[100];
+ artifactFieldsArray = downloadArtifactFieldsList.toArray(downloadArtifactFieldsArray);
+ formattedString = buildStringAccrodingToArray(artifactFieldsArray, auditingFields);
+ break;
+ case DISTRIBUTION_STATE_CHANGE_REQUEST:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.ACTIVATE_DISTRIBUTION_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_STATE_CHANGE_APPROV:
+ case DISTRIBUTION_STATE_CHANGE_REJECT:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.CHANGE_DISTRIBUTION_STATUS_ARRAY, auditingFields);
+ break;
+ case CREATE_DISTRIBUTION_TOPIC:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.CREATE_TOPIC_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case ADD_KEY_TO_TOPIC_ACL:
+ case REMOVE_KEY_FROM_TOPIC_ACL:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.ADD_REMOVE_TOPIC_KEY_ACL_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_STATUS:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.DISTRIBUTION_STATUS_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_NOTIFY:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.DISTRIBUTION_NOTIFY_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_DEPLOY:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.DISTRIBUTION_DEPLOY_ARRAY, auditingFields);
+ break;
+ case GET_UEB_CLUSTER:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.GET_UEB_CLUSTER_ARRAY, auditingFields);
+ break;
+ case DISTRIBUTION_ARTIFACT_DOWNLOAD:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.DISTRIBUTION_DOWNLOAD_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case AUTH_REQUEST:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.AUTH_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case ADD_ECOMP_USER_CREDENTIALS:
+ case GET_ECOMP_USER_CREDENTIALS:
+ case DELETE_ECOMP_USER_CREDENTIALS:
+ case UPDATE_ECOMP_USER_CREDENTIALS:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.ECOMP_USER_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case ADD_CATEGORY:
+ case ADD_SUB_CATEGORY:
+ case ADD_GROUPING:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.CATEGORY_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case GET_USERS_LIST:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.GET_USERS_LIST_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case GET_CATEGORY_HIERARCHY:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.GET_CATEGORY_HIERARCHY_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case GET_ASSET_LIST:
+ case GET_FILTERED_ASSET_LIST:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.EXTERNAL_GET_ASSET_LIST_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case GET_ASSET_METADATA:
+ case GET_TOSCA_MODEL:
+ formattedString = buildStringAccrodingToArray(AuditingLogFormatConstants.EXTERNAL_GET_ASSET_TEMPLATE_ARRAY, auditingFields);
+ break;
+ case ARTIFACT_UPLOAD_BY_API:
+ case ARTIFACT_DELETE_BY_API:
+ case ARTIFACT_UPDATE_BY_API:
+ ArrayList<AuditingFieldsKeysEnum> uploadArtifactFieldsList = new ArrayList(Arrays.asList(AuditingLogFormatConstants.EXTERNAL_CRUD_API_ARTIFACT_ARRAY));
+ AuditingFieldsKeysEnum[] uploadArtifactFieldsArray = new AuditingFieldsKeysEnum[100];
+ artifactFieldsArray = uploadArtifactFieldsList.toArray(uploadArtifactFieldsArray);
+ formattedString = buildStringAccrodingToArray(artifactFieldsArray, auditingFields);
+ break;
+ default:
+ break;
+ }
+
+ return formattedString;
+ }
+
+ private static StringBuilder buildStringAccrodingToArray(AuditingFieldsKeysEnum[] sortedFieldsArray, EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ StringBuilder formattedString = new StringBuilder();
+ for (int i = 0; i < sortedFieldsArray.length; i++) {
+ AuditingFieldsKeysEnum key = sortedFieldsArray[i];
+
+ Object fieldVal = auditingFields.get(key);
+ if (fieldVal != null) {
+ formattedString.append(key.getDisplayName()).append(" = \"").append(fieldVal).append("\"");
+ if (i < sortedFieldsArray.length - 1) {
+ formattedString.append(" ");
+ }
+ }
+ }
+ return formattedString;
+ }
+
+ protected static String getModifier(String modifierName, String modifierUid) {
+ if (modifierUid == null || modifierUid.equals(Constants.EMPTY_STRING)) {
+ return Constants.EMPTY_STRING;
+ }
+ StringBuilder sb = new StringBuilder();
+ if (modifierName != null) {
+ sb.append(modifierName);
+ }
+ sb.append("(").append(modifierUid).append(")");
+ return sb.toString();
+ }
+
+ protected static String getUser(String userData) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(userData);
+ return sb.toString();
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
new file mode 100644
index 0000000000..aa5afa4a8e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.auditing.impl;
+
+import java.util.EnumMap;
+import java.util.Map.Entry;
+
+import javax.annotation.Resource;
+
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.resources.data.auditing.AuditRecordFactory;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component("auditingManager")
+public class AuditingManager implements IAuditingManager {
+
+ private static Logger log = LoggerFactory.getLogger(AuditingManager.class.getName());
+
+ @Resource
+ private AuditingDao auditingDao;
+ @Autowired
+ private AuditCassandraDao cassandraDao;
+
+ @Override
+ public void auditEvent(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ try {
+ boolean disableAudit = ConfigurationManager.getConfigurationManager().getConfiguration().isDisableAudit();
+ if (disableAudit) {
+ return;
+ }
+ // Adding UUID from thread local
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_REQUEST_ID, ThreadLocalsHolder.getUuid());
+
+ Object status = auditingFields.get(AuditingFieldsKeysEnum.AUDIT_STATUS);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, String.valueOf(status));
+
+ // normalizing empty string values - US471661
+ normalizeEmptyAuditStringValues(auditingFields);
+
+ // Format modifier
+ formatModifier(auditingFields);
+
+ // Format user
+ formatUser(auditingFields);
+
+ // Logging the event
+ AuditingLogFormatUtil.logAuditEvent(auditingFields);
+
+ // Determining the type of the auditing data object
+ AuditingActionEnum actionEnum = AuditingActionEnum.getActionByName((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_ACTION));
+ log.info("audit event {} of type {}", actionEnum.getName(), actionEnum.getAuditingEsType());
+ ActionStatus addRecordStatus = auditingDao.addRecord(auditingFields, actionEnum.getAuditingEsType());
+ if (!addRecordStatus.equals(ActionStatus.OK)) {
+ log.warn("Failed to persist auditing event: {}", addRecordStatus.name());
+ }
+
+ AuditingGenericEvent recordForCassandra = AuditRecordFactory.createAuditRecord(auditingFields);
+ if (recordForCassandra != null) {
+ CassandraOperationStatus result = cassandraDao.saveRecord(recordForCassandra);
+ if (!result.equals(CassandraOperationStatus.OK)) {
+ log.warn("Failed to persist to cassandra auditing event: {}", addRecordStatus.name());
+ }
+ }
+
+ } catch (Exception e) {
+ // Error during auditing shouldn't terminate flow
+ log.warn("Error during auditEvent: {}", e);
+ }
+ }
+
+ private void formatUser(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ if (auditingFields.get(AuditingFieldsKeysEnum.AUDIT_USER_UID) != null) {
+ String userDetails = (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_USER_UID);
+
+ String user = AuditingLogFormatUtil.getUser(userDetails);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_UID, user);
+ }
+ }
+
+ private void formatModifier(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ String modifier = AuditingLogFormatUtil.getModifier((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME), (String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID));
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier);
+ auditingFields.remove(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME);
+ }
+
+ private void normalizeEmptyAuditStringValues(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ for (Entry<AuditingFieldsKeysEnum, Object> auditingEntry : auditingFields.entrySet()) {
+ if (auditingEntry.getKey().getValueClass().equals(String.class)) {
+ String auditingValue = (String) auditingEntry.getValue();
+ boolean isEmpty = false;
+ if (auditingValue != null) {
+ String trimmedValue = auditingValue.trim();
+ if ((trimmedValue.equals(Constants.EMPTY_STRING)) || trimmedValue.equals(Constants.NULL_STRING) || trimmedValue.equals(Constants.DOUBLE_NULL_STRING)) {
+ isEmpty = true;
+ }
+ } else {// is null
+ isEmpty = true;
+ }
+ // Normalizing to ""
+ if (isEmpty) {
+ auditingEntry.setValue(Constants.EMPTY_STRING);
+ }
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/AsdcComponentsCleanerTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/AsdcComponentsCleanerTask.java
new file mode 100644
index 0000000000..b3b842b9e4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/AsdcComponentsCleanerTask.java
@@ -0,0 +1,175 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.clean;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.CleanComponentsConfiguration;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component("asdcComponentsCleaner")
+public class AsdcComponentsCleanerTask implements Runnable {
+
+ private static Logger log = LoggerFactory.getLogger(AsdcComponentsCleanerTask.class.getName());
+
+ @javax.annotation.Resource
+ private ComponentsCleanBusinessLogic componentsCleanBusinessLogic = null;
+
+ private List<NodeTypeEnum> componentsToClean;
+ private long cleaningIntervalInMinutes;
+
+ private ScheduledExecutorService scheduledService = Executors.newScheduledThreadPool(1, new BasicThreadFactory.Builder().namingPattern("ComponentsCleanThread-%d").build());
+ ScheduledFuture<?> scheduledFuture = null;
+
+ @PostConstruct
+ public void init() {
+ log.trace("Enter init method of AsdcComponentsCleaner");
+ Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
+ CleanComponentsConfiguration cleanComponentsConfiguration = configuration.getCleanComponentsConfiguration();
+
+ if (cleanComponentsConfiguration == null) {
+ log.info("ERROR - configuration is not valid!!! missing cleanComponentsConfiguration");
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeComponentCleanerSystemError, "AsdcComponentsCleanerTask.init()", "AsdcComponentsCleanerTask.init()");
+ BeEcompErrorManager.getInstance().logBeComponentCleanerSystemError("AsdcComponentsCleanerTask-init", "fecth configuration");
+ return;
+
+ }
+ componentsToClean = new ArrayList<NodeTypeEnum>();
+ List<String> components = cleanComponentsConfiguration.getComponentsToClean();
+ if (components == null) {
+ log.info("no component were configured for cleaning");
+ }
+ for (String component : components) {
+ NodeTypeEnum typeEnum = NodeTypeEnum.getByNameIgnoreCase(component);
+ if (typeEnum != null)
+ componentsToClean.add(typeEnum);
+ }
+
+ long intervalInMinutes = cleanComponentsConfiguration.getCleanIntervalInMinutes();
+
+ if (intervalInMinutes < 1) {
+ log.warn("cleaningIntervalInMinutes value should be greater than or equal to 1 minute. use default");
+ intervalInMinutes = 60;
+ }
+ cleaningIntervalInMinutes = intervalInMinutes;
+
+ startTask();
+
+ log.trace("End init method of AsdcComponentsCleaner");
+ }
+
+ @PreDestroy
+ public void destroy() {
+ this.stopTask();
+ shutdownExecutor();
+ }
+
+ public void startTask() {
+
+ log.debug("start task for cleaning components");
+
+ try {
+
+ if (scheduledService != null) {
+ log.debug("Start Cleaning components task. interval {} minutes", cleaningIntervalInMinutes);
+ scheduledFuture = scheduledService.scheduleAtFixedRate(this, 5, cleaningIntervalInMinutes, TimeUnit.MINUTES);
+
+ }
+ } catch (Exception e) {
+ log.debug("unexpected error occured", e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeComponentCleanerSystemError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeComponentCleanerSystemError("AsdcComponentsCleanerTask-startTask", e.getMessage());
+
+ }
+ }
+
+ public void stopTask() {
+ if (scheduledFuture != null) {
+ boolean result = scheduledFuture.cancel(true);
+ log.debug("Stop cleaning task. result = {}", result);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ if (false == result) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeComponentCleanerSystemError, methodName, "try to stop the polling task");
+ BeEcompErrorManager.getInstance().logBeComponentCleanerSystemError("AsdcComponentsCleanerTask-stopTask", "try to stop the polling task");
+ }
+ scheduledFuture = null;
+ }
+
+ }
+
+ private void shutdownExecutor() {
+ if (scheduledService == null)
+ return;
+
+ scheduledService.shutdown(); // Disable new tasks from being submitted
+ try {
+ // Wait a while for existing tasks to terminate
+ if (!scheduledService.awaitTermination(60, TimeUnit.SECONDS)) {
+ scheduledService.shutdownNow(); // Cancel currently executing
+ // tasks
+ // Wait a while for tasks to respond to being cancelled
+ if (!scheduledService.awaitTermination(60, TimeUnit.SECONDS))
+ log.debug("Pool did not terminate");
+ }
+ } catch (InterruptedException ie) {
+ // (Re-)Cancel if current thread also interrupted
+ scheduledService.shutdownNow();
+ // Preserve interrupt status
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+ componentsCleanBusinessLogic.cleanComponents(componentsToClean);
+ } catch (Throwable e) {
+ log.error("unexpected error occured", e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeComponentCleanerSystemError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeComponentCleanerSystemError("AsdcComponentsCleanerTask-run", e.getMessage());
+ }
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/ComponentsCleanBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/ComponentsCleanBusinessLogic.java
new file mode 100644
index 0000000000..b12b55ba8b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/clean/ComponentsCleanBusinessLogic.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.clean;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("componentsCleanBusinessLogic")
+public class ComponentsCleanBusinessLogic extends BaseBusinessLogic {
+
+ @Autowired
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @Autowired
+ private ServiceBusinessLogic serviceBusinessLogic;
+
+ private static Logger log = LoggerFactory.getLogger(ComponentsCleanBusinessLogic.class.getName());
+
+ public Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponents(List<NodeTypeEnum> componentsToClean) {
+
+ Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents = new HashMap<NodeTypeEnum, Either<List<String>, ResponseFormat>>();
+
+ log.trace("start cleanComponents");
+ for (NodeTypeEnum type : componentsToClean) {
+ switch (type) {
+ case Resource:
+ processDeletionForType(cleanedComponents, NodeTypeEnum.Resource, resourceBusinessLogic);
+ break;
+ case Service:
+ processDeletionForType(cleanedComponents, NodeTypeEnum.Service, serviceBusinessLogic);
+ break;
+ default:
+ log.debug("{} component type does not have cleaning method defined", type);
+ break;
+ }
+ }
+
+ log.trace("end cleanComponents");
+ return cleanedComponents;
+ }
+
+ private void processDeletionForType(Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents, NodeTypeEnum type, ComponentBusinessLogic componentBusinessLogic) {
+ Either<List<String>, ResponseFormat> deleteMarkedResources = componentBusinessLogic.deleteMarkedComponents();
+ if (deleteMarkedResources.isRight()) {
+ log.debug("failed to clean deleted components of type {}. error: {}", type, deleteMarkedResources.right().value().getFormattedMessage());
+ } else {
+ if (log.isDebugEnabled()) {
+ StringBuilder sb = new StringBuilder("list of deleted components - type " + type + ": ");
+ for (String id : deleteMarkedResources.left().value()) {
+ sb.append(id).append(", ");
+ }
+ log.debug(sb.toString());
+ }
+ }
+ cleanedComponents.put(type, deleteMarkedResources);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
new file mode 100644
index 0000000000..e1a1270fe3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
@@ -0,0 +1,196 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+public class ArtifactInfoImpl implements IArtifactInfo {
+
+ private String artifactName;
+ private ArtifactTypeEnum artifactType;
+ private String artifactURL;
+ private String artifactChecksum;
+ private String artifactDescription;
+ private Integer artifactTimeout;
+ private String artifactUUID;
+ private String artifactVersion;
+ private String generatedFromUUID;
+ private List<String> relatedArtifacts;
+
+ public ArtifactInfoImpl() {
+ }
+
+ private ArtifactInfoImpl(ArtifactDefinition artifactDef, String generatedFromUUID, List<String> relatedArtifacts) {
+ artifactName = artifactDef.getArtifactName();
+ artifactType = ArtifactTypeEnum.findType(artifactDef.getArtifactType());
+ artifactChecksum = artifactDef.getArtifactChecksum();
+ artifactDescription = artifactDef.getDescription();
+ artifactTimeout = artifactDef.getTimeout();
+ artifactUUID = artifactDef.getArtifactUUID();
+ artifactVersion = artifactDef.getArtifactVersion();
+ this.relatedArtifacts = relatedArtifacts;
+ this.generatedFromUUID = generatedFromUUID;
+ }
+
+ public static List<ArtifactInfoImpl> convertToArtifactInfoImpl(Service service, ComponentInstance resourceInstance, Collection<ArtifactDefinition> list) {
+ List<ArtifactInfoImpl> ret = new ArrayList<ArtifactInfoImpl>();
+ Map<String, List<ArtifactDefinition>> artifactIdToDef = list.stream().collect(Collectors.groupingBy(ArtifactDefinition::getUniqueId));
+ if (list != null) {
+ for (ArtifactDefinition artifactDef : list) {
+ String generatedFromUUID = null;
+ if (artifactDef.getGeneratedFromId() != null && !artifactDef.getGeneratedFromId().isEmpty()) {
+ ArtifactDefinition artifactFrom = artifactIdToDef.get(artifactDef.getGeneratedFromId()).get(0);
+ generatedFromUUID = artifactFrom.getArtifactUUID();
+ }
+ ArtifactInfoImpl artifactInfoImpl = new ArtifactInfoImpl(artifactDef, generatedFromUUID, getUpdatedRequiredArtifactsFromNamesToUuids(artifactDef, resourceInstance.getDeploymentArtifacts()));
+ String artifactURL = ServiceDistributionArtifactsBuilder.buildResourceInstanceArtifactUrl(service, resourceInstance, artifactDef.getArtifactName());
+ artifactInfoImpl.setArtifactURL(artifactURL);
+ ret.add(artifactInfoImpl);
+ }
+ }
+ return ret;
+
+ }
+
+ public static List<ArtifactInfoImpl> convertServiceArtifactToArtifactInfoImpl(Service service, Collection<ArtifactDefinition> list) {
+ List<ArtifactInfoImpl> ret = new ArrayList<ArtifactInfoImpl>();
+ Map<String, List<ArtifactDefinition>> artifactIdToDef = list.stream().collect(Collectors.groupingBy(ArtifactDefinition::getUniqueId));
+ if (list != null) {
+ for (ArtifactDefinition artifactDef : list) {
+ String generatedFromUUID = null;
+ if (artifactDef.getGeneratedFromId() != null && !artifactDef.getGeneratedFromId().isEmpty()) {
+ ArtifactDefinition artifactFrom = artifactIdToDef.get(artifactDef.getGeneratedFromId()).get(0);
+ generatedFromUUID = artifactFrom.getArtifactUUID();
+ }
+ ArtifactInfoImpl artifactInfoImpl = new ArtifactInfoImpl(artifactDef, generatedFromUUID, getUpdatedRequiredArtifactsFromNamesToUuids(artifactDef, service.getDeploymentArtifacts()));
+ String artifactURL = ServiceDistributionArtifactsBuilder.buildServiceArtifactUrl(service, artifactDef.getArtifactName());
+ artifactInfoImpl.setArtifactURL(artifactURL);
+ ret.add(artifactInfoImpl);
+ }
+ }
+ return ret;
+
+ }
+
+ private static List<String> getUpdatedRequiredArtifactsFromNamesToUuids(ArtifactDefinition artifactDefinition, Map<String, ArtifactDefinition> artifacts) {
+ List<String> requiredArtifacts = null;
+ if (artifactDefinition != null && artifactDefinition.getRequiredArtifacts() != null && !artifactDefinition.getRequiredArtifacts().isEmpty() && artifacts != null && !artifacts.isEmpty()) {
+ requiredArtifacts = artifacts.values().stream().filter(art -> artifactDefinition.getRequiredArtifacts().contains(art.getArtifactName())).map(art -> art.getArtifactUUID()).collect(Collectors.toList());
+ }
+ return requiredArtifacts;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ public ArtifactTypeEnum getArtifactType() {
+ return artifactType;
+ }
+
+ public void setArtifactType(ArtifactTypeEnum artifactType) {
+ this.artifactType = artifactType;
+ }
+
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ public String getArtifactChecksum() {
+ return artifactChecksum;
+ }
+
+ public void setArtifactChecksum(String artifactChecksum) {
+ this.artifactChecksum = artifactChecksum;
+ }
+
+ public String getArtifactDescription() {
+ return artifactDescription;
+ }
+
+ public void setArtifactDescription(String artifactDescription) {
+ this.artifactDescription = artifactDescription;
+ }
+
+ public Integer getArtifactTimeout() {
+ return artifactTimeout;
+ }
+
+ public void setArtifactTimeout(Integer artifactTimeout) {
+ this.artifactTimeout = artifactTimeout;
+ }
+
+ public List<String> getRelatedArtifacts() {
+ return relatedArtifacts;
+ }
+
+ public void setRelatedArtifacts(List<String> relatedArtifacts) {
+ this.relatedArtifacts = relatedArtifacts;
+ }
+
+ @Override
+ public String toString() {
+ return "ArtifactInfoImpl [artifactName=" + artifactName + ", artifactType=" + artifactType + ", artifactURL=" + artifactURL + ", artifactChecksum=" + artifactChecksum + ", artifactDescription=" + artifactDescription + ", artifactTimeout="
+ + artifactTimeout + ", artifactUUID=" + artifactUUID + ", artifactVersion=" + artifactVersion + ", generatedFromUUID=" + generatedFromUUID + ", relatedArtifacts=" + relatedArtifacts + "]";
+ }
+
+ public String getArtifactUUID() {
+ return artifactUUID;
+ }
+
+ public void setArtifactUUID(String artifactUUID) {
+ this.artifactUUID = artifactUUID;
+ }
+
+ public String getArtifactVersion() {
+ return artifactVersion;
+ }
+
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
+
+ public String getGeneratedFromUUID() {
+ return generatedFromUUID;
+ }
+
+ public void setGeneratedFromUUID(String generatedFromUUID) {
+ this.generatedFromUUID = generatedFromUUID;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaErrorResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaErrorResponse.java
new file mode 100644
index 0000000000..149ea2286a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaErrorResponse.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+
+public class CambriaErrorResponse {
+
+ public static final int HTTP_OK = 200;
+
+ public static final int HTTP_INTERNAL_SERVER_ERROR = 500;
+
+ CambriaOperationStatus operationStatus;
+ Integer httpCode;
+ List<String> variables = new ArrayList<String>();
+
+ public CambriaErrorResponse() {
+ super();
+ }
+
+ public CambriaErrorResponse(CambriaOperationStatus operationStatus) {
+ super();
+ this.operationStatus = operationStatus;
+ }
+
+ public CambriaErrorResponse(CambriaOperationStatus operationStatus, Integer httpCode) {
+ super();
+ this.operationStatus = operationStatus;
+ this.httpCode = httpCode;
+ }
+
+ public CambriaOperationStatus getOperationStatus() {
+ return operationStatus;
+ }
+
+ public void setOperationStatus(CambriaOperationStatus operationStatus) {
+ this.operationStatus = operationStatus;
+ }
+
+ public Integer getHttpCode() {
+ return httpCode;
+ }
+
+ public void setHttpCode(Integer httpCode) {
+ this.httpCode = httpCode;
+ }
+
+ public void addVariable(String variable) {
+ variables.add(variable);
+ }
+
+ public List<String> getVariables() {
+ return variables;
+ }
+
+ public void setVariables(List<String> variables) {
+ this.variables = variables;
+ }
+
+ @Override
+ public String toString() {
+ return "CambriaErrorResponse [operationStatus=" + operationStatus + ", httpCode=" + httpCode + ", variables=" + variables + "]";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
new file mode 100644
index 0000000000..3528ed9be3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
@@ -0,0 +1,610 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
+import com.att.nsa.cambria.client.CambriaClientBuilders.TopicManagerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
+import com.att.nsa.cambria.client.CambriaClientBuilders.IdentityManagerBuilder;
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.att.nsa.cambria.client.CambriaIdentityManager;
+import com.att.nsa.cambria.client.CambriaPublisher.message;
+import com.att.nsa.cambria.client.CambriaTopicManager;
+import com.google.gson.Gson;
+
+import fj.data.Either;
+
+public class CambriaHandler {
+
+ private static Logger logger = LoggerFactory.getLogger(CambriaHandler.class.getName());
+
+ public static String PARTITION_KEY = "asdc" + "aa";
+
+ private Gson gson = new Gson();
+
+ /**
+ * process the response error from Cambria client
+ *
+ * @param message
+ * @return
+ */
+ private Integer processMessageException(String message) {
+
+ String[] patterns = { "(HTTP Status )(\\d\\d\\d)", "(HTTP/\\d.\\d )(\\d\\d\\d)" };
+
+ Integer result = checkPattern(patterns[0], message, 2);
+ if (result != null) {
+ return result;
+ }
+ result = checkPattern(patterns[1], message, 2);
+
+ return result;
+
+ }
+
+ /**
+ * check whether the message has a match with a given pattern inside it
+ *
+ * @param patternStr
+ * @param message
+ * @param groupIndex
+ * @return
+ */
+ private Integer checkPattern(String patternStr, String message, int groupIndex) {
+ Integer result = null;
+
+ Pattern pattern = Pattern.compile(patternStr);
+ Matcher matcher = pattern.matcher(message);
+ boolean find = matcher.find();
+ if (find) {
+ String httpCode = matcher.group(groupIndex);
+ if (httpCode != null) {
+ try {
+ result = Integer.valueOf(httpCode);
+ } catch (NumberFormatException e) {
+ logger.debug("Failed to parse http code {}", httpCode);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * retrieve all topics from U-EB server
+ *
+ * @param hostSet
+ * @return
+ */
+ public Either<Set<String>, CambriaErrorResponse> getTopics(List<String> hostSet) {
+
+ CambriaTopicManager createTopicManager = null;
+ try {
+
+ createTopicManager = new TopicManagerBuilder().usingHosts(hostSet).build();
+ Set<String> topics = createTopicManager.getTopics();
+
+ if (topics == null || true == topics.isEmpty()) {
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.NOT_FOUND, null);
+ return Either.right(cambriaErrorResponse);
+ }
+
+ return Either.left(topics);
+
+ } catch (IOException | GeneralSecurityException e) {
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ logger.debug("Failed to fetch topics from U-EB server", e);
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "get topics");
+
+ return Either.right(cambriaErrorResponse);
+ } finally {
+ if (createTopicManager != null) {
+ createTopicManager.close();
+ }
+ }
+
+ }
+
+ /**
+ * process the error message from Cambria client.
+ *
+ * set Cambria status and http code in case we succeed to fetch it
+ *
+ * @param errorMessage
+ * @return
+ */
+ private CambriaErrorResponse processError(Exception e) {
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse();
+
+ Integer httpCode = processMessageException(e.getMessage());
+
+ if (httpCode != null) {
+ cambriaErrorResponse.setHttpCode(httpCode);
+ switch (httpCode.intValue()) {
+
+ case 401:
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.AUTHENTICATION_ERROR);
+ break;
+ case 409:
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.TOPIC_ALREADY_EXIST);
+ break;
+ case 500:
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.INTERNAL_SERVER_ERROR);
+ break;
+ default:
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.CONNNECTION_ERROR);
+ }
+ } else {
+
+ boolean found = false;
+ Throwable throwable = e.getCause();
+ if (throwable != null) {
+ String message = throwable.getMessage();
+
+ Throwable cause = throwable.getCause();
+
+ if (cause != null) {
+ Class<?> clazz = cause.getClass();
+ String className = clazz.getName();
+ if (className.endsWith("UnknownHostException")) {
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.UNKNOWN_HOST_ERROR);
+ cambriaErrorResponse.addVariable(message);
+ found = true;
+ }
+ }
+ }
+
+ if (false == found) {
+ cambriaErrorResponse.setOperationStatus(CambriaOperationStatus.CONNNECTION_ERROR);
+ cambriaErrorResponse.setHttpCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ return cambriaErrorResponse;
+ }
+
+ /**
+ * write the error to the log
+ *
+ * @param cambriaErrorResponse
+ * @param errorMessage
+ * @param methodName
+ * @param operationDesc
+ */
+ private void writeErrorToLog(CambriaErrorResponse cambriaErrorResponse, String errorMessage, String methodName, String operationDesc) {
+
+ String httpCode = (cambriaErrorResponse.getHttpCode() == null ? "" : String.valueOf(cambriaErrorResponse.getHttpCode()));
+
+ switch (cambriaErrorResponse.getOperationStatus()) {
+ case UNKNOWN_HOST_ERROR:
+ String hostname = cambriaErrorResponse.getVariables().get(0);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebUnkownHostError, methodName, hostname);
+ BeEcompErrorManager.getInstance().logBeUebUnkownHostError(methodName, httpCode);
+ break;
+ case AUTHENTICATION_ERROR:
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebAuthenticationError, methodName, httpCode);
+ BeEcompErrorManager.getInstance().logBeUebAuthenticationError(methodName, httpCode);
+ break;
+ case CONNNECTION_ERROR:
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebConnectionError, methodName, httpCode);
+ BeEcompErrorManager.getInstance().logBeUebConnectionError(methodName, httpCode);
+ break;
+
+ case INTERNAL_SERVER_ERROR:
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, methodName, operationDesc);
+ BeEcompErrorManager.getInstance().logBeUebSystemError(methodName, operationDesc);
+ break;
+
+ }
+
+ }
+
+ /**
+ * create a topic if it does not exists in the topicsList
+ *
+ * @param hostSet
+ * - list of U-EB servers
+ * @param apiKey
+ * @param secretKey
+ * @param topicsList
+ * - list of exists topics
+ * @param topicName
+ * - topic to create
+ * @param partitionCount
+ * @param replicationCount
+ * @return
+ */
+ public CambriaErrorResponse createTopic(Collection<String> hostSet, String apiKey, String secretKey, String topicName, int partitionCount, int replicationCount) {
+
+ CambriaTopicManager createTopicManager = null;
+ try {
+ createTopicManager = new TopicManagerBuilder().usingHosts(hostSet).authenticatedBy(apiKey, secretKey).build();
+ createTopicManager.createTopic(topicName, "ASDC distribution notification topic", partitionCount, replicationCount);
+
+ } catch (GeneralSecurityException | HttpException | IOException e) {
+ logger.debug("Failed to create topic {}", topicName, e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ if (cambriaErrorResponse.getOperationStatus() != CambriaOperationStatus.TOPIC_ALREADY_EXIST) {
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "create topic");
+ }
+
+ return cambriaErrorResponse;
+
+ } finally {
+ if (createTopicManager != null) {
+ createTopicManager.close();
+ }
+ }
+ return new CambriaErrorResponse(CambriaOperationStatus.OK);
+ }
+
+ public CambriaErrorResponse unRegisterFromTopic(Collection<String> hostSet, String topicName, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum) {
+ CambriaTopicManager createTopicManager = null;
+ try {
+ createTopicManager = new TopicManagerBuilder().usingHosts(hostSet).authenticatedBy(managerApiKey, managerSecretKey).build();
+
+ if (subscriberTypeEnum == SubscriberTypeEnum.PRODUCER) {
+ createTopicManager.revokeProducer(topicName, subscriberApiKey);
+ } else {
+ createTopicManager.revokeConsumer(topicName, subscriberApiKey);
+ }
+
+ } catch (HttpObjectNotFoundException | GeneralSecurityException e) {
+ logger.debug("Failed to unregister {} from topic {} as {}", managerApiKey, topicName, subscriberTypeEnum.toString().toLowerCase(), e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebObjectNotFoundError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeUebObjectNotFoundError(methodName, e.getMessage());
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OBJECT_NOT_FOUND, HttpStatus.SC_NOT_FOUND);
+ return cambriaErrorResponse;
+
+ } catch (HttpException | IOException e) {
+ logger.debug("Failed to unregister {} from topic {} as producer", managerApiKey, topicName, e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "unregister from topic as " + subscriberTypeEnum.toString().toLowerCase());
+
+ return cambriaErrorResponse;
+ } finally {
+ if (createTopicManager != null) {
+ createTopicManager.close();
+ }
+ }
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+ return cambriaErrorResponse;
+ }
+
+ /**
+ *
+ * register a public key (subscriberId) to a given topic as a CONSUMER or PRODUCER
+ *
+ * @param hostSet
+ * @param topicName
+ * @param managerApiKey
+ * @param managerSecretKey
+ * @param subscriberApiKey
+ * @param subscriberTypeEnum
+ * @return
+ */
+ public CambriaErrorResponse registerToTopic(Collection<String> hostSet, String topicName, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum) {
+
+ CambriaTopicManager createTopicManager = null;
+ try {
+ createTopicManager = new TopicManagerBuilder().usingHosts(hostSet).authenticatedBy(managerApiKey, managerSecretKey).build();
+
+ if (subscriberTypeEnum == SubscriberTypeEnum.PRODUCER) {
+ createTopicManager.allowProducer(topicName, subscriberApiKey);
+ } else {
+ createTopicManager.allowConsumer(topicName, subscriberApiKey);
+ }
+
+ } catch (HttpObjectNotFoundException | GeneralSecurityException e) {
+ logger.debug("Failed to register {} to topic {} as {}", managerApiKey, topicName, subscriberTypeEnum.toString().toLowerCase(), e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebObjectNotFoundError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeUebObjectNotFoundError(methodName, e.getMessage());
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OBJECT_NOT_FOUND, HttpStatus.SC_NOT_FOUND);
+ return cambriaErrorResponse;
+
+ } catch (HttpException | IOException e) {
+ logger.debug("Failed to register {} to topic {} as {}", managerApiKey, topicName, subscriberTypeEnum.toString().toLowerCase(), e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "register to topic as " + subscriberTypeEnum.toString().toLowerCase());
+
+ return cambriaErrorResponse;
+ } finally {
+ if (createTopicManager != null) {
+ createTopicManager.close();
+ }
+ }
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+ return cambriaErrorResponse;
+ }
+
+ /**
+ * create and retrieve a Cambria Consumer for a specific topic
+ *
+ * @param hostSet
+ * @param topicName
+ * @param apiKey
+ * @param secretKey
+ * @param consumerId
+ * @param consumerGroup
+ * @param timeoutMS
+ * @return
+ * @throws Exception
+ */
+ public CambriaConsumer createConsumer(Collection<String> hostSet, String topicName, String apiKey, String secretKey, String consumerId, String consumerGroup, int timeoutMS) throws Exception {
+
+ CambriaConsumer consumer = new ConsumerBuilder().authenticatedBy(apiKey, secretKey).knownAs(consumerGroup, consumerId).onTopic(topicName).usingHosts(hostSet).withSocketTimeout(timeoutMS).build();
+ consumer.setApiCredentials(apiKey, secretKey);
+ return consumer;
+ }
+
+ public void closeConsumer(CambriaConsumer consumer) {
+
+ if (consumer != null) {
+ consumer.close();
+ }
+
+ }
+
+ /**
+ * use the topicConsumer to fetch messages from topic. in case no messages were fetched, empty ArrayList will be returned (not error)
+ *
+ * @param topicConsumer
+ * @return
+ */
+ public Either<Iterable<String>, CambriaErrorResponse> fetchFromTopic(CambriaConsumer topicConsumer) {
+
+ try {
+ Iterable<String> messages = topicConsumer.fetch();
+ if (messages == null) {
+ messages = new ArrayList<String>();
+ }
+ return Either.left(messages);
+
+ } catch (IOException e) {
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ logger.debug("Failed to fetch from U-EB topic. error={}", e.getMessage());
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "get messages from topic");
+
+ return Either.right(cambriaErrorResponse);
+
+ } catch (Exception e) {
+ logger.debug("Failed to fetch from U-EB topic", e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(methodName, e.getMessage());
+
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ return Either.right(cambriaErrorResponse);
+ }
+ }
+
+ /**
+ * Publish notification message to a given queue
+ *
+ * @param topicName
+ * @param uebPublicKey
+ * @param uebSecretKey
+ * @param uebServers
+ * @param data
+ * @return
+ */
+ public CambriaErrorResponse sendNotification(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data) {
+
+ CambriaBatchingPublisher createSimplePublisher = null;
+
+ try {
+
+ String json = gson.toJson(data);
+ logger.trace("Before sending notification data {} to topic {}", json, topicName);
+
+ createSimplePublisher = new PublisherBuilder().onTopic(topicName).usingHosts(uebServers).build();
+ createSimplePublisher.setApiCredentials(uebPublicKey, uebSecretKey);
+
+ int result = createSimplePublisher.send(PARTITION_KEY, json);
+
+ try {
+ Thread.sleep(1 * 1000);
+ } catch (InterruptedException e) {
+ logger.debug("Failed during sleep after sending the message.", e);
+ }
+
+ logger.debug("After sending notification data to topic {}. result is {}", topicName, result);
+
+ CambriaErrorResponse response = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
+
+ return response;
+
+ } catch (IOException | GeneralSecurityException e) {
+ logger.debug("Failed to send notification {} to topic {} ", data, topicName, e);
+
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ CambriaErrorResponse cambriaErrorResponse = processError(e);
+
+ writeErrorToLog(cambriaErrorResponse, e.getMessage(), methodName, "send notification");
+
+ return cambriaErrorResponse;
+ } finally {
+ if (createSimplePublisher != null) {
+ logger.debug("Before closing publisher");
+ createSimplePublisher.close();
+ logger.debug("After closing publisher");
+ }
+ }
+ }
+
+ private String convertListToString(List<String> list) {
+ StringBuilder builder = new StringBuilder();
+
+ if (list != null) {
+ for (int i = 0; i < list.size(); i++) {
+ builder.append(list.get(i));
+ if (i < list.size() - 1) {
+ builder.append(",");
+ }
+ }
+ }
+
+ return builder.toString();
+ }
+
+ public CambriaErrorResponse sendNotificationAndClose(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data, long waitBeforeCloseTimeout) {
+
+ CambriaBatchingPublisher createSimplePublisher = null;
+
+ CambriaErrorResponse response = null;
+ try {
+
+ String json = gson.toJson(data);
+ logger.debug("Before sending notification data {} to topic {}", json, topicName);
+
+ createSimplePublisher = new PublisherBuilder().onTopic(topicName).usingHosts(uebServers).build();
+ createSimplePublisher.setApiCredentials(uebPublicKey, uebSecretKey);
+
+ int result = createSimplePublisher.send(PARTITION_KEY, json);
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ logger.debug("Failed during sleep after sending the message.", e);
+ }
+
+ logger.debug("After sending notification data to topic {}. result is {}", topicName, result);
+
+ } catch (IOException | GeneralSecurityException e) {
+ logger.debug("Failed to send notification {} to topic {} ", data, topicName, e);
+
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ response = processError(e);
+
+ writeErrorToLog(response, e.getMessage(), methodName, "send notification");
+
+ return response;
+
+ }
+
+ logger.debug("Before closing publisher. Maximum timeout is {} seconds.", waitBeforeCloseTimeout);
+ try {
+ List<message> messagesInQ = createSimplePublisher.close(waitBeforeCloseTimeout, TimeUnit.SECONDS);
+ if (messagesInQ != null && false == messagesInQ.isEmpty()) {
+ logger.debug("Cambria client returned {} non sent messages.", messagesInQ.size());
+ response = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+ writeErrorToLog(response, "closing publisher returned non sent messages", methodName, "send notification");
+ } else {
+ logger.debug("No message left in the queue after closing cambria publisher");
+ response = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
+ }
+ } catch (IOException | InterruptedException e) {
+ logger.debug("Failed to close cambria publisher", e);
+ response = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+ writeErrorToLog(response, "closing publisher returned non sent messages", methodName, "send notification");
+ }
+ logger.debug("After closing publisher");
+
+ return response;
+
+ }
+
+ public CambriaErrorResponse getApiKey(String server, String apiKey) {
+
+ CambriaErrorResponse response = null;
+
+ List<String> hostSet = new ArrayList<>();
+ hostSet.add(server);
+ CambriaIdentityManager createIdentityManager = null;
+ try {
+ createIdentityManager = new IdentityManagerBuilder().usingHosts(hostSet).build();
+ createIdentityManager.getApiKey(apiKey);
+ response = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
+
+ } catch (HttpException | IOException | CambriaApiException | GeneralSecurityException e) {
+ logger.debug("Failed to fetch api key {} from server ", apiKey, server, e);
+
+ response = processError(e);
+
+ }
+
+ return response;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DeConfigurationStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DeConfigurationStatus.java
new file mode 100644
index 0000000000..5e4c08275f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DeConfigurationStatus.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public enum DeConfigurationStatus {
+
+ OK(""), MISSING_CONFIGURATION("");
+
+ private String description;
+
+ DeConfigurationStatus(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java
new file mode 100644
index 0000000000..6cb31c8cf2
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java
@@ -0,0 +1,367 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("distributionEngine")
+public class DistributionEngine implements IDistributionEngine {
+
+ public static final Pattern FQDN_PATTERN = Pattern.compile("^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*(:[0-9]{2,4})*$", Pattern.CASE_INSENSITIVE);
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentUtils;
+
+ @javax.annotation.Resource
+ private DistributionNotificationSender distributionNotificationSender;
+
+ @javax.annotation.Resource
+ private ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder;
+
+ @javax.annotation.Resource
+ private DistributionEngineClusterHealth distributionEngineClusterHealth;
+
+ private static Logger logger = LoggerFactory.getLogger(DistributionEngine.class.getName());
+
+ private Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<String, DistributionEngineInitTask>();
+ private Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<String, DistributionEnginePollingTask>();
+
+ private Map<String, AtomicBoolean> envNamePerStatus = new HashMap<String, AtomicBoolean>();
+
+ @Override
+ public boolean isActive() {
+
+ if (true == envNamePerInitTask.isEmpty()) {
+ return false;
+ }
+
+ for (DistributionEngineInitTask task : envNamePerInitTask.values()) {
+ boolean active = task.isActive();
+ if (active == false) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @PostConstruct
+ private void init() {
+
+ logger.trace("Enter init method of DistributionEngine");
+
+ DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+
+ boolean startDistributionEngine = distributionEngineConfiguration.isStartDistributionEngine();
+ logger.debug("Distribution engine activation parameter is {}", startDistributionEngine);
+ if (false == startDistributionEngine) {
+ logger.info("The disribution engine is disabled");
+
+ this.distributionEngineClusterHealth.setHealthCheckUebIsDisabled();
+
+ return;
+ }
+
+ boolean isValidConfig = validateConfiguration(distributionEngineConfiguration);
+
+ if (false == isValidConfig) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, DistributionEngineInitTask.INIT_DISTRIBUTION_ENGINE_FLOW, "validate distribution configuration in init phase");
+ BeEcompErrorManager.getInstance().logBeUebSystemError(DistributionEngineInitTask.INIT_DISTRIBUTION_ENGINE_FLOW, "validate distribution configuration in init phase");
+
+ this.distributionEngineClusterHealth.setHealthCheckUebConfigurationError();
+ return;
+ }
+
+ List<String> environments = distributionEngineConfiguration.getEnvironments();
+
+ for (String envName : environments) {
+
+ DistributionEnginePollingTask distributionEnginePollingTask = new DistributionEnginePollingTask(distributionEngineConfiguration, envName, componentUtils, distributionEngineClusterHealth);
+
+ logger.debug("Init task for environment {}", envName);
+
+ AtomicBoolean status = new AtomicBoolean(false);
+ envNamePerStatus.put(envName, status);
+ DistributionEngineInitTask distributionEngineInitTask = new DistributionEngineInitTask(0l, distributionEngineConfiguration, envName, status, componentUtils, distributionEnginePollingTask);
+ distributionEngineInitTask.startTask();
+ envNamePerInitTask.put(envName, distributionEngineInitTask);
+ envNamePerPollingTask.put(envName, distributionEnginePollingTask);
+ }
+
+ logger.debug("Init UEB health check");
+ distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
+
+ logger.trace("Exit init method of DistributionEngine");
+
+ }
+
+ @PreDestroy
+ public void shutdown() {
+ logger.info("distribution engine shutdown - start");
+ if (envNamePerInitTask != null) {
+ for (DistributionEngineInitTask task : envNamePerInitTask.values()) {
+ task.destroy();
+ }
+ }
+ if (envNamePerPollingTask != null) {
+ for (DistributionEnginePollingTask task : envNamePerPollingTask.values()) {
+ task.destroy();
+ }
+ }
+
+ }
+
+ /**
+ * validate mandatory configuration parameters received
+ *
+ * @param deConfiguration
+ * @return
+ */
+ protected boolean validateConfiguration(DistributionEngineConfiguration deConfiguration) {
+
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ boolean result = true;
+ result = isValidServers(deConfiguration.getUebServers(), methodName, "uebServers") && result;
+ result = isValidParam(deConfiguration.getEnvironments(), methodName, "environments") && result;
+ result = isValidParam(deConfiguration.getUebPublicKey(), methodName, "uebPublicKey") && result;
+ result = isValidParam(deConfiguration.getUebSecretKey(), methodName, "uebSecretKey") && result;
+ result = isValidParam(deConfiguration.getDistributionNotifTopicName(), methodName, "distributionNotifTopicName") && result;
+ result = isValidParam(deConfiguration.getDistributionStatusTopicName(), methodName, "distributionStatusTopicName") && result;
+ result = isValidObject(deConfiguration.getCreateTopic(), methodName, "createTopic") && result;
+ result = isValidObject(deConfiguration.getDistributionStatusTopic(), methodName, "distributionStatusTopic") && result;
+ result = isValidObject(deConfiguration.getInitMaxIntervalSec(), methodName, "initMaxIntervalSec") && result;
+ result = isValidObject(deConfiguration.getInitRetryIntervalSec(), methodName, "initRetryIntervalSec") && result;
+ result = isValidParam(deConfiguration.getDistributionStatusTopic().getConsumerId(), methodName, "consumerId") && result;
+ result = isValidParam(deConfiguration.getDistributionStatusTopic().getConsumerGroup(), methodName, "consumerGroup") && result;
+ result = isValidObject(deConfiguration.getDistributionStatusTopic().getFetchTimeSec(), methodName, "fetchTimeSec") && result;
+ result = isValidObject(deConfiguration.getDistributionStatusTopic().getPollingIntervalSec(), methodName, "pollingIntervalSec") && result;
+
+ return result;
+ }
+
+ private boolean isValidServers(List<String> uebServers, String methodName, String paramName) {
+
+ if (uebServers == null || uebServers.size() == 0) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingConfigurationError, methodName, paramName);
+ BeEcompErrorManager.getInstance().logBeMissingConfigurationError(methodName, paramName);
+ return false;
+ }
+
+ if (uebServers.size() < 2) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeConfigurationInvalidListSizeError, methodName, paramName, "2");
+ BeEcompErrorManager.getInstance().logBeConfigurationInvalidListSizeError(methodName, paramName, 2);
+ return false;
+ }
+
+ for (String serverFqdn : uebServers) {
+ if (false == isValidFqdn(serverFqdn)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidConfigurationError, methodName, paramName, serverFqdn);
+ BeEcompErrorManager.getInstance().logBeInvalidConfigurationError(methodName, paramName, serverFqdn);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean isValidFqdn(String serverFqdn) {
+
+ try {
+ Matcher matcher = FQDN_PATTERN.matcher(serverFqdn);
+ return matcher.matches();
+
+ } catch (Exception e) {
+ logger.debug("Failed to match value of address {}", serverFqdn, e);
+ return false;
+ }
+
+ }
+
+ private boolean isEmptyParam(String param) {
+
+ if (param == null || true == param.isEmpty()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isValidParam(String paramValue, String methodName, String paramName) {
+
+ if (isEmptyParam(paramValue)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingConfigurationError, methodName, paramName);
+ BeEcompErrorManager.getInstance().logBeMissingConfigurationError(methodName, paramName);
+ return false;
+ }
+ return true;
+
+ }
+
+ private boolean isValidParam(List<String> paramValue, String methodName, String paramName) {
+
+ if (isEmptyList(paramValue)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingConfigurationError, methodName, paramName);
+ BeEcompErrorManager.getInstance().logBeMissingConfigurationError(methodName, paramName);
+ return false;
+ }
+ return true;
+
+ }
+
+ private boolean isValidObject(Object paramValue, String methodName, String paramName) {
+
+ if (paramValue == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingConfigurationError, methodName, paramName);
+ BeEcompErrorManager.getInstance().logBeMissingConfigurationError(methodName, paramName);
+ return false;
+ }
+ return true;
+
+ }
+
+ private boolean isEmptyList(List<String> list) {
+ if (list == null || true == list.isEmpty()) {
+ return true;
+ }
+ return false;
+ }
+
+ private String getEnvironmentErrorDescription(StorageOperationStatus status) {
+
+ switch (status) {
+ case DISTR_ENVIRONMENT_NOT_AVAILABLE:
+ return "environment is unavailable";
+ case DISTR_ENVIRONMENT_NOT_FOUND:
+ return "environment is not configured in our system";
+ case DISTR_ENVIRONMENT_SENT_IS_INVALID:
+ return "environment name is invalid";
+
+ default:
+ return "unkhown";
+
+ }
+ }
+
+ public StorageOperationStatus isEnvironmentAvailable(String envName) {
+
+ if (envName == null || true == envName.isEmpty()) {
+
+ return StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID;
+ }
+
+ AtomicBoolean status = envNamePerStatus.get(envName);
+ if (status == null) {
+ return StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND;
+ }
+
+ if (false == status.get()) {
+ return StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE;
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ public StorageOperationStatus isEnvironmentAvailable() {
+
+ String envName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
+
+ return isEnvironmentAvailable(envName);
+ }
+
+ @Override
+ public void disableEnvironment(String envName) {
+ // TODO disable tasks
+ AtomicBoolean status = envNamePerStatus.get(envName);
+ status.set(false);
+ }
+
+ @Override
+ public StorageOperationStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envName, String userId, String modifierName) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Received notify service request. distributionId = {}, serviceUuid = {}, serviceUid = {}, envName = {}, userId = {}, modifierName {}", distributionId, service.getUUID(), service.getUniqueId(), envName, userId, modifierName);
+ }
+
+ DistributionEngineConfiguration deConfiguration = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+
+ String distributionNotifTopicName = deConfiguration.getDistributionNotifTopicName();
+ String topicName = DistributionEngineInitTask.buildTopicName(distributionNotifTopicName, envName);
+
+ StorageOperationStatus sendNotification = distributionNotificationSender.sendNotification(topicName, distributionId, deConfiguration, envName, notificationData, service, userId, modifierName);
+
+ logger.debug("Finish notifyService. status is {}", sendNotification);
+
+ return sendNotification;
+ }
+
+ @Override
+ public Either<INotificationData, StorageOperationStatus> isReadyForDistribution(Service service, String distributionId, String envName) {
+ StorageOperationStatus status = isEnvironmentAvailable(envName);
+ if (status != StorageOperationStatus.OK) {
+ String envErrorDec = getEnvironmentErrorDescription(status);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, DistributionNotificationSender.DISTRIBUTION_NOTIFICATION_SENDING,
+ "Environment name " + envName + " is not available. Reason : " + envErrorDec);
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionNotificationSender.DISTRIBUTION_NOTIFICATION_SENDING, "Environment name " + envName + " is not available. Reason : " + envErrorDec);
+ return Either.right(status);
+ }
+
+ Either<Boolean, StorageOperationStatus> isServiceContainsDeploymentArtifactsStatus = serviceDistributionArtifactsBuilder.isServiceContainsDeploymentArtifacts(service);
+ if (isServiceContainsDeploymentArtifactsStatus.isRight()) {
+ StorageOperationStatus operationStatus = isServiceContainsDeploymentArtifactsStatus.right().value();
+ return Either.right(operationStatus);
+ } else {
+ Boolean isDeploymentArtifactExists = isServiceContainsDeploymentArtifactsStatus.left().value();
+ if (isDeploymentArtifactExists == null || isDeploymentArtifactExists.booleanValue() == false) {
+ return Either.right(StorageOperationStatus.DISTR_ARTIFACT_NOT_FOUND);
+ }
+ }
+
+ INotificationData value = serviceDistributionArtifactsBuilder.buildResourceInstanceForDistribution(service, distributionId);
+ value = serviceDistributionArtifactsBuilder.buildServiceForDistribution(value, service);
+
+ return Either.left(value);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
new file mode 100644
index 0000000000..a3d0362c61
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
@@ -0,0 +1,356 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component("distribution-engine-cluster-health")
+public class DistributionEngineClusterHealth {
+
+ protected static String UEB_HEALTH_LOG_CONTEXT = "ueb.healthcheck";
+
+ private static Logger healthLogger = LoggerFactory.getLogger(UEB_HEALTH_LOG_CONTEXT);
+
+ private static final String UEB_HEALTH_CHECK_STR = "uebHealthCheck";
+
+ boolean lastHealthState = false;
+
+ Object lockOject = new Object();
+
+ private long reconnectInterval = 5;
+
+ private long healthCheckReadTimeout = 20;
+
+ private static Logger logger = LoggerFactory.getLogger(DistributionEngineClusterHealth.class.getName());
+
+ private List<String> uebServers = null;
+
+ private String publicApiKey = null;
+
+ public enum HealthCheckInfoResult {
+
+ OK(new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.UP, null, ClusterStatusDescription.OK.getDescription())), UNAVAILABLE(
+ new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.UNAVAILABLE.getDescription())), NOT_CONFIGURED(
+ new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.NOT_CONFIGURED.getDescription())), DISABLED(
+ new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.DISABLED.getDescription()));
+
+ private HealthCheckInfo healthCheckInfo;
+
+ HealthCheckInfoResult(HealthCheckInfo healthCheckInfo) {
+ this.healthCheckInfo = healthCheckInfo;
+ }
+
+ public HealthCheckInfo getHealthCheckInfo() {
+ return healthCheckInfo;
+ }
+
+ }
+
+ private HealthCheckInfo healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.getHealthCheckInfo();
+
+ private Map<String, AtomicBoolean> envNamePerStatus = null;
+
+ private ScheduledFuture<?> scheduledFuture = null;
+
+ ScheduledExecutorService healthCheckScheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "UEB-Health-Check-Task");
+ }
+ });
+
+ HealthCheckScheduledTask healthCheckScheduledTask = null;
+
+ public enum ClusterStatusDescription {
+
+ OK("OK"), UNAVAILABLE("U-EB cluster is not available"), NOT_CONFIGURED("U-EB cluster is not configured"), DISABLED("DE is disabled in configuration");
+
+ private String desc;
+
+ ClusterStatusDescription(String desc) {
+ this.desc = desc;
+ }
+
+ public String getDescription() {
+ return desc;
+ }
+
+ }
+
+ /**
+ * Health Check Task Scheduler.
+ *
+ * It schedules a task which send a apiKey get query towards the UEB servers. In case a query to the first UEB server is failed, then a second query is sent to the next UEB server.
+ *
+ *
+ * @author esofer
+ *
+ */
+ public class HealthCheckScheduledTask implements Runnable {
+
+ List<UebHealthCheckCall> healthCheckCalls = new ArrayList<>();
+
+ public HealthCheckScheduledTask(List<String> uebServers) {
+
+ logger.debug("Create health check calls for servers {}", uebServers);
+ if (uebServers != null) {
+ for (String server : uebServers) {
+ healthCheckCalls.add(new UebHealthCheckCall(server, publicApiKey));
+ }
+ }
+ }
+
+ @Override
+ public void run() {
+
+ healthLogger.trace("Executing UEB Health Check Task - Start");
+
+ boolean healthStatus = verifyAtLeastOneEnvIsUp();
+
+ if (true == healthStatus) {
+ boolean queryUebStatus = queryUeb();
+ if (queryUebStatus == lastHealthState) {
+ return;
+ }
+
+ synchronized (lockOject) {
+ if (queryUebStatus != lastHealthState) {
+ logger.trace("UEB Health State Changed to {}. Issuing alarm / recovery alarm...", healthStatus);
+ lastHealthState = queryUebStatus;
+ logAlarm(lastHealthState);
+ if (true == queryUebStatus) {
+ healthCheckInfo = HealthCheckInfoResult.OK.getHealthCheckInfo();
+ } else {
+ healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.getHealthCheckInfo();
+ }
+ }
+ }
+ } else {
+ healthLogger.trace("Not all UEB Environments are up");
+ }
+
+ }
+
+ /**
+ * verify that at least one environment is up.
+ *
+ */
+ private boolean verifyAtLeastOneEnvIsUp() {
+
+ boolean healthStatus = false;
+
+ if (envNamePerStatus != null) {
+ Collection<AtomicBoolean> values = envNamePerStatus.values();
+ if (values != null) {
+ for (AtomicBoolean status : values) {
+ if (true == status.get()) {
+ healthStatus = true;
+ break;
+ }
+ }
+ }
+ }
+
+ return healthStatus;
+ }
+
+ /**
+ * executor for the query itself
+ */
+ ExecutorService healthCheckExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "UEB-Health-Check-Thread");
+ }
+ });
+
+ /**
+ * go all UEB servers and send a get apiKeys query. In case a query is succeed, no query is sent to the rest of UEB servers.
+ *
+ *
+ * @return
+ */
+ private boolean queryUeb() {
+
+ Boolean result = false;
+ int retryNumber = 1;
+ for (UebHealthCheckCall healthCheckCall : healthCheckCalls) {
+ try {
+
+ healthLogger.debug("Before running Health Check retry query number {} towards UEB server {}", retryNumber, healthCheckCall.getServer());
+
+ Future<Boolean> future = healthCheckExecutor.submit(healthCheckCall);
+ result = future.get(healthCheckReadTimeout, TimeUnit.SECONDS);
+
+ healthLogger.debug("After running Health Check retry query number {} towards UEB server {}. Result is {}", retryNumber, healthCheckCall.getServer(), result);
+
+ if (result != null && true == result.booleanValue()) {
+ break;
+ }
+
+ } catch (Exception e) {
+ String message = e.getMessage();
+ if (message == null) {
+ message = e.getClass().getName();
+ }
+ healthLogger.debug("Error occured during running Health Check retry query towards UEB server {}. Result is {}", healthCheckCall.getServer(), message);
+ }
+ retryNumber++;
+
+ }
+
+ return result;
+
+ }
+
+ public List<UebHealthCheckCall> getHealthCheckCalls() {
+ return healthCheckCalls;
+ }
+
+ }
+
+ @PostConstruct
+ private void init() {
+
+ logger.trace("Enter init method of DistributionEngineClusterHealth");
+
+ Long reconnectIntervalConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getUebHealthCheckReconnectIntervalInSeconds();
+ if (reconnectIntervalConfig != null) {
+ reconnectInterval = reconnectIntervalConfig.longValue();
+ }
+ Long healthCheckReadTimeoutConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getUebHealthCheckReadTimeout();
+ if (healthCheckReadTimeoutConfig != null) {
+ healthCheckReadTimeout = healthCheckReadTimeoutConfig.longValue();
+ }
+
+ DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+
+ this.uebServers = distributionEngineConfiguration.getUebServers();
+ this.publicApiKey = distributionEngineConfiguration.getUebPublicKey();
+
+ this.healthCheckScheduledTask = new HealthCheckScheduledTask(this.uebServers);
+
+ logger.trace("Exit init method of DistributionEngineClusterHealth");
+
+ }
+
+ @PreDestroy
+ private void destroy() {
+
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
+ }
+
+ if (healthCheckScheduler != null) {
+ healthCheckScheduler.shutdown();
+ }
+
+ }
+
+ /**
+ * Start health check task.
+ *
+ * @param envNamePerStatus
+ * @param startTask
+ */
+ public void startHealthCheckTask(Map<String, AtomicBoolean> envNamePerStatus, boolean startTask) {
+ this.envNamePerStatus = envNamePerStatus;
+
+ if (startTask == true && this.scheduledFuture == null) {
+ this.scheduledFuture = this.healthCheckScheduler.scheduleAtFixedRate(healthCheckScheduledTask, 0, reconnectInterval, TimeUnit.SECONDS);
+ }
+ }
+
+ public void startHealthCheckTask(Map<String, AtomicBoolean> envNamePerStatus) {
+ startHealthCheckTask(envNamePerStatus, true);
+ }
+
+ private void logAlarm(boolean lastHealthState) {
+ if (lastHealthState == true) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeHealthCheckRecovery, UEB_HEALTH_CHECK_STR);
+ BeEcompErrorManager.getInstance().logBeHealthCheckUebClusterRecovery(UEB_HEALTH_CHECK_STR);
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeHealthCheckError, UEB_HEALTH_CHECK_STR);
+ BeEcompErrorManager.getInstance().logBeHealthCheckUebClusterError(UEB_HEALTH_CHECK_STR);
+ }
+ }
+
+ public HealthCheckInfo getHealthCheckInfo() {
+ return healthCheckInfo;
+ }
+
+ /**
+ * change the health check to DISABLE
+ */
+ public void setHealthCheckUebIsDisabled() {
+ healthCheckInfo = HealthCheckInfoResult.DISABLED.getHealthCheckInfo();
+ }
+
+ /**
+ * change the health check to NOT CONFGIURED
+ */
+ public void setHealthCheckUebConfigurationError() {
+ healthCheckInfo = HealthCheckInfoResult.NOT_CONFIGURED.getHealthCheckInfo();
+ }
+
+ public void setHealthCheckOkAndReportInCaseLastStateIsDown() {
+
+ if (lastHealthState == true) {
+ return;
+ }
+ synchronized (lockOject) {
+ if (lastHealthState == false) {
+ logger.debug("Going to update health check state to available");
+ lastHealthState = true;
+ healthCheckInfo = HealthCheckInfoResult.OK.getHealthCheckInfo();
+ logAlarm(lastHealthState);
+ }
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTask.java
new file mode 100644
index 0000000000..1eeaa1229e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTask.java
@@ -0,0 +1,293 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class DistributionEngineInitTask implements Runnable {
+
+ public static final String INIT_DISTRIBUTION_ENGINE_FLOW = "initDistributionEngine";
+ public static final String ALREADY_EXISTS = "ALREADY_EXISTS";
+ public static final String CONSUMER = "CONSUMER";
+ public static final String PRODUCER = "PRODUCER";
+ public static final String CREATED = "CREATED";
+ public static final String FAILED = "FAILED";
+ public static final Integer HTTP_OK = 200;
+
+ private Long delayBeforeStartFlow = 0l;
+ private DistributionEngineConfiguration deConfiguration;
+ private String envName;
+ private long retryInterval;
+ private long currentRetryInterval;
+ private long maxInterval;
+ // private boolean active = false;
+ boolean maximumRetryInterval = false;
+ private AtomicBoolean status = null;
+ ComponentsUtils componentsUtils = null;
+ DistributionEnginePollingTask distributionEnginePollingTask = null;
+
+ private CambriaHandler cambriaHandler = new CambriaHandler();
+
+ public DistributionEngineInitTask(Long delayBeforeStartFlow, DistributionEngineConfiguration deConfiguration, String envName, AtomicBoolean status, ComponentsUtils componentsUtils, DistributionEnginePollingTask distributionEnginePollingTask) {
+ super();
+ this.delayBeforeStartFlow = delayBeforeStartFlow;
+ this.deConfiguration = deConfiguration;
+ this.envName = envName;
+ this.retryInterval = deConfiguration.getInitRetryIntervalSec();
+ this.currentRetryInterval = retryInterval;
+ this.maxInterval = deConfiguration.getInitMaxIntervalSec();
+ this.status = status;
+ this.componentsUtils = componentsUtils;
+ this.distributionEnginePollingTask = distributionEnginePollingTask;
+ }
+
+ private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
+
+ private static Logger logger = LoggerFactory.getLogger(DistributionEngineInitTask.class.getName());
+
+ ScheduledFuture<?> scheduledFuture = null;
+
+ public void startTask() {
+ if (scheduledExecutorService != null) {
+ Integer retryInterval = deConfiguration.getInitRetryIntervalSec();
+ logger.debug("Start Distribution Engine init task. retry interval {} seconds, delay before first run {} seconds", retryInterval, delayBeforeStartFlow);
+ this.scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(this, delayBeforeStartFlow, retryInterval, TimeUnit.SECONDS);
+
+ }
+ }
+
+ public void restartTask() {
+
+ this.stopTask();
+
+ logger.debug("Start Distribution Engine init task. next run in {} seconds", this.currentRetryInterval);
+
+ long lastCurrentInterval = currentRetryInterval;
+ incrementRetryInterval();
+
+ this.scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(this, lastCurrentInterval, this.currentRetryInterval, TimeUnit.SECONDS);
+
+ }
+
+ protected void incrementRetryInterval() {
+ if (currentRetryInterval < maxInterval) {
+ currentRetryInterval *= 2;
+ if (currentRetryInterval > maxInterval) {
+ setMaxRetryInterval();
+ }
+ } else {
+ setMaxRetryInterval();
+ }
+ }
+
+ private void setMaxRetryInterval() {
+ currentRetryInterval = maxInterval;
+ maximumRetryInterval = true;
+ logger.debug("Set next retry init interval to {}", maxInterval);
+ }
+
+ public void stopTask() {
+ if (scheduledFuture != null) {
+ boolean result = scheduledFuture.cancel(true);
+ logger.debug("Stop reinit task. result = {}", result);
+ if (false == result) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, INIT_DISTRIBUTION_ENGINE_FLOW, "try to stop the reinit task");
+ BeEcompErrorManager.getInstance().logBeUebSystemError(INIT_DISTRIBUTION_ENGINE_FLOW, "try to stop the reinit task");
+ }
+ scheduledFuture = null;
+ }
+ }
+
+ public void destroy() {
+ this.stopTask();
+ if (scheduledExecutorService != null) {
+ scheduledExecutorService.shutdown();
+ }
+ }
+
+ @Override
+ public void run() {
+
+ boolean result = false;
+ result = initFlow();
+
+ if (true == result) {
+ this.stopTask();
+ this.status.set(true);
+ if (this.distributionEnginePollingTask != null) {
+ String topicName = buildTopicName(deConfiguration.getDistributionStatusTopicName(), envName);
+ logger.debug("start polling distribution status topic {}", topicName);
+ this.distributionEnginePollingTask.startTask(topicName);
+ }
+ } else {
+ if (false == maximumRetryInterval) {
+ this.restartTask();
+ }
+ }
+ }
+
+ /**
+ * run initialization flow
+ *
+ * @return
+ */
+ public boolean initFlow() {
+
+ logger.trace("Start init flow for environment {}", this.envName);
+
+ Set<String> topicsList = null;
+ Either<Set<String>, CambriaErrorResponse> getTopicsRes = null;
+
+ getTopicsRes = cambriaHandler.getTopics(deConfiguration.getUebServers());
+ if (getTopicsRes.isRight()) {
+ CambriaErrorResponse status = getTopicsRes.right().value();
+ if (status.getOperationStatus() == CambriaOperationStatus.NOT_FOUND) {
+ topicsList = new HashSet<>();
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, INIT_DISTRIBUTION_ENGINE_FLOW, "try retrieve list of topics from U-EB server");
+
+ BeEcompErrorManager.getInstance().logBeUebSystemError(INIT_DISTRIBUTION_ENGINE_FLOW, "try retrieve list of topics from U-EB server");
+
+ return false;
+ }
+ } else {
+ topicsList = getTopicsRes.left().value();
+ }
+
+ String notificationTopic = buildTopicName(deConfiguration.getDistributionNotifTopicName(), this.envName);
+ logger.debug("Going to handle topic {}", notificationTopic);
+
+ boolean status = createTopicIfNotExists(topicsList, notificationTopic);
+ if (false == status) {
+ return false;
+ }
+
+ CambriaErrorResponse registerProducerStatus = registerToTopic(notificationTopic, SubscriberTypeEnum.PRODUCER);
+
+ CambriaOperationStatus createStatus = registerProducerStatus.getOperationStatus();
+
+ if (createStatus != CambriaOperationStatus.OK) {
+ return false;
+ }
+
+ String statusTopic = buildTopicName(deConfiguration.getDistributionStatusTopicName(), this.envName);
+ logger.debug("Going to handle topic {}", statusTopic);
+ status = createTopicIfNotExists(topicsList, statusTopic);
+ if (false == status) {
+ return false;
+ }
+
+ CambriaErrorResponse registerConcumerStatus = registerToTopic(statusTopic, SubscriberTypeEnum.CONSUMER);
+
+ if (registerConcumerStatus.getOperationStatus() != CambriaOperationStatus.OK) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private CambriaErrorResponse registerToTopic(String topicName, SubscriberTypeEnum subscriberType) {
+ CambriaErrorResponse registerStatus = cambriaHandler.registerToTopic(deConfiguration.getUebServers(), topicName, deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), deConfiguration.getUebPublicKey(), subscriberType);
+
+ String role = CONSUMER;
+ if (subscriberType == SubscriberTypeEnum.PRODUCER) {
+ role = PRODUCER;
+ }
+ auditRegistration(topicName, registerStatus, role);
+ return registerStatus;
+ }
+
+ private void auditRegistration(String notificationTopic, CambriaErrorResponse registerProducerStatus, String role) {
+ if (componentsUtils != null) {
+ Integer httpCode = registerProducerStatus.getHttpCode();
+ String httpCodeStr = String.valueOf(httpCode);
+ this.componentsUtils.auditDistributionEngine(AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL, this.envName, notificationTopic, role, deConfiguration.getUebPublicKey(), httpCodeStr);
+ }
+ }
+
+ private boolean createTopicIfNotExists(Set<String> topicsList, String topicName) {
+
+ if (topicsList.contains(topicName)) {
+ if (componentsUtils != null) {
+ this.componentsUtils.auditDistributionEngine(AuditingActionEnum.CREATE_DISTRIBUTION_TOPIC, this.envName, topicName, null, null, ALREADY_EXISTS);
+ }
+ return true;
+ }
+
+ CambriaErrorResponse createDistribTopicStatus = cambriaHandler.createTopic(deConfiguration.getUebServers(), deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), topicName, deConfiguration.getCreateTopic().getPartitionCount(),
+ deConfiguration.getCreateTopic().getReplicationCount());
+
+ CambriaOperationStatus status = createDistribTopicStatus.getOperationStatus();
+ if (status == CambriaOperationStatus.TOPIC_ALREADY_EXIST) {
+ if (componentsUtils != null) {
+ this.componentsUtils.auditDistributionEngine(AuditingActionEnum.CREATE_DISTRIBUTION_TOPIC, this.envName, topicName, null, null, ALREADY_EXISTS);
+ }
+ } else if (status == CambriaOperationStatus.OK) {
+ if (componentsUtils != null) {
+ this.componentsUtils.auditDistributionEngine(AuditingActionEnum.CREATE_DISTRIBUTION_TOPIC, this.envName, topicName, null, null, CREATED);
+ }
+ } else {
+ if (componentsUtils != null) {
+ this.componentsUtils.auditDistributionEngine(AuditingActionEnum.CREATE_DISTRIBUTION_TOPIC, this.envName, topicName, null, null, FAILED);
+ }
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, INIT_DISTRIBUTION_ENGINE_FLOW, "try to create topic " + topicName);
+
+ BeEcompErrorManager.getInstance().logBeUebSystemError(INIT_DISTRIBUTION_ENGINE_FLOW, "try to create topic " + topicName);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public static String buildTopicName(String topicName, String environment) {
+ return topicName + "-" + environment.toUpperCase();
+ }
+
+ public boolean isActive() {
+ return this.status.get();
+ }
+
+ public long getCurrentRetryInterval() {
+ return currentRetryInterval;
+ }
+
+ protected void setCambriaHandler(CambriaHandler cambriaHandler) {
+ this.cambriaHandler = cambriaHandler;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java
new file mode 100644
index 0000000000..fc7c473d6b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java
@@ -0,0 +1,207 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionStatusTopicConfig;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class DistributionEnginePollingTask implements Runnable {
+
+ public static final String DISTRIBUTION_STATUS_POLLING = "distributionEngineStatusPolling";
+
+ private String topicName;
+ private ComponentsUtils componentUtils;
+ private int fetchTimeoutInSec = 15;
+ private int pollingIntervalInSec;
+ private String consumerId;
+ private String consumerGroup;
+ private DistributionEngineConfiguration distributionEngineConfiguration;
+
+ private CambriaHandler cambriaHandler = new CambriaHandler();
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ private ScheduledExecutorService scheduledPollingService = Executors.newScheduledThreadPool(1, new BasicThreadFactory.Builder().namingPattern("TopicPollingThread-%d").build());
+
+ private static Logger logger = LoggerFactory.getLogger(DistributionEnginePollingTask.class.getName());
+
+ ScheduledFuture<?> scheduledFuture = null;
+ private CambriaConsumer cambriaConsumer = null;
+
+ private DistributionEngineClusterHealth distributionEngineClusterHealth = null;
+
+ public DistributionEnginePollingTask(DistributionEngineConfiguration distributionEngineConfiguration, String envName, ComponentsUtils componentUtils, DistributionEngineClusterHealth distributionEngineClusterHealth) {
+
+ this.componentUtils = componentUtils;
+ this.distributionEngineConfiguration = distributionEngineConfiguration;
+ DistributionStatusTopicConfig statusConfig = distributionEngineConfiguration.getDistributionStatusTopic();
+ this.pollingIntervalInSec = statusConfig.getPollingIntervalSec();
+ this.fetchTimeoutInSec = statusConfig.getFetchTimeSec();
+ this.consumerGroup = statusConfig.getConsumerGroup();
+ this.consumerId = statusConfig.getConsumerId();
+ this.distributionEngineClusterHealth = distributionEngineClusterHealth;
+ }
+
+ public void startTask(String topicName) {
+
+ this.topicName = topicName;
+ logger.debug("start task for polling topic {}", topicName);
+ if (fetchTimeoutInSec < 15) {
+ logger.warn("fetchTimeout value should be greater or equal to 15 sec. use default");
+ fetchTimeoutInSec = 15;
+ }
+ try {
+ cambriaConsumer = cambriaHandler.createConsumer(distributionEngineConfiguration.getUebServers(), topicName, distributionEngineConfiguration.getUebPublicKey(), distributionEngineConfiguration.getUebSecretKey(), consumerId, consumerGroup,
+ fetchTimeoutInSec * 1000);
+
+ if (scheduledPollingService != null) {
+ logger.debug("Start Distribution Engine polling task. polling interval {} seconds", pollingIntervalInSec);
+ scheduledFuture = scheduledPollingService.scheduleAtFixedRate(this, 0, pollingIntervalInSec, TimeUnit.SECONDS);
+
+ }
+ } catch (Exception e) {
+ logger.debug("unexpected error occured", e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(methodName, e.getMessage());
+ }
+ }
+
+ public void stopTask() {
+ if (scheduledFuture != null) {
+ boolean result = scheduledFuture.cancel(true);
+ logger.debug("Stop polling task. result = {}", result);
+ if (false == result) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, DISTRIBUTION_STATUS_POLLING, "try to stop the polling task");
+ BeEcompErrorManager.getInstance().logBeUebSystemError(DISTRIBUTION_STATUS_POLLING, "try to stop the polling task");
+ }
+ scheduledFuture = null;
+ }
+ if (cambriaConsumer != null) {
+ logger.debug("close consumer");
+ cambriaHandler.closeConsumer(cambriaConsumer);
+ }
+
+ }
+
+ public void destroy() {
+ this.stopTask();
+ shutdownExecutor();
+ }
+
+ @Override
+ public void run() {
+ logger.trace("run() method. polling queue {}", topicName);
+
+ try {
+ // init error
+ if (cambriaConsumer == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, DISTRIBUTION_STATUS_POLLING, "polling task was not initialized properly");
+ BeEcompErrorManager.getInstance().logBeUebSystemError(DISTRIBUTION_STATUS_POLLING, "polling task was not initialized properly");
+ stopTask();
+ return;
+ }
+
+ Either<Iterable<String>, CambriaErrorResponse> fetchResult = cambriaHandler.fetchFromTopic(cambriaConsumer);
+ // fetch error
+ if (fetchResult.isRight()) {
+ CambriaErrorResponse errorResponse = fetchResult.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, DISTRIBUTION_STATUS_POLLING, "failed to fetch messages from topic " + topicName + " error: " + fetchResult.right().value());
+ BeEcompErrorManager.getInstance().logBeUebSystemError(DISTRIBUTION_STATUS_POLLING, "failed to fetch messages from topic " + topicName + " error: " + fetchResult.right().value());
+
+ // TODO: if status== internal error (connection problem) change
+ // state to inactive
+ // in next try, if succeed - change to active
+ return;
+ }
+
+ // success
+ Iterable<String> messages = fetchResult.left().value();
+ for (String message : messages) {
+ logger.trace("received message {}", message);
+ try {
+ DistributionStatusNotification notification = gson.fromJson(message, DistributionStatusNotification.class);
+ componentUtils.auditDistributionStatusNotification(AuditingActionEnum.DISTRIBUTION_STATUS, notification.getDistributionID(), notification.getConsumerID(), topicName, notification.getArtifactURL(),
+ String.valueOf(notification.getTimestamp()), notification.getStatus().name(), notification.getErrorReason());
+
+ distributionEngineClusterHealth.setHealthCheckOkAndReportInCaseLastStateIsDown();
+
+ } catch (Exception e) {
+ logger.debug("failed to convert message to object", e);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUebSystemError, DISTRIBUTION_STATUS_POLLING, "failed to parse message " + message + " from topic " + topicName + " error: " + fetchResult.right().value());
+ BeEcompErrorManager.getInstance().logBeUebSystemError(DISTRIBUTION_STATUS_POLLING, "failed to parse message " + message + " from topic " + topicName + " error: " + fetchResult.right().value());
+ }
+
+ }
+ } catch (Exception e) {
+ logger.debug("unexpected error occured", e);
+ String methodName = new Object() {
+ }.getClass().getEnclosingMethod().getName();
+
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, methodName, e.getMessage());
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(methodName, e.getMessage());
+ }
+
+ }
+
+ private void shutdownExecutor() {
+ if (scheduledPollingService == null)
+ return;
+
+ scheduledPollingService.shutdown(); // Disable new tasks from being
+ // submitted
+ try {
+ // Wait a while for existing tasks to terminate
+ if (!scheduledPollingService.awaitTermination(60, TimeUnit.SECONDS)) {
+ scheduledPollingService.shutdownNow(); // Cancel currently
+ // executing tasks
+ // Wait a while for tasks to respond to being cancelled
+ if (!scheduledPollingService.awaitTermination(60, TimeUnit.SECONDS))
+ logger.debug("Pool did not terminate");
+ }
+ } catch (InterruptedException ie) {
+ // (Re-)Cancel if current thread also interrupted
+ scheduledPollingService.shutdownNow();
+ // Preserve interrupt status
+ Thread.currentThread().interrupt();
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionNotificationSender.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionNotificationSender.java
new file mode 100644
index 0000000000..667276db2c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionNotificationSender.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionException;
+
+import javax.annotation.PreDestroy;
+
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component("distributionNotificationSender")
+public class DistributionNotificationSender {
+
+ protected static final String DISTRIBUTION_NOTIFICATION_SENDING = "distributionNotificationSending";
+
+ private static Logger logger = LoggerFactory.getLogger(DistributionNotificationSender.class.getName());
+
+ // final String BASE_ARTIFACT_URL = "/asdc/v1/catalog/services/%s/%s/";
+ // final String RESOURCE_ARTIFACT_URL = BASE_ARTIFACT_URL
+ // + "resources/%s/%s/artifacts/%s";
+ // final String SERVICE_ARTIFACT_URL = BASE_ARTIFACT_URL + "artifacts/%s";
+
+ @javax.annotation.Resource
+ InterfaceLifecycleOperation interfaceLifecycleOperation;
+
+ @javax.annotation.Resource
+ protected IServiceOperation serviceOperation;
+
+ @javax.annotation.Resource
+ protected ResourceOperation resourceOperation;
+
+ @javax.annotation.Resource
+ protected ComponentsUtils componentUtils;
+
+ ExecutorService executorService = null;
+
+ CambriaHandler cambriaHandler = new CambriaHandler();
+
+ NotificationExecutorService notificationExecutorService = new NotificationExecutorService();
+
+ public DistributionNotificationSender() {
+ super();
+
+ DistributionNotificationTopicConfig distributionNotificationTopic = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getDistributionNotificationTopic();
+
+ executorService = notificationExecutorService.createExcecutorService(distributionNotificationTopic);
+ }
+
+ @PreDestroy
+ public void shutdown() {
+ logger.debug("Going to close notificationExecutorService");
+ if (executorService != null) {
+
+ long maxWaitingTime = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getDistributionNotificationTopic().getMaxWaitingAfterSendingSeconds();
+
+ notificationExecutorService.shutdownAndAwaitTermination(executorService, maxWaitingTime + 1);
+ }
+ }
+
+ public StorageOperationStatus sendNotification(String topicName, String distributionId, DistributionEngineConfiguration deConfiguration, String envName, INotificationData notificationData, Service service, String userId, String modifierName) {
+
+ Runnable task = new PublishNotificationRunnable(envName, distributionId, service, notificationData, deConfiguration, topicName, userId, modifierName, cambriaHandler, componentUtils, ThreadLocalsHolder.getUuid());
+ try {
+ executorService.submit(task);
+ } catch (RejectedExecutionException e) {
+ logger.warn("Failed to submit task. Number of threads exceeeds", e);
+ return StorageOperationStatus.OVERLOAD;
+ }
+
+ return StorageOperationStatus.OK;
+ }
+
+ /**
+ * Audit the publishing notification in case of internal server error.
+ *
+ * @param topicName
+ * @param status
+ * @param distributionId
+ * @param envName
+ */
+ private void auditDistributionNotificationInternalServerError(String topicName, StorageOperationStatus status, String distributionId, String envName) {
+
+ if (this.componentUtils != null) {
+ this.componentUtils.auditDistributionNotification(AuditingActionEnum.DISTRIBUTION_NOTIFY, "", " ", "Service", " ", " ", " ", envName, " ", topicName, distributionId, "Error: Internal Server Error. " + status, " ");
+ }
+ }
+
+ protected CambriaErrorResponse publishNotification(INotificationData data, DistributionEngineConfiguration deConfiguration, String topicName) {
+
+ CambriaErrorResponse status = cambriaHandler.sendNotification(topicName, deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), deConfiguration.getUebServers(), data);
+
+ return status;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java
new file mode 100644
index 0000000000..73a0336361
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public class DistributionStatusNotification {
+
+ String distributionID;
+ String consumerID;
+ long timestamp;
+ String artifactURL;
+ DistributionStatusNotificationEnum status;
+ String errorReason;
+
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ public void setDistributionID(String distributionId) {
+ this.distributionID = distributionId;
+ }
+
+ public String getConsumerID() {
+ return consumerID;
+ }
+
+ public void setConsumerID(String consumerId) {
+ this.consumerID = consumerId;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ public DistributionStatusNotificationEnum getStatus() {
+ return status;
+ }
+
+ public void setStatus(DistributionStatusNotificationEnum status) {
+ this.status = status;
+ }
+
+ public String getErrorReason() {
+ return errorReason;
+ }
+
+ public void setErrorReason(String errorReason) {
+ this.errorReason = errorReason;
+ }
+
+ @Override
+ public String toString() {
+ return "DistributionStatusNotification [distributionId=" + distributionID + ", consumerId=" + consumerID + ", timestamp=" + timestamp + ", artifactURL=" + artifactURL + ", status=" + status + ", errorReason=" + errorReason + "]";
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotificationEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotificationEnum.java
new file mode 100644
index 0000000000..bd77f3915a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotificationEnum.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public enum DistributionStatusNotificationEnum {
+
+ DOWNLOAD_OK, DOWNLOAD_ERROR, ALREADY_DOWNLOADED, DEPLOY_OK, DEPLOY_ERROR, ALREADY_DEPLOYED, NOTIFIED, NOT_NOTIFIED
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java
new file mode 100644
index 0000000000..169f4f3efa
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+public interface IArtifactInfo {
+
+ /** Artifact File name */
+ String getArtifactName();
+
+ /**
+ * Artifact Type.<br>
+ * Following are valid values : HEAT , DG_XML. <br>
+ * List of values will be extended in post-1510 releases.
+ */
+ ArtifactTypeEnum getArtifactType();
+
+ /**
+ * Relative artifact's URL. Should be used in REST GET API to download the artifact's payload.<br>
+ * The full artifact URL will be in the following format :<br>
+ * https://{serverBaseURL}/{resourcePath}<br>
+ * serverBaseURL - Hostname ( ASDC LB FQDN) + optional port <br>
+ * resourcePath - "artifactURL" <br>
+ * Ex : https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml
+ */
+ String getArtifactURL();
+
+ /**
+ * Base-64 encoded MD5 checksum of the artifact's payload.<br>
+ * Should be used for data integrity validation when an artifact's payload is downloaded.<br>
+ */
+ String getArtifactChecksum();
+
+ /**
+ * Installation timeout. Used by the orchestrator.
+ */
+ Integer getArtifactTimeout();
+
+ /**
+ * Artifact description
+ */
+ String getArtifactDescription();
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java
new file mode 100644
index 0000000000..a27156616b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import fj.data.Either;
+
+public interface IDistributionEngine {
+
+ public boolean isActive();
+
+ public StorageOperationStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envName, String userId, String modifierName);
+
+ public StorageOperationStatus isEnvironmentAvailable(String envName);
+
+ /**
+ * Currently, it used for tests. For real implementation we need cancel the initialization task and the polling task.
+ *
+ * @param envName
+ */
+ public void disableEnvironment(String envName);
+
+ public Either<INotificationData, StorageOperationStatus> isReadyForDistribution(Service service, String distributionId, String envName);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/INotificationData.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/INotificationData.java
new file mode 100644
index 0000000000..48f6c42823
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/INotificationData.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.List;
+
+public interface INotificationData {
+ /**
+ * Global Distribution Identifier: UUID generated by ASDC per each distribution activation.<br>
+ * Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getDistributionID();
+
+ /** Logical Service Name. */
+ String getServiceName();
+
+ /**
+ * Service Version.<br>
+ * Two dot (".") separated digit blocks.<br>
+ * Ex. : "2.0"
+ */
+ String getServiceVersion();
+
+ /**
+ * Global UUID generated by ASDC per each service version. Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex. : AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getServiceUUID();
+
+ /**
+ * Service description
+ */
+ String getServiceDescription();
+
+ /**
+ * ServiceInvariant UUID
+ */
+ String getServiceInvariantUUID();
+
+ /** List of the resource instances */
+ List<JsonContainerResourceInstance> getResources();
+
+ /** List of the artifacts */
+ List<ArtifactInfoImpl> getServiceArtifacts();
+
+ void setDistributionID(String distributionId);
+
+ /** Logical Service Name. */
+ void setServiceName(String serviceName);
+
+ /**
+ * Service Version.<br>
+ * Two dot (".") separated digit blocks.<br>
+ * Ex. : "2.0"
+ */
+ void setServiceVersion(String serviceVersion);
+
+ /**
+ * Global UUID generated by ASDC per each service version. Generated UUID is compliant with RFC 4122.<br>
+ * It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-").<br>
+ * Ex. : AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ void setServiceUUID(String serviceUUID);
+
+ /**
+ * Service Description
+ */
+ void setServiceDescription(String serviceDescription);
+
+ /**
+ * ServiceInvariant UUID
+ */
+ void setServiceInvariantUUID(String serviceInvariantUuid);
+
+ /** List of the Resource Instances */
+ void setResources(List<JsonContainerResourceInstance> resource);
+
+ /** List of the Resource Instances */
+ void setServiceArtifacts(List<ArtifactInfoImpl> artifacts);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IResourceArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IResourceArtifactInfo.java
new file mode 100644
index 0000000000..9a77b9f94f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IResourceArtifactInfo.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public interface IResourceArtifactInfo extends IArtifactInfo {
+
+ /** resource name */
+ String getResourceName();
+
+ /** resource version */
+ String getResourceVersion();
+
+ /**
+ * Global UUID of the resource that specific artifact belongs to.<br>
+ * It is generated by ASDC per each resource version.<br>
+ * Generated UUID is compliant with RFC 4122. It is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen ("-"). <br>
+ * Ex.: AA97B177-9383-4934-8543-0F91A7A02836
+ */
+ String getResourceUUID();
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IServiceArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IServiceArtifactInfo.java
new file mode 100644
index 0000000000..e102f742ac
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IServiceArtifactInfo.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public interface IServiceArtifactInfo extends IArtifactInfo {
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/JsonContainerResourceInstance.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/JsonContainerResourceInstance.java
new file mode 100644
index 0000000000..25a6f46c90
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/JsonContainerResourceInstance.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.List;
+
+import org.openecomp.sdc.be.model.ComponentInstance;
+
+public class JsonContainerResourceInstance {
+ private String resourceInstanceName, resourceName, resourceVersion, resoucreType, resourceUUID, resourceInvariantUUID;
+ private List<ArtifactInfoImpl> artifacts;
+
+ public JsonContainerResourceInstance(ComponentInstance resourceInstance, String resourceType, List<ArtifactInfoImpl> artifacts) {
+ super();
+ this.resourceInstanceName = resourceInstance.getName();
+ this.resourceName = resourceInstance.getComponentName();
+ this.resourceVersion = resourceInstance.getComponentVersion();
+ this.resoucreType = resourceType;
+ this.resourceUUID = resourceInstance.getComponentUid();
+ this.artifacts = artifacts;
+ }
+
+ public JsonContainerResourceInstance(ComponentInstance resourceInstance, String resourceInvariantUUID, String resourceType, List<ArtifactInfoImpl> artifacts) {
+ super();
+ this.resourceInstanceName = resourceInstance.getName();
+ this.resourceName = resourceInstance.getComponentName();
+ this.resourceVersion = resourceInstance.getComponentVersion();
+ this.resoucreType = resourceType;
+ this.resourceUUID = resourceInstance.getComponentUid();
+ this.resourceInvariantUUID = resourceInvariantUUID;
+ this.artifacts = artifacts;
+ }
+
+ public String getResourceInstanceName() {
+ return resourceInstanceName;
+ }
+
+ public void setResourceInstanceName(String resourceInstanceName) {
+ this.resourceInstanceName = resourceInstanceName;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getResoucreType() {
+ return resoucreType;
+ }
+
+ public void setResoucreType(String resoucreType) {
+ this.resoucreType = resoucreType;
+ }
+
+ public String getResourceUUID() {
+ return resourceUUID;
+ }
+
+ public void setResourceUUID(String resourceUUID) {
+ this.resourceUUID = resourceUUID;
+ }
+
+ public List<ArtifactInfoImpl> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactInfoImpl> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ public String getResourceInvariantUUID() {
+ return resourceInvariantUUID;
+ }
+
+ public void setResourceInvariantUUID(String resourceInvariantUUID) {
+ this.resourceInvariantUUID = resourceInvariantUUID;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationDataImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationDataImpl.java
new file mode 100644
index 0000000000..8a2ef8e63b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationDataImpl.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.List;
+
+public class NotificationDataImpl implements INotificationData {
+
+ private String distributionID;
+ private String serviceName;
+ private String serviceVersion;
+ private String serviceUUID;
+ private String serviceDescription;
+ private String serviceInvariantUUID;
+ private List<JsonContainerResourceInstance> resources;
+ private List<ArtifactInfoImpl> serviceArtifacts;
+
+ @Override
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ @Override
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ @Override
+ public String getServiceVersion() {
+ return serviceVersion;
+ }
+
+ @Override
+ public String getServiceUUID() {
+ return serviceUUID;
+ }
+
+ public void setDistributionID(String distributionID) {
+ this.distributionID = distributionID;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public void setServiceVersion(String serviceVersion) {
+ this.serviceVersion = serviceVersion;
+ }
+
+ public void setServiceUUID(String serviceUUID) {
+ this.serviceUUID = serviceUUID;
+ }
+
+ public String getServiceDescription() {
+ return serviceDescription;
+ }
+
+ public void setServiceDescription(String serviceDescription) {
+ this.serviceDescription = serviceDescription;
+ }
+
+ @Override
+ public String toString() {
+ return "NotificationDataImpl [distributionID=" + distributionID + ", serviceName=" + serviceName + ", serviceVersion=" + serviceVersion + ", serviceUUID=" + serviceUUID + ", serviceInvariantUUID=" + serviceInvariantUUID + "]";
+ }
+
+ @Override
+ public List<JsonContainerResourceInstance> getResources() {
+ return resources;
+ }
+
+ @Override
+ public void setResources(List<JsonContainerResourceInstance> resources) {
+ this.resources = resources;
+
+ }
+
+ @Override
+ public List<ArtifactInfoImpl> getServiceArtifacts() {
+ // TODO Auto-generated method stub
+ return serviceArtifacts;
+ }
+
+ @Override
+ public void setServiceArtifacts(List<ArtifactInfoImpl> serviceArtifacts) {
+ this.serviceArtifacts = serviceArtifacts;
+
+ }
+
+ @Override
+ public String getServiceInvariantUUID() {
+ return serviceInvariantUUID;
+ }
+
+ @Override
+ public void setServiceInvariantUUID(String serviceInvariantUUID) {
+ this.serviceInvariantUUID = serviceInvariantUUID;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
new file mode 100644
index 0000000000..74fbb2c660
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+public class NotificationExecutorService {
+
+ private static Logger logger = LoggerFactory.getLogger(NotificationExecutorService.class.getName());
+
+ public ExecutorService createExcecutorService(DistributionNotificationTopicConfig distributionNotificationTopic) {
+
+ Integer minThreadPoolSize = distributionNotificationTopic.getMinThreadPoolSize();
+ if (minThreadPoolSize == null) {
+ minThreadPoolSize = 0;
+ }
+
+ Integer maxThreadPoolSize = distributionNotificationTopic.getMaxThreadPoolSize();
+ if (maxThreadPoolSize == null) {
+ maxThreadPoolSize = 10;
+ }
+
+ ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
+ threadFactoryBuilder.setNameFormat("distribution-notification-thread-%d");
+ ThreadFactory threadFactory = threadFactoryBuilder.build();
+
+ ExecutorService executorService = new ThreadPoolExecutor(minThreadPoolSize, maxThreadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);
+
+ return executorService;
+ }
+
+ public void shutdownAndAwaitTermination(ExecutorService pool, long maxTimeToWait) {
+
+ logger.debug("shutdown NotificationExecutorService");
+ pool.shutdown(); // Disable new tasks from being submitted
+ try {
+ // Wait a while for existing tasks to terminate
+ if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
+ pool.shutdownNow(); // Cancel currently executing tasks
+ // Wait a while for tasks to respond to being cancelled
+ if (!pool.awaitTermination(maxTimeToWait, TimeUnit.SECONDS)) {
+ logger.debug("Failed to close executor service");
+ }
+ }
+ } catch (InterruptedException ie) {
+ // (Re-)Cancel if current thread also interrupted
+ pool.shutdownNow();
+ // Preserve interrupt status
+ Thread.currentThread().interrupt();
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/PublishNotificationRunnable.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/PublishNotificationRunnable.java
new file mode 100644
index 0000000000..362f3948ed
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/PublishNotificationRunnable.java
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PublishNotificationRunnable implements Runnable {
+
+ private String envName;
+ private String distributionId;
+ private Service service;
+ private INotificationData data;
+ private DistributionEngineConfiguration deConfiguration;
+ private String topicName;
+ private CambriaHandler cambriaHandler;
+ private ComponentsUtils componentUtils;
+ private String userId;
+ private String modifierName;
+ private String requestId;
+
+ private static Logger logger = LoggerFactory.getLogger(PublishNotificationRunnable.class.getName());
+
+ public PublishNotificationRunnable(String envName, String distributionId, Service service, INotificationData data, DistributionEngineConfiguration deConfiguration, String topicName, String userId, String modifierName,
+ CambriaHandler cambriaHandler, ComponentsUtils componentUtils, String requestId) {
+ super();
+ this.envName = envName;
+ this.distributionId = distributionId;
+ this.service = service;
+ this.data = data;
+ this.deConfiguration = deConfiguration;
+ this.topicName = topicName;
+ this.cambriaHandler = cambriaHandler;
+ this.componentUtils = componentUtils;
+ this.userId = userId;
+ this.modifierName = modifierName;
+ this.requestId = requestId;
+ }
+
+ public INotificationData getData() {
+ return data;
+ }
+
+ public void setData(INotificationData data) {
+ this.data = data;
+ }
+
+ public DistributionEngineConfiguration getDeConfiguration() {
+ return deConfiguration;
+ }
+
+ public void setDeConfiguration(DistributionEngineConfiguration deConfiguration) {
+ this.deConfiguration = deConfiguration;
+ }
+
+ public String getTopicName() {
+ return topicName;
+ }
+
+ public void setTopicName(String topicName) {
+ this.topicName = topicName;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getModifierName() {
+ return modifierName;
+ }
+
+ public void setModifierName(String modifierName) {
+ this.modifierName = modifierName;
+ }
+
+ @Override
+ public void run() {
+
+ long startTime = System.currentTimeMillis();
+ ThreadLocalsHolder.setUuid(this.requestId);
+
+ CambriaErrorResponse status = cambriaHandler.sendNotificationAndClose(topicName, deConfiguration.getUebPublicKey(), deConfiguration.getUebSecretKey(), deConfiguration.getUebServers(), data,
+ deConfiguration.getDistributionNotificationTopic().getMaxWaitingAfterSendingSeconds().longValue());
+
+ logger.info("After publishing service {} of version {}. Status is {}", service.getName(), service.getVersion(), status.getHttpCode());
+ auditDistributionNotification(topicName, status, service, distributionId, envName, userId, modifierName);
+
+ long endTime = System.currentTimeMillis();
+ logger.debug("After building and publishing artifacts object. Total took {} milliseconds.", (endTime - startTime));
+
+ }
+
+ private void auditDistributionNotification(String topicName, CambriaErrorResponse status, Service service, String distributionId, String envName, String userId, String modifierName) {
+ if (this.componentUtils != null) {
+ Integer httpCode = status.getHttpCode();
+ String httpCodeStr = String.valueOf(httpCode);
+
+ String desc = getDescriptionFromErrorResponse(status);
+
+ this.componentUtils.auditDistributionNotification(AuditingActionEnum.DISTRIBUTION_NOTIFY, service.getUUID(), service.getName(), "Service", service.getVersion(), userId, modifierName, envName, service.getLifecycleState().name(), topicName,
+ distributionId, desc, httpCodeStr);
+ }
+ }
+
+ private String getDescriptionFromErrorResponse(CambriaErrorResponse status) {
+
+ CambriaOperationStatus operationStatus = status.getOperationStatus();
+
+ switch (operationStatus) {
+ case OK:
+ return "OK";
+ case AUTHENTICATION_ERROR:
+ return "Error: Authentication problem towards U-EB server";
+ case INTERNAL_SERVER_ERROR:
+ return "Error: Internal U-EB server error";
+ case UNKNOWN_HOST_ERROR:
+ return "Error: Cannot reach U-EB server host";
+ case CONNNECTION_ERROR:
+ return "Error: Cannot connect to U-EB server";
+ case OBJECT_NOT_FOUND:
+ return "Error: object not found in U-EB server";
+ default:
+ return "Error: Internal Cambria server problem";
+
+ }
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ResourceArtifactInfoImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ResourceArtifactInfoImpl.java
new file mode 100644
index 0000000000..31f3cb6fda
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ResourceArtifactInfoImpl.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public class ResourceArtifactInfoImpl extends ArtifactInfoImpl implements IResourceArtifactInfo {
+
+ private String resourceName;
+ private String resourceVersion;
+ private String resourceUUID;
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getResourceUUID() {
+ return resourceUUID;
+ }
+
+ public void setResourceUUID(String resourceUUID) {
+ this.resourceUUID = resourceUUID;
+ }
+
+ @Override
+ public String toString() {
+ return "ResourceArtifactInfoImpl [resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceUUID=" + resourceUUID + super.toString() + "]";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceArtifactInfoImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceArtifactInfoImpl.java
new file mode 100644
index 0000000000..50d1700f37
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceArtifactInfoImpl.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public class ServiceArtifactInfoImpl extends ArtifactInfoImpl implements IServiceArtifactInfo {
+
+ @Override
+ public String toString() {
+ return "ServiceArtifactInfoImpl [" + super.toString() + "]";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java
new file mode 100644
index 0000000000..da148ee80a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("serviceDistributionArtifactsBuilder")
+public class ServiceDistributionArtifactsBuilder {
+
+ private int defaultArtifactInstallTimeout = 60;
+
+ private static Logger logger = LoggerFactory.getLogger(ServiceDistributionArtifactsBuilder.class.getName());
+
+ final static String BASE_ARTIFACT_URL = "/asdc/v1/catalog/services/%s/%s/";
+ final static String RESOURCE_ARTIFACT_URL = BASE_ARTIFACT_URL + "resources/%s/%s/artifacts/%s";
+ final static String SERVICE_ARTIFACT_URL = BASE_ARTIFACT_URL + "artifacts/%s";
+
+ final static String RESOURCE_INSTANCE_ARTIFACT_URL = BASE_ARTIFACT_URL + "resourceInstances/%s/artifacts/%s";
+
+ @javax.annotation.Resource
+ ServiceOperation serviceOperation;
+
+ @javax.annotation.Resource
+ ResourceOperation resourceOperation;
+
+ @javax.annotation.Resource
+ InterfaceLifecycleOperation interfaceLifecycleOperation;
+
+ @javax.annotation.Resource
+ IArtifactOperation artifactOperation;
+
+ /*
+ * @javax.annotation.Resource private InformationDeployedArtifactsBusinessLogic informationDeployedArtifactsBusinessLogic;
+ */
+
+ @PostConstruct
+ private void init() {
+ defaultArtifactInstallTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
+ }
+
+ public ServiceOperation getServiceOperation() {
+ return serviceOperation;
+ }
+
+ public void setServiceOperation(ServiceOperation serviceOperation) {
+ this.serviceOperation = serviceOperation;
+ }
+
+ public ResourceOperation getResourceOperation() {
+ return resourceOperation;
+ }
+
+ public void setResourceOperation(ResourceOperation resourceOperation) {
+ this.resourceOperation = resourceOperation;
+ }
+
+ public InterfaceLifecycleOperation getInterfaceLifecycleOperation() {
+ return interfaceLifecycleOperation;
+ }
+
+ public void setInterfaceLifecycleOperation(InterfaceLifecycleOperation interfaceLifecycleOperation) {
+ this.interfaceLifecycleOperation = interfaceLifecycleOperation;
+ }
+
+ public INotificationData buildResourceInstanceForDistribution(Service service, String distributionId) {
+ INotificationData notificationData = new NotificationDataImpl();
+
+ notificationData.setResources(convertRIToJsonContanier(service));
+ notificationData.setServiceName(service.getName());
+ notificationData.setServiceVersion(service.getVersion());
+ notificationData.setDistributionID(distributionId);
+ notificationData.setServiceUUID(service.getUUID());
+ notificationData.setServiceDescription(service.getDescription());
+ notificationData.setServiceInvariantUUID(service.getInvariantUUID());
+
+ logger.debug("Before returning notification data object {}", notificationData);
+
+ return notificationData;
+
+ }
+
+ public INotificationData buildServiceForDistribution(INotificationData notificationData, Service service) {
+
+ notificationData.setServiceArtifacts(convertServiceArtifactsToArtifactInfo(service));
+
+ logger.debug("Before returning notification data object {}", notificationData);
+
+ return notificationData;
+
+ }
+
+ private List<ArtifactInfoImpl> convertServiceArtifactsToArtifactInfo(Service service) {
+
+ Map<String, ArtifactDefinition> serviceArtifactsMap = service.getDeploymentArtifacts();
+ List<ArtifactDefinition> ret = new ArrayList<ArtifactDefinition>();
+
+ for (ArtifactDefinition artifactDef : serviceArtifactsMap.values()) {
+ if (artifactDef.checkEsIdExist()) {
+ ret.add(artifactDef);
+ }
+ }
+ List<ArtifactInfoImpl> artifacts = ArtifactInfoImpl.convertServiceArtifactToArtifactInfoImpl(service, ret);
+ return artifacts;
+ }
+
+ private List<JsonContainerResourceInstance> convertRIToJsonContanier(Service service) {
+ List<JsonContainerResourceInstance> ret = new ArrayList<JsonContainerResourceInstance>();
+ if (service.getComponentInstances() != null) {
+ for (ComponentInstance resourceInstance : service.getComponentInstances()) {
+ String resoucreType = "VF";
+ List<ArtifactDefinition> artifactsDefList = getArtifactsWithPayload(resourceInstance);
+ List<ArtifactInfoImpl> artifacts = ArtifactInfoImpl.convertToArtifactInfoImpl(service, resourceInstance, artifactsDefList);
+ Either<String, StorageOperationStatus> responseResult = resourceOperation.getInvariantUUID(NodeTypeEnum.Resource, resourceInstance.getComponentUid(), false);
+ String resourceInvariantUUID = null;
+ if (responseResult.isRight()) {
+ logger.debug("Resource {} Invariant UUID retrieving failed", resourceInstance.getComponentUid());
+ } else {
+ resourceInvariantUUID = responseResult.left().value();
+ }
+ JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(resourceInstance, resourceInvariantUUID, resoucreType, artifacts);
+ ret.add(jsonContainer);
+ }
+
+ }
+ return ret;
+ }
+
+ private List<ArtifactDefinition> getArtifactsWithPayload(ComponentInstance resourceInstance) {
+ List<ArtifactDefinition> ret = new ArrayList<ArtifactDefinition>();
+
+ // List<ArtifactDefinition> informationDeployedArtifacts =
+ // informationDeployedArtifactsBusinessLogic.getInformationalDeployedArtifactsForResourceInstance(resourceInstance);
+ List<ArtifactDefinition> deployableArtifacts = new ArrayList<ArtifactDefinition>();
+ // deployableArtifacts.addAll(informationDeployedArtifacts);
+ if (resourceInstance.getDeploymentArtifacts() != null) {
+ deployableArtifacts.addAll(resourceInstance.getDeploymentArtifacts().values());
+ }
+
+ for (ArtifactDefinition artifactDef : deployableArtifacts) {
+ if (artifactDef.checkEsIdExist()) {
+ ret.add(artifactDef);
+ }
+ }
+
+ return ret;
+ }
+
+ /**
+ * build the url for resource intance artifact
+ *
+ * @param service
+ * @param resourceData
+ * @param artifactName
+ * @return
+ */
+ public static String buildResourceInstanceArtifactUrl(Service service, ComponentInstance resourceInstance, String artifactName) {
+
+ String url = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, service.getSystemName(), service.getVersion(), resourceInstance.getNormalizedName(), artifactName);
+
+ logger.debug("After building artifact url {}", url);
+
+ return url;
+ }
+
+ /**
+ * build the url for resource intance artifact
+ *
+ * @param service
+ * @param resourceData
+ * @param artifactName
+ * @return
+ */
+ public static String buildServiceArtifactUrl(Service service, String artifactName) {
+
+ String url = String.format(SERVICE_ARTIFACT_URL, service.getSystemName(), service.getVersion(), artifactName);
+
+ logger.debug("After building artifact url {}", url);
+
+ return url;
+
+ }
+
+ /**
+ * Retrieve all deployment artifacts of all resources under a given service
+ *
+ * @param resourceArtifactsResult
+ * @param service
+ * @param deConfiguration
+ * @return
+ */
+ public Either<Boolean, StorageOperationStatus> isServiceContainsDeploymentArtifacts(Service service) {
+
+ Either<Boolean, StorageOperationStatus> result = Either.left(false);
+ Map<String, ArtifactDefinition> serviseArtifactsMap = service.getDeploymentArtifacts();
+ if (serviseArtifactsMap != null && !serviseArtifactsMap.isEmpty()) {
+ result = Either.left(true);
+ return result;
+ }
+
+ List<ComponentInstance> resourceInstances = service.getComponentInstances();
+
+ if (resourceInstances != null) {
+ for (ComponentInstance resourceInstance : resourceInstances) {
+
+ Map<String, ArtifactDefinition> deploymentArtifactsMapper = resourceInstance.getDeploymentArtifacts();
+ // List<ArtifactDefinition> informationDeployedArtifacts =
+ // informationDeployedArtifactsBusinessLogic.getInformationalDeployedArtifactsForResourceInstance(resourceInstance);
+
+ boolean isDeployableArtifactFound = isContainsPayload(deploymentArtifactsMapper.values());// ||
+ // isContainsPayload(informationDeployedArtifacts);
+ if (isDeployableArtifactFound) {
+ result = Either.left(true);
+ break;
+ }
+
+ }
+
+ }
+
+ return result;
+ }
+
+ private boolean isContainsPayload(Collection<ArtifactDefinition> collection) {
+ boolean payLoadFound = collection != null && collection.stream().anyMatch(p -> p.checkEsIdExist());
+ return payLoadFound;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/SubscriberTypeEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/SubscriberTypeEnum.java
new file mode 100644
index 0000000000..f8c0e3f593
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/SubscriberTypeEnum.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+public enum SubscriberTypeEnum {
+
+ CONSUMER, PRODUCER;
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/TestQueue.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/TestQueue.java
new file mode 100644
index 0000000000..c9e3c4e34d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/TestQueue.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+public class TestQueue {
+
+ public static void main(String[] args) {
+ ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder();
+ threadFactoryBuilder.setNameFormat("distribution-notification-thread");
+ ThreadFactory threadFactory = threadFactoryBuilder.build();
+ // TODO: add the package of google to the pom
+
+ ExecutorService executorService = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);
+ // ExecutorService executorService = new ThreadPoolExecutor(0, 2, 60L,
+ // TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(20));
+
+ // 2 threads are always up and they handle the tasks. in case core size
+ // is 0, only one is handles the tasks.
+ // ExecutorService executorService = new ThreadPoolExecutor(0, 2, 60L,
+ // TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(20));
+
+ // TODO : check what happen when the number of threads are full. Throw
+ // RejectedExecutionException
+ // TODO : check what happen whether the pool is full and the size of
+ // pool
+
+ ExecutorService newCachedThreadPool = Executors.newCachedThreadPool(threadFactory);
+ Runnable task = new Runnable() {
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ try {
+ System.out.println("iN SLEEP" + Thread.currentThread());
+ Thread.sleep(10 * 1000);
+ System.out.println("OUT SLEEP");
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ };
+
+ for (int i = 0; i < 4; i++) {
+ try {
+ executorService.submit(task);
+ } catch (RejectedExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ newCachedThreadPool.submit(task);
+ System.out.println("After submitting the task");
+
+ MyWorker[] watchThreads = new MyWorker[1];
+ BlockingQueue<String> queue = new ArrayBlockingQueue<>(5);
+ for (int i = 0; i < watchThreads.length; i++) {
+ MyWorker myWorker = new MyWorker(queue);
+ myWorker.start();
+ }
+
+ for (int i = 0; i < 1; i++) {
+ try {
+ queue.put("message " + i);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ public static class MyTimerTask extends TimerTask {
+
+ AtomicBoolean state;
+ Thread thread;
+
+ public MyTimerTask(AtomicBoolean state, Thread thread) {
+ super();
+ this.state = state;
+ this.thread = thread;
+
+ System.out.println("After create timer");
+ }
+
+ @Override
+ public void run() {
+ System.out.println("In running of Timer task");
+ if (state.get() == false) {
+ System.out.println("In running of Timer task. Going to interrupt thread");
+ // thread.interrupt();
+ } else {
+ System.out.println("In running of Timer task. Finished.");
+ }
+ }
+
+ }
+
+ public static class MyWorker extends Thread {
+
+ boolean active = true;
+ private final BlockingQueue<String> queue;
+
+ public MyWorker(BlockingQueue<String> queue) {
+ this.queue = queue;
+ }
+
+ Timer timer = new Timer();
+
+ public void run() {
+ try {
+ while (active) {
+ String s = queue.take();
+ System.out.println("Thread " + Thread.currentThread() + " fecthed a message " + s);
+
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ MyTimerTask myTimerTask = new MyTimerTask(atomicBoolean, this);
+ timer.schedule(myTimerTask, 10 * 1000);
+ doWork(s);
+ atomicBoolean.set(true);
+
+ }
+ } catch (InterruptedException ie) {
+
+ System.out.println("Interrupted our thread");
+ ie.printStackTrace();
+ }
+ }
+
+ private void doWork(String s) {
+ // TODO Auto-generated method stub
+
+ CambriaHandler cambriaHandler = new CambriaHandler();
+ INotificationData data = new NotificationDataImpl();
+ List<String> servers = new ArrayList<>();
+ servers.add("aaaaaaa");
+ cambriaHandler.sendNotification("topicName", "uebPublicKey", "uebSecretKey", servers, data);
+
+ System.out.println("IN WORK " + s);
+ try {
+ Thread.sleep(1 * 1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+
+ for (int i = 0; i < 10; i++) {
+ System.out.println("*************************************************");
+ }
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java
new file mode 100644
index 0000000000..c522ca91b5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UebHealthCheckCall implements Callable<Boolean> {
+
+ CambriaHandler cambriaHandler = new CambriaHandler();
+
+ String server;
+ String publicApiKey;
+
+ private static Logger healthLogger = LoggerFactory.getLogger(DistributionEngineClusterHealth.UEB_HEALTH_LOG_CONTEXT);
+
+ private static Logger logger = LoggerFactory.getLogger(UebHealthCheckCall.class.getName());
+
+ public UebHealthCheckCall(String server, String publicApiKey) {
+ super();
+ this.server = server;
+ this.publicApiKey = publicApiKey;
+ }
+
+ @Override
+ public Boolean call() {
+
+ healthLogger.trace("Going to run health check towards ueb server {}", server);
+
+ boolean result = false;
+ CambriaErrorResponse cambriaErrorResponse = cambriaHandler.getApiKey(server, publicApiKey);
+
+ logger.debug("After running Health check towards ueb server {}. Result is {}", server, cambriaErrorResponse);
+
+ if (cambriaErrorResponse.httpCode < CambriaErrorResponse.HTTP_INTERNAL_SERVER_ERROR) {
+ logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to true", server, cambriaErrorResponse.httpCode);
+ result = true;
+ }
+
+ healthLogger.trace("Result after running health check towards ueb server {} is {}. Returned result is {} ", server, cambriaErrorResponse, result);
+
+ return result;
+ }
+
+ public String getServer() {
+ return server;
+ }
+
+ public CambriaHandler getCambriaHandler() {
+ return cambriaHandler;
+ }
+
+ public void setCambriaHandler(CambriaHandler cambriaHandler) {
+ this.cambriaHandler = cambriaHandler;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java
new file mode 100644
index 0000000000..89cb6d91ee
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.common.api.Constants;
+
+public class VfModuleArtifactPayload {
+ public VfModuleArtifactPayload(GroupDefinition group) {
+ vfModuleModelName = group.getName();
+ vfModuleModelInvariantUUID = group.getInvariantUUID();
+ vfModuleModelVersion = group.getVersion();
+ vfModuleModelUUID = group.getGroupUUID();
+ vfModuleModelDescription = group.getDescription();
+
+ artifacts = group.getArtifactsUuid();
+ // Base Value is set from properties
+ setBaseValue(group);
+
+ }
+
+ private void setBaseValue(GroupDefinition group) {
+ if (group.getProperties() != null) {
+ Optional<GroupProperty> findBaseProperty = group.getProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
+ if (findBaseProperty.isPresent()) {
+ isBase = Boolean.valueOf(findBaseProperty.get().getValue());
+ }
+
+ }
+ }
+
+ private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelDescription;
+ private Boolean isBase;
+ private List<String> artifacts;
+
+ public List<String> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<String> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
+ Integer thisCounter = Integer.parseInt(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1]);
+ Integer otherCounter = Integer.parseInt(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1]);
+ return thisCounter.compareTo(otherCounter);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
new file mode 100644
index 0000000000..e01d4c238c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
@@ -0,0 +1,573 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.AdditionalInfoParameterInfo;
+import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.model.tosca.converters.StringConvertor;
+import org.openecomp.sdc.be.model.tosca.validators.StringValidator;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.WebApplicationContext;
+
+import fj.data.Either;
+
+@Component("additionalInformationBusinessLogic")
+public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
+
+ private static final String CREATE_ADDITIONAL_INFORMATION = "CreateAdditionalInformation";
+
+ private static final String UPDATE_ADDITIONAL_INFORMATION = "UpdateAdditionalInformation";
+
+ private static final String DELETE_ADDITIONAL_INFORMATION = "DeleteAdditionalInformation";
+
+ private static final String GET_ADDITIONAL_INFORMATION = "GetAdditionalInformation";
+
+ private static Logger log = LoggerFactory.getLogger(AdditionalInformationBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private IAdditionalInformationOperation additionalInformationOperation = null;
+
+ @javax.annotation.Resource
+ private IResourceOperation resourceOperation;
+
+ @javax.annotation.Resource
+ private IServiceOperation serviceOperation;
+
+ @javax.annotation.Resource
+ private IGraphLockOperation graphLockOperation;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+
+ return webApplicationContext.getBean(class1);
+ }
+
+ /**
+ * Create new additional information on resource/service on graph
+ *
+ * @param resourceId
+ * @param propertyName
+ * @param newPropertyDefinition
+ * @param userId
+ * @return Either<PropertyDefinition, ActionStatus>
+ */
+ public Either<AdditionalInfoParameterInfo, ResponseFormat> createAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Additional Information", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
+
+ ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ // lock component
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, CREATE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
+ log.info("Failed to lock component {} error - {}", resourceId, lockResult);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+ try {
+ responseFormat = validateMaxSizeNotReached(nodeType, resourceId, additionalInfoParameterInfo);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ // validate label
+ responseFormat = validateAndConvertKey(additionalInfoParameterInfo, CREATE_ADDITIONAL_INFORMATION);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ // validate value
+ responseFormat = validateAndConvertValue(additionalInfoParameterInfo, CREATE_ADDITIONAL_INFORMATION);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.createAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getKey(),
+ additionalInfoParameterInfo.getValue(), true);
+
+ if (addResult.isRight()) {
+ StorageOperationStatus status = addResult.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, CREATE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeSystemError(CREATE_ADDITIONAL_INFORMATION);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.Label));
+ return result;
+
+ } else {
+ AdditionalInformationDefinition informationDefinition = addResult.left().value();
+
+ AdditionalInfoParameterInfo createdAI = findAdditionInformationKey(informationDefinition.getParameters(), additionalInfoParameterInfo.getKey());
+ result = Either.left(createdAI);
+ return result;
+ }
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, nodeType);
+ }
+
+ }
+
+ /**
+ * Validate the value format. Format the value.
+ *
+ * @param additionalInfoParameterInfo
+ * @return null in case of success. Otherwise response format.
+ */
+ private ResponseFormat validateAndConvertValue(AdditionalInfoParameterInfo additionalInfoParameterInfo, String context) {
+ ResponseFormat result = null;
+
+ String value = additionalInfoParameterInfo.getValue();
+ log.debug("Going to validate additional information value {}", value);
+
+ Either<String, ResponseFormat> valueValidRes = validateValue(value);
+ if (valueValidRes.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidValueError, context, additionalInfoParameterInfo.getValue(), "additional information value", "string");
+ BeEcompErrorManager.getInstance().logBeInvalidValueError(context, additionalInfoParameterInfo.getValue(), "additional information value", "string");
+ result = valueValidRes.right().value();
+ } else {
+ String newValue = valueValidRes.left().value();
+ if (log.isTraceEnabled()) {
+ if (value != null && false == value.equals(newValue)) {
+ log.trace("The additional information value was normalized from {} to {}", value, newValue);
+ }
+ }
+ additionalInfoParameterInfo.setValue(newValue);
+ }
+ return result;
+ }
+
+ /**
+ * @param additionalInfoParameterInfo
+ * @return
+ */
+ private ResponseFormat validateAndConvertKey(AdditionalInfoParameterInfo additionalInfoParameterInfo, String context) {
+
+ String key = additionalInfoParameterInfo.getKey();
+ log.debug("Going to validate additional information key {}", key);
+
+ ResponseFormat result = null;
+ ResponseFormat responseFormat;
+ Either<String, ResponseFormat> validateKeyRes = validateAndNormalizeKey(key);
+ if (validateKeyRes.isRight()) {
+ responseFormat = validateKeyRes.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidValueError, context, additionalInfoParameterInfo.getKey(), "additional information label", "string");
+ BeEcompErrorManager.getInstance().logBeInvalidValueError(context, additionalInfoParameterInfo.getKey(), "additional information label", "string");
+ result = responseFormat;
+
+ } else {
+ String convertedKey = validateKeyRes.left().value();
+
+ if (log.isTraceEnabled()) {
+ if (key != null && false == key.equals(convertedKey)) {
+ log.trace("The additional information key {} was normalized to {}", key, convertedKey);
+ }
+ }
+ additionalInfoParameterInfo.setKey(convertedKey);
+ }
+ return result;
+ }
+
+ /**
+ * verify that the maximal number of additional information properties has not been reached.
+ *
+ * @param nodeType
+ * @param componentId
+ * @param additionalInfoParameterInfo
+ * @return response format in case the maximal number has been reached.
+ */
+ private ResponseFormat validateMaxSizeNotReached(NodeTypeEnum nodeType, String componentId, AdditionalInfoParameterInfo additionalInfoParameterInfo) {
+
+ ResponseFormat result;
+ Integer additionalInformationMaxNumberOfKeys = ConfigurationManager.getConfigurationManager().getConfiguration().getAdditionalInformationMaxNumberOfKeys();
+
+ Either<Integer, StorageOperationStatus> checkRes = additionalInformationOperation.getNumberOfAdditionalInformationParameters(nodeType, componentId, true);
+ if (checkRes.isRight()) {
+ StorageOperationStatus status = checkRes.right().value();
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None);
+ return result;
+ }
+ Integer currentNumberOfProperties = checkRes.left().value();
+ if (currentNumberOfProperties >= additionalInformationMaxNumberOfKeys) {
+ log.info("The current number of additional information properties is {}. The maximum allowed additional information properties is {}", currentNumberOfProperties, currentNumberOfProperties);
+ result = componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None);
+ return result;
+ }
+
+ return null;
+ }
+
+ /**
+ * validate additional information value
+ *
+ * @param value
+ * @return
+ */
+ private Either<String, ResponseFormat> validateValue(String value) {
+
+ boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(value);
+ if (false == isNonEmptyString) {
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED));
+ }
+
+ boolean valid = StringValidator.getInstance().isValid(value, null);
+ if (false == valid) {
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, new AdditionalInfoParameterInfo(null, value), null, AdditionalInformationEnum.Value));
+ }
+
+ String converted = StringConvertor.getInstance().convert(value, null, null);
+
+ return Either.left(converted);
+ }
+
+ private AdditionalInfoParameterInfo findAdditionInformationKey(List<AdditionalInfoParameterInfo> parameters, String key) {
+
+ for (AdditionalInfoParameterInfo infoParameterInfo : parameters) {
+ if (infoParameterInfo.getKey().equals(key)) {
+ return infoParameterInfo;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * validate and normalize the key
+ *
+ * @param additionalInfoParameterInfo
+ * @return
+ */
+ private Either<String, ResponseFormat> validateAndNormalizeKey(String key) {
+
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ additionalInfoParameterInfo.setKey(key);
+
+ key = ValidationUtils.normalizeAdditionalInformation(key);
+ boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(key);
+ if (false == isNonEmptyString) {
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, null, null, AdditionalInformationEnum.Label));
+ }
+ boolean isValidString = ValidationUtils.validateAdditionalInformationKeyName(key);
+ if (false == isValidString) {
+ if (false == ValidationUtils.validateLength(key, ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH)) {
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, null, AdditionalInformationEnum.Label));
+ }
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, null, AdditionalInformationEnum.Label));
+ }
+
+ return Either.left(key);
+ }
+
+ /**
+ * update key and value of a given additional information.
+ *
+ * @param nodeType
+ * @param resourceId
+ * @param additionalInfoParameterInfo
+ * @param additionalInformationUid
+ * - Future use
+ * @param userId
+ * @return
+ */
+ public Either<AdditionalInfoParameterInfo, ResponseFormat> updateAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Additional Information", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
+
+ ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+ // lock component
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, UPDATE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(UPDATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
+ log.info("Failed to lock component {} error - {}", resourceId, lockResult);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+ try {
+
+ // validate input
+ responseFormat = validateAndConvertKey(additionalInfoParameterInfo, UPDATE_ADDITIONAL_INFORMATION);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ responseFormat = validateAndConvertValue(additionalInfoParameterInfo, UPDATE_ADDITIONAL_INFORMATION);
+ if (responseFormat != null) {
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.updateAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(),
+ additionalInfoParameterInfo.getKey(), additionalInfoParameterInfo.getValue(), true);
+
+ if (addResult.isRight()) {
+ StorageOperationStatus status = addResult.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, UPDATE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeSystemError(UPDATE_ADDITIONAL_INFORMATION);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
+ return result;
+ } else {
+ AdditionalInformationDefinition informationDefinition = addResult.left().value();
+ AdditionalInfoParameterInfo parameterInfo = findAdditionInformationKey(informationDefinition.getParameters(), additionalInfoParameterInfo.getKey());
+ result = Either.left(parameterInfo);
+ return result;
+ }
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, nodeType);
+ }
+
+ }
+
+ /**
+ * Delete an additional information label
+ *
+ * @param nodeType
+ * @param resourceId
+ * @param additionalInfoParameterInfo
+ * @param additionalInformationUid
+ * - Null. Future use.
+ * @param userId
+ * @return
+ */
+ public Either<AdditionalInfoParameterInfo, ResponseFormat> deleteAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Additional Information", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
+
+ ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
+ if (responseFormat != null) {
+ return Either.right(responseFormat);
+ }
+ // lock component
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, DELETE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(DELETE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
+ log.info("Failed to lock component {} error - {}", resourceId, lockResult);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+
+ try {
+
+ Either<AdditionalInfoParameterInfo, StorageOperationStatus> findIdRes = additionalInformationOperation.getAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
+ if (findIdRes.isRight()) {
+ StorageOperationStatus status = findIdRes.right().value();
+ if (status != StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, GET_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeSystemError(GET_ADDITIONAL_INFORMATION);
+ }
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
+ return result;
+ }
+
+ AdditionalInfoParameterInfo foundAdditionalInfo = findIdRes.left().value();
+
+ Either<AdditionalInformationDefinition, StorageOperationStatus> addResult = additionalInformationOperation.deleteAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
+
+ if (addResult.isRight()) {
+ StorageOperationStatus status = addResult.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, DELETE_ADDITIONAL_INFORMATION);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(DELETE_ADDITIONAL_INFORMATION);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
+ return result;
+ } else {
+ result = Either.left(foundAdditionalInfo);
+ return result;
+ }
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, nodeType);
+ }
+
+ }
+
+ /**
+ * @param nodeType
+ * @param resourceId
+ * @param additionalInfoParameterInfo
+ * @param additionalInformationUid
+ * @param userId
+ * @return
+ */
+ public Either<AdditionalInfoParameterInfo, ResponseFormat> getAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String additionalInformationUid, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Additional Information", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
+
+ try {
+
+ Either<AdditionalInfoParameterInfo, StorageOperationStatus> findIdRes = additionalInformationOperation.getAdditionalInformationParameter(nodeType, resourceId, additionalInfoParameterInfo.getUniqueId(), true);
+
+ if (findIdRes.isRight()) {
+ StorageOperationStatus status = findIdRes.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, AdditionalInformationEnum.None));
+ }
+
+ AdditionalInfoParameterInfo foundAdditionalInfo = findIdRes.left().value();
+
+ result = Either.left(foundAdditionalInfo);
+
+ return result;
+
+ } finally {
+ commitOrRollback(result);
+ }
+
+ }
+
+ /**
+ * Get all additional information properties of a given resource/service
+ *
+ * @param nodeType
+ * @param resourceId
+ * @param additionalInformationUid
+ * - Future use
+ * @param userId
+ * @return
+ */
+ public Either<AdditionalInformationDefinition, ResponseFormat> getAllAdditionalInformation(NodeTypeEnum nodeType, String resourceId, String additionalInformationUid, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get All Additional Information", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<AdditionalInformationDefinition, ResponseFormat> result = null;
+
+ try {
+
+ Either<AdditionalInformationDefinition, TitanOperationStatus> findIdRes = additionalInformationOperation.getAllAdditionalInformationParameters(nodeType, resourceId, false);
+ if (findIdRes.isRight()) {
+ StorageOperationStatus status = DaoStatusConverter.convertTitanStatusToStorageStatus(findIdRes.right().value());
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForAdditionalInformation(status);
+ result = Either.right(componentsUtils.getResponseFormatAdditionalProperty(actionStatus));
+ } else {
+ AdditionalInformationDefinition informationDefinition = findIdRes.left().value();
+ result = Either.left(informationDefinition);
+ }
+
+ return result;
+
+ } finally {
+ commitOrRollback(result);
+ }
+
+ }
+
+ private ResponseFormat verifyCanWorkOnComponent(NodeTypeEnum nodeType, String resourceId, String userId) {
+
+ switch (nodeType) {
+ case Resource:
+
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnResource(resourceId, resourceOperation, userId)) {
+ return componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ }
+ break;
+ case Service:
+
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnService(resourceId, serviceOperation, userId)) {
+ return componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ }
+ break;
+ default:
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT, nodeType.getName());
+ }
+
+ return null;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
new file mode 100644
index 0000000000..16ed4a1868
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -0,0 +1,4127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration.DeploymentArtifactTypeConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.validation.DeploymentArtifactHeatConfiguration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.heat.HeatParameterType;
+import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
+import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IHeatParametersOperation;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.resources.data.ArtifactData;
+import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.be.tosca.CsarUtils;
+import org.openecomp.sdc.be.tosca.ToscaError;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.tosca.ToscaRepresentation;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.yaml.snakeyaml.Yaml;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.sun.org.apache.xerces.internal.parsers.SAXParser;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("artifactBusinessLogic")
+public class ArtifactsBusinessLogic extends BaseBusinessLogic {
+ private static final String ARTIFACT_TYPE_OTHER = "OTHER";
+ private static final String ARTIFACT_DESCRIPTION = "artifact description";
+ private static final String ARTIFACT_LABEL = "artifact label";
+ private static final String ARTIFACT_URL = "artifact url";
+ private static final String ARTIFACT_NAME = "artifact name";
+ private static final String ARTIFACT_PAYLOAD = "artifact payload";
+
+ private static final String ARTIFACT_PLACEHOLDER_TYPE = "type";
+ private static final String ARTIFACT_PLACEHOLDER_DISPLAY_NAME = "displayName";
+ private static final Object ARTIFACT_PLACEHOLDER_DESCRIPTION = "description";
+
+ private static Integer defaultHeatTimeout;
+ private static final Integer NON_HEAT_TIMEOUT = 0;
+ private static Logger log = LoggerFactory.getLogger(ArtifactsBusinessLogic.class.getName());
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ @javax.annotation.Resource
+ private IArtifactOperation artifactOperation;
+
+ // @javax.annotation.Resource
+ // private IResourceUploader daoUploader;
+
+ @javax.annotation.Resource
+ private IInterfaceLifecycleOperation interfaceLifecycleOperation;
+ @javax.annotation.Resource
+ private IUserAdminOperation userOperaton;
+
+ // @javax.annotation.Resource
+ // private ESCatalogDAO esCatalogDao;
+
+ @javax.annotation.Resource
+ private IElementOperation elementOperation;
+
+ @javax.annotation.Resource
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @javax.annotation.Resource
+ private ServiceBusinessLogic serviceBusinessLogic;
+
+ @javax.annotation.Resource
+ private UserBusinessLogic userAdminManager;
+
+ @javax.annotation.Resource
+ private IHeatParametersOperation heatParametersOperation;
+
+ @javax.annotation.Resource
+ private IComponentInstanceOperation resourceInstanceOperation;
+
+ @Autowired
+ private ArtifactCassandraDao artifactCassandraDao;
+
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+
+ @Autowired
+ private CsarUtils csarUtils;
+
+ @Autowired
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
+
+ @Autowired
+ private IUserBusinessLogic userBusinessLogic;
+
+ public ArtifactsBusinessLogic() {
+ defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
+ if ((defaultHeatTimeout == null) || (defaultHeatTimeout < 1)) {
+ defaultHeatTimeout = 60;
+ }
+ }
+
+ public static enum ArtifactOperation {
+
+ Create(false), Update(false), Delete(false), Download(false);
+
+ private boolean isExternalApi;
+
+ ArtifactOperation(boolean isExternalApi) {
+ this.isExternalApi = isExternalApi;
+ }
+
+ public boolean isExternalApi() {
+ return isExternalApi;
+ }
+
+ public void setExternalApi(boolean isExternalApi) {
+ this.isExternalApi = isExternalApi;
+ }
+ }
+
+ // new flow US556184
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperation operation, String artifactId, ArtifactDefinition artifactInfo,
+ String origMd5, String originData, String interfaceName, String operationName, String parentId, String containerComponentType) {
+ return handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, originData, interfaceName, operationName, parentId, containerComponentType, true, false);
+ }
+
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperation operation, String artifactId, ArtifactDefinition artifactInfo,
+ String origMd5, String originData, String interfaceName, String operationName, String parentId, String containerComponentType, boolean shouldLock, boolean inTransaction) {
+ // step 1
+ // detect auditing type
+ AuditingActionEnum auditingAction = detectAuditingType(operation, origMd5);
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ // step 2
+ // check header
+ if (userId == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ log.debug("handleArtifactRequest - no HTTP_CSP_HEADER , component id {}", componentId);
+ handleAuditing(auditingAction, null, componentId, null, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ // step 3
+ // check user existence
+ // step 4
+ // check user's role
+ Either<User, ResponseFormat> userResult = validateUserExists(userId, auditingAction, componentId, artifactId, componentType, inTransaction);
+ if (userResult.isRight()) {
+ return Either.right(userResult.right().value());
+ }
+
+ User user = userResult.left().value();
+ Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, auditingAction, componentId, artifactId, componentType, operation);
+ if (validateUserRole.isRight()) {
+ return Either.right(validateUserRole.right().value());
+ }
+
+ // steps 5 - 6 - 7
+ // 5. check service/resource existence
+ // 6. check service/resource check out
+ // 7. user is owner of checkout state
+ org.openecomp.sdc.be.model.Component component = null;
+ // ComponentInstance resourceInstance = null;
+ String realComponentId = componentType == ComponentTypeEnum.RESOURCE_INSTANCE ? parentId : componentId;
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(realComponentId, userId, auditingAction, user, artifactId, componentType, containerComponentType, inTransaction);
+ if (validateComponent.isRight()) {
+ return Either.right(validateComponent.right().value());
+ }
+ component = validateComponent.left().value();
+ Either<Boolean, ResponseFormat> validateWorkOnResource = validateWorkOnComponent(component, userId, auditingAction, user, artifactId, operation, componentType);
+ if (validateWorkOnResource.isRight()) {
+ return Either.right(validateWorkOnResource.right().value());
+ }
+ // step 8
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result = validateAndHandleArtifact(componentId, componentType, operation, artifactId, artifactInfo, origMd5, originData, interfaceName, operationName, parentId, user, component,
+ shouldLock, inTransaction);
+
+ return result;
+ }
+
+ /**
+ * This Method validates only the Artifact and does not validate user / role / component ect...<br>
+ * For regular usage use <br>
+ * {@link #handleArtifactRequest(String, String, ComponentTypeEnum, ArtifactOperation, String, ArtifactDefinition, String, String, String, String, String, String)}
+ *
+ * @return
+ */
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> validateAndHandleArtifact(String componentUniqueId, ComponentTypeEnum componentType, ArtifactOperation operation, String artifactUniqueId, ArtifactDefinition artifactDefinition,
+ String origMd5, String originData, String interfaceName, String operationName, String parentId, User user, Component component, boolean shouldLock, boolean inTransaction) {
+ Component parent = component;
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+
+ AuditingActionEnum auditingAction = detectAuditingType(operation, origMd5);
+ artifactDefinition = validateArtifact(componentUniqueId, componentType, operation, artifactUniqueId, artifactDefinition, parentId, auditingAction, user, component, parent, shouldLock, errorWrapper);
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result;
+ if (errorWrapper.isEmpty()) {
+ // step 10
+ result = doAction(componentUniqueId, componentType, operation, artifactUniqueId, artifactDefinition, origMd5, originData, interfaceName, operationName, auditingAction, user, parent, shouldLock, inTransaction);
+ } else {
+ result = Either.right(errorWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ private ArtifactDefinition validateArtifact(String componentId, ComponentTypeEnum componentType, ArtifactOperation operation, String artifactId, ArtifactDefinition artifactInfo, String parentId, AuditingActionEnum auditingAction, User user,
+ org.openecomp.sdc.be.model.Component component, org.openecomp.sdc.be.model.Component parent, boolean shouldLock, Wrapper<ResponseFormat> errorWrapper) {
+ if (operation == ArtifactOperation.Update || operation == ArtifactOperation.Delete || operation == ArtifactOperation.Download) {
+ Either<ArtifactDefinition, ResponseFormat> validateArtifact = validateArtifact(componentId, componentType, artifactId, component, auditingAction, parentId);
+ if (validateArtifact.isRight()) {
+ ResponseFormat responseFormat = validateArtifact.right().value();
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ errorWrapper.setInnerElement(validateArtifact.right().value());
+ } else if (operation == ArtifactOperation.Download) {
+ artifactInfo = validateArtifact.left().value();
+ handleHeatEnvDownload(componentId, user, component, validateArtifact, shouldLock, errorWrapper);
+ }
+ }
+ return artifactInfo;
+ }
+
+ private void handleHeatEnvDownload(String componentId, User user, org.openecomp.sdc.be.model.Component component, Either<ArtifactDefinition, ResponseFormat> validateArtifact, boolean shouldLock, Wrapper<ResponseFormat> errorWrapper) {
+ ArtifactDefinition validatedArtifact = validateArtifact.left().value();
+
+ if (validatedArtifact.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())) {
+ ComponentInstance componentInstance = component.getComponentInstances().stream().filter(p -> p.getUniqueId().equals(componentId)).findAny().get();
+ ArtifactDefinition heatEnvWithHeatParams = componentInstance.getDeploymentArtifacts().values().stream().filter(p -> p.getUniqueId().equals(validatedArtifact.getUniqueId())).findAny().get();
+ Either<ArtifactDefinition, ResponseFormat> eitherGenerated = generateHeatEnvArtifact(heatEnvWithHeatParams, component, componentInstance.getName(), user, shouldLock);
+ if (eitherGenerated.isRight()) {
+ errorWrapper.setInnerElement(eitherGenerated.right().value());
+ }
+ }
+ }
+
+ private boolean artifactGenerationRequired(org.openecomp.sdc.be.model.Component component, ArtifactDefinition artifactInfo) {
+ return artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA && (component.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || component.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateAndSaveToscaArtifact(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest,
+ boolean shouldLock, boolean inTransaction, boolean fetchTemplatesFromDB) {
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generated = generateToscaArtifact(component, artifactDefinition, isInCertificationRequest, fetchTemplatesFromDB, shouldLock, inTransaction);
+ if (generated.isRight()) {
+ return generated;
+ }
+ byte[] decodedPayload = artifactDefinition.getPayloadData();
+ artifactDefinition.setEsId(artifactDefinition.getUniqueId());
+ artifactDefinition.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(decodedPayload));
+ return lockComponentAndUpdateArtifact(component.getUniqueId(), artifactDefinition, AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, artifactDefinition.getUniqueId(), user, component.getComponentType(), component, decodedPayload, null, null,
+ shouldLock, inTransaction);
+
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateToscaArtifact(Component parent, ArtifactDefinition artifactInfo, boolean isInCertificationRequest, boolean fetchTemplatesFromDB, boolean shouldLock,
+ boolean inTransaction) {
+ log.debug("tosca artifact generation");
+ if (artifactInfo.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())) {
+ Either<byte[], ResponseFormat> generated = csarUtils.createCsar(parent, fetchTemplatesFromDB, isInCertificationRequest, shouldLock, inTransaction);
+
+ if (generated.isRight()) {
+ log.debug("Failed to export tosca csar for component {} error {}", parent.getUniqueId(), generated.right().value());
+
+ return Either.right(generated.right().value());
+ }
+ byte[] value = generated.left().value();
+ artifactInfo.setPayload(value);
+
+ } else {
+ Either<ToscaRepresentation, ToscaError> exportComponent = toscaExportUtils.exportComponent(parent);
+ if (exportComponent.isRight()) {
+ log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), exportComponent.right().value());
+ ActionStatus status = componentsUtils.convertFromToscaError(exportComponent.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(status);
+ return Either.right(responseFormat);
+ }
+ log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
+ String payload = exportComponent.left().value().getMainYaml();
+ artifactInfo.setPayloadData(payload);
+ }
+ return Either.left(Either.left(artifactInfo));
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> doAction(String componentId, ComponentTypeEnum componentType, ArtifactOperation operation, String artifactId, ArtifactDefinition artifactInfo, String origMd5,
+ String originData, String interfaceName, String operationName, AuditingActionEnum auditingAction, User user, org.openecomp.sdc.be.model.Component parent, boolean shouldLock, boolean inTransaction) {
+ if (interfaceName != null && operationName != null) {
+ interfaceName = interfaceName.toLowerCase();
+ operationName = operationName.toLowerCase();
+ }
+ switch (operation) {
+ case Download:
+ if (artifactGenerationRequired(parent, artifactInfo)) {
+ return generateToscaArtifact(parent, artifactInfo, false, false, shouldLock, inTransaction);
+ }
+ return handleDownload(componentId, artifactId, user, auditingAction, componentType, parent, shouldLock, inTransaction);
+ case Delete:
+ return handleDelete(componentId, artifactId, user, auditingAction, componentType, parent, interfaceName, operationName, shouldLock, inTransaction);
+ case Update:
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+ if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)
+ && (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_VOL || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_ENV)) {
+ return handleUpdateHeatEnv(componentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, originData, origMd5, operation, shouldLock, inTransaction);
+ }
+ return handleUpdate(componentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceName, operationName, shouldLock, inTransaction);
+ case Create:
+ return handleCreate(componentId, artifactInfo, operation, auditingAction, user, componentType, parent, origMd5, originData, interfaceName, operationName, shouldLock, inTransaction);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param componentId
+ * @param artifactId
+ * @param userId
+ * @param componentType
+ * @param parentId
+ * TODO
+ * @return
+ */
+
+ public Either<ImmutablePair<String, byte[]>, ResponseFormat> handleDownloadToscaModelRequest(Component component, ArtifactDefinition csarArtifact, boolean shouldLock, boolean inTransaction) {
+ if (artifactGenerationRequired(component, csarArtifact)) {
+ Either<byte[], ResponseFormat> generated = csarUtils.createCsar(component, false, false, shouldLock, inTransaction);
+
+ if (generated.isRight()) {
+ log.debug("Failed to export tosca csar for component {} error {}", component.getUniqueId(), generated.right().value());
+
+ return Either.right(generated.right().value());
+ }
+ return Either.left(new ImmutablePair<String, byte[]>(csarArtifact.getArtifactName(), generated.left().value()));
+ }
+ return downloadArtifact(csarArtifact);
+ }
+
+ public Either<ImmutablePair<String, byte[]>, ResponseFormat> handleDownloadRequestById(String componentId, String artifactId, String userId, ComponentTypeEnum componentType, String parentId, String containerComponentType) {
+ // perform all validation in common flow
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result = handleArtifactRequest(componentId, userId, componentType, ArtifactOperation.Download, artifactId, null, null, null, null, null, parentId, containerComponentType);
+ if (result.isRight()) {
+ return Either.right(result.right().value());
+ }
+ ArtifactDefinition artifactDefinition;
+ Either<ArtifactDefinition, Operation> insideValue = result.left().value();
+ if (insideValue.isLeft()) {
+ artifactDefinition = insideValue.left().value();
+ } else {
+ artifactDefinition = insideValue.right().value().getImplementation();
+ }
+ // for tosca artifacts generated on download without saving
+ if (artifactDefinition.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA && artifactDefinition.getPayloadData() != null) {
+ return Either.left(new ImmutablePair<String, byte[]>(artifactDefinition.getArtifactName(), artifactDefinition.getPayloadData()));
+ }
+ return downloadArtifact(artifactDefinition);
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> validateArtifact(String componentId, ComponentTypeEnum componentType, String artifactId, org.openecomp.sdc.be.model.Component component, AuditingActionEnum auditingAction, String parentId) {
+ // step 9
+ // check artifact existence
+ Either<ArtifactDefinition, StorageOperationStatus> artifactResult = artifactOperation.getArtifactById(artifactId, false);
+ if (artifactResult.isRight()) {
+ if (artifactResult.right().value().equals(StorageOperationStatus.ARTIFACT_NOT_FOUND)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, "");
+ log.debug("addArtifact - artifact {} not found", artifactId);
+ return Either.right(responseFormat);
+
+ } else {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(artifactResult.right().value()));
+ log.debug("addArtifact - failed to fetch artifact {}, error {}", artifactId, artifactResult.right().value());
+ return Either.right(responseFormat);
+ }
+ }
+ // step 9.1
+ // check artifact belong to component
+ boolean found = false;
+ switch (componentType) {
+ case RESOURCE:
+ case SERVICE:
+ found = checkArtifactInComponent(component, artifactId);
+ break;
+ case RESOURCE_INSTANCE:
+ found = checkArtifactInResourceInstance(component, componentId, artifactId);
+ break;
+ default:
+
+ }
+ if (!found) {
+ // String component =
+ // componentType.equals(ComponentTypeEnum.RESOURCE) ? "resource" :
+ // "service";
+ String componentName = componentType.name().toLowerCase();
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ARTIFACT_NOT_FOUND, componentName);
+ log.debug("addArtifact - Component artifact not found component Id {}, artifact id {}", componentId, artifactId);
+ return Either.right(responseFormat);
+ }
+ return Either.left(artifactResult.left().value());
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleCreate(String parentId, ArtifactDefinition artifactInfo, ArtifactOperation operation, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
+ org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
+
+ String artifactId = null;
+
+ // step 11
+ Either<byte[], ResponseFormat> payloadEither = validateInput(parentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName, inTransaction);
+ if (payloadEither.isRight()) {
+ return Either.right(payloadEither.right().value());
+ }
+ byte[] decodedPayload = payloadEither.left().value();
+ NodeTypeEnum parentType = convertParentType(componentType);
+ // lock resource
+
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Upload Artifact - lock ");
+ if (lockComponent.isRight()) {
+ handleAuditing(auditingAction, parent, parentId, user, null, null, null, lockComponent.right().value(), componentType, null);
+ return Either.right(lockComponent.right().value());
+ }
+ }
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+
+ try {
+ resultOp = createArtifact(parent, parentId, artifactInfo, decodedPayload, user, componentType, auditingAction, interfaceType, operationName);
+ return resultOp;
+ } finally {
+ if (shouldLock) {
+ unlockComponent(resultOp, parent, inTransaction);
+ }
+
+ }
+
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> lockComponentAndUpdateArtifact(String parentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user,
+ ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component parent, byte[] decodedPayload, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
+
+ NodeTypeEnum parentType = convertParentType(componentType);
+
+ // lock resource
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Update Artifact - lock ");
+ if (lockComponent.isRight()) {
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right().value(), componentType, null);
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ try {
+ resultOp = updateArtifactFlow(parent, parentId, artifactId, artifactInfo, user, decodedPayload, componentType, auditingAction, interfaceType, operationName);
+ return resultOp;
+
+ } finally {
+ if (shouldLock) {
+ unlockComponent(resultOp, parent, inTransaction);
+ }
+ }
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleUpdate(String parentId, ArtifactDefinition artifactInfo, ArtifactOperation operation, AuditingActionEnum auditingAction, String artifactId, User user,
+ ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
+
+ Either<byte[], ResponseFormat> payloadEither = validateInput(parentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName, inTransaction);
+
+ if (payloadEither.isRight()) {
+ return Either.right(payloadEither.right().value());
+ }
+ byte[] decodedPayload = payloadEither.left().value();
+
+ return lockComponentAndUpdateArtifact(parentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, decodedPayload, interfaceType, operationName, shouldLock, inTransaction);
+ }
+
+ private Either<byte[], ResponseFormat> validateInput(String parentId, ArtifactDefinition artifactInfo, ArtifactOperation operation, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
+ org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean inTransaction) {
+ // Md5 validations
+ Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
+ if (validateMd5.isRight()) {
+ ResponseFormat responseFormat = validateMd5.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+
+ // step 11
+ Either<ArtifactDefinition, ResponseFormat> validateResult = validateInput(parentId, artifactInfo, operation, artifactId, user, interfaceType, operationName, componentType, parent, inTransaction);
+ if (validateResult.isRight()) {
+ ResponseFormat responseFormat = validateResult.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(validateResult.right().value());
+ }
+
+ Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
+ if (payloadEither.isRight()) {
+ ResponseFormat responseFormat = payloadEither.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ log.debug("Error during handle payload");
+ return Either.right(responseFormat);
+ }
+
+ // validate heat parameters. this part must be after the parameters are
+ // extracted in "handlePayload"
+ Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParamers(artifactInfo, artifactInfo.getArtifactType());
+ if (validateAndConvertHeatParamers.isRight()) {
+ ResponseFormat responseFormat = validateAndConvertHeatParamers.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, null, artifactId, responseFormat, componentType, null);
+ log.debug("Error during handle payload");
+ return Either.right(responseFormat);
+ }
+ return payloadEither;
+ }
+
+ public void handleAuditing(AuditingActionEnum auditingActionEnum, Component component, String componentId, User user, ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid, ResponseFormat responseFormat,
+ ComponentTypeEnum componentTypeEnum, String resourceInstanceName) {
+
+ if (auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE)) {
+ return;
+ }
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = createArtifactAuditingFields(artifactDefinition, prevArtifactUuid, currentArtifactUuid);
+
+ if (user == null) {
+ user = new User();
+ user.setUserId("UNKNOWN");
+ }
+ switch (componentTypeEnum) {
+
+ case RESOURCE:
+ Resource resource = (Resource) component;
+ if (resource == null) {
+ // In that case, component ID should be instead of name
+ resource = new Resource();
+ resource.setName(componentId);
+ }
+ componentsUtils.auditResource(responseFormat, user, resource, null, null, auditingActionEnum, auditingFields);
+ break;
+
+ case SERVICE:
+ Service service = (Service) component;
+ if (service == null) {
+ // In that case, component ID should be instead of name
+ service = new Service();
+ service.setName(componentId);
+ }
+ componentsUtils.auditComponent(responseFormat, user, service, null, null, auditingActionEnum, ComponentTypeEnum.SERVICE, auditingFields);
+ break;
+
+ case RESOURCE_INSTANCE:
+ if (resourceInstanceName == null) {
+ resourceInstanceName = getResourceInstanceNameFromComponent(component, componentId);
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
+ componentsUtils.auditComponent(responseFormat, user, component, null, null, auditingActionEnum, ComponentTypeEnum.RESOURCE_INSTANCE, auditingFields);
+
+ break;
+ default:
+ break;
+ }
+ }
+
+ private String getResourceInstanceNameFromComponent(Component component, String componentId) {
+ ComponentInstance resourceInstance = component.getComponentInstances().stream().filter(p -> p.getUniqueId().equals(componentId)).findFirst().orElse(null);
+ String resourceInstanceName = null;
+ if (resourceInstance != null) {
+ resourceInstanceName = resourceInstance.getName();
+ }
+ return resourceInstanceName;
+ }
+
+ public EnumMap<AuditingFieldsKeysEnum, Object> createArtifactAuditingFields(ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid) {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ // Putting together artifact info
+ String artifactData = buildAuditingArtifactData(artifactDefinition);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ARTIFACT_DATA, artifactData);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID, prevArtifactUuid);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_CURR_ARTIFACT_UUID, currentArtifactUuid);
+ return auditingFields;
+ }
+
+ // -----
+
+ private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
+ StringBuilder sb = new StringBuilder();
+ if (artifactDefinition != null) {
+ sb.append(artifactDefinition.getArtifactGroupType().getType()).append(",").append("'").append(artifactDefinition.getArtifactLabel()).append("'").append(",").append(artifactDefinition.getArtifactType()).append(",")
+ .append(artifactDefinition.getArtifactName()).append(",").append(artifactDefinition.getTimeout()).append(",").append(artifactDefinition.getEsId());
+
+ sb.append(",");
+ if (artifactDefinition.getArtifactVersion() != null) {
+
+ sb.append(artifactDefinition.getArtifactVersion());
+ } else {
+ sb.append(" ");
+ }
+ sb.append(",");
+ if (artifactDefinition.getArtifactUUID() != null) {
+ sb.append(artifactDefinition.getArtifactUUID());
+ } else {
+ sb.append(" ");
+ }
+ }
+ return sb.toString();
+ }
+
+ private Either<Boolean, ResponseFormat> validateMd5(String origMd5, String originData, byte[] payload, ArtifactOperation operation) {
+
+ if (origMd5 != null) {
+ String encodeBase64Str = GeneralUtility.calculateMD5ByString(originData);
+
+ if (false == encodeBase64Str.equals(origMd5)) {
+ log.debug("The calculated md5 is different then the received one");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_MD5));
+ }
+ } else {
+ if (operation == ArtifactOperation.Create) {
+ log.debug("Missing md5 header during artifact create");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_MD5));
+ }
+ // Update metadata
+ if (payload != null && payload.length != 0) {
+ log.debug("Cannot have payload while md5 header is missing");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> validateInput(String parentId, ArtifactDefinition artifactInfo, ArtifactOperation operation, String artifactId, User user, String interfaceName, String operationName,
+ ComponentTypeEnum componentType, Component parentComponent, boolean inTransaction) {
+
+ Either<Boolean, ResponseFormat> validateAndSetArtifactname = validateAndSetArtifactname(artifactInfo);
+ if (validateAndSetArtifactname.isRight()) {
+ return Either.right(validateAndSetArtifactname.right().value());
+ }
+ Either<ArtifactDefinition, ResponseFormat> artifactById = fetchCurrentArtifact(operation, artifactId);
+ if (artifactById.isRight()) {
+ return Either.right(artifactById.right().value());
+ }
+ ArtifactDefinition currentArtifactInfo = artifactById.left().value();
+ if (operationName != null && interfaceName != null) {
+ operationName = operationName.toLowerCase();
+ interfaceName = interfaceName.toLowerCase();
+ }
+ Either<ActionStatus, ResponseFormat> logicalNameStatus = handleArtifactLabel(parentId, operation, artifactId, artifactInfo, interfaceName, operationName, currentArtifactInfo, componentType, inTransaction);
+ if (logicalNameStatus.isRight()) {
+ return Either.right(logicalNameStatus.right().value());
+ }
+ // This is a patch to block possibility of updating service api fields
+ // through other artifacts flow
+
+ if (!operation.equals(ArtifactOperation.Create)) {
+ checkAndSetUnUpdatableFields(user, artifactInfo, currentArtifactInfo, (operationName != null ? ArtifactGroupTypeEnum.LIFE_CYCLE : ArtifactGroupTypeEnum.INFORMATIONAL));
+ } else {
+ checkCreateFields(user, artifactInfo, (operationName != null ? ArtifactGroupTypeEnum.LIFE_CYCLE : ArtifactGroupTypeEnum.INFORMATIONAL));
+ }
+
+ composeArtifactId(parentId, artifactId, artifactInfo, interfaceName, operationName);
+ if (currentArtifactInfo != null) {
+ artifactInfo.setMandatory(currentArtifactInfo.getMandatory());
+ }
+
+ // artifactGroupType is not allowed to be updated
+ if (!operation.equals(ArtifactOperation.Create)) {
+ Either<ArtifactDefinition, ResponseFormat> validateGroupType = validateOrSetArtifactGroupType(artifactInfo, currentArtifactInfo);
+ if (validateGroupType.isRight()) {
+ return Either.right(validateGroupType.right().value());
+ }
+ }
+ // TODO TEMP !!!
+ NodeTypeEnum parentType = convertParentType(componentType);
+
+ // TODO TEMP !!!
+ boolean isCreate = operation.equals(ArtifactOperation.Create);
+
+ if (isDeploymentArtifact(artifactInfo)) {
+ Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parentComponent, parentId, user.getUserId(), isCreate, artifactInfo, currentArtifactInfo, parentType);
+ if (deploymentValidationResult.isRight()) {
+ return Either.right(deploymentValidationResult.right().value());
+ }
+ } else {
+ artifactInfo.setTimeout(NON_HEAT_TIMEOUT);
+
+ /*
+ * if (informationDeployedArtifactsBusinessLogic. isInformationDeployedArtifact(artifactInfo)) { Either<Boolean, ResponseFormat> validationResult = informationDeployedArtifactsBusinessLogic.validateArtifact( isCreate, artifactInfo,
+ * parentComponent, parentType); if (validationResult.isRight()) { return Either.right(validationResult.right().value()); } }
+ */
+ }
+
+ Either<Boolean, ResponseFormat> descriptionResult = validateAndCleanDescription(artifactInfo);
+ if (descriptionResult.isRight()) {
+ return Either.right(descriptionResult.right().value());
+ }
+
+ if (currentArtifactInfo != null && currentArtifactInfo.getArtifactGroupType().equals(ArtifactGroupTypeEnum.SERVICE_API)) {
+ Either<ActionStatus, ResponseFormat> validateServiceApiType = validateArtifactType(user.getUserId(), artifactInfo, parentType);
+ if (validateServiceApiType.isRight()) {
+ return Either.right(validateServiceApiType.right().value());
+ }
+ // Change of type is not allowed and should be ignored
+
+ artifactInfo.setArtifactType(ARTIFACT_TYPE_OTHER);
+
+ Either<Boolean, ResponseFormat> validateUrl = validateAndServiceApiUrl(artifactInfo);
+ if (validateUrl.isRight()) {
+ return Either.right(validateUrl.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> validateUpdate = validateFirstUpdateHasPayload(artifactInfo, currentArtifactInfo);
+ if (validateUpdate.isRight()) {
+ log.debug("serviceApi first update cnnot be without payload.");
+ return Either.right(validateUpdate.right().value());
+ }
+ } else {
+ Either<ActionStatus, ResponseFormat> validateArtifactType = validateArtifactType(user.getUserId(), artifactInfo, parentType);
+ if (validateArtifactType.isRight()) {
+ return Either.right(validateArtifactType.right().value());
+ }
+ if (artifactInfo.getApiUrl() != null) {
+ artifactInfo.setApiUrl(null);
+ log.error("Artifact URL cannot be set through this API - ignoring");
+ }
+
+ if (artifactInfo.getServiceApi() != null) {
+ if (artifactInfo.getServiceApi()) {
+ artifactInfo.setServiceApi(false);
+ log.error("Artifact service API flag cannot be changed - ignoring");
+ }
+ }
+ }
+
+ return Either.left(artifactInfo);
+ }
+
+ private NodeTypeEnum convertParentType(ComponentTypeEnum componentType) {
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ return NodeTypeEnum.Resource;
+ } else if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)) {
+ return NodeTypeEnum.ResourceInstance;
+ } else {
+ return NodeTypeEnum.Service;
+ }
+ }
+
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete(String parentId, String artifactId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component parent,
+ String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
+ NodeTypeEnum parentType = convertParentType(componentType);
+ // lock resource
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Delete Artifact - lock resource: ");
+ if (lockComponent.isRight()) {
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right().value(), componentType, null);
+ return Either.right(lockComponent.right().value());
+ }
+ }
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ Either<ArtifactDefinition, Operation> insideEither = null;
+ StorageOperationStatus error = null;
+ boolean isLeft = false;
+ ArtifactDefinition artifactDefinition = null;
+ Integer artifactParentsCount = 1;
+ try {
+ if (interfaceType != null && operationName != null) {
+ log.debug("Try to delete inteface lifecycle artifact {}", artifactId);
+
+ Either<Operation, StorageOperationStatus> result = interfaceLifecycleOperation.deleteInterfaceOperation(parentId, interfaceType, UniqueIdBuilder.buildOperationByInterfaceUniqueId(parentId, interfaceType, operationName),
+ inTransaction);
+ isLeft = result.isLeft();
+ if (isLeft) {
+ artifactDefinition = result.left().value().getImplementation();
+ insideEither = Either.right(result.left().value());
+ }
+ } else {
+ log.debug("Try to delete artifact, get parents {}", artifactId);
+
+ Either<Integer, StorageOperationStatus> parentsOfArtifact = artifactOperation.getParentsOfArtifact(artifactId, parentType);
+ if (parentsOfArtifact.isRight()) {
+ log.debug("Failed to delete entry on graph for artifact {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(parentsOfArtifact.right().value()), "");
+ resultOp = Either.right(responseFormat);
+ } else {
+
+ artifactParentsCount = parentsOfArtifact.left().value();
+ log.debug("Number of parents nodes on graph for artifact {} is {}", artifactId, artifactParentsCount);
+
+ Either<ArtifactDefinition, StorageOperationStatus> result = artifactOperation.removeArifactFromResource(parentId, artifactId, parentType, false, true);
+ isLeft = result.isLeft();
+ if (isLeft) {
+ log.debug("Artifact removed from graph {}", artifactId);
+
+ artifactDefinition = result.left().value();
+ insideEither = Either.left(result.left().value());
+ } else {
+ error = result.right().value();
+ }
+ }
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ if (isLeft) {
+ StorageOperationStatus deleteIfNotOnGraph = StorageOperationStatus.OK;
+ if (artifactParentsCount < 2) {
+ log.debug("Number of parent nodes is 1. Need to delete from ES {}", artifactId);
+ deleteIfNotOnGraph = deleteIfNotOnGraph(artifactId, artifactDefinition.getEsId(), true);
+ }
+ if (deleteIfNotOnGraph.equals(StorageOperationStatus.OK)) {
+ if (artifactDefinition.getMandatory() || artifactDefinition.getServiceApi()) {
+ log.debug("Artifact is mandatory or service API. Clean all fields for {}", artifactId);
+ artifactDefinition.setEsId("");
+ artifactDefinition.setArtifactName("");
+ artifactDefinition.setDescription("");
+ artifactDefinition.setApiUrl("");
+ artifactDefinition.setArtifactChecksum("");
+ setDefaultArtifactTimeout(artifactDefinition.getArtifactGroupType(), artifactDefinition);
+ artifactDefinition.setArtifactUUID("");
+ long time = System.currentTimeMillis();
+ artifactDefinition.setPayloadUpdateDate(time);
+ artifactDefinition.setHeatParameters(null);
+ artifactDefinition.setHeatParamsUpdateDate(null);
+ Either<ArtifactDefinition, StorageOperationStatus> resStatus = null;
+ if (artifactParentsCount < 2) {
+ log.debug("Only one parent , clean existing placeholder for {}", artifactId);
+ resStatus = artifactOperation.updateArifactOnResource(artifactDefinition, parentId, artifactId, parentType, true);
+ } else {
+ log.debug("more than one parent , create new placeholder for {}", artifactId);
+ artifactDefinition.setUniqueId(null);
+ resStatus = artifactOperation.addArifactToComponent(artifactDefinition, parentId, parentType, true, true);
+ }
+ if (resStatus.isRight()) {
+ log.debug("Failed to clean placeholder for {}", artifactId);
+ responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(resStatus.right().value()), artifactDefinition.getArtifactDisplayName());
+ resultOp = Either.right(responseFormat);
+ } else {
+ log.debug("Placeholder was cleaned for {}", artifactId);
+
+ ArtifactDefinition artifactUfterChange = resStatus.left().value();
+
+ insideEither = Either.left(artifactUfterChange);
+ resultOp = Either.left(insideEither);
+ }
+ } else {
+ log.debug("Artifact isn't mandatory/service API. Removed. {}", artifactId);
+ resultOp = Either.left(insideEither);
+ }
+
+ } else {
+ log.debug("failed to delete artifact from ES {} status {}", artifactId, deleteIfNotOnGraph);
+ responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(deleteIfNotOnGraph), artifactDefinition.getArtifactDisplayName());
+ resultOp = Either.right(responseFormat);
+ }
+ } else {
+ log.debug("Failed to delete entry on graph for artifact {}", artifactId);
+ responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(error), "");
+ resultOp = Either.right(responseFormat);
+ }
+ handleAuditing(auditingAction, parent, parentId, user, artifactDefinition, null, artifactId, responseFormat, componentType, null);
+ return resultOp;
+ } finally {
+ if (shouldLock) {
+ unlockComponent(resultOp, parent, inTransaction);
+ }
+ }
+
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDownload(String componentId, String artifactId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType,
+ org.openecomp.sdc.be.model.Component parent, boolean shouldLock, boolean inTransaction) {
+ Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactOperation.getArtifactById(artifactId, false);
+ if (artifactById.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(artifactById.right().value());
+ log.debug("Error when getting artifact info by id{}, error: {}", artifactId, actionStatus.name());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(actionStatus, "");
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ ArtifactDefinition artifactDefinition = artifactById.left().value();
+ if (artifactDefinition == null) {
+ log.debug("Empty artifact definition returned from DB by artifact id {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, "");
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ Either<ArtifactDefinition, Operation> insideEither = Either.left(artifactDefinition);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(auditingAction, parent, componentId, user, artifactDefinition, null, artifactId, responseFormat, componentType, null);
+ return Either.left(insideEither);
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> fetchCurrentArtifact(ArtifactOperation operation, String artifactId) {
+ Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactOperation.getArtifactById(artifactId, true);
+ if (!operation.equals(ArtifactOperation.Create) && artifactById.isRight()) {
+ // in case of update artifact must be
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeArtifactMissingError, "Artifact Update / Upload", artifactId);
+ BeEcompErrorManager.getInstance().logBeArtifactMissingError("Artifact Update / Upload", artifactId);
+ log.debug("Failed to fetch artifact {}. error: {}", artifactId, artifactById.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(artifactById.right().value()), artifactId));
+ }
+ if (operation.equals(ArtifactOperation.Create) && artifactById.isLeft()) {
+ log.debug("Artifact {} already exist", artifactId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactById.left().value().getArtifactLabel()));
+ }
+ ArtifactDefinition currentArtifactInfo = null;
+ if (artifactById.isLeft()) {
+ // get previous value
+ currentArtifactInfo = artifactById.left().value();
+ }
+ return Either.left(currentArtifactInfo);
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleArtifactLabel(String componentId, ArtifactOperation operation, String artifactId, ArtifactDefinition artifactInfo, String interfaceName, String operationName,
+ ArtifactDefinition currentArtifactInfo, ComponentTypeEnum componentType, boolean inTransaction) {
+ String artifactLabel = artifactInfo.getArtifactLabel();
+
+ if (operationName == null && (artifactInfo.getArtifactLabel() == null || artifactInfo.getArtifactLabel().isEmpty())) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingArtifactInformationError, "Artifact Update / Upload", "artifactLabel");
+ BeEcompErrorManager.getInstance().logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ log.debug("missing artifact logical name for component {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_LABEL));
+ }
+ if (operation.equals(ArtifactOperation.Create) && !artifactInfo.getMandatory()) {
+
+ if (operationName != null) {
+ if (artifactInfo.getArtifactLabel() != null && !operationName.equals(artifactInfo.getArtifactLabel())) {
+ log.debug("artifact label cannot be set {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED));
+ } else {
+ artifactLabel = operationName;
+ }
+ }
+ String displayName = artifactInfo.getArtifactDisplayName();
+ if (displayName == null || displayName.isEmpty())
+ displayName = artifactLabel;
+ displayName = ValidationUtils.cleanArtifactDisplayName(displayName);
+ artifactInfo.setArtifactDisplayName(displayName);
+
+ if (!ValidationUtils.validateArtifactLabel(artifactLabel)) {
+ log.debug("Invalid format form Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactLabel);
+
+ if (artifactLabel.isEmpty()) {
+ log.debug("missing normalized artifact logical name for component {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_LABEL));
+ }
+
+ if (!ValidationUtils.validateArtifactLabelLength(artifactLabel)) {
+ log.debug("Invalid lenght form Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_LABEL, String.valueOf(ValidationUtils.ARTIFACT_LABEL_LENGTH)));
+ }
+ if (!validateLabelUniqueness(componentId, artifactLabel, componentType, inTransaction)) {
+ log.debug("Non unique Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactLabel));
+ }
+ }
+ artifactInfo.setArtifactLabel(artifactLabel);
+
+ if (currentArtifactInfo != null && !currentArtifactInfo.getArtifactLabel().equals(artifactInfo.getArtifactLabel())) {
+ log.info("Logical artifact's name cannot be changed {}", artifactId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED));
+ }
+ return Either.left(ActionStatus.OK);
+ }
+
+ private boolean validateLabelUniqueness(String parentId, String artifactLabel, ComponentTypeEnum componentType, boolean inTransaction) {
+ boolean isUnique = true;
+ NodeTypeEnum parentType;
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ parentType = NodeTypeEnum.Resource;
+ } else {
+ parentType = NodeTypeEnum.Service;
+ }
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts = artifactOperation.getArtifacts(parentId, parentType, inTransaction);
+ if (artifacts.isLeft()) {
+ for (String label : artifacts.left().value().keySet()) {
+ if (label.equals(artifactLabel)) {
+ isUnique = false;
+ break;
+ }
+ }
+ }
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation.getAllInterfacesOfResource(parentId, true, inTransaction);
+ if (allInterfacesOfResource.isLeft()) {
+ for (InterfaceDefinition interace : allInterfacesOfResource.left().value().values()) {
+ for (Operation operation : interace.getOperations().values()) {
+ if (operation.getImplementation() != null && operation.getImplementation().getArtifactLabel().equals(artifactLabel)) {
+ isUnique = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return isUnique;
+ }
+
+ // ***************************************************************
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> createArtifact(org.openecomp.sdc.be.model.Component parent, String parentId, ArtifactDefinition artifactInfo, byte[] decodedPayload, User user,
+ ComponentTypeEnum componentTypeEnum, AuditingActionEnum auditingActionEnum, String interfaceType, String operationName) {
+
+ ESArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ Either<ArtifactDefinition, Operation> insideEither = null;
+
+ if (artifactData == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Upload Artifact");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Upload Artifact");
+ log.debug("Failed to create artifact object for ES.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, null, responseFormat, componentTypeEnum, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+
+ }
+ // set on graph object id of artifact in ES!
+ artifactInfo.setEsId(artifactData.getId());
+
+ boolean isLeft = false;
+ String artifactUniqueId = null;
+ ArtifactDefinition artifactDefinition = null;
+ StorageOperationStatus error = null;
+ if (interfaceType != null && operationName != null) {
+ // lifecycle artifact
+ Operation operation = convertToOperation(artifactInfo, operationName);
+
+ Either<Operation, StorageOperationStatus> result = interfaceLifecycleOperation.updateInterfaceOperation(parentId, interfaceType, operationName, operation);
+
+ isLeft = result.isLeft();
+ if (isLeft) {
+ artifactUniqueId = result.left().value().getImplementation().getUniqueId();
+ artifactDefinition = result.left().value().getImplementation();
+
+ insideEither = Either.right(result.left().value());
+ resultOp = Either.left(insideEither);
+ } else {
+ error = result.right().value();
+ }
+ } else {
+ // information/deployment/api aritfacts
+ log.debug("Try to create entry on graph");
+ NodeTypeEnum nodeType = convertParentType(componentTypeEnum);
+ Either<ArtifactDefinition, StorageOperationStatus> result = artifactOperation.addArifactToComponent(artifactInfo, parentId, nodeType, true, true);
+
+ isLeft = result.isLeft();
+ if (isLeft) {
+ artifactUniqueId = result.left().value().getUniqueId();
+ artifactDefinition = result.left().value();
+
+ insideEither = Either.left(result.left().value());
+ resultOp = Either.left(insideEither);
+ } else {
+ error = result.right().value();
+ }
+ }
+ if (isLeft) {
+ boolean res = saveArtifacts(artifactData, parentId, false);
+ // String uniqueId = artifactDefinition.getUniqueId();
+
+ if (res) {
+ log.debug("Artifact saved into ES - {}", artifactUniqueId);
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, artifactUniqueId, artifactUniqueId, responseFormat, componentTypeEnum, null);
+ return resultOp;
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Upload Artifact");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Upload Artifact");
+ log.debug("Failed to save the artifact.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, artifactUniqueId, responseFormat, componentTypeEnum, null);
+
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+ }
+ } else {
+ log.debug("Failed to create entry on graph for artifact {}", artifactInfo.getArtifactName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(error), artifactInfo.getArtifactDisplayName());
+ handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, null, responseFormat, componentTypeEnum, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+ }
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateDeploymentArtifact(Component parentComponent, String parentId, String userId, boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, NodeTypeEnum parentType) {
+
+ Either<Boolean, ResponseFormat> result = Either.left(true);
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<ResponseFormat>();
+
+ validateArtifactTypeExists(responseWrapper, artifactInfo);
+
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+
+ Map<String, DeploymentArtifactTypeConfig> resourceDeploymentArtifacts = fillDeploymentArtifactTypeConf(parentType);
+
+ if (responseWrapper.isEmpty()) {
+ validateDeploymentArtifactConf(artifactInfo, responseWrapper, artifactType, resourceDeploymentArtifacts);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ // Common code for all types
+ // not allowed to change artifactType
+ if (!isCreate) {
+ Either<Boolean, ResponseFormat> validateServiceApiType = validateArtifactTypeNotChanged(artifactInfo, currentArtifact);
+ if (validateServiceApiType.isRight()) {
+ responseWrapper.setInnerElement(validateServiceApiType.right().value());
+ }
+ }
+ }
+ if (responseWrapper.isEmpty()) {
+ if (parentType.equals(NodeTypeEnum.Resource)) {
+ // if (parentComponent instanceof Resource) {
+ Resource resource = (Resource) parentComponent;
+ ResourceTypeEnum resourceType = resource.getResourceType();
+ DeploymentArtifactTypeConfig config = resourceDeploymentArtifacts.get(artifactType.getType());
+ if (config == null) {
+ responseWrapper.setInnerElement(ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType()));
+ } else {
+ List<String> myList = config.getValidForResourceTypes();
+ Either<Boolean, ResponseFormat> either = validateResourceType(resourceType, artifactInfo, myList);
+ if (either.isRight()) {
+ responseWrapper.setInnerElement(either.right().value());
+ }
+ }
+ }
+ }
+ if (responseWrapper.isEmpty()) {
+ validateFileExtension(responseWrapper, () -> getDeploymentArtifactTypeConfig(parentType, artifactType), artifactInfo, parentType, artifactType);
+ }
+
+ if (responseWrapper.isEmpty() && !NodeTypeEnum.ResourceInstance.equals(parentType)) {
+ String artifactName = artifactInfo.getArtifactName();
+ if (isCreate || !artifactName.equalsIgnoreCase(currentArtifact.getArtifactName())) {
+ validateSingleDeploymentArtifactName(responseWrapper, artifactName, parentComponent, parentType);
+ }
+ }
+
+ if (responseWrapper.isEmpty()) {
+ switch (artifactType) {
+ case HEAT:
+ case HEAT_VOL:
+ case HEAT_NET: {
+ result = validateHeatDeploymentArtifact(parentComponent, userId, isCreate, artifactInfo, currentArtifact, parentType);
+ break;
+ }
+ case HEAT_ENV: {
+ result = validateHeatEnvDeploymentArtifact(parentComponent, parentId, userId, isCreate, artifactInfo, parentType);
+ artifactInfo.setTimeout(NON_HEAT_TIMEOUT);
+ break;
+ }
+ case DCAE_INVENTORY_TOSCA:
+ case DCAE_INVENTORY_JSON:
+ case DCAE_INVENTORY_POLICY:
+ // Validation is done in handle payload.
+ case DCAE_INVENTORY_DOC:
+ case DCAE_INVENTORY_BLUEPRINT:
+ case DCAE_INVENTORY_EVENT:
+ // No specific validation
+ default: {
+ artifactInfo.setTimeout(NON_HEAT_TIMEOUT);
+ }
+ }
+
+ }
+
+ if (!responseWrapper.isEmpty()) {
+ result = Either.right(responseWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ private void validateDeploymentArtifactConf(ArtifactDefinition artifactInfo, Wrapper<ResponseFormat> responseWrapper, ArtifactTypeEnum artifactType, Map<String, DeploymentArtifactTypeConfig> resourceDeploymentArtifacts) {
+ if ((resourceDeploymentArtifacts == null) || !resourceDeploymentArtifacts.containsKey(artifactType.name())) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
+ responseWrapper.setInnerElement(responseFormat);
+ log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
+ }
+ }
+
+ private Map<String, DeploymentArtifactTypeConfig> fillDeploymentArtifactTypeConf(NodeTypeEnum parentType) {
+ Map<String, DeploymentArtifactTypeConfig> resourceDeploymentArtifacts = null;
+ if (parentType.equals(NodeTypeEnum.Resource)) {
+ resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+ } else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts();
+ } else {
+ resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts();
+ }
+ return resourceDeploymentArtifacts;
+ }
+
+ public void validateArtifactTypeExists(Wrapper<ResponseFormat> responseWrapper, ArtifactDefinition artifactInfo) {
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+ if (artifactType == null) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(responseFormat);
+ log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
+ }
+ }
+
+ private DeploymentArtifactTypeConfig getDeploymentArtifactTypeConfig(NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
+ DeploymentArtifactTypeConfig retConfig = null;
+ String fileType = artifactType.getType();
+ if (parentType.equals(NodeTypeEnum.Resource)) {
+ retConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts().get(fileType);
+ } else if (parentType.equals(NodeTypeEnum.Service)) {
+ retConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts().get(fileType);
+ } else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ retConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts().get(fileType);
+ }
+ return retConfig;
+ }
+
+ private Either<Boolean, ResponseFormat> extractHeatParameters(ArtifactDefinition artifactInfo) {
+ // extract heat parameters
+ if (artifactInfo.getPayloadData() != null) {
+ String heatDecodedPayload = GeneralUtility.isBase64Encoded(artifactInfo.getPayloadData()) ? new String(Base64.decodeBase64(artifactInfo.getPayloadData())) : new String(artifactInfo.getPayloadData());
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParamsWithoutImplicitTypes(heatDecodedPayload, artifactInfo.getArtifactType());
+ if (heatParameters.isRight() && (!heatParameters.right().value().equals(ResultStatusEnum.ELEMENT_NOT_FOUND))) {
+ log.info("failed to parse heat parameters ");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, artifactInfo.getArtifactType());
+ return Either.right(responseFormat);
+ } else if (heatParameters.isLeft() && heatParameters.left().value() != null) {
+ artifactInfo.setHeatParameters(heatParameters.left().value());
+ }
+ }
+ return Either.left(true);
+
+ }
+
+ // Valid extension
+ public void validateFileExtension(Wrapper<ResponseFormat> responseWrapper, IDeploymentArtifactTypeConfigGetter deploymentConfigGetter, ArtifactDefinition artifactInfo, NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
+ String fileType = artifactType.getType();
+ List<String> acceptedTypes = null;
+ DeploymentArtifactTypeConfig deploymentAcceptedTypes = deploymentConfigGetter.getDeploymentArtifactConfig();
+ if (!parentType.equals(NodeTypeEnum.Resource) && !parentType.equals(NodeTypeEnum.Service) && !parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ log.debug("parent type of artifact can be either resource or service");
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return;
+ }
+
+ if (deploymentAcceptedTypes == null) {
+ log.debug("parent type of artifact can be either resource or service");
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType()));
+ return;
+ } else {
+ acceptedTypes = deploymentAcceptedTypes.getAcceptedTypes();
+ }
+ /*
+ * No need to check specific types. In case there are no acceptedTypes in configuration, then any type is accepted.
+ *
+ * if ((!artifactType.equals(ArtifactTypeEnum.OTHER) && !artifactType.equals(ArtifactTypeEnum.HEAT_ARTIFACT )) && (acceptedTypes == null || acceptedTypes.isEmpty()) ) { log.debug( "No accepted types found for type {}, parent type {}",
+ * fileType, parentType.getName()); String methodName = new Object() { }.getClass().getEnclosingMethod().getName(); String configEntryMissing = (parentType.equals(NodeTypeEnum.Resource)) ? "resourceDeploymentArtifacts:" + fileType :
+ * "serviceDeploymentArtifacts:" + fileType; BeEcompErrorManager.getInstance().processEcompError(EcompErrorName. BeMissingConfigurationError, methodName, configEntryMissing); BeEcompErrorManager.getInstance().logBeMissingConfigurationError(
+ * methodName, configEntryMissing); responseWrapper.setInnerElement(componentsUtils.getResponseFormat( ActionStatus.GENERAL_ERROR)); return; }
+ */
+
+ String artifactName = artifactInfo.getArtifactName();
+ String fileExtension = GeneralUtility.getFilenameExtension(artifactName);
+ // Pavel - File extension validation is case-insensitive - Ella,
+ // 21/02/2016
+ if (acceptedTypes != null && !acceptedTypes.isEmpty() && !acceptedTypes.contains(fileExtension.toLowerCase())) {
+ log.debug("File extension \"{}\" is not allowed for {} which is of type:{}", fileExtension, artifactName, fileType);
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.WRONG_ARTIFACT_FILE_EXTENSION, fileType));
+ return;
+ }
+ }
+
+ private Either<Boolean, ResponseFormat> validateHeatEnvDeploymentArtifact(Component parentComponent, String parentId, String userId, boolean isCreate, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<ResponseFormat>();
+ Wrapper<ArtifactDefinition> heatMDWrapper = new Wrapper<ArtifactDefinition>();
+ Wrapper<byte[]> payloadWrapper = new Wrapper<>();
+
+ if (errorWrapper.isEmpty()) {
+ validateValidYaml(errorWrapper, artifactInfo);
+ }
+
+ if (errorWrapper.isEmpty()) {
+ // Validate Heat Exist
+ validateHeatExist(artifactInfo.getUniqueId(), errorWrapper, heatMDWrapper, getDeploymentArtifacts(parentComponent, parentType, parentId));
+ }
+
+ if (errorWrapper.isEmpty() && isCreate) {
+ // Validate Only Single HeatEnv Artifact
+ validateSingleArtifactType(errorWrapper, ArtifactTypeEnum.HEAT_ENV, parentComponent, parentType, parentId);
+ }
+
+ if (errorWrapper.isEmpty() && !heatMDWrapper.isEmpty()) {
+ fillArtifactPayloadValidation(errorWrapper, payloadWrapper, heatMDWrapper.getInnerElement());
+ }
+
+ if (errorWrapper.isEmpty() && !heatMDWrapper.isEmpty()) {
+ validateEnvVsHeat(errorWrapper, artifactInfo, heatMDWrapper.getInnerElement(), payloadWrapper.getInnerElement());
+ }
+
+ // Init Response
+ Either<Boolean, ResponseFormat> eitherResponse;
+ if (errorWrapper.isEmpty()) {
+ eitherResponse = Either.left(true);
+ } else {
+ eitherResponse = Either.right(errorWrapper.getInnerElement());
+ }
+ return eitherResponse;
+ }
+
+ public void fillArtifactPayloadValidation(Wrapper<ResponseFormat> errorWrapper, Wrapper<byte[]> payloadWrapper, ArtifactDefinition artifactDefinition) {
+ if (artifactDefinition.getPayloadData() == null || artifactDefinition.getPayloadData().length == 0) {
+ Either<Boolean, ResponseFormat> fillArtifactPayload = fillArtifactPayload(payloadWrapper, artifactDefinition);
+ if (fillArtifactPayload.isRight()) {
+ errorWrapper.setInnerElement(fillArtifactPayload.right().value());
+ log.debug("Error getting payload for artifact:{}", artifactDefinition.getArtifactName());
+ }
+ } else {
+ payloadWrapper.setInnerElement(artifactDefinition.getPayloadData());
+ }
+ }
+
+ public Either<Boolean, ResponseFormat> fillArtifactPayload(Wrapper<byte[]> payloadWrapper, ArtifactDefinition artifactMD) {
+ Either<Boolean, ResponseFormat> result = Either.left(true);
+ Either<ESArtifactData, CassandraOperationStatus> eitherArtifactData = artifactCassandraDao.getArtifact(artifactMD.getEsId());
+ // Either<ESArtifactData, ResourceUploadStatus> eitherArtifactData =
+ // esCatalogDao.getArtifact(artifactMD.getEsId());
+ if (eitherArtifactData.isLeft()) {
+ byte[] data = eitherArtifactData.left().value().getDataAsArray();
+ if (!GeneralUtility.isBase64Encoded(data)) {
+ data = Base64.encodeBase64(data);
+ }
+ payloadWrapper.setInnerElement(data);
+ } else {
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(eitherArtifactData.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus));
+ result = Either.right(responseFormat);
+ }
+ return result;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private void validateEnvVsHeat(Wrapper<ResponseFormat> errorWrapper, ArtifactDefinition envArtifact, ArtifactDefinition heatArtifact, byte[] heatPayloadData) {
+
+ String envPayload = (GeneralUtility.isBase64Encoded(envArtifact.getPayloadData())) ? new String(Base64.decodeBase64(envArtifact.getPayloadData())) : new String(envArtifact.getPayloadData());
+ Map<String, Object> heatEnvToscaJson = (Map<String, Object>) new Yaml().load(envPayload);
+
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(heatPayloadData)) ? new String(Base64.decodeBase64(heatPayloadData)) : new String(heatPayloadData);
+ Map<String, Object> heatToscaJson = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+
+ Either<Map<String, Object>, ResultStatusEnum> eitherHeatEnvProperties = ImportUtils.findFirstToscaMapElement(heatEnvToscaJson, ToscaTagNamesEnum.PARAMETERS);
+ Either<Map<String, Object>, ResultStatusEnum> eitherHeatProperties = ImportUtils.findFirstToscaMapElement(heatToscaJson, ToscaTagNamesEnum.PARAMETERS);
+ if (eitherHeatEnvProperties.isRight()) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.CORRUPTED_FORMAT, "Heat Env");
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Invalid heat env format for file:{}", envArtifact.getArtifactName());
+ } else if (eitherHeatProperties.isRight()) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, envArtifact.getArtifactName(), heatArtifact.getArtifactName());
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Validation of heat_env for artifact:{} vs heat artifact for artifact :{} failed", envArtifact.getArtifactName(), heatArtifact.getArtifactName());
+ } else {
+ Set<String> heatPropertiesKeys = eitherHeatProperties.left().value().keySet();
+ Set<String> heatEnvPropertiesKeys = eitherHeatEnvProperties.left().value().keySet();
+ heatEnvPropertiesKeys.removeAll(heatPropertiesKeys);
+ if (heatEnvPropertiesKeys.size() > 0) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, envArtifact.getArtifactName(), heatArtifact.getArtifactName());
+ errorWrapper.setInnerElement(responseFormat);
+ }
+ }
+ }
+
+ private void validateValidYaml(Wrapper<ResponseFormat> errorWrapper, ArtifactDefinition artifactInfo) {
+ YamlToObjectConverter yamlConvertor = new YamlToObjectConverter();
+ boolean isYamlValid = yamlConvertor.isValidYaml(artifactInfo.getPayloadData());
+ if (!isYamlValid) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.INVALID_YAML, artifactInfo.getArtifactType());
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Yaml is not valid for artifact : {}", artifactInfo.getArtifactName());
+ }
+ }
+
+ public boolean isValidXml(byte[] xmlToParse) {
+ XMLReader parser = new SAXParser();
+ boolean isXmlValid = true;
+ try {
+ parser.parse(new InputSource(new ByteArrayInputStream(xmlToParse)));
+ } catch (IOException | SAXException e) {
+ isXmlValid = false;
+ }
+ return isXmlValid;
+ }
+
+ public boolean isValidJson(byte[] jsonToParse) {
+ String parsed = new String(jsonToParse);
+ try {
+ gson.fromJson(parsed, Object.class);
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+
+ public void validateSingleArtifactType(Wrapper<ResponseFormat> errorWrapper, ArtifactTypeEnum allowedArtifactType, Component parentComponent, NodeTypeEnum parentType, String parentRiId) {
+ boolean typeArtifactFound = false;
+ // Iterator<ArtifactDefinition> parentDeploymentArtifactsItr =
+ // (parentType == NodeTypeEnum.Resource) ?
+ // informationDeployedArtifactsBusinessLogic.getAllDeployableArtifacts((Resource)
+ // parentComponent).iterator()
+ // : getDeploymentArtifacts(parentComponent, parentType).iterator();
+
+ Iterator<ArtifactDefinition> parentDeploymentArtifactsItr = getDeploymentArtifacts(parentComponent, parentType, parentRiId).iterator();
+
+ while (!typeArtifactFound && parentDeploymentArtifactsItr.hasNext()) {
+ ArtifactTypeEnum foundArtifactType = ArtifactTypeEnum.findType(parentDeploymentArtifactsItr.next().getArtifactType());
+ typeArtifactFound = (foundArtifactType == allowedArtifactType);
+ }
+ if (typeArtifactFound) {
+ String parentName = parentComponent.getName();
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.DEPLOYMENT_ARTIFACT_OF_TYPE_ALREADY_EXISTS, parentType.name(), parentName, allowedArtifactType.getType(), allowedArtifactType.getType());
+
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Can't upload artifact of type: {}, because another artifact of this type already exist.", allowedArtifactType.getType());
+
+ }
+ }
+
+ public void validateSingleDeploymentArtifactName(Wrapper<ResponseFormat> errorWrapper, String artifactName, Component parentComponent, NodeTypeEnum parentType) {
+ boolean artifactNameFound = false;
+ // Iterator<ArtifactDefinition> parentDeploymentArtifactsItr =
+ // (parentType == NodeTypeEnum.Resource) ?
+ // informationDeployedArtifactsBusinessLogic.getAllDeployableArtifacts((Resource)
+ // parentComponent).iterator()
+ // : getDeploymentArtifacts(parentComponent, parentType).iterator();
+
+ Iterator<ArtifactDefinition> parentDeploymentArtifactsItr = getDeploymentArtifacts(parentComponent, parentType, null).iterator();
+
+ while (!artifactNameFound && parentDeploymentArtifactsItr.hasNext()) {
+ artifactNameFound = (artifactName.equalsIgnoreCase(parentDeploymentArtifactsItr.next().getArtifactName()));
+ }
+ if (artifactNameFound) {
+ String parentName = parentComponent.getName();
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS, parentType.name(), parentName, artifactName);
+
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Can't upload artifact: {}, because another artifact with this name already exist.", artifactName);
+
+ }
+ }
+
+ private void validateHeatExist(String heatEnvId, Wrapper<ResponseFormat> errorWrapper, Wrapper<ArtifactDefinition> heatArtifactMDWrapper, Collection<ArtifactDefinition> parentDeploymentArtifacts) {
+ boolean heatFound = false;
+ Either<ArtifactDefinition, StorageOperationStatus> res = artifactOperation.getHeatArtifactByHeatEnvId(heatEnvId, true);
+ if (res.isRight()) {
+ return;
+ }
+ ArtifactDefinition heatArtifact = res.left().value();
+ Iterator<ArtifactDefinition> parentArtifactsItr = parentDeploymentArtifacts.iterator();
+ while (!heatFound && parentArtifactsItr.hasNext()) {
+ ArtifactDefinition currArtifact = parentArtifactsItr.next();
+ if (heatArtifact.getUniqueId().equals(currArtifact.getUniqueId())) {
+ heatFound = true;
+ heatArtifactMDWrapper.setInnerElement(currArtifact);
+ log.trace("In validateHeatExist found artifact {}", currArtifact);
+ /*
+ * ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(currArtifact.getArtifactType()); if(artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_VOL || artifactType == ArtifactTypeEnum.HEAT_NET){
+ * heatFound = true; } if (heatFound) { heatArtifactMDWrapper.setInnerElement(currArtifact); }
+ */
+ }
+ }
+ if (!heatFound) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISSING_HEAT);
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Can't create heat env artifact because No heat Artifact exist.");
+ }
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateHeatDeploymentArtifact(Component parentComponent, String userId, boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, NodeTypeEnum parentType) {
+ log.trace("Started HEAT pre-payload validation for artifact {}", artifactInfo.getArtifactLabel());
+ // timeout > 0 for HEAT artifacts
+ Integer timeout = artifactInfo.getTimeout();
+ Integer defaultTimeout = (isCreate) ? defaultHeatTimeout : currentArtifact.getTimeout();
+ if (timeout == null) {
+ artifactInfo.setTimeout(defaultTimeout);
+ // HEAT artifact but timeout is invalid
+ } else if (timeout < 1) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_TIMEOUT));
+ }
+
+ // US649856 - Allow several HEAT files on Resource
+ /*
+ * if (isCreate) { Wrapper<ResponseFormat> errorWrapper = new Wrapper<>(); validateSingleArtifactType(errorWrapper, ArtifactTypeEnum.findType(artifactInfo.getArtifactType()), parentComponent, parentType); if (!errorWrapper.isEmpty()) { return
+ * Either.right(errorWrapper.getInnerElement()); } }
+ */
+
+ log.trace("Ended HEAT validation for artifact {}", artifactInfo.getArtifactLabel());
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateResourceType(ResourceTypeEnum resourceType, ArtifactDefinition artifactInfo, List<String> typeList) {
+ String listToString = (typeList != null) ? typeList.toString() : "";
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactInfo.getArtifactName(), listToString, resourceType.getValue());
+ Either<Boolean, ResponseFormat> either = Either.right(responseFormat);
+ String resourceTypeName = resourceType.name();
+ if (typeList != null && typeList.contains(resourceTypeName)) {
+ either = Either.left(true);
+ }
+ return either;
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers(ArtifactDefinition artifactInfo, String artifactType) {
+ if (artifactInfo.getHeatParameters() != null) {
+ for (HeatParameterDefinition heatParam : artifactInfo.getHeatParameters()) {
+ String parameterType = heatParam.getType();
+ HeatParameterType heatParameterType = HeatParameterType.isValidType(parameterType);
+ String artifactTypeStr = artifactType != null ? artifactType : ArtifactTypeEnum.HEAT.getType();
+ if (heatParameterType == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_HEAT_PARAMETER_TYPE, artifactTypeStr, heatParam.getType());
+ return Either.right(responseFormat);
+ }
+
+ StorageOperationStatus validateAndUpdateProperty = heatParametersOperation.validateAndUpdateProperty(heatParam);
+ if (validateAndUpdateProperty != StorageOperationStatus.OK) {
+ log.debug("Heat parameter {} is invalid. Status is: {}", heatParam.getName(), validateAndUpdateProperty);
+ ActionStatus status = ActionStatus.INVALID_HEAT_PARAMETER_VALUE;
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, artifactTypeStr, heatParam.getType(), heatParam.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ }
+ return Either.left(artifactInfo);
+ }
+
+ public List<ArtifactDefinition> getDeploymentArtifacts(Component parentComponent, NodeTypeEnum parentType, String ciId) {
+ List<ArtifactDefinition> deploymentArtifacts = new ArrayList<>();
+ if (parentComponent.getDeploymentArtifacts() != null && ciId != null) {
+ if (NodeTypeEnum.ResourceInstance == parentType) {
+ Either<ComponentInstance, ResponseFormat> getRI = getRIFromComponent(parentComponent, ciId, null, null, null);
+ if (getRI.isRight()) {
+ return deploymentArtifacts;
+ }
+ ComponentInstance ri = getRI.left().value();
+ deploymentArtifacts.addAll(ri.getDeploymentArtifacts().values());
+ } else {
+ deploymentArtifacts.addAll(parentComponent.getDeploymentArtifacts().values());
+ }
+ }
+ return deploymentArtifacts;
+ }
+
+ private void checkCreateFields(User user, ArtifactDefinition artifactInfo, ArtifactGroupTypeEnum type) {
+ // on create if null add informational to current
+ if (artifactInfo.getArtifactGroupType() == null) {
+ artifactInfo.setArtifactGroupType(type);
+ }
+ if (artifactInfo.getUniqueId() != null) {
+ log.error("artifact uniqid cannot be set ignoring");
+ }
+ artifactInfo.setUniqueId(null);
+
+ if (artifactInfo.getArtifactRef() != null) {
+ log.error("artifact ref cannot be set ignoring");
+ }
+ artifactInfo.setArtifactRef(null);
+
+ if (artifactInfo.getArtifactRepository() != null) {
+ log.error("artifact repository cannot be set ignoring");
+ }
+ artifactInfo.setArtifactRepository(null);
+
+ if (artifactInfo.getUserIdCreator() != null) {
+ log.error("creator uuid cannot be set ignoring");
+ }
+ artifactInfo.setArtifactCreator(user.getUserId());
+
+ if (artifactInfo.getUserIdLastUpdater() != null) {
+ log.error("userId of last updater cannot be set ignoring");
+ }
+ artifactInfo.setUserIdLastUpdater(user.getUserId());
+
+ if (artifactInfo.getCreatorFullName() != null) {
+ log.error("creator Full name cannot be set ignoring");
+ }
+ String fullName = user.getFirstName() + " " + user.getLastName();
+ artifactInfo.setUpdaterFullName(fullName);
+
+ if (artifactInfo.getUpdaterFullName() != null) {
+ log.error("updater Full name cannot be set ignoring");
+ }
+ artifactInfo.setUpdaterFullName(fullName);
+
+ if (artifactInfo.getCreationDate() != null) {
+ log.error("Creation Date cannot be set ignoring");
+ }
+ long time = System.currentTimeMillis();
+ artifactInfo.setCreationDate(time);
+
+ if (artifactInfo.getLastUpdateDate() != null) {
+ log.error("Last Update Date cannot be set ignoring");
+ }
+ artifactInfo.setLastUpdateDate(time);
+
+ if (artifactInfo.getEsId() != null) {
+ log.error("es id cannot be set ignoring");
+ }
+ artifactInfo.setEsId(null);
+
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> fetchCurrentArtifact(boolean isCreate, String artifactId) {
+ Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactOperation.getArtifactById(artifactId, true);
+ if (isCreate == false && artifactById.isRight()) {
+ // in case of update artifact must be
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeArtifactMissingError, "Artifact Update / Upload", artifactId);
+ BeEcompErrorManager.getInstance().logBeArtifactMissingError("Artifact Update / Upload", artifactId);
+ log.debug("Failed to fetch artifact {}. error: {}", artifactId, artifactById.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(artifactById.right().value()), artifactId));
+ }
+ if (isCreate && artifactById.isLeft()) {
+ log.debug("Artifact {} already exist", artifactId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactById.left().value().getArtifactLabel()));
+ }
+ ArtifactDefinition currentArtifactInfo = null;
+ if (artifactById.isLeft()) {
+ // get previous value
+ currentArtifactInfo = artifactById.left().value();
+ }
+ return Either.left(currentArtifactInfo);
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleArtifactLabel(String resourceId, boolean isCreate, String artifactId, ArtifactDefinition artifactInfo, String interfaceName, String operationName, ArtifactDefinition currentArtifactInfo,
+ NodeTypeEnum parentType) {
+ String artifactLabel = artifactInfo.getArtifactLabel();
+
+ if (operationName == null && (artifactInfo.getArtifactLabel() == null || artifactInfo.getArtifactLabel().isEmpty())) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingArtifactInformationError, "Artifact Update / Upload", "artifactLabel");
+ BeEcompErrorManager.getInstance().logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ log.debug("missing artifact logical name for component {}", resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_LABEL));
+ }
+ if (isCreate && !artifactInfo.getMandatory()) {
+
+ if (operationName != null) {
+ if (artifactInfo.getArtifactLabel() != null && !operationName.equals(artifactInfo.getArtifactLabel())) {
+ log.debug("artifact label cannot be set {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED));
+ } else {
+ artifactLabel = operationName;
+ }
+ }
+ String displayName = ValidationUtils.cleanArtifactDisplayName(artifactLabel);
+ artifactInfo.setArtifactDisplayName(displayName);
+
+ if (!ValidationUtils.validateArtifactLabel(artifactLabel)) {
+ log.debug("Invalid format form Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactLabel);
+
+ if (artifactLabel.isEmpty()) {
+ log.debug("missing normalized artifact logical name for component {}", resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_LABEL));
+ }
+
+ if (!ValidationUtils.validateArtifactLabelLength(artifactLabel)) {
+ log.debug("Invalid lenght form Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_LABEL, String.valueOf(ValidationUtils.ARTIFACT_LABEL_LENGTH)));
+ }
+ if (!validateLabelUniqueness(resourceId, artifactLabel, parentType)) {
+ log.debug("Non unique Artifact label : {}", artifactLabel);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactLabel));
+ }
+ }
+ artifactInfo.setArtifactLabel(artifactLabel);
+
+ if (currentArtifactInfo != null && !currentArtifactInfo.getArtifactLabel().equals(artifactInfo.getArtifactLabel())) {
+ log.info("Logical artifact's name cannot be changed {}", artifactId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED));
+ }
+ return Either.left(ActionStatus.OK);
+ }
+
+ private boolean validateLabelUniqueness(String parentId, String artifactLabel, NodeTypeEnum parentType) {
+ boolean isUnique = true;
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts = artifactOperation.getArtifacts(parentId, parentType, true);
+ if (artifacts.isLeft()) {
+ for (String label : artifacts.left().value().keySet()) {
+ if (label.equals(artifactLabel)) {
+ isUnique = false;
+ break;
+ }
+ }
+ }
+ if (parentType.equals(NodeTypeEnum.Resource)) {
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation.getAllInterfacesOfResource(parentId, true);
+ if (allInterfacesOfResource.isLeft()) {
+ for (InterfaceDefinition interace : allInterfacesOfResource.left().value().values()) {
+ for (Operation operation : interace.getOperations().values()) {
+ if (operation.getImplementation() != null && operation.getImplementation().getArtifactLabel().equals(artifactLabel)) {
+ isUnique = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return isUnique;
+ }
+
+ private String composeArtifactId(String resourceId, String artifactId, ArtifactDefinition artifactInfo, String interfaceName, String operationName) {
+ String id = artifactId;
+ if (artifactId == null || artifactId.isEmpty()) {
+ String uniqueId = null;
+ if (interfaceName != null && operationName != null) {
+ uniqueId = UniqueIdBuilder.buildArtifactByInterfaceUniqueId(resourceId, interfaceName, operationName, artifactInfo.getArtifactLabel());
+ } else {
+ uniqueId = UniqueIdBuilder.buildPropertyUniqueId(resourceId, artifactInfo.getArtifactLabel());
+ }
+ artifactInfo.setUniqueId(uniqueId);
+ artifactInfo.setEsId(uniqueId);
+ id = uniqueId;
+ } else {
+ artifactInfo.setUniqueId(artifactId);
+ artifactInfo.setEsId(artifactId);
+ }
+ return id;
+ }
+
+ private Either<ActionStatus, ResponseFormat> validateArtifactType(String userId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
+ if (artifactInfo.getArtifactType() == null || artifactInfo.getArtifactType().isEmpty()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeMissingArtifactInformationError, "Artifact Upload / Update");
+ BeEcompErrorManager.getInstance().logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ log.debug("Missing artifact type for artifact {}", artifactInfo.getArtifactName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE));
+ }
+
+ boolean artifactTypeExist = false;
+ Either<List<ArtifactType>, ActionStatus> allArtifactTypes = null;
+ ArtifactGroupTypeEnum artifactGroupType = artifactInfo.getArtifactGroupType();
+
+ if ((artifactGroupType != null) && artifactGroupType.equals(ArtifactGroupTypeEnum.DEPLOYMENT)) {
+ allArtifactTypes = getDeploymentArtifactTypes(userId, artifactInfo, parentType);
+ } else {
+
+ allArtifactTypes = elementOperation.getAllArtifactTypes();
+ }
+ if (allArtifactTypes.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidConfigurationError, "Artifact Upload / Update", "artifactTypes", allArtifactTypes.right().value().name());
+ BeEcompErrorManager.getInstance().logBeInvalidConfigurationError("Artifact Upload / Update", "artifactTypes", allArtifactTypes.right().value().name());
+ log.debug("Failed to retrieve list of suported artifact types. error: {}", allArtifactTypes.right().value());
+ return Either.right(componentsUtils.getResponseFormatByUserId(allArtifactTypes.right().value(), userId));
+ }
+
+ for (ArtifactType type : allArtifactTypes.left().value()) {
+ if (type.getName().equalsIgnoreCase(artifactInfo.getArtifactType())) {
+ artifactInfo.setArtifactType(artifactInfo.getArtifactType().toUpperCase());
+ artifactTypeExist = true;
+ break;
+ }
+ }
+
+ if (!artifactTypeExist) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidTypeError, "Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo.getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
+ BeEcompErrorManager.getInstance().logBeInvalidTypeError("Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo.getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
+ log.debug("Not supported artifact type = {}", artifactInfo.getArtifactType());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType()));
+ }
+
+ return Either.left(ActionStatus.OK);
+ }
+
+ private Either<List<ArtifactType>, ActionStatus> getDeploymentArtifactTypes(String userId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
+
+ Map<String, DeploymentArtifactTypeConfig> deploymentArtifacts = null;
+ List<ArtifactType> artifactTypes = new ArrayList<ArtifactType>();
+
+ if (parentType.equals(NodeTypeEnum.Service)) {
+ deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts();
+ } else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts();
+ } else {
+ deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+ }
+ if (deploymentArtifacts != null) {
+ for (String artifactType : deploymentArtifacts.keySet()) {
+ ArtifactType artifactT = new ArtifactType();
+ artifactT.setName(artifactType);
+ artifactTypes.add(artifactT);
+ }
+ return Either.left(artifactTypes);
+ } else {
+ return Either.right(ActionStatus.GENERAL_ERROR);
+ }
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateFirstUpdateHasPayload(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ if (currentArtifact.getEsId() == null && (artifactInfo.getPayloadData() == null || artifactInfo.getPayloadData().length == 0)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD));
+ }
+ return Either.left(true);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndSetArtifactname(ArtifactDefinition artifactInfo) {
+ if (artifactInfo.getArtifactName() == null || artifactInfo.getArtifactName().isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_NAME));
+ }
+
+ String normalizeFileName = ValidationUtils.normalizeFileName(artifactInfo.getArtifactName());
+ if (normalizeFileName == null || normalizeFileName.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_NAME));
+ }
+ artifactInfo.setArtifactName(normalizeFileName);
+
+ if (!ValidationUtils.validateArtifactNameLength(artifactInfo.getArtifactName())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_NAME, String.valueOf(ValidationUtils.ARTIFACT_NAME_LENGTH)));
+ }
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateArtifactTypeNotChanged(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ if (artifactInfo.getArtifactType() == null || artifactInfo.getArtifactType().isEmpty()) {
+ log.info("artifact type is missing operation ignored");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE));
+ }
+
+ if (!currentArtifact.getArtifactType().equalsIgnoreCase(artifactInfo.getArtifactType())) {
+ log.info("artifact type cannot be changed operation ignored");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ return Either.left(true);
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> validateOrSetArtifactGroupType(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ if (artifactInfo.getArtifactGroupType() == null) {
+ artifactInfo.setArtifactGroupType(currentArtifact.getArtifactGroupType());
+ }
+
+ else if (!currentArtifact.getArtifactGroupType().getType().equalsIgnoreCase(artifactInfo.getArtifactGroupType().getType())) {
+ log.info("artifact group type cannot be changed. operation failed");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ return Either.left(artifactInfo);
+ }
+
+ private void checkAndSetUnUpdatableFields(User user, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, ArtifactGroupTypeEnum type) {
+
+ // on update if null add informational to current
+ if (currentArtifact.getArtifactGroupType() == null && type != null) {
+ currentArtifact.setArtifactGroupType(type);
+ }
+
+ if (artifactInfo.getUniqueId() != null && !currentArtifact.getUniqueId().equals(artifactInfo.getUniqueId())) {
+ log.error("artifact uniqid cannot be set ignoring");
+ }
+ artifactInfo.setUniqueId(currentArtifact.getUniqueId());
+
+ if (artifactInfo.getArtifactRef() != null && !currentArtifact.getArtifactRef().equals(artifactInfo.getArtifactRef())) {
+ log.error("artifact ref cannot be set ignoring");
+ }
+ artifactInfo.setArtifactRef(currentArtifact.getArtifactRef());
+
+ if (artifactInfo.getArtifactRepository() != null && !currentArtifact.getArtifactRepository().equals(artifactInfo.getArtifactRepository())) {
+ log.error("artifact repository cannot be set ignoring");
+ }
+ artifactInfo.setArtifactRepository(currentArtifact.getArtifactRepository());
+
+ if (artifactInfo.getUserIdCreator() != null && !currentArtifact.getUserIdCreator().equals(artifactInfo.getUserIdCreator())) {
+ log.error("creator uuid cannot be set ignoring");
+ }
+ artifactInfo.setUserIdCreator(currentArtifact.getUserIdCreator());
+
+ if (artifactInfo.getArtifactCreator() != null && !currentArtifact.getArtifactCreator().equals(artifactInfo.getArtifactCreator())) {
+ log.error("artifact creator cannot be set ignoring");
+ }
+ artifactInfo.setArtifactCreator(currentArtifact.getArtifactCreator());
+
+ if (artifactInfo.getUserIdLastUpdater() != null && !currentArtifact.getUserIdLastUpdater().equals(artifactInfo.getUserIdLastUpdater())) {
+ log.error("userId of last updater cannot be set ignoring");
+ }
+ artifactInfo.setUserIdLastUpdater(user.getUserId());
+
+ if (artifactInfo.getCreatorFullName() != null && !currentArtifact.getCreatorFullName().equals(artifactInfo.getCreatorFullName())) {
+ log.error("creator Full name cannot be set ignoring");
+ }
+ artifactInfo.setCreatorFullName(currentArtifact.getCreatorFullName());
+
+ if (artifactInfo.getUpdaterFullName() != null && !currentArtifact.getUpdaterFullName().equals(artifactInfo.getUpdaterFullName())) {
+ log.error("updater Full name cannot be set ignoring");
+ }
+ String fullName = user.getFirstName() + " " + user.getLastName();
+ artifactInfo.setUpdaterFullName(fullName);
+
+ if (artifactInfo.getCreationDate() != null && !currentArtifact.getCreationDate().equals(artifactInfo.getCreationDate())) {
+ log.error("Creation Date cannot be set ignoring");
+ }
+ artifactInfo.setCreationDate(currentArtifact.getCreationDate());
+
+ if (artifactInfo.getLastUpdateDate() != null && !currentArtifact.getLastUpdateDate().equals(artifactInfo.getLastUpdateDate())) {
+ log.error("Last Update Date cannot be set ignoring");
+ }
+ long time = System.currentTimeMillis();
+ artifactInfo.setLastUpdateDate(time);
+
+ if (artifactInfo.getEsId() != null && !currentArtifact.getEsId().equals(artifactInfo.getEsId())) {
+ log.error("es id cannot be set ignoring");
+ }
+ artifactInfo.setEsId(currentArtifact.getUniqueId());
+
+ if (artifactInfo.getArtifactDisplayName() != null && !currentArtifact.getArtifactDisplayName().equals(artifactInfo.getArtifactDisplayName())) {
+ log.error(" Artifact Display Name cannot be set ignoring");
+ }
+ artifactInfo.setArtifactDisplayName(currentArtifact.getArtifactDisplayName());
+
+ if (artifactInfo.getServiceApi() != null && !currentArtifact.getServiceApi().equals(artifactInfo.getServiceApi())) {
+ log.debug("serviceApi cannot be set. ignoring.");
+ }
+ artifactInfo.setServiceApi(currentArtifact.getServiceApi());
+
+ if (artifactInfo.getArtifactGroupType() != null && !currentArtifact.getArtifactGroupType().equals(artifactInfo.getArtifactGroupType())) {
+ log.debug("artifact group cannot be set. ignoring.");
+ }
+ artifactInfo.setArtifactGroupType(currentArtifact.getArtifactGroupType());
+
+ artifactInfo.setArtifactVersion(currentArtifact.getArtifactVersion());
+
+ if (artifactInfo.getArtifactUUID() != null && !artifactInfo.getArtifactUUID().isEmpty() && !currentArtifact.getArtifactUUID().equals(artifactInfo.getArtifactUUID())) {
+ log.debug("artifact UUID cannot be set. ignoring.");
+ }
+ artifactInfo.setArtifactUUID(currentArtifact.getArtifactUUID());
+
+ if ((artifactInfo.getHeatParameters() != null) && (currentArtifact.getHeatParameters() != null) && !artifactInfo.getHeatParameters().isEmpty() && !currentArtifact.getHeatParameters().isEmpty()) {
+ checkAndSetUnupdatableHeatParams(artifactInfo.getHeatParameters(), currentArtifact.getHeatParameters());
+ }
+ }
+
+ private void checkAndSetUnupdatableHeatParams(List<HeatParameterDefinition> heatParameters, List<HeatParameterDefinition> currentParameters) {
+
+ Map<String, HeatParameterDefinition> currentParametersMap = getMapOfParameters(currentParameters);
+ for (HeatParameterDefinition parameter : heatParameters) {
+ HeatParameterDefinition currentParam = currentParametersMap.get(parameter.getUniqueId());
+
+ if (currentParam != null) {
+
+ if (parameter.getName() != null && !parameter.getName().equalsIgnoreCase(currentParam.getName())) {
+ log.debug("heat parameter name cannot be updated ({}). ignoring.", parameter.getName());
+ parameter.setName(currentParam.getName());
+ }
+ if (parameter.getDefaultValue() != null && !parameter.getDefaultValue().equalsIgnoreCase(currentParam.getDefaultValue())) {
+ log.debug("heat parameter defaultValue cannot be updated ({}). ignoring.", parameter.getDefaultValue());
+ parameter.setDefaultValue(currentParam.getDefaultValue());
+ }
+ if (parameter.getType() != null && !parameter.getType().equalsIgnoreCase(currentParam.getType())) {
+ log.debug("heat parameter type cannot be updated ({}). ignoring.", parameter.getType());
+ parameter.setType(currentParam.getType());
+ }
+ if (parameter.getDescription() != null && !parameter.getDescription().equalsIgnoreCase(currentParam.getDescription())) {
+ log.debug("heat parameter description cannot be updated ({}). ignoring.", parameter.getDescription());
+ parameter.setDescription(currentParam.getDescription());
+ }
+
+ // check and set current value
+ if ((parameter.getCurrentValue() == null) && (currentParam.getDefaultValue() != null)) {
+ log.debug("heat parameter current value is null. set it to default value {}). ignoring.", parameter.getDefaultValue());
+ parameter.setCurrentValue(currentParam.getDefaultValue());
+ }
+ }
+ }
+ }
+
+ private Map<String, HeatParameterDefinition> getMapOfParameters(List<HeatParameterDefinition> currentParameters) {
+
+ Map<String, HeatParameterDefinition> currentParamsMap = new HashMap<String, HeatParameterDefinition>();
+ for (HeatParameterDefinition param : currentParameters) {
+ currentParamsMap.put(param.getUniqueId(), param);
+ }
+ return currentParamsMap;
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndServiceApiUrl(ArtifactDefinition artifactInfo) {
+ if (!ValidationUtils.validateStringNotEmpty(artifactInfo.getApiUrl())) {
+ log.debug("Artifact url cannot be empty.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_URL));
+ }
+ artifactInfo.setApiUrl(artifactInfo.getApiUrl().toLowerCase());
+
+ if (!ValidationUtils.validateUrl(artifactInfo.getApiUrl())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_API_URL));
+ }
+ if (!ValidationUtils.validateUrlLength(artifactInfo.getApiUrl())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_URL, String.valueOf(ValidationUtils.API_URL_LENGTH)));
+ }
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndCleanDescription(ArtifactDefinition artifactInfo) {
+ if (artifactInfo.getDescription() == null || artifactInfo.getDescription().isEmpty()) {
+ log.debug("Artifact description cannot be empty.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_DESCRIPTION));
+ }
+ String description = artifactInfo.getDescription();
+ description = ValidationUtils.removeNoneUtf8Chars(description);
+ description = ValidationUtils.normaliseWhitespace(description);
+ description = ValidationUtils.stripOctets(description);
+ description = ValidationUtils.removeHtmlTagsOnly(description);
+ if (!ValidationUtils.validateIsEnglish(description)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ if (!ValidationUtils.validateLength(description, ValidationUtils.ARTIFACT_DESCRIPTION_MAX_LENGTH)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_DESCRIPTION, String.valueOf(ValidationUtils.ARTIFACT_DESCRIPTION_MAX_LENGTH)));
+ }
+ artifactInfo.setDescription(description);
+ return Either.left(true);
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateArtifactFlow(org.openecomp.sdc.be.model.Component parent, String parentId, String artifactId, ArtifactDefinition artifactInfo, User user, byte[] decodedPayload,
+ ComponentTypeEnum componentType, AuditingActionEnum auditingAction, String interfaceType, String operationName) {
+ ESArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
+ String prevArtifactId = null;
+ String currArtifactId = artifactId;
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ Either<ArtifactDefinition, Operation> insideEither = null;
+
+ if (artifactData == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Update Artifact");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Update Artifact");
+ log.debug("Failed to create artifact object for ES.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+ }
+ log.debug("Try to update entry on graph");
+ String artifactUniqueId = null;
+ ArtifactDefinition artifactDefinition = null;
+ StorageOperationStatus error = null;
+
+ boolean isLeft = false;
+ if (interfaceType != null && operationName != null) {
+ // lifecycle artifact
+ Operation operation = convertToOperation(artifactInfo, operationName);
+
+ Either<Operation, StorageOperationStatus> result = interfaceLifecycleOperation.updateInterfaceOperation(parentId, interfaceType, operationName, operation);
+
+ isLeft = result.isLeft();
+ if (isLeft) {
+ artifactUniqueId = result.left().value().getUniqueId();
+ artifactDefinition = result.left().value().getImplementation();
+
+ insideEither = Either.right(result.left().value());
+ resultOp = Either.left(insideEither);
+ } else {
+ error = result.right().value();
+ }
+ } else {
+
+ NodeTypeEnum convertParentType = convertParentType(componentType);
+ Either<ArtifactDefinition, StorageOperationStatus> result = artifactOperation.updateArifactOnResource(artifactInfo, parentId, artifactId, convertParentType, true);
+ isLeft = result.isLeft();
+ if (isLeft) {
+ artifactUniqueId = result.left().value().getUniqueId();
+ artifactDefinition = result.left().value();
+
+ insideEither = Either.left(result.left().value());
+ resultOp = Either.left(insideEither);
+ } else {
+ error = result.right().value();
+ }
+ }
+ if (isLeft) {
+ log.debug("Enty on graph is updated. Update artifact in ES");
+ boolean res;
+ // Changing previous and current artifactId for auditing
+ prevArtifactId = currArtifactId;
+ currArtifactId = artifactDefinition.getUniqueId();
+
+ if (!artifactDefinition.getUniqueId().equals(artifactId)) {
+ // different ids ==> artifact node was cloned .
+ // if no data in request get from ES
+ if (decodedPayload == null) {
+ if (!artifactDefinition.getMandatory() || artifactDefinition.getEsId() != null) {
+ Either<ESArtifactData, CassandraOperationStatus> artifactFromCassandra = artifactCassandraDao.getArtifact(artifactId);
+ // Either<ESArtifactData, ResourceUploadStatus>
+ // artifactfromES = daoUploader.getArtifact(artifactId);
+ if (artifactFromCassandra.isRight()) {
+ log.debug("Failed to get artifact data from ES for artifact id {}", artifactId);
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactFromCassandra.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus));
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+ }
+ // clone data to new artifact
+ artifactData.setData(artifactFromCassandra.left().value().getData());
+ }
+ }
+ artifactData.setId(artifactDefinition.getUniqueId());
+ // create new entry in ES
+ res = true;
+ if (artifactData.getData() != null) {
+ res = saveArtifacts(artifactData, parentId, false);
+ // set on graph object id of artifact in ES!
+ if (res) {
+ artifactInfo.setEsId(artifactData.getId());
+ Either<ArtifactDefinition, StorageOperationStatus> updateArifactRes = artifactOperation.updateArifactDefinition(artifactInfo, true);
+ if (updateArifactRes.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateArifactRes.right().value()));
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+
+ } else {
+ insideEither = Either.left(updateArifactRes.left().value());
+ resultOp = Either.left(insideEither);
+ }
+ }
+ }
+ } else {
+ res = true;
+ if (artifactData.getData() != null) {
+ // override artifact in ES
+ res = saveArtifacts(artifactData, parentId, true);
+ if (res && artifactDefinition.getMandatory()) {
+ artifactInfo.setEsId(artifactData.getId());
+ Either<ArtifactDefinition, StorageOperationStatus> updateArifactRes = artifactOperation.updateArifactDefinition(artifactInfo, true);
+ if (updateArifactRes.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(updateArifactRes.right().value()), artifactId);
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ return resultOp;
+
+ }
+ }
+ }
+ }
+ if (res) {
+ log.debug("Artifact saved into ES - {}", artifactUniqueId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ // resultOp = Either.left(result.left().value());
+ // return resultOp;
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Update Artifact");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Update Artifact");
+ log.debug("Failed to save the artifact.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ // return resultOp;
+ }
+ } else {
+ log.debug("Failed to create entry on graph for artifact {}", artifactInfo.getArtifactDisplayName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(error), artifactInfo.getArtifactDisplayName());
+ handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ resultOp = Either.right(responseFormat);
+ // return resultOp;
+ }
+
+ return resultOp;
+ }
+
+ private Either<byte[], ResponseFormat> handlePayload(ArtifactDefinition artifactInfo, boolean isArtifactMetadataUpdate) {
+ log.trace("Starting payload handling");
+ byte[] payload = artifactInfo.getPayloadData();
+ byte[] decodedPayload = null;
+
+ if (payload != null && payload.length != 0) {
+
+ decodedPayload = Base64.decodeBase64(payload);
+ if (decodedPayload.length == 0) {
+ log.debug("Failed to decode the payload.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return Either.right(responseFormat);
+ }
+
+ String checkSum = GeneralUtility.calculateMD5ByByteArray(decodedPayload);
+ artifactInfo.setArtifactChecksum(checkSum);
+ log.trace("Calculated checksum, base64 payload: {}, checksum: {}", payload, checkSum);
+
+ // Specific payload validations of different types
+ Either<Boolean, ResponseFormat> isValidPayload = Either.left(true);
+ if (isDeploymentArtifact(artifactInfo)) {
+ log.trace("Starting deployment artifacts payload validation");
+ String artifactType = artifactInfo.getArtifactType();
+ if (ArtifactTypeEnum.HEAT.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.HEAT_VOL.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.HEAT_NET.getType().equalsIgnoreCase(artifactType)
+ || ArtifactTypeEnum.HEAT_ENV.getType().equalsIgnoreCase(artifactType)) {
+ isValidPayload = validateDeploymentHeatPayload(decodedPayload, artifactType);
+ if (isValidPayload.isLeft()) {
+ isValidPayload = extractHeatParameters(artifactInfo);
+ }
+ } else if (ArtifactTypeEnum.YANG_XML.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VNF_CATALOG.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VF_LICENSE.getType().equalsIgnoreCase(artifactType)
+ || ArtifactTypeEnum.VENDOR_LICENSE.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().equalsIgnoreCase(artifactType)
+ || ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equalsIgnoreCase(artifactType)) {
+ isValidPayload = validateYangPayload(decodedPayload, artifactType);
+ // else
+ // if(ArtifactTypeEnum.APPC_CONFIG.getType().equalsIgnoreCase(artifactType)
+ // || ){
+ } else if (ArtifactTypeEnum.DCAE_INVENTORY_JSON.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.DCAE_INVENTORY_TOSCA.getType().equalsIgnoreCase(artifactType)) {
+ String artifactFileName = artifactInfo.getArtifactName();
+ String fileExtension = GeneralUtility.getFilenameExtension(artifactFileName).toLowerCase();
+ switch (fileExtension) {
+ case "xml":
+ isValidPayload = validateYangPayload(decodedPayload, artifactType);
+ break;
+ case "json":
+ isValidPayload = validateJsonPayload(decodedPayload, artifactType);
+ break;
+ case "yml":
+ case "yaml":
+ isValidPayload = validateYmlPayload(decodedPayload, artifactType);
+ break;
+ }
+ }
+ }
+ if (isValidPayload.isRight()) {
+ ResponseFormat responseFormat = isValidPayload.right().value();
+ return Either.right(responseFormat);
+ }
+
+ } // null/empty payload is normal if called from metadata update ONLY.
+ // The validation of whether this is metadata/payload update case is
+ // currently done separately
+ else {
+ if (!isArtifactMetadataUpdate) {
+ log.debug("Payload is missing.");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
+ return Either.right(responseFormat);
+ }
+ }
+ log.trace("Ended payload handling");
+ return Either.left(decodedPayload);
+ }
+
+ private Either<Boolean, ResponseFormat> validateDeploymentHeatPayload(byte[] payload, String artifactType) {
+ // Basic YAML validation
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ if (!yamlToObjectConverter.isValidYaml(payload)) {
+ log.debug("Invalid YAML format");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML, artifactType);
+ return Either.right(responseFormat);
+ }
+ if (!ArtifactTypeEnum.HEAT_ENV.getType().equalsIgnoreCase(artifactType)) {
+ // HEAT specific YAML validation
+ DeploymentArtifactHeatConfiguration heatConfiguration = yamlToObjectConverter.convert(payload, DeploymentArtifactHeatConfiguration.class);
+ if (heatConfiguration == null || heatConfiguration.getHeat_template_version() == null || heatConfiguration.getResources() == null) {
+ log.debug("HEAT doesn't contain required \"heat_template_version\" and \"resources\" sections ");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, artifactType);
+ return Either.right(responseFormat);
+ }
+ }
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateYmlPayload(byte[] decodedPayload, String artifactType) {
+ Either<Boolean, ResponseFormat> res = Either.left(true);
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ if (!yamlToObjectConverter.isValidYaml(decodedPayload)) {
+ log.debug("Invalid YAML format");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML, artifactType);
+ res = Either.right(responseFormat);
+ }
+
+ return res;
+ }
+
+ private Either<Boolean, ResponseFormat> validateYangPayload(byte[] payload, String artifactType) {
+ boolean isXmlValid = isValidXml(payload);
+ if (!isXmlValid) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.INVALID_XML, artifactType);
+ log.debug("Invalid XML content");
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateJsonPayload(byte[] payload, String type) {
+ boolean isJsonValid = isValidJson(payload);
+ if (!isJsonValid) {
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.INVALID_JSON, type);
+ log.debug("Invalid JSON content");
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ }
+
+ public void handleTransaction(Either<Operation, ResponseFormat> opState) {
+ if (opState == null || opState.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ }
+
+ public Either<Operation, ResponseFormat> deleteArtifactByInterface(String resourceId, String interfaceType, String operationName, String userId, String artifactId, ImmutablePair<User, Resource> userResourceAuditPair, boolean shouldLock,
+ boolean inTransaction) {
+ User user = new User();
+ user.setUserId(userId);
+ Either<Resource, StorageOperationStatus> parent = resourceOperation.getResource(resourceId);
+ if (parent.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(parent.right().value()));
+ return Either.right(responseFormat);
+ }
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = handleDelete(resourceId, artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, parent.left().value(), interfaceType, operationName,
+ false, inTransaction);
+ if (handleDelete.isRight()) {
+ return Either.right(handleDelete.right().value());
+ }
+ Either<ArtifactDefinition, Operation> result = handleDelete.left().value();
+ return Either.left(result.right().value());
+
+ }
+
+ public StorageOperationStatus deleteAllComponentArtifactsIfNotOnGraph(List<ArtifactDefinition> artifacts) {
+
+ if (artifacts != null && !artifacts.isEmpty()) {
+ for (ArtifactDefinition artifactDefinition : artifacts) {
+ String esId = artifactDefinition.getEsId();
+ if (esId != null && !esId.isEmpty()) {
+ StorageOperationStatus deleteIfNotOnGraph = deleteIfNotOnGraph(artifactDefinition.getUniqueId(), esId, false);
+ if (!deleteIfNotOnGraph.equals(StorageOperationStatus.OK)) {
+ return deleteIfNotOnGraph;
+ }
+ }
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private Operation convertToOperation(ArtifactDefinition artifactInfo, String operationName) {
+ Operation op = new Operation();
+ long time = System.currentTimeMillis();
+ op.setCreationDate(time);
+
+ String artifactName = artifactInfo.getArtifactName();
+ artifactInfo.setArtifactName(createInterfaceArtifactNameFromOperation(operationName, artifactName));
+
+ op.setImplementation(artifactInfo);
+ op.setLastUpdateDate(time);
+ return op;
+ }
+
+ private String createInterfaceArtifactNameFromOperation(String operationName, String artifactName) {
+ String newArtifactName = operationName + "_" + artifactName;
+ log.trace("converting artifact name {} to {}", artifactName, newArtifactName);
+ return newArtifactName;
+ }
+
+ public StorageOperationStatus deleteIfNotOnGraph(String artifactId, String artifactEsId, boolean deleteOnlyPayload) {
+ log.debug("deleteIfNotOnGraph: delete only payload = {}", deleteOnlyPayload);
+ Either<ArtifactData, TitanOperationStatus> checkArtifactNode = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ArtifactRef), artifactId, ArtifactData.class);
+ if ((artifactEsId != null && !artifactEsId.isEmpty())) {
+ boolean isNotExistOnGraph = checkArtifactNode.isRight() && checkArtifactNode.right().value().equals(TitanOperationStatus.NOT_FOUND);
+
+ if ((isNotExistOnGraph) || (checkArtifactNode.left().value().getArtifactDataDefinition().getMandatory() && deleteOnlyPayload)
+ || (ArtifactGroupTypeEnum.SERVICE_API.equals(checkArtifactNode.left().value().getArtifactDataDefinition().getArtifactGroupType()) && deleteOnlyPayload)) {
+ // last one. need to delete in ES
+ log.debug("Entry on graph is deleted. Delete artifact in ES for id = {}", artifactEsId);
+ artifactCassandraDao.deleteArtifact(artifactEsId);
+ return StorageOperationStatus.OK;
+ // return
+ // componentsUtils.getResponseFormatByResourceId(ActionStatus.OK,
+ // resourceId);
+
+ } else {
+ log.debug("Entry on graph is deleted. Exist more connections on this artifact. Don't delete artifact in ES for id = {}", artifactEsId);
+ return StorageOperationStatus.OK;
+ }
+
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ // download by MSO
+ public Either<byte[], ResponseFormat> downloadRsrcArtifactByNames(String serviceName, String serviceVersion, String resourceName, String resourceVersion, String artifactName) {
+
+ // General validation
+ if (serviceName == null || serviceVersion == null || resourceName == null || resourceVersion == null || artifactName == null) {
+ log.debug("One of the function parameteres is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ // Normalizing artifact name
+ artifactName = ValidationUtils.normalizeFileName(artifactName);
+
+ // Resource validation
+ Either<Resource, ResponseFormat> validateResourceNameAndVersion = validateResourceNameAndVersion(resourceName, resourceVersion);
+ if (validateResourceNameAndVersion.isRight()) {
+ return Either.right(validateResourceNameAndVersion.right().value());
+ }
+
+ Resource resource = validateResourceNameAndVersion.left().value();
+ String resourceId = resource.getUniqueId();
+
+ // Service validation
+ Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
+ if (validateServiceNameAndVersion.isRight()) {
+ return Either.right(validateServiceNameAndVersion.right().value());
+ }
+
+ Map<String, ArtifactDefinition> artifacts = resource.getDeploymentArtifacts();
+ if (artifacts == null || artifacts.isEmpty()) {
+ log.debug("Deployment artifacts of resource {} are not found", resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ ArtifactDefinition deploymentArtifact = null;
+
+ for (ArtifactDefinition artifactDefinition : artifacts.values()) {
+ if (artifactDefinition.getArtifactName() != null && artifactDefinition.getArtifactName().equals(artifactName)) {
+ log.debug("Found deployment artifact {}", artifactName);
+ deploymentArtifact = artifactDefinition;
+ break;
+ }
+ }
+
+ if (deploymentArtifact == null) {
+ log.debug("No deployment artifact {} was found for resource {}", artifactName, resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ // Downloading the artifact
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(deploymentArtifact);
+ if (downloadArtifactEither.isRight()) {
+ log.debug("Download artifact {} failed", artifactName);
+ return Either.right(downloadArtifactEither.right().value());
+ }
+ log.trace("Download of resource artifact succeeded, uniqueId {}", deploymentArtifact.getUniqueId());
+ return Either.left(downloadArtifactEither.left().value().getRight());
+ }
+
+ // download by MSO
+ public Either<byte[], ResponseFormat> downloadRsrcInstArtifactByNames(String serviceName, String serviceVersion, String resourceInstanceName, String artifactName) {
+
+ // General validation
+ if (serviceName == null || serviceVersion == null || resourceInstanceName == null || artifactName == null) {
+ log.debug("One of the function parameteres is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ // Normalizing artifact name
+ artifactName = ValidationUtils.normalizeFileName(artifactName);
+
+ // Resource validation
+ /*
+ * Either<Resource, ResponseFormat> validateResourceNameAndVersion = validateResourceNameAndVersion(resourceName, resourceVersion); if (validateResourceNameAndVersion.isRight()) { return
+ * Either.right(validateResourceNameAndVersion.right().value()); }
+ *
+ * Resource resource = validateResourceNameAndVersion.left().value(); String resourceId = resource.getUniqueId();
+ */
+
+ // Service validation
+ Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
+ if (validateServiceNameAndVersion.isRight()) {
+ return Either.right(validateServiceNameAndVersion.right().value());
+ }
+
+ Service service = validateServiceNameAndVersion.left().value();
+
+ // ResourceInstance validation
+ Either<ComponentInstance, ResponseFormat> validateResourceInstance = validateResourceInstance(service, resourceInstanceName);
+ if (validateResourceInstance.isRight()) {
+ return Either.right(validateResourceInstance.right().value());
+ }
+
+ ComponentInstance resourceInstance = validateResourceInstance.left().value();
+
+ Map<String, ArtifactDefinition> artifacts = resourceInstance.getDeploymentArtifacts();
+
+ final String finalArtifactName = artifactName;
+ Predicate<ArtifactDefinition> filterArtifactByName = p -> p.getArtifactName().equals(finalArtifactName);
+
+ boolean hasDeploymentArtifacts = artifacts != null && artifacts.values().stream().anyMatch(filterArtifactByName);
+ ArtifactDefinition deployableArtifact;
+
+ if (!hasDeploymentArtifacts) {
+ log.debug("Deployment artifact with name {} not found", artifactName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ log.debug("Found deployment artifact {}", artifactName);
+ deployableArtifact = artifacts.values().stream().filter(filterArtifactByName).findFirst().get();
+ // Downloading the artifact
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(deployableArtifact);
+
+ if (downloadArtifactEither.isRight()) {
+ log.debug("Download artifact {} failed", artifactName);
+ return Either.right(downloadArtifactEither.right().value());
+ }
+ log.trace("Download of resource artifact succeeded, uniqueId {}", deployableArtifact.getUniqueId());
+ return Either.left(downloadArtifactEither.left().value().getRight());
+ }
+
+ private Either<ComponentInstance, ResponseFormat> validateResourceInstance(Service service, String resourceInstanceName) {
+
+ List<ComponentInstance> riList = service.getComponentInstances();
+ for (ComponentInstance ri : riList) {
+ if (ri.getNormalizedName().equals(resourceInstanceName))
+ return Either.left(ri);
+ }
+
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND, resourceInstanceName));
+ }
+
+ private Either<Service, ResponseFormat> validateServiceNameAndVersion(String serviceName, String serviceVersion) {
+
+ Either<List<Service>, StorageOperationStatus> serviceListBySystemName = serviceOperation.getServiceListBySystemName(serviceName, false);
+ if (serviceListBySystemName.isRight()) {
+ log.debug("Couldn't fetch any service with name {}", serviceName);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceListBySystemName.right().value(), ComponentTypeEnum.SERVICE), serviceName));
+ }
+ List<Service> serviceList = serviceListBySystemName.left().value();
+ if (serviceList == null || serviceList.isEmpty()) {
+ log.debug("Couldn't fetch any service with name {}", serviceName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceName));
+ }
+
+ Service foundService = null;
+ for (Service service : serviceList) {
+ if (service.getVersion().equals(serviceVersion)) {
+ log.trace("Found service with version {}", serviceVersion);
+ foundService = service;
+ break;
+ }
+ }
+
+ if (foundService == null) {
+ log.debug("Couldn't find version {} for service {}", serviceVersion, serviceName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.SERVICE.getValue(), serviceVersion));
+ }
+ return Either.left(foundService);
+ }
+
+ private Either<Resource, ResponseFormat> validateResourceNameAndVersion(String resourceName, String resourceVersion) {
+ Either<List<Resource>, StorageOperationStatus> resourceListBySystemName = resourceOperation.getResourceListBySystemName(resourceName, false);
+ if (resourceListBySystemName.isRight()) {
+ log.debug("Couldn't fetch any resource with name {}", resourceName);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceListBySystemName.right().value()), resourceName));
+ }
+ List<Resource> resourceList = resourceListBySystemName.left().value();
+ if (resourceList == null || resourceList.isEmpty()) {
+ log.debug("Couldn't fetch any resource with name {}", resourceName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName));
+ }
+
+ Resource foundResource = null;
+ for (Resource resource : resourceList) {
+ if (resource.getVersion().equals(resourceVersion)) {
+ log.trace("Found resource with version {}", resourceVersion);
+ foundResource = resource;
+ break;
+ }
+ }
+
+ if (foundResource == null) {
+ log.debug("Couldn't find version {} for resource {}", resourceVersion, resourceName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.RESOURCE.getValue(), resourceVersion));
+ }
+ return Either.left(foundResource);
+ }
+
+ public Either<byte[], ResponseFormat> downloadServiceArtifactByNames(String serviceName, String serviceVersion, String artifactName) {
+ // Validation
+ log.trace("Starting download of service interface artifact, serviceName {}, serviceVersion {}, artifact name {}", serviceName, serviceVersion, artifactName);
+ if (serviceName == null || serviceVersion == null || artifactName == null) {
+ log.debug("One of the function parameteres is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ // Normalizing artifact name
+ artifactName = ValidationUtils.normalizeFileName(artifactName);
+
+ // Service validation
+ Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
+ if (validateServiceNameAndVersion.isRight()) {
+ return Either.right(validateServiceNameAndVersion.right().value());
+ }
+
+ String serviceId = validateServiceNameAndVersion.left().value().getUniqueId();
+
+ // Looking for deployment artifacts
+ Service service = validateServiceNameAndVersion.left().value();
+ Map<String, ArtifactDefinition> artifacts = service.getDeploymentArtifacts();
+ if (artifacts == null || artifacts.isEmpty()) {
+ log.debug("Deployment artifacts of service {} are not found", serviceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ ArtifactDefinition deploymentArtifact = null;
+
+ for (ArtifactDefinition artifactDefinition : artifacts.values()) {
+ if (artifactDefinition.getArtifactName().equals(artifactName)) {
+ log.debug("Found deployment artifact {}", artifactName);
+ deploymentArtifact = artifactDefinition;
+ }
+ }
+
+ if (deploymentArtifact == null) {
+ log.debug("No deployment artifact {} was found for service {}", artifactName, serviceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ // Downloading the artifact
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(deploymentArtifact);
+ if (downloadArtifactEither.isRight()) {
+ log.debug("Download artifact {} failed", artifactName);
+ return Either.right(downloadArtifactEither.right().value());
+ }
+ log.trace("Download of service artifact succeeded, uniqueId {}", deploymentArtifact.getUniqueId());
+ return Either.left(downloadArtifactEither.left().value().getRight());
+ }
+
+ public Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifact(String artifactUniqueId) {
+ log.trace("Starting download of artifact, uniqueId {}", artifactUniqueId);
+ Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactOperation.getArtifactById(artifactUniqueId, false);
+ if (artifactById.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(artifactById.right().value());
+ log.debug("Error when getting artifact info by id{}, error: {}", artifactUniqueId, actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, ""));
+ }
+ ArtifactDefinition artifactDefinition = artifactById.left().value();
+ if (artifactDefinition == null) {
+ log.debug("Empty artifact definition returned from DB by artifact id {}", artifactUniqueId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ""));
+ }
+
+ return downloadArtifact(artifactDefinition);
+ }
+
+ private boolean checkArtifactInComponent(org.openecomp.sdc.be.model.Component component, String artifactId) {
+ boolean found = false;
+ Map<String, ArtifactDefinition> artifactsS = component.getArtifacts();
+ if (artifactsS != null) {
+ for (Map.Entry<String, ArtifactDefinition> entry : artifactsS.entrySet()) {
+ if (entry.getValue().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ Map<String, ArtifactDefinition> deploymentArtifactsS = component.getDeploymentArtifacts();
+ if (!found && deploymentArtifactsS != null) {
+ for (Map.Entry<String, ArtifactDefinition> entry : deploymentArtifactsS.entrySet()) {
+ if (entry.getValue().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ Map<String, ArtifactDefinition> toscaArtifactsS = component.getToscaArtifacts();
+ if (!found && toscaArtifactsS != null) {
+ for (Map.Entry<String, ArtifactDefinition> entry : toscaArtifactsS.entrySet()) {
+ if (entry.getValue().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ switch (component.getComponentType()) {
+ case RESOURCE:
+ Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
+ if (!found && interfaces != null) {
+ for (Map.Entry<String, InterfaceDefinition> entry : interfaces.entrySet()) {
+ Map<String, Operation> operations = entry.getValue().getOperations();
+ for (Map.Entry<String, Operation> entryOp : operations.entrySet()) {
+ if (entryOp.getValue().getImplementation() != null && entryOp.getValue().getImplementation().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case SERVICE:
+ Map<String, ArtifactDefinition> apiArtifacts = ((Service) component).getServiceApiArtifacts();
+ if (!found && apiArtifacts != null) {
+ for (Map.Entry<String, ArtifactDefinition> entry : apiArtifacts.entrySet()) {
+ if (entry.getValue().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ break;
+ default:
+
+ }
+
+ return found;
+ }
+
+ private boolean checkArtifactInResourceInstance(Component component, String resourceInstanceId, String artifactId) {
+
+ boolean found = false;
+ List<ComponentInstance> resourceInstances = component.getComponentInstances();
+ ComponentInstance resourceInstance = null;
+ for (ComponentInstance ri : resourceInstances) {
+ if (ri.getUniqueId().equals(resourceInstanceId)) {
+ resourceInstance = ri;
+ break;
+ }
+ }
+ if (resourceInstance != null) {
+ Map<String, ArtifactDefinition> artifacts = resourceInstance.getDeploymentArtifacts();
+ if (artifacts != null) {
+ for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
+ if (entry.getValue().getUniqueId().equals(artifactId)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ return found;
+ }
+
+ private Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists(String componentId, String userId, AuditingActionEnum auditingAction, User user, String artifactId, ComponentTypeEnum componentType,
+ String containerComponentType, boolean inTransaction) {
+
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ if (containerComponentType != null && NodeTypeEnum.ResourceInstance == nodeType) {
+ nodeType = (ComponentTypeEnum.findByParamName(containerComponentType)).getNodeType();
+ }
+ ComponentOperation componentOperation = getComponentOperation(nodeType);
+
+ if (componentOperation == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ log.debug("addArtifact - not supported component type {}", componentType);
+ handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ Either<? extends org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResult = componentOperation.getComponent(componentId, inTransaction);
+
+ if (componentResult.isRight()) {
+ ActionStatus status = (componentType.equals(ComponentTypeEnum.RESOURCE)) ? ActionStatus.RESOURCE_NOT_FOUND : ActionStatus.SERVICE_NOT_FOUND;
+ ComponentTypeEnum componentForAudit = (componentType.equals(ComponentTypeEnum.RESOURCE)) ? ComponentTypeEnum.RESOURCE : ComponentTypeEnum.SERVICE;
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, componentId);
+ log.debug("Service not found, serviceId {}", componentId);
+ handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentForAudit, null);
+ return Either.right(responseFormat);
+ }
+ return Either.left(componentResult.left().value());
+ }
+
+ private Either<Boolean, ResponseFormat> validateWorkOnComponent(org.openecomp.sdc.be.model.Component component, String userId, AuditingActionEnum auditingAction, User user, String artifactId, ArtifactOperation operation,
+ ComponentTypeEnum componentType) {
+ if (operation != ArtifactOperation.Download) {
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ String uniqueId = component.getUniqueId();
+ log.debug("Service status isn't CHECKOUT or user isn't owner, serviceId {}", uniqueId);
+ handleAuditing(auditingAction, component, uniqueId, user, null, null, artifactId, canWork.right().value(), component.getComponentType(), null);
+ return Either.right(canWork.right().value());
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateWorkOnResource(Resource resource, String userId, AuditingActionEnum auditingAction, User user, String artifactId, ArtifactOperation operation) {
+ if (operation != ArtifactOperation.Download) {
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ String uniqueId = resource.getUniqueId();
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("Resource status isn't CHECKOUT or user isn't owner, resourceId {}", uniqueId);
+ handleAuditing(auditingAction, resource, uniqueId, user, null, null, artifactId, responseFormat, ComponentTypeEnum.RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateUserRole(User user, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperation operation) {
+
+ if (operation != ArtifactOperation.Download) {
+ String role = user.getRole();
+ if (!role.equals(Role.ADMIN.name()) && !role.equals(Role.DESIGNER.name())) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("addArtifact - user isn't permitted to perform operation, userId {}, role {}", user.getUserId(), role);
+ handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<User, ResponseFormat> validateUserExists(String userId, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType) {
+
+ return validateUserExists(userId, auditingAction, componentId, artifactId, componentType, false);
+
+ }
+
+ private Either<User, ResponseFormat> validateUserExists(String userId, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, boolean inTransaction) {
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, auditingAction.getName(), inTransaction);
+
+ if (validateUserExists.isRight()) {
+ User user = new User();
+ user.setUserId(userId);
+ handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, validateUserExists.right().value(), componentType, null);
+ return Either.right(validateUserExists.right().value());
+ }
+ return Either.left(validateUserExists.left().value());
+ }
+
+ private AuditingActionEnum detectAuditingType(ArtifactOperation operation, String origMd5) {
+ AuditingActionEnum auditingAction = null;
+ switch (operation) {
+ case Create:
+ auditingAction = operation.isExternalApi() ? AuditingActionEnum.ARTIFACT_UPLOAD_BY_API : AuditingActionEnum.ARTIFACT_UPLOAD;
+ break;
+ case Update:
+ auditingAction = operation.isExternalApi() ? AuditingActionEnum.ARTIFACT_UPLOAD_BY_API : origMd5 == null ? AuditingActionEnum.ARTIFACT_METADATA_UPDATE : AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE;
+ break;
+ case Delete:
+ auditingAction = operation.isExternalApi() ? AuditingActionEnum.ARTIFACT_DELETE_BY_API : AuditingActionEnum.ARTIFACT_DELETE;
+ break;
+ case Download:
+ auditingAction = operation.isExternalApi() ? AuditingActionEnum.DOWNLOAD_ARTIFACT : AuditingActionEnum.ARTIFACT_DOWNLOAD;
+ break;
+ default:
+ break;
+ }
+ return auditingAction;
+ }
+
+ private Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifact(ArtifactDefinition artifactDefinition) {
+ String esArtifactId = artifactDefinition.getEsId();
+ Either<ESArtifactData, CassandraOperationStatus> artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
+ if (artifactfromES.isRight()) {
+ CassandraOperationStatus resourceUploadStatus = artifactfromES.right().value();
+ StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
+ log.debug("Error when getting artifact from ES, error: {}", actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName()));
+ }
+
+ ESArtifactData esArtifactData = artifactfromES.left().value();
+ byte[] data = esArtifactData.getDataAsArray();
+ if (data == null) {
+ log.debug("Artifact data from ES is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactDefinition.getArtifactDisplayName()));
+ }
+ String artifactName = artifactDefinition.getArtifactName();
+ log.trace("Download of artifact succeeded, uniqueId {}, artifact file name {}", artifactDefinition.getUniqueId(), artifactName);
+ return Either.left(new ImmutablePair<String, byte[]>(artifactName, data));
+ }
+
+ public ESArtifactData createEsArtifactData(ArtifactDataDefinition artifactInfo, byte[] artifactPayload) {
+ ESArtifactData artifactData = new ESArtifactData(artifactInfo.getEsId(), artifactPayload);
+ return artifactData;
+ }
+
+ private boolean saveArtifacts(ESArtifactData artifactData, String resourceId, boolean reload) {
+
+ CassandraOperationStatus resourceUploadStatus = artifactCassandraDao.saveArtifact(artifactData);
+
+ if (resourceUploadStatus.equals(CassandraOperationStatus.OK)) {
+ log.debug("Artifact {} was saved in component {}.", artifactData.getId(), resourceId);
+ } else {
+ log.info("Failed to save artifact {}.", artifactData.getId());
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isArtifactMetadataUpdate(AuditingActionEnum auditingActionEnum) {
+ return (auditingActionEnum.equals(AuditingActionEnum.ARTIFACT_METADATA_UPDATE));
+ }
+
+ private boolean isDeploymentArtifact(ArtifactDefinition artifactInfo) {
+ return (ArtifactGroupTypeEnum.DEPLOYMENT.equals(artifactInfo.getArtifactGroupType()));
+ }
+
+ public IResourceOperation getResourceOperation() {
+ return this.resourceOperation;
+ }
+
+ public Either<ArtifactDefinition, ResponseFormat> createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, String userId, ArtifactGroupTypeEnum groupType, boolean inTransaction) {
+ Either<User, ActionStatus> user = userAdminManager.getUser(userId, inTransaction);
+ if (user.isRight()) {
+ ResponseFormat responseFormat;
+ if (user.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ log.debug("create artifact placeholder - not authorized user, userId {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ } else {
+ log.debug("create artifact placeholder - failed to authorize user, userId {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(user.right().value());
+ }
+ return Either.right(responseFormat);
+ }
+
+ ArtifactDefinition artifactDefinition = createArtifactPlaceHolderInfo(resourceId, logicalName, artifactInfoMap, user.left().value(), groupType);
+ return Either.left(artifactDefinition);
+ }
+
+ public ArtifactDefinition createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, User user, ArtifactGroupTypeEnum groupType) {
+ ArtifactDefinition artifactInfo = new ArtifactDefinition();
+
+ String artifactName = (String) artifactInfoMap.get(ARTIFACT_PLACEHOLDER_DISPLAY_NAME);
+ String artifactType = (String) artifactInfoMap.get(ARTIFACT_PLACEHOLDER_TYPE);
+ String artifactDescription = (String) artifactInfoMap.get(ARTIFACT_PLACEHOLDER_DESCRIPTION);
+
+ artifactInfo.setArtifactDisplayName(artifactName);
+ artifactInfo.setArtifactLabel(logicalName.toLowerCase());
+ artifactInfo.setArtifactType(artifactType);
+ artifactInfo.setDescription(artifactDescription);
+ artifactInfo.setArtifactGroupType(groupType);
+ setDefaultArtifactTimeout(groupType, artifactInfo);
+
+ setArtifactPlaceholderCommonFields(resourceId, user, artifactInfo);
+
+ return artifactInfo;
+ }
+
+ private void setDefaultArtifactTimeout(ArtifactGroupTypeEnum groupType, ArtifactDefinition artifactInfo) {
+ if (groupType.equals(ArtifactGroupTypeEnum.DEPLOYMENT)) {
+ artifactInfo.setTimeout(defaultHeatTimeout);
+ } else {
+ artifactInfo.setTimeout(NON_HEAT_TIMEOUT);
+ }
+ }
+
+ private void setArtifactPlaceholderCommonFields(String resourceId, User user, ArtifactDefinition artifactInfo) {
+ String uniqueId = null;
+
+ if (resourceId != null) {
+ uniqueId = UniqueIdBuilder.buildPropertyUniqueId(resourceId.toLowerCase(), artifactInfo.getArtifactLabel().toLowerCase());
+ artifactInfo.setUniqueId(uniqueId);
+ }
+ artifactInfo.setUserIdCreator(user.getUserId());
+ String fullName = user.getFullName();
+ artifactInfo.setUpdaterFullName(fullName);
+
+ long time = System.currentTimeMillis();
+
+ artifactInfo.setCreatorFullName(fullName);
+ artifactInfo.setCreationDate(time);
+
+ artifactInfo.setLastUpdateDate(time);
+ artifactInfo.setUserIdLastUpdater(user.getUserId());
+
+ artifactInfo.setMandatory(true);
+ }
+
+ public Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifacts(String parentId, NodeTypeEnum parentType, boolean inTransaction, ArtifactGroupTypeEnum groupType) {
+ return artifactOperation.getArtifacts(parentId, parentType, inTransaction, groupType.getType());
+ }
+
+ public Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact(ArtifactDefinition artifactHeatEnv, ArtifactDefinition artifact, String parentId, NodeTypeEnum parentType, boolean inTransaction) {
+ return artifactOperation.addHeatEnvArtifact(artifactHeatEnv, artifact, parentId, parentType, inTransaction);
+
+ }
+
+ private Either<ESArtifactData, ResponseFormat> createEsHeatEnvArtifactDataFromString(ArtifactDefinition artifactDefinition, String parameters) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
+ sb.append(parameters);
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
+ byte[] payload = sb.toString().getBytes();
+
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+
+ /*
+ * if (!yamlToObjectConverter.isValidYaml(payload)) { log.debug("Invalid YAML format"); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML, ArtifactTypeEnum.HEAT_ENV.getType()); return
+ * Either.right(responseFormat); }
+ */
+
+ ESArtifactData artifactData = createEsArtifactData(artifactDefinition, payload);
+ return Either.left(artifactData);
+ }
+
+ /**
+ *
+ * @param artifactDefinition
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> generateHeatEnvArtifact(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier, boolean shouldLock) {
+ List<HeatParameterDefinition> heatParameters = artifactDefinition.getHeatParameters();
+ heatParameters.sort(Comparator.comparing(e -> e.getName()));
+ StringBuilder sb = new StringBuilder("parameters:\n");
+ if (heatParameters != null) {
+
+ for (HeatParameterDefinition heatParameterDefinition : heatParameters) {
+ if (heatParameterDefinition.getCurrentValue() != null) {
+ HeatParameterType type = HeatParameterType.isValidType(heatParameterDefinition.getType());
+ if (type != null) {
+ switch (type) {
+ case BOOLEAN:
+ sb.append(" ").append(heatParameterDefinition.getName()).append(":").append(" ").append(Boolean.parseBoolean(heatParameterDefinition.getCurrentValue())).append("\n");
+ break;
+ case NUMBER:
+ // if
+ // (ValidationUtils.isFloatNumber(heatParameterDefinition.getCurrentValue()))
+ // {
+ // sb.append("
+ // ").append(heatParameterDefinition.getName()).append(":").append("
+ // ").append(Float.parseFloat(heatParameterDefinition.getCurrentValue())).append("\n");
+ // } else {
+ // sb.append("
+ // ").append(heatParameterDefinition.getName()).append(":").append("
+ // ").append(Integer.parseInt(heatParameterDefinition.getCurrentValue())).append("\n");
+ // }
+ sb.append(" ").append(heatParameterDefinition.getName()).append(":").append(" ").append(new BigDecimal(heatParameterDefinition.getCurrentValue()).toPlainString()).append("\n");
+ break;
+ case COMMA_DELIMITED_LIST:
+ case JSON:
+ sb.append(" ").append(heatParameterDefinition.getName()).append(":").append(" ").append(heatParameterDefinition.getCurrentValue()).append("\n");
+ break;
+ default:
+ String value = heatParameterDefinition.getCurrentValue();
+ boolean starts = value.startsWith("\"");
+ boolean ends = value.endsWith("\"");
+ if (!(starts && ends)) {
+ starts = value.startsWith("'");
+ ends = value.endsWith("'");
+ if (!(starts && ends)) {
+ value = "\"" + value + "\"";
+ }
+ }
+ sb.append(" ").append(heatParameterDefinition.getName()).append(":").append(" ").append(value);
+ sb.append("\n");
+ break;
+
+ }
+ }
+ }
+ }
+ }
+ return generateAndSaveHeatEnvArtifact(artifactDefinition, sb.toString(), component, resourceInstanceName, modifier, shouldLock);
+
+ }
+
+ /**
+ *
+ * @param artifactDefinition
+ * @param payload
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> generateAndSaveHeatEnvArtifact(ArtifactDefinition artifactDefinition, String payload, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier,
+ boolean shouldLock) {
+ return generateArtifactPayload(artifactDefinition, component, resourceInstanceName, modifier, shouldLock, () -> artifactDefinition.getHeatParamsUpdateDate(), () -> createEsHeatEnvArtifactDataFromString(artifactDefinition, payload));
+
+ }
+
+ protected Either<ArtifactDefinition, ResponseFormat> generateArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier, boolean shouldLock,
+ Supplier<Long> payloadUpdateDateGen, Supplier<Either<ESArtifactData, ResponseFormat>> esDataCreator) {
+
+ if (artifactDefinition.getPayloadUpdateDate() == null || artifactDefinition.getPayloadUpdateDate() == 0 || artifactDefinition.getPayloadUpdateDate() < payloadUpdateDateGen.get()) {
+
+ log.trace("Generaing payload for {} artifact {}", artifactDefinition.getArtifactType(), artifactDefinition.getEsId());
+ Either<ESArtifactData, ResponseFormat> artifactDataRes = esDataCreator.get();
+ ESArtifactData artifactData = null;
+
+ if (artifactDataRes.isLeft()) {
+ artifactData = artifactDataRes.left().value();
+ } else {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
+ ComponentTypeEnum.RESOURCE_INSTANCE, resourceInstanceName);
+
+ return Either.right(artifactDataRes.right().value());
+ }
+ String newCheckSum = GeneralUtility.calculateMD5ByByteArray(artifactData.getDataAsArray());
+ String oldCheckSum;
+ String esArtifactId = artifactDefinition.getEsId();
+ Either<ESArtifactData, CassandraOperationStatus> artifactfromES;
+ ESArtifactData esArtifactData;
+ if (esArtifactId != null && !esArtifactId.isEmpty()) {
+ artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
+ if (artifactfromES.isRight()) {
+ CassandraOperationStatus resourceUploadStatus = artifactfromES.right().value();
+ StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
+ log.debug("Error when getting artifact from ES, error: {}", actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName()));
+ }
+ esArtifactData = artifactfromES.left().value();
+ oldCheckSum = GeneralUtility.calculateMD5ByByteArray(esArtifactData.getDataAsArray());
+ } else {
+ oldCheckSum = artifactDefinition.getArtifactChecksum();
+ }
+ Either<ArtifactDefinition, StorageOperationStatus> updateArifactDefinitionStatus;
+
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "Update Artifact - lock resource: ");
+ if (lockComponent.isRight()) {
+ handleAuditing(AuditingActionEnum.ARTIFACT_METADATA_UPDATE, component, component.getUniqueId(), modifier, null, null, artifactDefinition.getUniqueId(), lockComponent.right().value(), component.getComponentType(), null);
+ return Either.right(lockComponent.right().value());
+ }
+ }
+ try {
+ if (oldCheckSum != null && oldCheckSum.equals(newCheckSum)) {
+
+ artifactDefinition.setPayloadUpdateDate(payloadUpdateDateGen.get());
+ updateArifactDefinitionStatus = artifactOperation.updateArifactDefinition(artifactDefinition, false);
+ log.trace("No real update done in payload for {} artifact, updating payloadUpdateDate {}", artifactDefinition.getArtifactType(), artifactDefinition.getEsId());
+ if (updateArifactDefinitionStatus.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(updateArifactDefinitionStatus.right().value()), artifactDefinition.getArtifactDisplayName());
+ log.trace("Failed to update payloadUpdateDate ", artifactDefinition.getEsId());
+ handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
+ ComponentTypeEnum.RESOURCE_INSTANCE, resourceInstanceName);
+
+ return Either.right(responseFormat);
+ }
+ } else {
+
+ oldCheckSum = artifactDefinition.getArtifactChecksum();
+ artifactDefinition.setArtifactChecksum(newCheckSum);
+ artifactOperation.updateUUID(artifactDefinition, oldCheckSum, artifactDefinition.getArtifactVersion());
+ artifactDefinition.setEsId(artifactDefinition.getUniqueId());
+ updateArifactDefinitionStatus = artifactOperation.updateArifactDefinition(artifactDefinition, true);
+
+ log.trace("Update Payload ", artifactDefinition.getEsId());
+
+ if (updateArifactDefinitionStatus.isLeft()) {
+
+ artifactData.setId(artifactDefinition.getUniqueId());
+ CassandraOperationStatus saveArtifactStatus = artifactCassandraDao.saveArtifact(artifactData);
+
+ if (saveArtifactStatus.equals(CassandraOperationStatus.OK)) {
+ titanGenericDao.commit();
+ log.debug("Artifact Saved In ES {}", artifactData.getId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
+ ComponentTypeEnum.RESOURCE_INSTANCE, resourceInstanceName);
+
+ } else {
+ titanGenericDao.rollback();
+ log.info("Failed to save artifact {}.", artifactData.getId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
+ ComponentTypeEnum.RESOURCE_INSTANCE, resourceInstanceName);
+
+ return Either.right(responseFormat);
+ }
+ } else {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(updateArifactDefinitionStatus.right().value()), artifactDefinition.getArtifactDisplayName());
+ log.debug("Failed To update artifact {}", artifactData.getId());
+ handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
+ ComponentTypeEnum.RESOURCE_INSTANCE, resourceInstanceName);
+
+ return Either.right(responseFormat);
+
+ }
+ }
+ } finally {
+ if (shouldLock) {
+ graphLockOperation.unlockComponent(component.getUniqueId(), component.getComponentType().getNodeType());
+ }
+ }
+ }
+
+ return Either.left(artifactDefinition);
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleUpdateHeatEnv(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
+ org.openecomp.sdc.be.model.Component parent, String originData, String origMd5, ArtifactOperation operation, boolean shouldLock, boolean inTransaction) {
+ NodeTypeEnum parentType = convertParentType(componentType);
+ String parentId = parent.getUniqueId();
+ Either<ArtifactDefinition, StorageOperationStatus> artifactRes = artifactOperation.getArtifactById(artifactId, false);
+ ArtifactDefinition currArtifact = artifactRes.left().value();
+
+ if (origMd5 != null) {
+ Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
+ if (validateMd5.isRight()) {
+ ResponseFormat responseFormat = validateMd5.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+
+ if (artifactInfo.getPayloadData() != null && artifactInfo.getPayloadData().length != 0) {
+ Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parent, componentId, user.getUserId(), false, artifactInfo, currArtifact, NodeTypeEnum.ResourceInstance);
+ if (deploymentValidationResult.isRight()) {
+ ResponseFormat responseFormat = deploymentValidationResult.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+
+ Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
+ if (payloadEither.isRight()) {
+ ResponseFormat responseFormat = payloadEither.right().value();
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ } else { // duplicate
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ }
+
+ // lock resource
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Update Artifact - lock ");
+ if (lockComponent.isRight()) {
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right().value(), componentType, null);
+ return Either.right(lockComponent.right().value());
+ }
+ }
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ try {
+ resultOp = updateHeatEnvParams(componentId, artifactId, artifactInfo, user, auditingAction, parent, componentType, currArtifact, origMd5, inTransaction);
+ return resultOp;
+
+ } finally {
+ // unlock resource
+ if (resultOp == null || resultOp.isRight()) {
+ log.debug("all changes rollback");
+ if (false == inTransaction)
+ titanGenericDao.rollback();
+ } else {
+ log.debug("all changes committed");
+ if (false == inTransaction)
+ titanGenericDao.commit();
+ }
+ if (shouldLock)
+ componentType = parent.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ graphLockOperation.unlockComponent(parent.getUniqueId(), nodeType);
+ // graphLockOperation.unlockComponent(parentId, parentType);
+ }
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateHeatEnvParams(String componentId, String artifactId, ArtifactDefinition artifactInfo, User user, AuditingActionEnum auditingAction, Component parent,
+ ComponentTypeEnum componentType, ArtifactDefinition currArtifact1, String origMd5, boolean inTransaction) {
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ Either<ArtifactDefinition, Operation> insideEither = null;
+ /*
+ * currently getArtifactById does not retrieve heatParameters Either<ArtifactDefinition, StorageOperationStatus> artifactRes = artifactOperation.getArtifactById(artifactId, false); ArtifactDefinition currArtifact = artifactRes.left().value();
+ */
+ Either<ComponentInstance, ResponseFormat> getRI = getRIFromComponent(parent, componentId, artifactId, auditingAction, user);
+ if (getRI.isRight()) {
+ return Either.right(getRI.right().value());
+ }
+ ComponentInstance ri = getRI.left().value();
+ Either<ArtifactDefinition, ResponseFormat> getArtifactRes = getArtifactFromRI(parent, ri, componentId, artifactId, auditingAction, user);
+ if (getArtifactRes.isRight()) {
+ return Either.right(getArtifactRes.right().value());
+ }
+ ArtifactDefinition currArtifact = getArtifactRes.left().value();
+
+ if (currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT.getType()) || currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_VOL.getType()) || currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_NET.getType())) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+ List<HeatParameterDefinition> currentHeatEnvParams = currArtifact.getHeatParameters();
+ List<HeatParameterDefinition> updatedHeatEnvParams = artifactInfo.getHeatParameters();
+ List<HeatParameterDefinition> reducedHeatEnvParams = new ArrayList<HeatParameterDefinition>();
+
+ // upload
+ if (origMd5 != null) {
+ Either<List<HeatParameterDefinition>, ResponseFormat> uploadParamsValidationResult = validateUploadParamsFromEnvFile(auditingAction, parent, user, artifactInfo, artifactId, componentType, ri.getName(), currentHeatEnvParams,
+ updatedHeatEnvParams, currArtifact.getArtifactName());
+ if (uploadParamsValidationResult.isRight()) {
+ ResponseFormat responseFormat = uploadParamsValidationResult.right().value();
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+ artifactInfo.setHeatParameters(updatedHeatEnvParams);
+ }
+
+ Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParamers(artifactInfo, ArtifactTypeEnum.HEAT_ENV.getType());
+ if (validateAndConvertHeatParamers.isRight()) {
+ ResponseFormat responseFormat = validateAndConvertHeatParamers.right().value();
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+
+ if (updatedHeatEnvParams != null && !updatedHeatEnvParams.isEmpty()) {
+ String paramName;
+ // fill reduced heat env parameters List for updating
+ for (HeatParameterDefinition heatEnvParam : updatedHeatEnvParams) {
+ paramName = heatEnvParam.getName();
+ for (HeatParameterDefinition currHeatParam : currentHeatEnvParams) {
+ if (paramName.equalsIgnoreCase(currHeatParam.getName())) {
+ String updatedParamValue = heatEnvParam.getCurrentValue();
+ if (updatedParamValue != null && updatedParamValue.equals("")) { // reset
+ heatEnvParam.setCurrentValue(heatEnvParam.getDefaultValue());
+ reducedHeatEnvParams.add(heatEnvParam);
+ } else if (updatedParamValue != null) {
+ reducedHeatEnvParams.add(heatEnvParam);
+ }
+ }
+ }
+ }
+ if (reducedHeatEnvParams.size() > 0) {
+ ArtifactDefinition reducedArtifactInfo = new ArtifactDefinition(artifactInfo);
+ reducedArtifactInfo.setHeatParameters(reducedHeatEnvParams);
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactResult = artifactOperation.updateArifactOnResource(reducedArtifactInfo, componentId, artifactInfo.getUniqueId(), componentType.getNodeType(), inTransaction);
+
+ if (updateArtifactResult.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateArtifactResult.right().value()));
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+ ArtifactDefinition updatedArtifact = updateArtifactResult.left().value();
+ String updatedArtifactId = updatedArtifact.getUniqueId();
+ if (!currArtifact.getUniqueId().equals(updatedArtifactId)) {
+ currArtifact.setUniqueId(updatedArtifactId);
+ currArtifact.setPayloadUpdateDate(updatedArtifact.getPayloadUpdateDate());
+ currArtifact.setCreationDate(updatedArtifact.getCreationDate());
+ currArtifact.setLastUpdateDate(updatedArtifact.getLastUpdateDate());
+ currArtifact.setEsId(updatedArtifact.getEsId());
+ }
+ currArtifact.setHeatParamsUpdateDate(System.currentTimeMillis());
+
+ Either<List<HeatParameterDefinition>, StorageOperationStatus> heatParamsForEnv = ((org.openecomp.sdc.be.model.operations.impl.ArtifactOperation) artifactOperation).getHeatParamsForEnv(currArtifact);
+ if (heatParamsForEnv.isRight()) {
+ log.debug("failed to get heat parameters values for heat artifact {}", updatedArtifact.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(heatParamsForEnv.right().value()));
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+ List<HeatParameterDefinition> updatedHeatParaetersList = heatParamsForEnv.left().value();
+ currArtifact.setHeatParameters(updatedHeatParaetersList);
+
+ Either<ArtifactDefinition, StorageOperationStatus> updateArifactRes = artifactOperation.updateArifactDefinition(currArtifact, true);
+ if (updateArifactRes.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", artifactId);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateArifactRes.right().value()));
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ }
+
+ insideEither = Either.left(currArtifact);
+ resultOp = Either.left(insideEither);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currArtifact, null, artifactId, responseFormat, componentType, ri.getName());
+ return resultOp;
+ }
+
+ public Either<List<HeatParameterDefinition>, ResponseFormat> validateUploadParamsFromEnvFile(AuditingActionEnum auditingAction, Component parent, User user, ArtifactDefinition artifactInfo, String artifactId, ComponentTypeEnum componentType,
+ String riName, List<HeatParameterDefinition> currentHeatEnvParams, List<HeatParameterDefinition> updatedHeatEnvParams, String currArtifactName) {
+
+ if (updatedHeatEnvParams == null || updatedHeatEnvParams.isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, artifactInfo.getArtifactName(), currArtifactName);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, riName);
+ return Either.right(responseFormat);
+ }
+
+ for (HeatParameterDefinition uploadedHeatParam : updatedHeatEnvParams) {
+ String paramName = uploadedHeatParam.getName();
+ boolean isExistsInHeat = false;
+ for (HeatParameterDefinition currHeatParam : currentHeatEnvParams) {
+ if (paramName.equalsIgnoreCase(currHeatParam.getName())) {
+
+ isExistsInHeat = true;
+ uploadedHeatParam.setType(currHeatParam.getType());
+ uploadedHeatParam.setCurrentValue(uploadedHeatParam.getDefaultValue());
+ uploadedHeatParam.setDefaultValue(currHeatParam.getDefaultValue());
+ uploadedHeatParam.setUniqueId(currHeatParam.getUniqueId());
+ break;
+ }
+ }
+ if (!isExistsInHeat) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, currArtifactName);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, riName);
+ return Either.right(responseFormat);
+ }
+ }
+ return Either.left(updatedHeatEnvParams);
+ }
+
+ private Either<ComponentInstance, ResponseFormat> getRIFromComponent(Component component, String riID, String artifactId, AuditingActionEnum auditingAction, User user) {
+ ResponseFormat responseFormat = null;
+ List<ComponentInstance> ris = component.getComponentInstances();
+ for (ComponentInstance ri : ris) {
+ if (riID.equals(ri.getUniqueId())) {
+ return Either.left(ri);
+ }
+ }
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, riID);
+ log.debug("Resource Instance not found, resourceInstanceId {}", riID);
+ handleAuditing(auditingAction, null, riID, user, null, null, artifactId, responseFormat, ComponentTypeEnum.RESOURCE_INSTANCE, null);
+ return Either.right(responseFormat);
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> getArtifactFromRI(Component component, ComponentInstance ri, String riID, String artifactId, AuditingActionEnum auditingAction, User user) {
+ ResponseFormat responseFormat = null;
+ Map<String, ArtifactDefinition> rtifactsMap = ri.getDeploymentArtifacts();
+ for (ArtifactDefinition artifact : rtifactsMap.values()) {
+ if (artifactId.equals(artifact.getUniqueId())) {
+ return Either.left(artifact);
+ }
+ }
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, riID, component.getUniqueId());
+ handleAuditing(auditingAction, component, riID, user, null, null, artifactId, responseFormat, ComponentTypeEnum.RESOURCE_INSTANCE, ri.getName());
+ return Either.right(responseFormat);
+ }
+
+ public ComponentOperation getComponentOperation(NodeTypeEnum componentType) {
+
+ switch (componentType) {
+ case Service:
+ case ResourceInstance:
+ return serviceOperation;
+ case Resource:
+ return resourceOperation;
+ default:
+ return null;
+ }
+ }
+
+ public ArtifactDefinition extractArtifactDefinition(Either<ArtifactDefinition, Operation> eitherArtifact) {
+ ArtifactDefinition ret;
+ if (eitherArtifact.isLeft()) {
+ ret = eitherArtifact.left().value();
+ } else {
+ ret = eitherArtifact.right().value().getImplementation();
+ }
+ return ret;
+ }
+
+ /**
+ * downloads artifact of component by UUIDs
+ *
+ * @param componentType
+ * @param componentUuid
+ * @param artifactUUID
+ * @param auditAdditionalParam
+ * @return
+ */
+ public Either<byte[], ResponseFormat> downloadComponentArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String artifactUUID, Map<AuditingFieldsKeysEnum, Object> auditAdditionalParam) {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<byte[], ResponseFormat> result;
+ byte[] downloadedArtifact = null;
+ Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ auditAdditionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, component.getName());
+ downloadedArtifact = downloadArtifact(component.getDeploymentArtifacts(), artifactUUID, errorWrapper, component.getName());
+ }
+ if (errorWrapper.isEmpty()) {
+ result = Either.left(downloadedArtifact);
+ } else {
+ result = Either.right(errorWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ /**
+ * downloads an artifact of resource instance of component by UUIDs
+ *
+ * @param componentType
+ * @param componentUuid
+ * @param resourceName
+ * @param artifactUUID
+ * @param auditAdditionalParam
+ * @return
+ */
+ public Either<byte[], ResponseFormat> downloadResourceInstanceArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID, Map<AuditingFieldsKeysEnum, Object> auditAdditionalParam) {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<byte[], ResponseFormat> result;
+ byte[] downloadedArtifact = null;
+ ComponentInstance resourceInstance = getRelatedComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ auditAdditionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstance.getName());
+ downloadedArtifact = downloadArtifact(resourceInstance.getDeploymentArtifacts(), artifactUUID, errorWrapper, resourceInstance.getName());
+ }
+ if (errorWrapper.isEmpty()) {
+ result = Either.left(downloadedArtifact);
+ } else {
+ result = Either.right(errorWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ /**
+ * uploads an artifact to a component by UUID
+ *
+ * @param data
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> uploadArtifactToComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactResult;
+ ArtifactDefinition uploadArtifact;
+ Component component = null;
+ String componentId = null;
+ ArtifactOperation operation = ArtifactOperation.Create;
+ operation.setExternalApi(true);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component != null) {
+ componentId = component.getUniqueId();
+ } else {
+ componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, getComponentRes.left().value().getMetadataDataDefinition().getName());
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, null, artifactInfo, origMd5, data, null, null, null, null);
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ uploadArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, uploadArtifact);
+ uploadArtifactResult = Either.left(uploadArtifact);
+ } else {
+ uploadArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return uploadArtifactResult;
+ }
+
+ /**
+ * upload an artifact to a resource instance by UUID
+ *
+ * @param data
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param resourceInstanceName
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> uploadArtifactToRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName,
+ Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactResult;
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ ArtifactDefinition uploadArtifact;
+ Component component = null;
+ String componentInstanceId;
+ String componentId;
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ImmutablePair<Component, ComponentInstance> componentRiPair = null;
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
+ } else {
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
+ ArtifactOperation operation = ArtifactOperation.Create;
+ operation.setExternalApi(true);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, null, artifactInfo, origMd5, data, null, null, componentId, ComponentTypeEnum.findParamByType(componentType));
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ", resourceInstanceName, componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ uploadArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, uploadArtifact);
+ uploadArtifactResult = Either.left(uploadArtifact);
+ } else {
+ uploadArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return uploadArtifactResult;
+ }
+
+ /**
+ * updates an artifact on a component by UUID
+ *
+ * @param data
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param artifactUUID
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> updateArtifactOnComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID,
+ Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ ArtifactDefinition updateArtifact;
+ Component component = null;
+ String componentId = null;
+ String artifactId = null;
+ ArtifactOperation operation = ArtifactOperation.Update;
+ operation.setExternalApi(true);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component != null) {
+ componentId = component.getUniqueId();
+ } else {
+ componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentId, componentType);
+ }
+ if (errorWrapper.isEmpty()) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, getComponentRes.left().value().getMetadataDataDefinition().getName());
+
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, data, null, null, null, null);
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ updateArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, updateArtifact);
+ updateArtifactResult = Either.left(updateArtifact);
+
+ } else {
+ updateArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return updateArtifactResult;
+ }
+
+ /**
+ * updates an artifact on a resource instance by UUID
+ *
+ * @param data
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param resourceInstanceName
+ * @param artifactUUID
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> updateArtifactOnRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
+ Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ ArtifactDefinition updateArtifact;
+ Component component = null;
+ String componentInstanceId = null;
+ String componentId = null;
+ String artifactId = null;
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ImmutablePair<Component, ComponentInstance> componentRiPair = null;
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
+ } else {
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentInstanceId, ComponentTypeEnum.RESOURCE_INSTANCE);
+ }
+ if (errorWrapper.isEmpty()) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
+ ArtifactOperation operation = ArtifactOperation.Update;
+ operation.setExternalApi(true);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, artifactInfo, origMd5, data, null, null, componentId, ComponentTypeEnum.findParamByType(componentType));
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ", resourceInstanceName, componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ updateArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, updateArtifact);
+ updateArtifactResult = Either.left(updateArtifact);
+ } else {
+ updateArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return updateArtifactResult;
+
+ }
+
+ /**
+ * deletes an artifact on a component by UUID
+ *
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param artifactUUID
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> deleteArtifactOnComponentByUUID(HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID, Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<ArtifactDefinition, ResponseFormat> deleteArtifactResult;
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ ArtifactDefinition deleteArtifact;
+ Component component = null;
+ String componentId = null;
+ String artifactId = null;
+ ArtifactOperation operation = ArtifactOperation.Delete;
+ operation.setExternalApi(true);
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component != null) {
+ componentId = component.getUniqueId();
+ } else {
+ componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentId, componentType);
+ }
+ if (errorWrapper.isEmpty()) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, getComponentRes.left().value().getMetadataDataDefinition().getName());
+
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, null, origMd5, null, null, null, null, null);
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ deleteArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, deleteArtifact);
+ deleteArtifactResult = Either.left(deleteArtifact);
+ } else {
+ deleteArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return deleteArtifactResult;
+ }
+
+ /**
+ * deletes an artifact an a resource instance by UUID
+ *
+ * @param request
+ * @param componentType
+ * @param componentUuid
+ * @param resourceInstanceName
+ * @param artifactUUID
+ * @param additionalParams
+ * @return
+ */
+ public Either<ArtifactDefinition, ResponseFormat> deleteArtifactOnRiByUUID(HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
+ Map<AuditingFieldsKeysEnum, Object> additionalParams) {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Either<ArtifactDefinition, ResponseFormat> deleteArtifactResult;
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
+ ArtifactDefinition deleteArtifact;
+ Component component = null;
+ String componentInstanceId = null;
+ String componentId = null;
+ String artifactId = null;
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ImmutablePair<Component, ComponentInstance> componentRiPair = null;
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentMetadataByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ if (errorWrapper.isEmpty() && !getComponentRes.left().value().getMetadataDataDefinition().getState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(), userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
+ } else {
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentInstanceId, ComponentTypeEnum.RESOURCE_INSTANCE);
+ }
+ if (errorWrapper.isEmpty()) {
+
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName);
+ ArtifactOperation operation = ArtifactOperation.Delete;
+ operation.setExternalApi(true);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, null, origMd5, null, null, null, componentId, ComponentTypeEnum.findParamByType(componentType));
+
+ if (actionResult.isRight()) {
+ log.debug("Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ", resourceInstanceName, componentType, componentUuid, actionResult.right().value());
+ errorWrapper.setInnerElement(actionResult.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ deleteArtifact = actionResult.left().value().left().value();
+ updateAuditParametersWithArtifactDefinition(additionalParams, deleteArtifact);
+ deleteArtifactResult = Either.left(deleteArtifact);
+ } else {
+ deleteArtifactResult = Either.right(errorWrapper.getInnerElement());
+ }
+ return deleteArtifactResult;
+ }
+
+ private ComponentInstance getRelatedComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
+ ComponentInstance componentInstance = null;
+ StorageOperationStatus status;
+ Either<ComponentInstance, StorageOperationStatus> getResourceInstanceRes = null;
+ Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ componentInstance = component.getComponentInstances().stream().filter(ci -> ci.getNormalizedName().equals(resourceInstanceName)).findAny().get();
+ if (componentInstance == null) {
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, "resource instance", component.getComponentType().getValue(), component.getName()));
+ log.debug("Component instance {} was not found for component {}", resourceInstanceName, component.getName());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ getResourceInstanceRes = resourceInstanceOperation.getResourceInstanceById(componentInstance.getUniqueId());
+ if (getResourceInstanceRes.isRight()) {
+ status = getResourceInstanceRes.right().value();
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ componentInstance = getResourceInstanceRes.left().value();
+ getResourceInstanceRes = resourceInstanceOperation.getFullComponentInstance(componentInstance, componentType.getNodeType());
+ if (getResourceInstanceRes.isRight()) {
+ status = getResourceInstanceRes.right().value();
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ } else {
+ componentInstance = getResourceInstanceRes.left().value();
+ }
+ }
+ return componentInstance;
+ }
+
+ private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(Component component, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
+
+ ImmutablePair<Component, ComponentInstance> relatedComponentComponentInstancePair = null;
+ ComponentInstance componentInstance = component.getComponentInstances().stream().filter(ci -> ci.getNormalizedName().equals(resourceInstanceName)).findAny().get();
+ if (componentInstance == null) {
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, "resource instance", component.getComponentType().getValue(), component.getName()));
+ log.debug("Component instance {} was not found for component {}", resourceInstanceName, component.getName());
+ } else {
+ relatedComponentComponentInstancePair = new ImmutablePair<>(component, componentInstance);
+ }
+ return relatedComponentComponentInstancePair;
+ }
+
+ private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
+ ComponentInstance componentInstance;
+ ImmutablePair<Component, ComponentInstance> relatedComponentComponentInstancePair = null;
+ Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ componentInstance = component.getComponentInstances().stream().filter(ci -> ci.getNormalizedName().equals(resourceInstanceName)).findAny().get();
+ if (componentInstance == null) {
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, "resource instance", component.getComponentType().getValue(), component.getName()));
+ log.debug("Component instance {} was not found for component {}", resourceInstanceName, component.getName());
+ } else {
+ relatedComponentComponentInstancePair = new ImmutablePair<>(component, componentInstance);
+ }
+ }
+ return relatedComponentComponentInstancePair;
+ }
+
+ private byte[] downloadArtifact(Map<String, ArtifactDefinition> artifacts, String artifactUUID, Wrapper<ResponseFormat> errorWrapper, String componentName) {
+
+ byte[] downloadedArtifact = null;
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = null;
+ List<ArtifactDefinition> deploymentArtifacts = null;
+ ArtifactDefinition deploymentArtifact = null;
+ if (artifacts != null && !artifacts.isEmpty()) {
+ deploymentArtifacts = artifacts.values().stream().filter(art -> art.getArtifactUUID() != null && art.getArtifactUUID().equals(artifactUUID)).collect(Collectors.toList());
+ }
+ if (deploymentArtifacts == null || deploymentArtifacts.isEmpty()) {
+ log.debug("Deployment artifact with uuid {} was not found for component {}", artifactUUID, componentName);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID));
+ }
+ if (errorWrapper.isEmpty()) {
+ deploymentArtifact = deploymentArtifacts.get(0);
+ downloadArtifactEither = downloadArtifact(deploymentArtifact);
+ if (downloadArtifactEither.isRight()) {
+ log.debug("Failed to download artifact {}. ", deploymentArtifact.getArtifactName());
+ errorWrapper.setInnerElement(downloadArtifactEither.right().value());
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ log.trace("Succeeded to download artifact with uniqueId {}", deploymentArtifact.getUniqueId());
+ downloadedArtifact = downloadArtifactEither.left().value().getRight();
+ }
+ return downloadedArtifact;
+ }
+
+ private Component getLatestComponentByUuid(ComponentTypeEnum componentType, String componentUuid, Wrapper<ResponseFormat> errorWrapper) {
+ Component component = null;
+ Either<Component, StorageOperationStatus> getComponentRes = getComponentOperation(componentType).getLatestComponentByUuid(componentType.getNodeType(), componentUuid);
+ if (getComponentRes.isRight()) {
+ StorageOperationStatus status = getComponentRes.right().value();
+ log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ } else {
+ component = getComponentRes.left().value();
+ }
+ return component;
+ }
+
+ private String getLatestParentArtifactDataIdByArtifactUUID(String artifactUUID, Wrapper<ResponseFormat> errorWrapper, String parentId, ComponentTypeEnum componentType) {
+ String artifactId = null;
+ ActionStatus actionStatus = ActionStatus.ARTIFACT_NOT_FOUND;
+ StorageOperationStatus storageStatus;
+ ArtifactDefinition latestArtifact = null;
+ List<ArtifactDefinition> artifacts = null;
+ NodeTypeEnum parentType;
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ parentType = NodeTypeEnum.Resource;
+ } else {
+ parentType = NodeTypeEnum.Service;
+ }
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifactsRes = artifactOperation.getArtifacts(parentId, parentType, false);
+ if (getArtifactsRes.isRight()) {
+ storageStatus = getArtifactsRes.right().value();
+ log.debug("Couldn't fetch artifacts data for parent component {} with uid {}, error: {}", componentType.name(), parentId, storageStatus);
+ if (!storageStatus.equals(StorageOperationStatus.NOT_FOUND)) {
+ actionStatus = componentsUtils.convertFromStorageResponse(storageStatus);
+ }
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
+ }
+ if (errorWrapper.isEmpty()) {
+ artifacts = getArtifactsRes.left().value().values().stream().filter(a -> a.getArtifactUUID() != null && a.getArtifactUUID().equals(artifactUUID)).collect(Collectors.toList());
+ if (artifacts == null || artifacts.isEmpty()) {
+ log.debug("Couldn't fetch artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType.name(), parentId, actionStatus);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ latestArtifact = artifacts.stream().max((a1, a2) -> {
+ int compareRes = Double.compare(Double.parseDouble(a1.getArtifactVersion()), Double.parseDouble(a2.getArtifactVersion()));
+ if (compareRes == 0) {
+ compareRes = Long.compare(a1.getLastUpdateDate() == null ? 0 : a1.getLastUpdateDate(), a2.getLastUpdateDate() == null ? 0 : a2.getLastUpdateDate());
+ }
+ return compareRes;
+ }).get();
+ if (latestArtifact == null) {
+ log.debug("Couldn't fetch latest artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType.name(), parentId, actionStatus);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
+ }
+ }
+ if (errorWrapper.isEmpty()) {
+ artifactId = latestArtifact.getUniqueId();
+ }
+ return artifactId;
+ }
+
+ private Component checkoutParentComponent(ComponentTypeEnum componentType, String parentId, String userId, Wrapper<ResponseFormat> errorWrapper) {
+
+ Component component = null;
+ Either<User, ActionStatus> getUserRes = userBusinessLogic.getUser(userId, false);
+ if (getUserRes.isRight()) {
+ log.debug("Could not fetch User of component {} with uid {} to checked out. Status is {}. ", componentType.getNodeType(), parentId, getUserRes.right().value());
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(getUserRes.right().value()));
+ }
+ if (errorWrapper.isEmpty()) {
+ User modifier = getUserRes.left().value();
+ LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction("External API checkout", LifecycleChanceActionEnum.UPDATE_FROM_EXTERNAL_API);
+ Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic.changeComponentState(componentType, parentId, modifier, LifeCycleTransitionEnum.CHECKOUT, changeInfo, false, true);
+ if (checkoutRes.isRight()) {
+ log.debug("Could not change state of component {} with uid {} to checked out. Status is {}. ", componentType.getNodeType(), parentId, checkoutRes.right().value().getStatus());
+ errorWrapper.setInnerElement(checkoutRes.right().value());
+ } else {
+ component = checkoutRes.left().value();
+ }
+ }
+ return component;
+ }
+
+ private void updateAuditParametersWithArtifactDefinition(Map<AuditingFieldsKeysEnum, Object> additionalParams, ArtifactDefinition artifact) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_CURR_ARTIFACT_UUID, artifact.getArtifactUUID());
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_ARTIFACT_DATA, buildAuditingArtifactData(artifact));
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, artifact.getUpdaterFullName());
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
new file mode 100644
index 0000000000..15fe86da33
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
@@ -0,0 +1,295 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.resources.data.AttributeData;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+/**
+ * This class holds the business logic relevant for attributes manipulation.
+ *
+ * @author mshitrit
+ *
+ */
+@Component("attributeBusinessLogic")
+public class AttributeBusinessLogic extends BaseBusinessLogic {
+
+ private static final String CREATE_ATTRIBUTE = "CreateAttribute";
+ private static final String UPDATE_ATTRIBUTE = "UpdateAttribute";
+ private static final String DELETE_ATTRIBUTE = "DeleteAttribute";
+
+ private static Logger log = LoggerFactory.getLogger(AttributeBusinessLogic.class.getName());
+
+ /**
+ * Created attribute on the resource with resourceId
+ *
+ * @param resourceId
+ * @param newAttributeDef
+ * @param userId
+ * @return AttributeDefinition if created successfully Or ResponseFormat
+ */
+ public Either<AttributeDefinition, ResponseFormat> createAttribute(String resourceId, AttributeDefinition newAttributeDef, String userId) {
+ Either<AttributeDefinition, ResponseFormat> result = null;
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Attribute", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (lockResult != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_ATTRIBUTE, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ log.info("Failed to lock component {}. Error - {}", resourceId, lockResult);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ try {
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = status.left().value();
+
+ // verify that resource is checked-out and the user is the last updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ // verify attribute does not exist in resource
+ if (isAttributeExist(resource.getAttributes(), resourceId, newAttributeDef.getName())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_ALREADY_EXIST, newAttributeDef.getName()));
+ }
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (eitherAllDataTypes.isRight()) {
+ return Either.right(eitherAllDataTypes.right().value());
+ }
+ // validate property default values
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttributeDef, eitherAllDataTypes.left().value());
+ if (defaultValuesValidation.isRight()) {
+ return Either.right(defaultValuesValidation.right().value());
+ }
+
+ handleDefaultValue(newAttributeDef, eitherAllDataTypes.left().value());
+
+ // add the new attribute to resource on graph
+ // need to get StorageOpaerationStatus and convert to ActionStatus from
+ // componentsUtils
+ Either<AttributeData, StorageOperationStatus> either = attributeOperation.addAttribute(newAttributeDef, resourceId);
+ if (either.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(either.right().value()), resource.getName()));
+ return result;
+ }
+
+ result = Either.left(attributeOperation.convertAttributeDataToAttributeDefinition(either.left().value(), newAttributeDef.getName(), resourceId));
+ return result;
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+
+ }
+
+ private boolean isAttributeExist(List<AttributeDefinition> attributes, String resourceUid, String propertyName) {
+ boolean isExist = false;
+ if (attributes != null) {
+ isExist = attributes.stream().filter(p -> Objects.equals(p.getName(), propertyName) && Objects.equals(p.getParentUniqueId(), resourceUid)).findAny().isPresent();
+ }
+ return isExist;
+
+ }
+
+ /**
+ * @param resourceId
+ * @param attributeId
+ * @param userId
+ * @return
+ */
+ public Either<AttributeDefinition, ResponseFormat> getAttribute(String resourceId, String attributeId, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Attribute", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = status.left().value();
+
+ List<AttributeDefinition> attributes = resource.getAttributes();
+ if (attributes == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_NOT_FOUND, ""));
+ } else {
+ Either<AttributeDefinition, ResponseFormat> result;
+ // verify attribute exist in resource
+ Optional<AttributeDefinition> optionalAtt = attributes.stream().filter(att -> att.getUniqueId().equals(attributeId) && att.getParentUniqueId().equals(resourceId)).findAny();
+
+ if (optionalAtt.isPresent()) {
+ result = Either.left(optionalAtt.get());
+ } else {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_NOT_FOUND, ""));
+ }
+ return result;
+ }
+
+ }
+
+ /**
+ * Updates Attribute on resource
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param newAttDef
+ * @param userId
+ * @return
+ */
+ public Either<AttributeDefinition, ResponseFormat> updateAttribute(String resourceId, String attributeId, AttributeDefinition newAttDef, String userId) {
+ Either<AttributeDefinition, ResponseFormat> result = null;
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (lockResult != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(UPDATE_ATTRIBUTE, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ try {
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> eitherResource = getResource(resourceId);
+ if (eitherResource.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = eitherResource.left().value();
+
+ // verify that resource is checked-out and the user is the last updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ // verify attribute exist in resource
+ Either<AttributeDefinition, ResponseFormat> eitherAttribute = getAttribute(resourceId, attributeId, userId);
+ if (eitherAttribute.isRight()) {
+ return Either.right(eitherAttribute.right().value());
+ }
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (eitherAllDataTypes.isRight()) {
+ return Either.right(eitherAllDataTypes.right().value());
+ }
+
+ // validate attribute default values
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttDef, eitherAllDataTypes.left().value());
+ if (defaultValuesValidation.isRight()) {
+ return Either.right(defaultValuesValidation.right().value());
+ }
+ // add the new property to resource on graph
+ Either<AttributeData, StorageOperationStatus> eitherAttUpdate = attributeOperation.updateAttribute(attributeId, newAttDef, eitherAllDataTypes.left().value());
+
+ if (eitherAttUpdate.isRight()) {
+ log.debug("Problem while updating attribute with id {}. Reason - {}", attributeId, eitherAttUpdate.right().value());
+ result = Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherAttUpdate.right().value()), resource.getName()));
+ return result;
+ }
+
+ result = Either.left(attributeOperation.convertAttributeDataToAttributeDefinition(eitherAttUpdate.left().value(), newAttDef.getName(), resourceId));
+ return result;
+ } finally {
+ commitOrRollback(result);
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+ }
+
+ /**
+ * Deletes Attribute on resource
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param userId
+ * @return
+ */
+ public Either<AttributeDefinition, ResponseFormat> deleteAttribute(String resourceId, String attributeId, String userId) {
+ Either<AttributeDefinition, ResponseFormat> result = null;
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Attribute", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (lockResult != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(DELETE_ATTRIBUTE, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+
+ try {
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> eitherResource = getResource(resourceId);
+ if (eitherResource.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = eitherResource.left().value();
+
+ // verify that resource is checked-out and the user is the last updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ // verify attribute exist in resource
+ Either<AttributeDefinition, ResponseFormat> eitherAttributeExist = getAttribute(resourceId, attributeId, userId);
+ if (eitherAttributeExist.isRight()) {
+ return Either.right(eitherAttributeExist.right().value());
+ }
+ String attributeName = eitherAttributeExist.left().value().getName();
+
+ // delete attribute of resource from graph
+ Either<AttributeData, StorageOperationStatus> eitherAttributeDelete = attributeOperation.deleteAttribute(attributeId);
+ if (eitherAttributeDelete.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(eitherAttributeDelete.right().value()), resource.getName()));
+ return result;
+ }
+ result = Either.left(attributeOperation.convertAttributeDataToAttributeDefinition(eitherAttributeDelete.left().value(), attributeName, resourceId));
+ return result;
+ } finally {
+ commitOrRollback(result);
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
new file mode 100644
index 0000000000..93ddff38d5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -0,0 +1,571 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.IComplexDefaultValue;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
+import org.openecomp.sdc.be.model.operations.api.IAttributeOperation;
+import org.openecomp.sdc.be.model.operations.api.IComponentOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
+import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.model.operations.impl.ProductOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+public abstract class BaseBusinessLogic {
+
+ @Autowired
+ protected ComponentsUtils componentsUtils;
+
+ @Autowired
+ protected IUserBusinessLogic userAdmin;
+
+ @Autowired
+ protected ResourceOperation resourceOperation;
+
+ @Autowired
+ protected IGraphLockOperation graphLockOperation;
+
+ @Autowired
+ protected ServiceOperation serviceOperation;
+
+ @Autowired
+ protected ProductOperation productOperation;
+
+ @Autowired
+ protected TitanGenericDao titanGenericDao;
+
+ @Autowired
+ protected IElementOperation elementDao;
+
+ @Autowired
+ protected IGroupOperation groupOperation;
+
+ @Autowired
+ protected IGroupTypeOperation groupTypeOperation;
+
+ @Autowired
+ protected IArtifactOperation artifactOperation;
+
+ @Autowired
+ protected IAttributeOperation attributeOperation;
+
+ @Autowired
+ protected IPropertyOperation propertyOperation;
+
+ @Autowired
+ protected ApplicationDataTypeCache applicationDataTypeCache;
+
+ public void setUserAdmin(UserBusinessLogic userAdmin) {
+ this.userAdmin = userAdmin;
+ }
+
+ public void setComponentsUtils(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ public void setGraphLockOperation(IGraphLockOperation graphLockOperation) {
+ this.graphLockOperation = graphLockOperation;
+ }
+
+ private static Logger log = LoggerFactory.getLogger(BaseBusinessLogic.class.getName());
+
+ protected Either<User, ResponseFormat> validateUserNotEmpty(User user, String ecompErrorContext) {
+ String userId = user.getUserId();
+
+ if (StringUtils.isEmpty(userId)) {
+ // user.setUserId("UNKNOWN");
+ log.debug("User header is missing ");
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUserMissingError, ecompErrorContext, user.getUserId());
+ BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ return Either.right(responseFormat);
+ }
+ return Either.left(user);
+ }
+
+ protected Either<User, ResponseFormat> validateUserExists(User user, String ecompErrorContext, boolean inTransaction) {
+ return validateUserExists(user.getUserId(), ecompErrorContext, inTransaction);
+ }
+
+ protected void validateUserExist(String userId, String ecompErrorContext, Wrapper<ResponseFormat> errorWrapper) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, ecompErrorContext, false);
+ if (resp.isRight()) {
+ errorWrapper.setInnerElement(resp.right().value());
+ }
+ }
+
+ public Either<User, ActionStatus> validateUserExistsActionStatus(String userId, String ecompErrorContext) {
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ log.debug("validateUserExists - not authorized user, userId {}", userId);
+ Either.right(ActionStatus.RESTRICTED_OPERATION);
+ } else {
+ log.debug("validateUserExists - failed to authorize user, userId {}", userId);
+ }
+ log.debug("User is not listed. userId {}", userId);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUserMissingError, ecompErrorContext, userId);
+ return Either.right(eitherCreator.right().value());
+ }
+ return Either.left(eitherCreator.left().value());
+ }
+
+ public Either<User, ResponseFormat> validateUserExists(String userId, String ecompErrorContext, boolean inTransaction) {
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, inTransaction);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ ResponseFormat responseFormat;
+ if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ if (log.isDebugEnabled())
+ log.debug("validateUserExists - not authorized user, userId {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ } else {
+ if (log.isDebugEnabled())
+ log.debug("validateUserExists - failed to authorize user, userId {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(eitherCreator.right().value());
+ }
+ if (log.isDebugEnabled())
+ log.debug("User is not listed. userId {}", userId);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUserMissingError, ecompErrorContext, userId);
+ BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
+ return Either.right(responseFormat);
+ }
+ return Either.left(eitherCreator.left().value());
+ }
+
+ protected Either<Boolean, ResponseFormat> validateUserRole(User user, List<Role> roles) {
+ Role userRole = Role.valueOf(user.getRole());
+ if (roles != null) {
+ if (!roles.contains(userRole)) {
+ if (log.isDebugEnabled())
+ log.debug("user is not in appropriate role to perform action");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ return Either.right(responseFormat);
+ }
+ return Either.left(Boolean.TRUE);
+ }
+ return Either.left(Boolean.FALSE);
+ }
+
+ protected Either<Boolean, ResponseFormat> lockComponent(Component component, String ecompErrorContext) {
+ return lockComponent(component.getUniqueId(), component, ecompErrorContext);
+ }
+
+ protected Either<Boolean, ResponseFormat> lockComponent(String componentId, Component component, String ecompErrorContext) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(componentId, nodeType);
+
+ if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
+ return Either.left(true);
+ } else {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(ecompErrorContext, nodeType.getName(), componentId);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(lockResourceStatus, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, component.getName());
+ log.debug("Failed to lock component {} error - {}", componentId, actionStatus);
+ return Either.right(responseFormat);
+ }
+ }
+
+ protected void unlockComponent(Either<?, ?> either, Component component, boolean inTransaction) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ if (false == inTransaction) {
+ if (either == null || either.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(component.getUniqueId(), nodeType);
+ }
+
+ protected void unlockComponent(Either<?, ?> either, Component component) {
+ unlockComponent(either, component, false);
+ }
+
+ protected <T> Either<Boolean, ResponseFormat> validateJsonBody(T bodyObject, Class<T> clazz) {
+ if (bodyObject == null) {
+ log.debug("Invalid JSON received for object of type {}", clazz.getSimpleName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ } else {
+ return Either.left(true);
+ }
+ }
+
+ protected Either<ComponentTypeEnum, ResponseFormat> validateComponentType(String componentType) {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum == null) {
+ log.debug("Invalid component type {}", componentType);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, componentType));
+ } else {
+ return Either.left(componentTypeEnum);
+ }
+ }
+
+ protected Either<Component, ResponseFormat> validateComponentExists(String componentId, ComponentTypeEnum componentType, boolean inTransaction, boolean createNewTransaction) {
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ Either<Component, StorageOperationStatus> componentFound = null;
+ // if(createNewTransaction){
+ // componentFound = componentOperation.getComponent_tx(componentId,
+ // inTransaction);
+ // }
+ // else{
+ componentFound = componentOperation.getComponent(componentId, inTransaction);
+ // }
+
+ if (componentFound.isRight()) {
+ StorageOperationStatus storageOperationStatus = componentFound.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
+ log.debug("Component with id {} was not found", componentId);
+ return Either.right(responseFormat);
+ }
+ return Either.left(componentFound.left().value());
+ }
+
+ protected Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists(String componentId, ComponentTypeEnum componentType, ComponentParametersView componentParametersView, String userId,
+ AuditingActionEnum auditingAction, User user) {
+
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+
+ if (componentOperation == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ log.debug("addGroup - not supported component type {}", componentType);
+ // handleAuditing(auditingAction, null, componentId, user, null,
+ // null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ Either<? extends org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResult = componentOperation.getComponent(componentId, componentParametersView, true);
+
+ if (componentResult.isRight()) {
+ ActionStatus status = (componentType.equals(ComponentTypeEnum.RESOURCE)) ? ActionStatus.RESOURCE_NOT_FOUND : ActionStatus.SERVICE_NOT_FOUND;
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, componentId);
+
+ log.debug("Service not found, serviceId {}", componentId);
+ // ComponentTypeEnum componentForAudit =
+ // (componentType.equals(ComponentTypeEnum.RESOURCE)) ?
+ // ComponentTypeEnum.RESOURCE : ComponentTypeEnum.SERVICE;
+ // handleAuditing(auditingAction, null, componentId, user, null,
+ // null, artifactId, responseFormat, componentForAudit, null);
+ return Either.right(responseFormat);
+ }
+ return Either.left(componentResult.left().value());
+ }
+
+ public Either<Boolean, ResponseFormat> validateCanWorkOnComponent(Component component, String userId) {
+ Either<Boolean, ResponseFormat> canWork = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ if (component.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
+ log.debug("Component {} is not checked-out", component.getName());
+ return canWork;
+ }
+
+ // verify user id is not null
+ if (userId == null) {
+ log.debug("Current user userId is null");
+ return canWork;
+ }
+
+ // verify component last update user is the current user
+ String lastUpdaterUserId = component.getLastUpdaterUserId();
+ if (!userId.equals(lastUpdaterUserId)) {
+ log.debug("Current user is not last updater, last updater userId: {}, current user userId: {}", lastUpdaterUserId, userId);
+ return canWork;
+ }
+
+ // verify resource is not deleted
+ if ((component.getIsDeleted() != null) && (component.getIsDeleted() == true)) {
+ log.debug("Component {} is marked as deleted", component.getUniqueId());
+ return canWork;
+ }
+
+ return Either.left(true);
+ }
+
+ public ComponentOperation getComponentOperation(ComponentTypeEnum componentTypeEnum) {
+ if (ComponentTypeEnum.SERVICE == componentTypeEnum) {
+ return serviceOperation;
+ } else if (ComponentTypeEnum.RESOURCE == componentTypeEnum) {
+ return resourceOperation;
+ } else if (ComponentTypeEnum.PRODUCT == componentTypeEnum) {
+ return productOperation;
+ }
+ return null;
+ }
+
+ public IComponentOperation getIComponentOperation(ComponentTypeEnum componentTypeEnum) {
+
+ switch (componentTypeEnum) {
+ case SERVICE:
+ return serviceOperation;
+ case RESOURCE:
+ return resourceOperation;
+ case PRODUCT:
+ return productOperation;
+ default:
+ break;
+ }
+
+ return null;
+ }
+
+ public ComponentOperation getComponentOperationByParentComponentType(ComponentTypeEnum parentComponentType) {
+ switch (parentComponentType) {
+ case SERVICE:
+ return resourceOperation;
+ case RESOURCE:
+ return resourceOperation;
+ case PRODUCT:
+ return serviceOperation;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ public ComponentTypeEnum getComponentTypeByParentComponentType(ComponentTypeEnum parentComponentType) {
+ switch (parentComponentType) {
+ case SERVICE:
+ return ComponentTypeEnum.RESOURCE;
+ case RESOURCE:
+ return ComponentTypeEnum.RESOURCE;
+ case PRODUCT:
+ return ComponentTypeEnum.SERVICE;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ // For UT
+ public void setTitanGenericDao(TitanGenericDao titanGenericDao) {
+ this.titanGenericDao = titanGenericDao;
+ }
+
+ protected Either<Map<String, DataTypeDefinition>, ResponseFormat> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) {
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
+ if (allDataTypes.isRight()) {
+ TitanOperationStatus operationStatus = allDataTypes.right().value();
+ if (operationStatus == TitanOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY));
+ } else {
+ BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ return Either.left(allDataTypes.left().value());
+ }
+
+ protected Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
+ log.debug("validate property");
+ String type = null;
+ String innerType = null;
+ if (!propertyOperation.isPropertyTypeValid(property)) {
+ log.info("Invalid type for property");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
+ return Either.right(responseFormat);
+ }
+ type = property.getType();
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, dataTypes);
+ innerType = propertyInnerTypeValid.getLeft();
+ if (!propertyInnerTypeValid.getRight().booleanValue()) {
+ log.info("Invalid inner type for property");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ if (!propertyOperation.isPropertyDefaultValueValid(property, dataTypes)) {
+ log.info("Invalid default value for property");
+ ResponseFormat responseFormat;
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType, property.getDefaultValue());
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
+ }
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(true);
+ }
+
+ protected Either<Resource, StorageOperationStatus> getResource(final String resourceId) {
+
+ log.debug("Get resource with id {}", resourceId);
+ Either<Resource, StorageOperationStatus> status = resourceOperation.getResource(resourceId);
+ if (status.isRight()) {
+ log.debug("Resource with id {} was not found", resourceId);
+ return Either.right(status.right().value());
+ }
+
+ Resource resource = status.left().value();
+ if (resource == null) {
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("Property Business Logic", ComponentTypeEnum.RESOURCE.getValue(), resourceId);
+ log.debug("General Error while get resource with id {}", resourceId);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ return Either.left(resource);
+ }
+
+ protected void handleDefaultValue(IComplexDefaultValue newAttributeDef, Map<String, DataTypeDefinition> dataTypes) {
+ // convert property
+ ToscaPropertyType type = ToscaPropertyType.isValidType(newAttributeDef.getType());
+ PropertyValueConverter converter = type.getConverter();
+ // get inner type
+ String innerType = null;
+
+ if (newAttributeDef != null) {
+ SchemaDefinition schema = newAttributeDef.getSchema();
+ if (schema != null) {
+ PropertyDataDefinition prop = schema.getProperty();
+ if (schema.getProperty() != null) {
+ innerType = prop.getType();
+ }
+ }
+ String convertedValue = null;
+ if (newAttributeDef.getDefaultValue() != null) {
+ convertedValue = converter.convert(newAttributeDef.getDefaultValue(), innerType, dataTypes);
+ newAttributeDef.setDefaultValue(convertedValue);
+ }
+ }
+ }
+
+ protected void validateComponentTypeEnum(ComponentTypeEnum componentTypeEnum, String errorContext, Wrapper<ResponseFormat> errorWrapper) {
+ if (componentTypeEnum == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(errorContext, "invalid component type", ErrorSeverity.INFO);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ }
+
+ }
+
+ protected void validateCanWorkOnComponent(String componentId, ComponentTypeEnum componentTypeEnum, String userId, Wrapper<ResponseFormat> errorWrapper) {
+ IComponentOperation componentOperation = getIComponentOperation(componentTypeEnum);
+ if (!ComponentValidationUtils.canWorkOnComponent(componentId, componentOperation, userId)) {
+ log.info("Restricted operation for user {} on {} {}", userId, componentTypeEnum.getValue(), componentId);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ }
+
+ protected void validateComponentLock(String componentId, ComponentTypeEnum componentTypeEnum, Wrapper<ResponseFormat> errorWrapper) {
+ StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug("Failed to lock {} {}", componentTypeEnum.getValue(), componentId);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ }
+
+ }
+
+ protected ToscaPropertyType getType(String propertyType) {
+
+ ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
+
+ return type;
+
+ }
+
+ protected void commitOrRollback(Either<? extends Object, ResponseFormat> result) {
+ if (result == null || result.isRight()) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ }
+
+ protected Either<Boolean, ResponseFormat> lockComponentByName(String name, Component component, String ecompErrorContext) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponentByName(name, nodeType);
+
+ if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
+ return Either.left(true);
+ } else {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(ecompErrorContext, nodeType.getName(), name);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(lockResourceStatus, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, component.getName());
+ log.debug("Failed to lock component {} error - {}", name, actionStatus);
+ return Either.right(responseFormat);
+ }
+ }
+
+ protected Either<Component, ResponseFormat> validateComponentExistsByFilter(String componentId, ComponentTypeEnum componentType, ComponentParametersView componentParametersView, boolean inTransaction) {
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ Either<Component, StorageOperationStatus> componentFound = null;
+ componentFound = componentOperation.getComponent(componentId, componentParametersView, inTransaction);
+
+ if (componentFound.isRight()) {
+ StorageOperationStatus storageOperationStatus = componentFound.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
+ log.debug("Component with id {} was not found", componentId);
+ return Either.right(responseFormat);
+ }
+ return Either.left(componentFound.left().value());
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
new file mode 100644
index 0000000000..5cf42cedd6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import javax.annotation.Resource;
+
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("capabilityTypeImportManager")
+public class CapabilityTypeImportManager {
+
+ private static Logger log = LoggerFactory.getLogger(CapabilityTypeImportManager.class.getName());
+ @Resource
+ private CapabilityTypeOperation capabilityTypeOperation;
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private CommonImportManager commonImportManager;
+
+ public Either<List<CapabilityTypeDefinition>, ResponseFormat> createCapabilityTypes(String capabilityYml) {
+ Either<List<CapabilityTypeDefinition>, ActionStatus> capabilityTypes = createCapabilityTypesFromYml(capabilityYml);
+ if (capabilityTypes.isRight()) {
+ ActionStatus status = capabilityTypes.right().value();
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByCapabilityType(status, null);
+ return Either.right(responseFormat);
+ }
+ return createCapabilityTypesByDao(capabilityTypes.left().value());
+
+ }
+
+ private Either<List<CapabilityTypeDefinition>, ActionStatus> createCapabilityTypesFromYml(String capabilityYml) {
+ return commonImportManager.createElementTypesFromYml(capabilityYml, (capTypeName, capTypeJsonData) -> createCapabilityType(capTypeName, capTypeJsonData));
+
+ }
+
+ private Either<List<CapabilityTypeDefinition>, ResponseFormat> createCapabilityTypesByDao(List<CapabilityTypeDefinition> capabilityTypesToCreate) {
+ List<CapabilityTypeDefinition> createdCapabilities = new ArrayList<>();
+ Either<List<CapabilityTypeDefinition>, ResponseFormat> eitherResult = Either.left(createdCapabilities);
+ Iterator<CapabilityTypeDefinition> capTypeItr = capabilityTypesToCreate.iterator();
+ boolean stopDao = false;
+ while (capTypeItr.hasNext() && !stopDao) {
+ CapabilityTypeDefinition capabilityType = capTypeItr.next();
+
+ log.info("send capabilityType {} to dao for create", capabilityType.getType());
+ Either<CapabilityTypeDefinition, StorageOperationStatus> dataModelResponse = capabilityTypeOperation.addCapabilityType(capabilityType);
+ if (dataModelResponse.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedAddingCapabilityTypeError, "Create CapabilityTypes");
+ BeEcompErrorManager.getInstance().logBeFailedAddingNodeTypeError("Create CapabilityTypes", "capability type");
+ log.debug("failed to create capabilityType: {}", capabilityType.getType());
+ if (dataModelResponse.right().value() != StorageOperationStatus.SCHEMA_VIOLATION) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByCapabilityType(componentsUtils.convertFromStorageResponseForCapabilityType(dataModelResponse.right().value()), capabilityType);
+ eitherResult = Either.right(responseFormat);
+ stopDao = true;
+ }
+
+ } else {
+ createdCapabilities.add(capabilityType);
+ }
+ if (!capTypeItr.hasNext()) {
+ log.info("capabilityTypes were created successfully!!!");
+ }
+
+ }
+
+ return eitherResult;
+
+ }
+
+ private CapabilityTypeDefinition createCapabilityType(String capabilityTypeName, Map<String, Object> toscaJson) {
+ CapabilityTypeDefinition capabilityType = new CapabilityTypeDefinition();
+
+ capabilityType.setType(capabilityTypeName);
+
+ // Description
+ final Consumer<String> descriptionSetter = description -> capabilityType.setDescription(description);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DESCRIPTION.getElementName(), descriptionSetter);
+ // Derived From
+ final Consumer<String> derivedFromSetter = derivedFrom -> capabilityType.setDerivedFrom(derivedFrom);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DERIVED_FROM.getElementName(), derivedFromSetter);
+ // Properties
+ commonImportManager.setPropertiesMap(toscaJson, (values) -> capabilityType.setProperties(values));
+
+ return capabilityType;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
new file mode 100644
index 0000000000..26ea80ac4b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
@@ -0,0 +1,274 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
+import org.openecomp.sdc.be.datamodel.utils.NodeTypeConvertUtils;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.yaml.snakeyaml.Yaml;
+
+import fj.data.Either;
+
+@Component("categoriesImportManager")
+public class CategoriesImportManager {
+
+ @javax.annotation.Resource
+ private IElementOperation elementOperation;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ private static Logger log = LoggerFactory.getLogger(CategoriesImportManager.class.getName());
+
+ public Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCategories(String categoriesTypesYml) {
+
+ Map<String, List<CategoryDefinition>> allCategories = createCategoriesFromYml(categoriesTypesYml);
+ return createCategoriesByDao(allCategories);
+ }
+
+ private Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCategoriesByDao(Map<String, List<CategoryDefinition>> allCategories) {
+ Map<String, List<CategoryDefinition>> result = new HashMap<>();
+ log.debug("createCategoriesByDao: starting to create Categories.");
+ for (Map.Entry<String, List<CategoryDefinition>> entry : allCategories.entrySet()) {
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(entry.getKey());
+ NodeTypeEnum nodeTypeCategory = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentType, CategoryTypeEnum.CATEGORY);
+ NodeTypeEnum nodeTypeSubCategory = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentType, CategoryTypeEnum.SUBCATEGORY);
+ NodeTypeEnum nodeTypeGroup = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentType, CategoryTypeEnum.GROUPING);
+ if (log.isDebugEnabled()) {
+ log.debug("createCategoriesByDao: creating componentType:{} nodeTypeCategory:{} nodeTypeSubCategory:{} nodeTypeGroup:{}", componentType, nodeTypeCategory, nodeTypeSubCategory, nodeTypeGroup);
+ }
+ List<CategoryDefinition> newCategoriesvalue = new ArrayList<>();
+ for (CategoryDefinition category : entry.getValue()) {
+
+ Either<CategoryDefinition, ResponseFormat> createdCategoryRes = createCategorieDeo(entry, category, nodeTypeCategory);
+ if (createdCategoryRes.isRight()) {
+ return Either.right(createdCategoryRes.right().value());
+ }
+
+ CategoryDefinition newcategory = createdCategoryRes.left().value();
+ String categoryId = newcategory.getUniqueId();
+ log.debug("createCategoriesByDao: create category was successful {}", newcategory);
+ List<SubCategoryDefinition> newsubcategories = new ArrayList<>();
+ List<SubCategoryDefinition> subcategories = category.getSubcategories();
+ if (subcategories != null) {
+ for (SubCategoryDefinition subcategory : subcategories) {
+ Either<SubCategoryDefinition, ResponseFormat> createdSubCategory = createSubCategorieDeo(entry, newcategory, subcategory, nodeTypeSubCategory);
+ if (createdSubCategory.isRight()) {
+ return Either.right(createdCategoryRes.right().value());
+ }
+ SubCategoryDefinition newsubcategory = createdSubCategory.left().value();
+ List<GroupingDefinition> groupings = subcategory.getGroupings();
+ if (groupings != null) {
+ List<GroupingDefinition> newgroupings = new ArrayList<>();
+ for (GroupingDefinition grouping : groupings) {
+ Either<GroupingDefinition, ResponseFormat> createdGrouping = createGroupingDeo(entry, grouping, subcategory, category, nodeTypeGroup);
+ if (createdGrouping.isRight()) {
+ return Either.right(createdCategoryRes.right().value());
+ }
+ newgroupings.add(createdGrouping.left().value());
+ }
+ newsubcategory.setGroupings(newgroupings);
+ }
+ newsubcategories.add(newsubcategory);
+ }
+ newcategory.setSubcategories(newsubcategories);
+ }
+ newCategoriesvalue.add(newcategory);
+ }
+ result.put(entry.getKey(), newCategoriesvalue);
+ }
+ return Either.left(result);
+ }
+
+ private Either<GroupingDefinition, ResponseFormat> createGroupingDeo(Map.Entry<String, List<CategoryDefinition>> entry, GroupingDefinition grouping, SubCategoryDefinition subcategory, CategoryDefinition category, NodeTypeEnum nodeTypeGroup) {
+
+ log.debug("createGroupingDeo: creating grouping {}", grouping);
+ Either<GroupingDefinition, ActionStatus> createdGrouping = elementOperation.createGrouping(subcategory.getUniqueId(), grouping, nodeTypeGroup);
+ if (createdGrouping.isRight()) {
+ if (ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY.equals(createdGrouping.right().value())) {
+ log.debug(" create grouping for {}. group {} already exists", entry.getKey(), grouping.getName());
+ String groupingId = UniqueIdBuilder.buildGroupingUid(grouping.getUniqueId(), grouping.getNormalizedName());
+ createdGrouping = elementOperation.getGroupingUniqueForType(nodeTypeGroup, groupingId);
+ if (createdGrouping.isRight()) {
+ log.debug("failed to get grouping that exists groupingId: {}, type: {}", groupingId, nodeTypeGroup);
+ return Either.right(componentsUtils.getResponseFormat(createdGrouping.right().value()));
+ }
+ }
+ log.debug("Failed to create groupingcategory for {}, category {}, subcategory {}, grouping {}, error {}", entry.getKey(), category.getName(), subcategory.getName(), (grouping != null ? grouping.getName() : null),
+ (createdGrouping != null && createdGrouping.right() != null ? createdGrouping.right().value() : null));
+ return Either.right(componentsUtils.getResponseFormat(createdGrouping.right().value()));
+ } else {
+ log.debug("createGroupingDeo: create Grouping was successful {}", createdGrouping.left().value());
+ }
+ return Either.left(createdGrouping.left().value());
+
+ }
+
+ private Either<SubCategoryDefinition, ResponseFormat> createSubCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition newcategory, SubCategoryDefinition subcategory, NodeTypeEnum nodeTypeSubCategory) {
+ log.debug("createSubCategorieDeo: creating subcategory {}", subcategory);
+ Either<SubCategoryDefinition, ActionStatus> createdSubCategory = elementOperation.createSubCategory(newcategory.getUniqueId(), subcategory, nodeTypeSubCategory);
+ if (createdSubCategory.isRight()) {
+ if (ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY.equals(createdSubCategory.right().value())) {
+ log.debug(" create subcategory for {} category {}, alreay exists retrieving", entry.getKey(), newcategory.getName(), subcategory.getName());
+ String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName());
+ createdSubCategory = elementOperation.getSubCategory(nodeTypeSubCategory, subCategoryId);
+ if (createdSubCategory.isRight()) {
+ log.debug("failed to get sub category that exists subCategoryId: {}, type: {}", subCategoryId, nodeTypeSubCategory);
+ return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value()));
+ }
+ } else {
+ log.debug("Failed to create subcategory for {} category {}, error {}", entry.getKey(), newcategory.getName(), subcategory.getName(), createdSubCategory.right().value());
+ return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value()));
+ }
+ } else {
+ log.debug("createSubCategorieDeo: create subcategory was successful {}", createdSubCategory.left().value());
+ }
+ return Either.left(createdSubCategory.left().value());
+ }
+
+ private Either<CategoryDefinition, ResponseFormat> createCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition category, NodeTypeEnum nodeTypeCategory) {
+ log.debug("createCategorieDeo: creating category {}", category);
+ Either<CategoryDefinition, ActionStatus> createdCategory = elementOperation.createCategory(category, nodeTypeCategory);
+ if (createdCategory.isRight()) {
+ log.debug("Failed to create category for {}, error {}", entry.getKey(), category.getName(), createdCategory.right().value());
+ if (!ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS.equals(createdCategory.right().value())) {
+ return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
+ } else {
+ log.debug("createCategorieDeo: category exists {} retriving.", category);
+ String categoryId = UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeTypeCategory);
+ createdCategory = elementOperation.getCategory(nodeTypeCategory, categoryId);
+ if (createdCategory.isRight()) {
+ log.debug("failed to get category that exists categoryId: {}, type: {}", categoryId, nodeTypeCategory);
+ return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
+ }
+ }
+ } else {
+ log.debug("createCategorieDeo: create category was successful {}", createdCategory.left().value());
+ }
+ return Either.left(createdCategory.left().value());
+ }
+
+ private Map<String, List<CategoryDefinition>> createCategoriesFromYml(String categoriesTypesYml) {
+ Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(categoriesTypesYml);
+ Map<String, List<CategoryDefinition>> allCategories = new HashMap<>();
+
+ Iterator<Entry<String, Object>> categoryEntryItr = toscaJson.entrySet().iterator();
+ while (categoryEntryItr.hasNext()) {
+ Entry<String, Object> categoryTypeEntry = categoryEntryItr.next();
+ String categoryType = categoryTypeEntry.getKey();
+ List<CategoryDefinition> categoriesPerType = null;
+ Map<String, Object> categoryPerType = null;
+ switch (categoryType) {
+ case ComponentTypeEnum.SERVICE_PARAM_NAME:
+ categoryPerType = (Map<String, Object>) categoryTypeEntry.getValue();
+ categoriesPerType = createServiceCategories(categoryPerType);
+ break;
+ case ComponentTypeEnum.RESOURCE_PARAM_NAME:
+ categoryPerType = (Map<String, Object>) categoryTypeEntry.getValue();
+ categoriesPerType = createResourceCategories(categoryPerType);
+ break;
+ case ComponentTypeEnum.PRODUCT_PARAM_NAME:
+ // TODO
+ break;
+ default:
+ log.debug("Not supported category type - {}", categoryType);
+ break;
+ }
+ if (categoriesPerType != null) {
+ allCategories.put(categoryType, categoriesPerType);
+ }
+ }
+ return allCategories;
+ }
+
+ private List<CategoryDefinition> createServiceCategories(Map<String, Object> categories) {
+ List<CategoryDefinition> categroiesDef = new ArrayList<>();
+ String catName = null;
+ List<String> icons = null;
+ for (Entry<String, Object> entry : categories.entrySet()) {
+ CategoryDefinition catDef = new CategoryDefinition();
+ Map<String, Object> category = (Map<String, Object>) entry.getValue();
+ catName = (String) category.get("name");
+ catDef.setName(catName);
+ icons = (List<String>) category.get("icons");
+ catDef.setIcons(icons);
+ String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(catName);
+ catDef.setNormalizedName(normalizedName);
+ categroiesDef.add(catDef);
+ }
+
+ return categroiesDef;
+ }
+
+ private List<CategoryDefinition> createResourceCategories(Map<String, Object> categoryPerType) {
+ List<CategoryDefinition> categroiesDef = new ArrayList<>();
+ for (Map.Entry<String, Object> entry : categoryPerType.entrySet()) {
+ Map<String, Object> category = (Map<String, Object>) entry.getValue();
+ CategoryDefinition catDef = new CategoryDefinition();
+ String catName = (String) category.get("name");
+ catDef.setName(catName);
+ String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(catName);
+ catDef.setNormalizedName(normalizedName);
+ Map<String, Object> subcategories = (Map<String, Object>) category.get("subcategories");
+ List<SubCategoryDefinition> subcateDef = new ArrayList<>();
+ for (Entry<String, Object> subcategory : subcategories.entrySet()) {
+ Map<String, Object> subcategoryInfo = (Map<String, Object>) subcategory.getValue();
+ SubCategoryDefinition subDef = new SubCategoryDefinition();
+ String subcategoryName = (String) subcategoryInfo.get("name");
+ subDef.setName(subcategoryName);
+ List<String> subcategoryIcons = (List<String>) subcategoryInfo.get("icons");
+ subDef.setIcons(subcategoryIcons);
+ normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(subcategoryName);
+ subDef.setNormalizedName(normalizedName);
+ subcateDef.add(subDef);
+ }
+
+ catDef.setSubcategories(subcateDef);
+ categroiesDef.add(catDef);
+ }
+ return categroiesDef;
+ }
+
+ public static void setLog(Logger log) {
+ CategoriesImportManager.log = log;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
new file mode 100644
index 0000000000..9b99b665f7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
@@ -0,0 +1,309 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import jersey.repackaged.com.google.common.base.Function;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.yaml.snakeyaml.Yaml;
+
+import fj.data.Either;
+
+@Component("commonImportManager")
+public class CommonImportManager {
+
+ private static Logger log = LoggerFactory.getLogger(CommonImportManager.class.getName());
+
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private PropertyOperation propertyOperation;
+
+ protected void setProperties(Map<String, Object> toscaJson, Consumer<List<PropertyDefinition>> consumer) {
+ consumer.accept(getProperties(toscaJson));
+ }
+
+ private List<PropertyDefinition> getProperties(Map<String, Object> toscaJson) {
+ List<PropertyDefinition> values = null;
+ Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(toscaJson);
+
+ if (properties.isLeft()) {
+ values = new ArrayList<>();
+ Map<String, PropertyDefinition> propertiesMap = properties.left().value();
+ if (propertiesMap != null && propertiesMap.isEmpty() == false) {
+
+ for (Entry<String, PropertyDefinition> entry : propertiesMap.entrySet()) {
+ String propName = entry.getKey();
+ PropertyDefinition propertyDefinition = entry.getValue();
+ PropertyDefinition newPropertyDefinition = new PropertyDefinition(propertyDefinition);
+ newPropertyDefinition.setName(propName);
+ values.add(newPropertyDefinition);
+ }
+ }
+ }
+
+ return values;
+ }
+
+ protected void setPropertiesMap(Map<String, Object> toscaJson, Consumer<Map<String, PropertyDefinition>> consumer) {
+ final List<PropertyDefinition> properties = getProperties(toscaJson);
+ if (properties != null) {
+ Map<String, PropertyDefinition> collect = properties.stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
+ consumer.accept(collect);
+ }
+
+ }
+
+ interface ICreateElementType<T1, T2, ElementType> {
+ ElementType createElement(T1 firstArg, T2 secondArg);
+ }
+
+ protected <ElementDefinition> Either<List<ElementDefinition>, ActionStatus> createElementTypesFromYml(String elementTypesYml, ICreateElementType<String, Map<String, Object>, ElementDefinition> createApi) {
+
+ List<ElementDefinition> elementTypes = new ArrayList<>();
+ try {
+ Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(elementTypesYml);
+
+ Iterator<Entry<String, Object>> elementTypesEntryItr = toscaJson.entrySet().iterator();
+ while (elementTypesEntryItr.hasNext()) {
+ Entry<String, Object> elementTypeNameDataEntry = elementTypesEntryItr.next();
+ String elementTypeName = elementTypeNameDataEntry.getKey();
+ Map<String, Object> elementTypeJsonData = (Map<String, Object>) elementTypeNameDataEntry.getValue();
+ ElementDefinition elementDefinition = createApi.createElement(elementTypeName, elementTypeJsonData);
+ elementTypes.add(elementDefinition);
+
+ }
+
+ } catch (Exception e) {
+ log.debug("Failed to yaml file {} {}", elementTypesYml, e);
+ return Either.right(ActionStatus.INVALID_YAML_FILE);
+ }
+ return Either.left(elementTypes);
+ }
+
+ protected <FieldType> void setField(Map<String, Object> toscaJson, String fieldName, Consumer<FieldType> setter) {
+ if (toscaJson.containsKey(fieldName)) {
+ FieldType fieldValue = (FieldType) toscaJson.get(fieldName);
+ setter.accept(fieldValue);
+ }
+
+ }
+
+ enum ElementTypeEnum {
+ PolicyType, GroupType, DataType, CapabilityType, InterfaceLifecycleType
+ };
+
+ private ActionStatus convertFromStorageResponseForElementType(StorageOperationStatus status, ElementTypeEnum elementTypeEnum) {
+ ActionStatus ret;
+ switch (elementTypeEnum) {
+ case GroupType:
+ ret = componentsUtils.convertFromStorageResponseForGroupType(status);
+ break;
+ case DataType:
+ ret = componentsUtils.convertFromStorageResponseForDataType(status);
+ break;
+ case CapabilityType:
+ ret = componentsUtils.convertFromStorageResponseForCapabilityType(status);
+ break;
+ case InterfaceLifecycleType:
+ ret = componentsUtils.convertFromStorageResponseForLifecycleType(status);
+ break;
+ default:
+ ret = componentsUtils.convertFromStorageResponse(status);
+ break;
+ }
+ return ret;
+ }
+
+ private <ElementTypeDefinition> ResponseFormat getResponseFormatForElementType(ActionStatus actionStatus, ElementTypeEnum elementTypeEnum, ElementTypeDefinition elementTypeDefinition) {
+ ResponseFormat ret;
+ switch (elementTypeEnum) {
+ case GroupType:
+ ret = componentsUtils.getResponseFormatByGroupType(actionStatus, (GroupTypeDefinition) elementTypeDefinition);
+ break;
+ case PolicyType:
+ ret = componentsUtils.getResponseFormatByPolicyType(actionStatus, (PolicyTypeDefinition) elementTypeDefinition);
+ break;
+ case DataType:
+ ret = componentsUtils.getResponseFormatByDataType(actionStatus, (DataTypeDefinition) elementTypeDefinition, null);
+ break;
+ case CapabilityType:
+ ret = componentsUtils.getResponseFormatByCapabilityType(actionStatus, (CapabilityTypeDefinition) elementTypeDefinition);
+ break;
+
+ default:
+ ret = componentsUtils.getResponseFormat(actionStatus);
+ break;
+ }
+ return ret;
+ }
+
+ protected <ElementTypeDefinition> Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> createElementTypesByDao(List<ElementTypeDefinition> elementTypesToCreate,
+ Function<ElementTypeDefinition, Either<ActionStatus, ResponseFormat>> validator, Function<ElementTypeDefinition, ImmutablePair<ElementTypeEnum, String>> elementInfoGetter,
+ Function<String, Either<ElementTypeDefinition, StorageOperationStatus>> elementFetcher, Function<ElementTypeDefinition, Either<ElementTypeDefinition, StorageOperationStatus>> elementAdder,
+ BiFunction<ElementTypeDefinition, ElementTypeDefinition, Either<ElementTypeDefinition, StorageOperationStatus>> elementUpgrader) {
+
+ List<ImmutablePair<ElementTypeDefinition, Boolean>> createdElementTypes = new ArrayList<>();
+
+ Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = Either.left(createdElementTypes);
+
+ Iterator<ElementTypeDefinition> elementTypeItr = elementTypesToCreate.iterator();
+
+ try {
+
+ while (elementTypeItr.hasNext()) {
+ ElementTypeDefinition elementType = elementTypeItr.next();
+ final ImmutablePair<ElementTypeEnum, String> elementInfo = elementInfoGetter.apply(elementType);
+ ElementTypeEnum elementTypeEnum = elementInfo.left;
+ String elementName = elementInfo.right;
+
+ Either<ActionStatus, ResponseFormat> validateElementType = validator.apply(elementType);
+ if (validateElementType.isRight()) {
+ ResponseFormat responseFormat = validateElementType.right().value();
+ log.debug("Failed in validation of element type {}. Response is {}", elementType, responseFormat.getFormattedMessage());
+ eitherResult = Either.right(responseFormat);
+ break;
+ }
+
+ log.info("send {} : {} to dao for create", elementTypeEnum.name(), elementName);
+
+ Either<ElementTypeDefinition, StorageOperationStatus> findElementType = elementFetcher.apply(elementName);
+ if (findElementType.isRight()) {
+ StorageOperationStatus status = findElementType.right().value();
+ log.debug("searched {} finished with result:{}", elementTypeEnum.name(), status.name());
+ if (status != StorageOperationStatus.NOT_FOUND) {
+ ResponseFormat responseFormat = getResponseFormatForElementType(convertFromStorageResponseForElementType(status, elementTypeEnum), elementTypeEnum, elementType);
+ eitherResult = Either.right(responseFormat);
+ break;
+ } else {
+ Either<ElementTypeDefinition, StorageOperationStatus> dataModelResponse = elementAdder.apply(elementType);
+
+ if (dataModelResponse.isRight()) {
+ try {
+ BeEcompErrorManager.getInstance().logBeFailedAddingNodeTypeError("Create {}", elementTypeEnum.name());
+ log.debug("failed to create {}: {}", elementTypeEnum.name(), elementName);
+ if (dataModelResponse.right().value() != StorageOperationStatus.SCHEMA_VIOLATION) {
+ ResponseFormat responseFormat = getResponseFormatForElementType(convertFromStorageResponseForElementType(dataModelResponse.right().value(), elementTypeEnum), elementTypeEnum, elementType);
+
+ eitherResult = Either.right(responseFormat);
+ break;
+ } else {
+ createdElementTypes.add(new ImmutablePair<ElementTypeDefinition, Boolean>(elementType, false));
+ }
+ } finally {
+ propertyOperation.getTitanGenericDao().rollback();
+ }
+ } else {
+ propertyOperation.getTitanGenericDao().commit();
+ createdElementTypes.add(new ImmutablePair<ElementTypeDefinition, Boolean>(elementType, true));
+ log.debug("{} : {} was created successfully.", elementTypeEnum.name(), elementName);
+ }
+ if (!elementTypeItr.hasNext()) {
+ log.info("all {} were created successfully!!!", elementTypeEnum.name());
+ }
+
+ }
+ } else {
+
+ if (elementUpgrader != null) {
+ Either<ElementTypeDefinition, StorageOperationStatus> upgradeResponse = null;
+ try {
+ upgradeResponse = elementUpgrader.apply(elementType, findElementType.left().value());
+ if (upgradeResponse.isRight()) {
+ StorageOperationStatus status = upgradeResponse.right().value();
+ if (status == StorageOperationStatus.OK) {
+ createdElementTypes.add(new ImmutablePair<ElementTypeDefinition, Boolean>(elementType, false));
+ } else {
+ ResponseFormat responseFormat = getResponseFormatForElementType(convertFromStorageResponseForElementType(upgradeResponse.right().value(), elementTypeEnum), elementTypeEnum, elementType);
+ eitherResult = Either.right(responseFormat);
+ break;
+ }
+ } else {
+ log.debug("{} : {} was upgraded successfully.", elementTypeEnum.name(), elementName);
+ createdElementTypes.add(new ImmutablePair<ElementTypeDefinition, Boolean>(elementType, true));
+ }
+ } finally {
+ if (upgradeResponse == null || upgradeResponse.isRight()) {
+ propertyOperation.getTitanGenericDao().rollback();
+ } else {
+ propertyOperation.getTitanGenericDao().commit();
+ }
+ }
+
+ } else {
+ // mshitrit Once GroupType Versions are supported add
+ // code here
+ createdElementTypes.add(new ImmutablePair<ElementTypeDefinition, Boolean>(elementType, false));
+ log.debug("{} : {} already exists.", elementTypeEnum.name(), elementName);
+ }
+
+ }
+
+ }
+ } finally {
+ if (eitherResult.isRight()) {
+ propertyOperation.getTitanGenericDao().rollback();
+ }
+ }
+
+ return eitherResult;
+
+ }
+
+ public <ElementTypeDefinition> Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> createElementTypes(String elementTypesYml, Function<String, Either<List<ElementTypeDefinition>, ActionStatus>> elementTypeFromYmlCreater,
+ Function<List<ElementTypeDefinition>, Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> elementTypeDaoCreater, ElementTypeEnum elementTypeEnum) {
+
+ Either<List<ElementTypeDefinition>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(elementTypesYml);
+ if (elementTypes.isRight()) {
+ ActionStatus status = elementTypes.right().value();
+ ResponseFormat responseFormat = getResponseFormatForElementType(status, elementTypeEnum, null);
+ return Either.right(responseFormat);
+ }
+ return elementTypeDaoCreater.apply(elementTypes.left().value());
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
new file mode 100644
index 0000000000..6c7b8b9bc7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -0,0 +1,860 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapReqDef;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ComponentCache;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
+
+ @Autowired
+ protected ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Autowired
+ protected ComponentCache componentCache;
+
+ private static Logger log = LoggerFactory.getLogger(ComponentBusinessLogic.class.getName());
+
+ private static final String TAG_FIELD_LABEL = "tag";
+
+ public abstract Either<List<String>, ResponseFormat> deleteMarkedComponents();
+
+ public abstract ComponentInstanceBusinessLogic getComponentInstanceBL();
+
+ public abstract Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText);
+
+ protected Either<User, ResponseFormat> validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
+ Either<User, ResponseFormat> userValidationResult = validateUserNotEmpty(user, ecompErrorContext);
+ ResponseFormat responseFormat;
+ if (userValidationResult.isRight()) {
+ user.setUserId("UNKNOWN");
+ responseFormat = userValidationResult.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", auditAction, component.getComponentType());
+ return Either.right(responseFormat);
+ }
+ Either<User, ResponseFormat> userResult = validateUserExists(user, ecompErrorContext, inTransaction);
+ if (userResult.isRight()) {
+ responseFormat = userResult.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", auditAction, component.getComponentType());
+ return Either.right(responseFormat);
+ }
+ user = userResult.left().value();
+ return userResult;
+ }
+
+ protected Either<Boolean, ResponseFormat> validateUserRole(User user, Component component, List<Role> roles, AuditingActionEnum auditAction, String comment) {
+ if (roles != null && roles.isEmpty()) {
+ roles.add(Role.ADMIN);
+ roles.add(Role.DESIGNER);
+ }
+ Either<Boolean, ResponseFormat> validationResult = validateUserRole(user, roles);
+ if (validationResult.isRight()) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+ if (componentType.equals(ComponentTypeEnum.SERVICE)) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, comment);
+ String distributionStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus();
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, distributionStatus);
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS, distributionStatus);
+ }
+ componentsUtils.auditComponent(validationResult.right().value(), user, component, "", "", auditAction, componentType, additionalParams);
+ }
+ return validationResult;
+ }
+
+ protected Either<Boolean, ResponseFormat> validateComponentName(User user, Component component, AuditingActionEnum actionEnum) {
+ ComponentTypeEnum type = component.getComponentType();
+ String componentName = component.getName();
+ if (!ValidationUtils.validateStringNotEmpty(componentName)) {
+ log.debug("component name is empty");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ if (!ValidationUtils.validateComponentNameLength(componentName)) {
+ log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ if (!validateTagPattern(componentName)) {
+ log.debug("Component name {} has invalid format", componentName);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+ component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
+ component.setSystemName(ValidationUtils.convertToSystemName(componentName));
+
+ return Either.left(true);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateDescriptionAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
+ ComponentTypeEnum type = component.getComponentType();
+ String description = component.getDescription();
+ if (!ValidationUtils.validateStringNotEmpty(description)) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ description = ValidationUtils.removeNoneUtf8Chars(description);
+ description = ValidationUtils.normaliseWhitespace(description);
+ description = ValidationUtils.stripOctets(description);
+ description = ValidationUtils.removeHtmlTagsOnly(description);
+
+ Either<Boolean, ResponseFormat> validatDescription = validateComponentDescription(description, type);
+ if (validatDescription.isRight()) {
+ ResponseFormat responseFormat = validatDescription.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, type);
+ return Either.right(responseFormat);
+ }
+ component.setDescription(description);
+ return Either.left(true);
+ }
+
+ public Either<Boolean, ResponseFormat> validateComponentDescription(String description, ComponentTypeEnum type) {
+ if (description != null) {
+ if (!ValidationUtils.validateDescriptionLength(description)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH));
+ }
+
+ if (!ValidationUtils.validateIsEnglish(description)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue()));
+ }
+ return Either.left(true);
+ }
+ return Either.left(false);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateComponentNameUnique(User user, Component component, AuditingActionEnum actionEnum) {
+ ComponentTypeEnum type = component.getComponentType();
+ ComponentOperation componentOperation = getComponentOperation(type);
+ Either<Boolean, StorageOperationStatus> dataModelResponse;
+ dataModelResponse = componentOperation.validateComponentNameExists(component.getName());
+
+ if (dataModelResponse.isLeft()) {
+ if (dataModelResponse.left().value()) {
+ return Either.left(true);
+ } else {
+ log.info("Component with name {} already exists", component.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getName());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+ }
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "validateComponentNameUnique");
+ BeEcompErrorManager.getInstance().logBeSystemError("validateComponentNameUnique");
+ log.debug("Error while validateComponentNameUnique for component: {}", component.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateContactId(User user, Component component, AuditingActionEnum actionEnum) {
+ log.debug("validate component contact info");
+ ComponentTypeEnum type = component.getComponentType();
+ String contactId = component.getContactId();
+
+ if (!ValidationUtils.validateStringNotEmpty(contactId)) {
+ log.info("contact info is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validateContactIdResponse = validateContactId(contactId, type);
+ if (validateContactIdResponse.isRight()) {
+ ResponseFormat responseFormat = validateContactIdResponse.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, type);
+ }
+ return validateContactIdResponse;
+ }
+
+ private Either<Boolean, ResponseFormat> validateContactId(String contactId, ComponentTypeEnum type) {
+ if (contactId != null) {
+ if (!ValidationUtils.validateContactId(contactId)) {
+ log.info("contact info is invalid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ return Either.left(false);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateIcon(User user, Component component, AuditingActionEnum actionEnum) {
+ log.debug("validate Icon");
+ ComponentTypeEnum type = component.getComponentType();
+ String icon = component.getIcon();
+ if (!ValidationUtils.validateStringNotEmpty(icon)) {
+ log.info("icon is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, type);
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validateIcon = validateIcon(icon, type);
+ if (validateIcon.isRight()) {
+ ResponseFormat responseFormat = validateIcon.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, type);
+ }
+ return validateIcon;
+ }
+
+ private Either<Boolean, ResponseFormat> validateIcon(String icon, ComponentTypeEnum type) {
+ if (icon != null) {
+ if (!ValidationUtils.validateIconLength(icon)) {
+ log.debug("icon exceeds max length");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH));
+ }
+
+ if (!ValidationUtils.validateIcon(icon)) {
+ log.info("icon is invalid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ return Either.left(false);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateTagsListAndRemoveDuplicates(User user, Component component, AuditingActionEnum actionEnum) {
+ List<String> tagsList = component.getTags();
+
+ Either<Boolean, ResponseFormat> validateTags = validateComponentTags(tagsList, component.getName(), component.getComponentType());
+ if (validateTags.isRight()) {
+ ResponseFormat responseFormat = validateTags.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, component.getComponentType());
+ return Either.right(responseFormat);
+ }
+ ValidationUtils.removeDuplicateFromList(tagsList);
+ return Either.left(true);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateComponentTags(List<String> tags, String name, ComponentTypeEnum componentType) {
+ log.debug("validate component tags");
+ boolean includesComponentName = false;
+ int tagListSize = 0;
+ if (tags != null && !tags.isEmpty()) {
+ for (String tag : tags) {
+ if (!ValidationUtils.validateTagLength(tag)) {
+ log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH));
+ }
+ if (validateTagPattern(tag)) {
+ if (!includesComponentName) {
+ includesComponentName = name.equals(tag);
+ }
+ } else {
+ log.debug("invalid tag {}", tag);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL));
+ }
+ tagListSize += tag.length() + 1;
+ }
+ if (tagListSize > 0) {
+ tagListSize--;
+ }
+
+ if (!includesComponentName) {
+ log.debug("tags must include component name");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME));
+ }
+ if (!ValidationUtils.validateTagListLength(tagListSize)) {
+ log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH));
+ }
+ return Either.left(true);
+ }
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS));
+ }
+
+ protected boolean validateTagPattern(String tag) {
+ return ValidationUtils.validateComponentNamePattern(tag);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateProjectCode(User user, Component component, AuditingActionEnum actionEnum) {
+ if (ComponentTypeEnum.RESOURCE.equals(component.getComponentType())) {
+ return Either.left(true);
+ }
+ log.debug("validate PROJECT_CODE name ");
+ String projectCode = component.getProjectCode();
+
+ if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
+ log.info("projectCode is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_PROJECT_CODE);
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, component.getComponentType());
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validateProjectCodeResponse = validateProjectCode(projectCode);
+ if (validateProjectCodeResponse.isRight()) {
+ ResponseFormat responseFormat = validateProjectCodeResponse.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, component.getComponentType());
+ }
+ return validateProjectCodeResponse;
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateProjectCode(String projectCode) {
+ if (projectCode != null) {
+ if (!ValidationUtils.validateProjectCode(projectCode)) {
+ log.info("projectCode is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROJECT_CODE);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ return Either.left(false);
+ }
+
+ protected void checkComponentFieldsForOverrideAttempt(Component component) {
+ if (component.getLifecycleState() != null) {
+ log.info("LifecycleState cannot be defined by user. This field will be overridden by the application");
+ }
+ if (component.getVersion() != null) {
+ log.info("Version cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.getCreatorUserId() != null) || (component.getCreatorFullName() != null)) {
+ log.info("Creator cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.getLastUpdaterUserId() != null) || (component.getLastUpdaterFullName() != null)) {
+ log.info("Last Updater cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.getCreationDate() != null)) {
+ log.info("Creation Date cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.isHighestVersion() != null)) {
+ log.info("Is Highest Version cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.getUUID() != null)) {
+ log.info("UUID cannot be defined by user. This field will be overridden by the application");
+ }
+ if ((component.getLastUpdateDate() != null)) {
+ log.info("Last Update Date cannot be defined by user. This field will be overridden by the application");
+ }
+ if (component.getUniqueId() != null) {
+ log.info("uid cannot be defined by user. This field will be overridden by the application.");
+ component.setUniqueId(null);
+ }
+ if (component.getInvariantUUID() != null) {
+ log.info("Invariant UUID cannot be defined by user. This field will be overridden by the application.");
+ }
+ }
+
+ protected Either<Boolean, ResponseFormat> validateComponentFieldsBeforeCreate(User user, Component component, AuditingActionEnum actionEnum) {
+ // validate component name uniqueness
+ log.debug("validate component name ");
+ Either<Boolean, ResponseFormat> componentNameValidation = validateComponentName(user, component, actionEnum);
+ if (componentNameValidation.isRight()) {
+ return componentNameValidation;
+ }
+
+ // validate description
+ log.debug("validate description");
+ Either<Boolean, ResponseFormat> descValidation = validateDescriptionAndCleanup(user, component, actionEnum);
+ if (descValidation.isRight()) {
+ return descValidation;
+ }
+
+ // validate tags
+ log.debug("validate tags");
+ Either<Boolean, ResponseFormat> tagsValidation = validateTagsListAndRemoveDuplicates(user, component, actionEnum);
+ if (tagsValidation.isRight()) {
+ return tagsValidation;
+ }
+
+ // validate contact info
+ log.debug("validate contact info");
+ Either<Boolean, ResponseFormat> contactIdValidation = validateContactId(user, component, actionEnum);
+ if (contactIdValidation.isRight()) {
+ return contactIdValidation;
+ }
+
+ // validate icon
+ log.debug("validate icon");
+ Either<Boolean, ResponseFormat> iconValidation = validateIcon(user, component, actionEnum);
+ if (iconValidation.isRight()) {
+ return iconValidation;
+ }
+ return Either.left(true);
+ }
+
+ /***
+ * Fetches Component From the DB
+ *
+ * @param componentId
+ * @param componentTypeEnum
+ * @return
+ */
+ public <R extends Component> Either<R, StorageOperationStatus> getComponent(String componentId, ComponentTypeEnum componentTypeEnum) {
+ ComponentOperation componentOperation = getComponentOperation(componentTypeEnum);
+ Either<R, StorageOperationStatus> eitherComponent = componentOperation.getComponent(componentId, false);
+ return eitherComponent;
+ }
+
+ public Either<CapReqDef, ResponseFormat> getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Component Instance", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
+ Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
+ Either<CapReqDef, ResponseFormat> eitherRet;
+ ComponentOperation componentOperation = getComponentOperation(componentTypeEnum);
+ Either<Component, ResponseFormat> eitherComponent = validateComponentExists(componentId, componentTypeEnum, false, true);
+ if (eitherComponent.isLeft()) {
+ Either<Map<String, List<CapabilityDefinition>>, TitanOperationStatus> eitherCapabilities = componentOperation.getCapabilities(eitherComponent.left().value(), componentTypeEnum.getNodeType(), false);
+ if (eitherCapabilities.isRight()) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ eitherRet = Either.right(errorResponse);
+ } else {
+ Either<Map<String, List<RequirementDefinition>>, TitanOperationStatus> eitherRequirements = componentOperation.getRequirements(eitherComponent.left().value(), componentTypeEnum.getNodeType(), false);
+ if (eitherRequirements.isRight()) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ eitherRet = Either.right(errorResponse);
+ } else {
+ requirements = eitherRequirements.left().value();
+ capabilities = eitherCapabilities.left().value();
+ eitherRet = Either.left(new CapReqDef(requirements, capabilities));
+ }
+ }
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "getRequirementsAndCapabilities", componentId);
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("getRequirementsAndCapabilities", componentTypeEnum.getValue(), componentId);
+ eitherRet = Either.right(eitherComponent.right().value());
+ }
+
+ return eitherRet;
+ }
+
+ public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponents(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids,
+ String userId) {
+
+ long startUser = System.currentTimeMillis();
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Latest Version Not Abstract Components", false);
+ long endUser = System.currentTimeMillis();
+ log.debug("Activation time of get user {} ms", (endUser - startUser));
+ ResponseFormat responseFormat;
+ if (resp.isLeft()) {
+
+ List<Component> result = new ArrayList<Component>();
+ Set<String> nonProcessesComponents = new HashSet<>();
+ nonProcessesComponents.addAll(componentUids);
+
+ long startGetComp = System.currentTimeMillis();
+ // Read components from cache
+ Set<String> filteredComponents = new HashSet<>();
+ filteredComponents.addAll(componentUids);
+
+ Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> allPartialComponents = componentCache.getComponentsForLeftPanel(componentTypeEnum, internalComponentType, filteredComponents);
+
+ if (allPartialComponents.isRight()) {
+ log.debug("Components was not fetched from cache. Status is {}", allPartialComponents.right().value());
+ } else {
+ ImmutableTriple<List<Component>, List<Component>, Set<String>> immutableTriple = allPartialComponents.left().value();
+ List<Component> processedComponents = immutableTriple.left;
+ if (processedComponents != null) {
+ result.addAll(processedComponents);
+ }
+ List<Component> dirtyComponents = immutableTriple.middle;
+ if (dirtyComponents != null) {
+ result.addAll(dirtyComponents);
+ }
+
+ Set<String> nonProcessesComponentsFromCache = immutableTriple.right;
+ nonProcessesComponents = nonProcessesComponentsFromCache;
+ }
+ long endGetComp = System.currentTimeMillis();
+ log.debug("Activation time of get Comp from cache {} ms", (endGetComp - startGetComp));
+
+ // Fecth non cached components
+ List<String> componentsUidToFetch = new ArrayList<String>();
+ componentsUidToFetch.addAll(nonProcessesComponents);
+
+ long startGetCompFromGraph = System.currentTimeMillis();
+ if (componentsUidToFetch.size() > 0) {
+ log.debug("Number of Components to fetch from graph is {}", componentsUidToFetch.size());
+ ComponentOperation componentOperation = getComponentOperation(componentTypeEnum);
+ Boolean isHighest = isHighest(highestFilter);
+ Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = componentOperation.getLatestVersionNotAbstractComponents(isAbstractAbstract, isHighest, componentTypeEnum, internalComponentType, componentsUidToFetch);
+
+ if (nonCheckoutCompResponse.isLeft()) {
+ log.debug("Retrived Resource successfully.");
+ result.addAll(nonCheckoutCompResponse.left().value());
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()));
+ }
+ }
+ long endGetCompFromGraph = System.currentTimeMillis();
+ log.debug("Activation time of get Comp from graph {} ms", (endGetCompFromGraph - startGetCompFromGraph));
+
+ return Either.left(result);
+ } else {
+ responseFormat = resp.right().value();
+ }
+
+ return Either.right(responseFormat);
+ }
+
+ private Boolean isHighest(HighestFilterEnum highestFilter) {
+ Boolean isHighest = null;
+ switch (highestFilter) {
+ case ALL:
+ break;
+ case HIGHEST_ONLY:
+ isHighest = true;
+ break;
+ case NON_HIGHEST_ONLY:
+ isHighest = false;
+ break;
+ default:
+ break;
+ }
+ return isHighest;
+ }
+
+ public Either<List<Map<String, String>>, ResponseFormat> getLatestVersionNotAbstractComponentsUidOnly(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, String internalComponentType, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Latest Version Not Abstract Components", false);
+ ResponseFormat responseFormat;
+ if (resp.isLeft()) {
+
+ ComponentOperation componentOperation = getComponentOperation(componentTypeEnum);
+ Boolean isHighest = isHighest(highestFilter);
+ Either<Collection<ComponentMetadataData>, StorageOperationStatus> nonCheckoutCompResponse = componentOperation.getLatestVersionNotAbstractComponentsMetadataOnly(isAbstractAbstract, isHighest, componentTypeEnum, internalComponentType);
+
+ if (nonCheckoutCompResponse.isLeft()) {
+ log.debug("Retrived Resource successfully.");
+ List<Map<String, String>> res = new ArrayList<>();
+
+ // Map<String,String>resMap =
+ // nonCheckoutCompResponse.left().value().stream().collect()
+ // .collect(Collectors.toMap(
+ // p -> p.getMetadataDataDefinition().getUniqueId(),
+ // p-> p.getMetadataDataDefinition().getVersion()));
+
+ res = nonCheckoutCompResponse.left().value().stream().map(p -> {
+ HashMap<String, String> map = new HashMap<>();
+ map.put("uid", p.getMetadataDataDefinition().getUniqueId());
+ map.put("version", p.getMetadataDataDefinition().getVersion());
+ Long lastUpdateDate = p.getMetadataDataDefinition().getLastUpdateDate();
+ String lastUpdateDateStr = lastUpdateDate != null ? String.valueOf(lastUpdateDate.longValue()) : "0";
+ map.put("timestamp", lastUpdateDateStr);
+ return map;
+ }).collect(Collectors.toList());
+
+ return Either.left(res);
+ }
+ responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()));
+ } else {
+ responseFormat = resp.right().value();
+ }
+
+ return Either.right(responseFormat);
+ }
+
+ public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
+
+ }
+
+ public void setToscaArtifactsPlaceHolders(Component component, User user) {
+ Map<String, ArtifactDefinition> artifactMap = component.getToscaArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<String, ArtifactDefinition>();
+ }
+ String componentUniqueId = component.getUniqueId();
+ String componentSystemName = component.getSystemName();
+ String componentType = component.getComponentType().getValue().toLowerCase();
+ Map<String, Object> toscaArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts();
+
+ if (toscaArtifacts != null) {
+ for (Entry<String, Object> artifactInfoMap : toscaArtifacts.entrySet()) {
+ Map<String, Object> artifactInfo = (Map<String, Object>) artifactInfoMap.getValue();
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(componentUniqueId, artifactInfoMap.getKey(), artifactInfo, user, ArtifactGroupTypeEnum.TOSCA);
+ artifactDefinition.setArtifactName(componentType + "-" + componentSystemName + artifactInfo.get("artifactName"));
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+ }
+ }
+ component.setToscaArtifacts(artifactMap);
+ }
+
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateToscaRes = null;
+ if (component.getToscaArtifacts() != null && !component.getToscaArtifacts().isEmpty()) {
+ ArtifactDefinition toscaArtifact = component.getToscaArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_TEMPLATE.getType())).findAny().get();
+ generateToscaRes = saveToscaArtifactPayload(toscaArtifact, component, user, isInCertificationRequest, shouldLock, inTransaction, true);
+ if (generateToscaRes.isRight()) {
+ return generateToscaRes;
+ }
+ toscaArtifact = component.getToscaArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().get();
+ generateToscaRes = saveToscaArtifactPayload(toscaArtifact, component, user, isInCertificationRequest, shouldLock, inTransaction, true);
+ }
+ // TODO if csar artifact fails delete template artifact
+ return generateToscaRes;
+ }
+
+ public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, boolean shouldLock,
+ boolean inTransaction, boolean fetchTemplatesFromDB) {
+ return artifactsBusinessLogic.generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction, fetchTemplatesFromDB);
+ }
+
+ public Either<ImmutablePair<String, byte[]>, ResponseFormat> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid, EnumMap<AuditingFieldsKeysEnum, Object> additionalParam) {
+ // get info
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ Either<Component, StorageOperationStatus> latestVersion = componentOperation.getLatestComponentByUuid(componentType.getNodeType(), uuid);
+ if (latestVersion.isRight()) {
+ ResponseFormat response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(latestVersion.right().value(), componentType));
+ return Either.right(response);
+
+ }
+ Component component = latestVersion.left().value();
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, component.getName());
+ // TODO remove after migration - handle artifact not found(no
+ // placeholder)
+ if (null == component.getToscaArtifacts() || component.getToscaArtifacts().isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+ }
+ ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().get();
+ return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact, true, false);
+ }
+
+ protected StorageOperationStatus markComponentToDelete(Component component) {
+
+ ComponentTypeEnum componentType = component.getComponentType();
+ String uniqueId = component.getUniqueId();
+ if ((component.getIsDeleted() != null) && (component.getIsDeleted() == true)) {
+ log.info("component {} already marked as deleted. id= {}, type={}", component.getName(), uniqueId, componentType);
+ return StorageOperationStatus.NOT_FOUND;
+ }
+
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+
+ Either<Component, StorageOperationStatus> markResourceToDelete = componentOperation.markComponentToDelete(component, true);
+ if (markResourceToDelete.isRight()) {
+ StorageOperationStatus result = markResourceToDelete.right().value();
+ log.debug("failed to mark component {} of type {} for delete. error = {}", uniqueId, componentType, result);
+ return result;
+ } else {
+ log.debug("Component {} of type {} was marked as deleted", uniqueId, componentType);
+ return StorageOperationStatus.OK;
+ }
+ }
+
+ public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent, AuditingActionEnum audatingAction) {
+ String descriptionUpdated = updatedComponent.getDescription();
+ String descriptionCurrent = currentComponent.getDescription();
+ if (descriptionUpdated != null && !descriptionCurrent.equals(descriptionUpdated)) {
+ Either<Boolean, ResponseFormat> validateDescriptionResponse = validateDescriptionAndCleanup(user, updatedComponent, audatingAction);
+ if (validateDescriptionResponse.isRight()) {
+ ResponseFormat errorRespons = validateDescriptionResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentComponent.setDescription(updatedComponent.getDescription());
+ }
+ return Either.left(true);
+ }
+
+ public Either<Boolean, ResponseFormat> validateAndUpdateProjectCode(User user, Component currentComponent, Component updatedComponent) {
+ String projectCodeUpdated = updatedComponent.getProjectCode();
+ String projectCodeCurrent = currentComponent.getProjectCode();
+ if (projectCodeUpdated != null && !projectCodeCurrent.equals(projectCodeUpdated)) {
+ Either<Boolean, ResponseFormat> validatProjectCodeResponse = validateProjectCode(user, updatedComponent, null);
+ if (validatProjectCodeResponse.isRight()) {
+ ResponseFormat errorRespons = validatProjectCodeResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentComponent.setProjectCode(updatedComponent.getProjectCode());
+ }
+ return Either.left(true);
+ }
+
+ public Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Component currentComponent, Component updatedComponent, boolean hasBeenCertified) {
+ String iconUpdated = updatedComponent.getIcon();
+ String iconCurrent = currentComponent.getIcon();
+ if (iconUpdated != null && !iconCurrent.equals(iconUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validatIconResponse = validateIcon(user, updatedComponent, null);
+ if (validatIconResponse.isRight()) {
+ ResponseFormat errorRespons = validatIconResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentComponent.setIcon(updatedComponent.getIcon());
+ } else {
+ log.info("icon {} cannot be updated once the component has been certified once.", iconUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_PARAMETER_CANNOT_BE_CHANGED, "Icon", currentComponent.getComponentType().name().toLowerCase());
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ protected Either<List<String>, ResponseFormat> deleteMarkedComponents(ComponentTypeEnum componentType) {
+
+ List<String> deletedComponents = new ArrayList<String>();
+ log.trace("start deleteMarkedComponents");
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ Either<List<String>, StorageOperationStatus> resourcesToDelete = componentOperation.getAllComponentsMarkedForDeletion();
+ if (resourcesToDelete.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourcesToDelete.right().value(), componentType));
+ return Either.right(responseFormat);
+ }
+
+ for (String resourceToDelete : resourcesToDelete.left().value()) {
+
+ Either<String, ResponseFormat> deleteMarkedResource = deleteMarkedComponent(resourceToDelete, componentType);
+ if (deleteMarkedResource.isLeft()) {
+ deletedComponents.add(deleteMarkedResource.left().value());
+ }
+ }
+
+ log.trace("end deleteMarkedComponents");
+ return Either.left(deletedComponents);
+ }
+
+ private Either<String, ResponseFormat> deleteMarkedComponent(String componentToDelete, ComponentTypeEnum componentType) {
+
+ Either<String, ResponseFormat> result = null;
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ NodeTypeEnum compNodeType = componentType.getNodeType();
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(componentToDelete, compNodeType);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "Delete marked component");
+ log.debug("Failed to lock component {}. error - {}", componentToDelete, lockResult);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+ try {
+
+ // check if resource has relations
+ Either<Boolean, StorageOperationStatus> isResourceInUse = componentOperation.isComponentInUse(componentToDelete);
+ if (isResourceInUse.isRight()) {
+ log.info("deleteMarkedResource - failed to find relations to resource. id = {}, type = {}, error = {}", componentToDelete, componentType, isResourceInUse.right().value().name());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ if (isResourceInUse.isLeft() && isResourceInUse.left().value() == false) {
+
+ // delete resource and its artifacts in one transaction
+ Either<List<ArtifactDefinition>, StorageOperationStatus> artifactsRes = componentOperation.getComponentArtifactsForDelete(componentToDelete, compNodeType, true);
+ if (artifactsRes.isRight() && !artifactsRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ log.info("failed to check artifacts for component node. id = {}, type = {}, error = {}", componentToDelete, componentType, artifactsRes.right().value().name());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
+ if (artifactsRes.isLeft()) {
+ artifactsToDelete = artifactsRes.left().value();
+ }
+
+ Either<Component, StorageOperationStatus> deleteComponentRes = componentOperation.deleteComponent(componentToDelete, true);
+ if (deleteComponentRes.isRight()) {
+ log.info("failed to delete component. id = {}, type = {}, error = {}", componentToDelete, componentType, deleteComponentRes.right().value().name());
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteComponentRes.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
+ result = Either.right(responseFormat);
+ } else {
+ log.trace("component was deleted, id = {}, type = {}", componentToDelete, componentType);
+ // delete related artifacts
+ StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(artifactsToDelete);
+ if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ log.debug("component and all its artifacts were deleted, id = {}, type = {}", componentToDelete, componentType);
+ result = Either.left(componentToDelete);
+ }
+ } else {
+ // resource in use
+ log.debug("componentis marked for delete but still in use, id = {}, type = {}", componentToDelete, componentType);
+ ActionStatus actionStatus = ActionStatus.RESTRICTED_OPERATION;
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ } finally {
+ if (result == null || result.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "delete marked component");
+ log.debug("operation failed. do rollback");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ graphLockOperation.unlockComponent(componentToDelete, compNodeType);
+ }
+
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
new file mode 100644
index 0000000000..89ef6f7e19
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -0,0 +1,1661 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.api.IComponentOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
+
+ private static final String ARTIFACT_PLACEHOLDER_FILE_EXTENSION = "fileExtension";
+
+ static final String HEAT_ENV_NAME = "heatEnv";
+ private static final String HEAT_ENV_SUFFIX = "env";
+
+ private static Logger log = LoggerFactory.getLogger(ComponentInstanceBusinessLogic.class.getName());
+
+ @Autowired
+ private IComponentInstanceOperation componentInstanceOperation;
+
+ @Autowired
+ private PropertyOperation propertyOperation;
+
+ @Autowired
+ private ArtifactsBusinessLogic artifactBusinessLogic;
+
+ @Autowired
+ private GroupOperation groupOperation;
+
+ public ComponentInstanceBusinessLogic() {
+ }
+
+ public Either<ComponentInstance, ResponseFormat> createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance) {
+ return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, true, true, true);
+ }
+
+ public Either<ComponentInstance, ResponseFormat> createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance, boolean inTransaction, boolean needLock,
+ boolean createNewTransaction) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Component Instance", inTransaction);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> validateValidJson = validateJsonBody(resourceInstance, ComponentInstance.class);
+ if (validateValidJson.isRight()) {
+ return Either.right(validateValidJson.right().value());
+ }
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentOperation containerOperation = getComponentOperation(containerComponentType);
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, inTransaction, createNewTransaction);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances = validateAllowedToContainCompInstances(containerComponent);
+ if (validateAllowedToContainCompInstances.isRight()) {
+ return Either.right(validateAllowedToContainCompInstances.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+ if (resourceInstance != null && containerComponentType != null) {
+ Either<Boolean, ResponseFormat> validateComponentInstanceParentState = validateComponentInstanceParentState(containerComponentType, resourceInstance);
+ if (validateComponentInstanceParentState.isRight()) {
+ return Either.right(validateComponentInstanceParentState.right().value());
+ }
+ }
+ if (needLock) {
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createComponentInstance");
+
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+ try {
+ log.debug("Try to create entry on graph");
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(resourceInstance, inTransaction);
+
+ if (eitherResourceName.isRight()) {
+ resultOp = Either.right(eitherResourceName.right().value());
+ return resultOp;
+ }
+ Component origComponent = eitherResourceName.left().value();
+
+ resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, userId, containerOperation, inTransaction);
+ return resultOp;
+
+ } finally {
+ if (needLock)
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ public Either<CreateAndAssotiateInfo, ResponseFormat> createAndAssociateRIToRI(String containerComponentParam, String containerComponentId, String userId, CreateAndAssotiateInfo createAndAssotiateInfo) {
+
+ Either<CreateAndAssotiateInfo, ResponseFormat> resultOp = null;
+ ComponentInstance resourceInstance = createAndAssotiateInfo.getNode();
+ RequirementCapabilityRelDef associationInfo = createAndAssotiateInfo.getAssociate();
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create And Associate RI To RI", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentOperation containerOperation = getComponentOperation(containerComponentType);
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, false, true);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances = validateAllowedToContainCompInstances(containerComponent);
+ if (validateAllowedToContainCompInstances.isRight()) {
+ return Either.right(validateAllowedToContainCompInstances.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createAndAssociateRIToRI");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+
+ try {
+ log.debug("Try to create entry on graph");
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(resourceInstance, true);
+
+ if (eitherResourceName.isRight()) {
+ resultOp = Either.right(eitherResourceName.right().value());
+ return resultOp;
+ }
+ Component origComponent = eitherResourceName.left().value();
+
+ Either<ComponentInstance, ResponseFormat> result = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, userId, containerOperation, true);
+ if (result.isRight()) {
+ log.debug("Failed to create resource instance {}", containerComponentId);
+ resultOp = Either.right(result.right().value());
+ return resultOp;
+
+ }
+
+ log.debug("Entity on graph is created.");
+ ComponentInstance resResourceInfo = result.left().value();
+ if (associationInfo.getFromNode() == null || associationInfo.getFromNode().isEmpty()) {
+ associationInfo.setFromNode(resResourceInfo.getUniqueId());
+ } else {
+ associationInfo.setToNode(resResourceInfo.getUniqueId());
+ }
+
+ RequirementCapabilityRelDef requirementCapabilityRelDef = associationInfo;// createRequirementCapabilityrelDef(associationInfo);
+
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> resultReqCapDef = componentInstanceOperation.associateResourceInstances(containerComponentId, containerNodeType, requirementCapabilityRelDef, true);
+ if (resultReqCapDef.isLeft()) {
+ log.debug("Enty on graph is created.");
+ RequirementCapabilityRelDef resReqCapabilityRelDef = resultReqCapDef.left().value();
+ CreateAndAssotiateInfo resInfo = new CreateAndAssotiateInfo(resResourceInfo, resReqCapabilityRelDef);
+ resultOp = Either.left(resInfo);
+ return resultOp;
+
+ } else {
+ log.info("Failed to associate node {} with node {}", associationInfo.getFromNode(), associationInfo.getToNode());
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(resultReqCapDef.right().value(), true), "", null));
+ return resultOp;
+ }
+
+ } finally {
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ private Either<Component, ResponseFormat> getOriginComponentNameFromComponentInstance(ComponentInstance componentInstance, boolean inTransaction) {
+ Either<Component, ResponseFormat> eitherResponse;
+ Either<Component, StorageOperationStatus> eitherComponent = getCompInstOriginComponentOperation().getComponent(componentInstance.getComponentUid(), inTransaction);
+ if (eitherComponent.isRight()) {
+ log.debug("Failed to get origin component with id {} for component instance {} ", componentInstance.getComponentUid(), componentInstance.getName());
+ eitherResponse = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponse(eitherComponent.right().value(), ComponentTypeEnum.RESOURCE), "", null));
+ } else {
+ eitherResponse = Either.left(eitherComponent.left().value());
+ }
+ return eitherResponse;
+ }
+
+ private Either<String, ResponseFormat> handleNameLogic(Component origComponent, ComponentInstance componentInstance, ComponentTypeEnum containerComponentType, String containerComponentId, boolean isCreate, boolean inTransaction) {
+ Either<String, ResponseFormat> eitherResult;
+ final ComponentOperation containerOperation = getComponentOperation(containerComponentType);
+
+ Either<Integer, StorageOperationStatus> componentInNumberStatus = containerOperation.increaseAndGetComponentInstanceCounter(containerComponentId, true);
+
+ if (componentInNumberStatus.isRight()) {
+ log.debug("Failed to get component instance number for container component {} ", containerComponentId);
+ eitherResult = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(componentInNumberStatus.right().value(), true), "", null));
+ } else {
+ String resourceInNumber = componentInNumberStatus.left().value().toString();
+ eitherResult = Either.left(resourceInNumber);
+ }
+
+ if (eitherResult.isLeft()) {
+ Either<Boolean, ResponseFormat> eitherSpecificLogic;
+ if (isCreate) {
+ eitherSpecificLogic = handleNameLogicForNewComponentInstance(origComponent, componentInstance, eitherResult.left().value(), containerComponentType, inTransaction);
+ } else {
+ eitherSpecificLogic = handleNameLogicForUpdatingComponentInstance(origComponent, componentInstance, componentInNumberStatus, containerComponentType, inTransaction);
+ }
+ if (eitherSpecificLogic.isRight()) {
+ eitherResult = Either.right(eitherSpecificLogic.right().value());
+ }
+ }
+ return eitherResult;
+ }
+
+ private Either<Boolean, ResponseFormat> handleNameLogicForUpdatingComponentInstance(Component origComponent, ComponentInstance componentInstance, Either<Integer, StorageOperationStatus> componentInNumberStatus,
+ ComponentTypeEnum containerComponentType, boolean inTransaction) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (componentInstance.getName() == null || componentInstance.getName().isEmpty()) {
+ if (origComponent == null) {
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(componentInstance, inTransaction);
+
+ if (eitherResourceName.isRight()) {
+ eitherResult = Either.right(eitherResourceName.right().value());
+ return eitherResult;
+ }
+ origComponent = eitherResourceName.left().value();
+
+ String resourceName = origComponent.getName();
+ String logicalName = componentInstanceOperation.createComponentInstLogicalName(componentInNumberStatus.left().value().toString(), resourceName);
+ componentInstance.setName(logicalName);
+ if (containerComponentType == ComponentTypeEnum.RESOURCE) {
+ Resource resource = (Resource) origComponent;
+ componentInstance.setToscaComponentName(resource.getToscaResourceName());
+ }
+
+ }
+ }
+
+ Either<Boolean, ResponseFormat> eitherValidation = validateComponentInstanceName(componentInstance.getName(), componentInstance, false);
+ if (eitherValidation.isRight()) {
+ eitherResult = Either.right(eitherValidation.right().value());
+ }
+ return eitherResult;
+ }
+
+ private Either<Boolean, ResponseFormat> handleNameLogicForNewComponentInstance(Component origComponent, ComponentInstance componentInstance, String resourceInNumber, ComponentTypeEnum containerComponentType, boolean inTransaction) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+
+ if (origComponent == null) {
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(componentInstance, inTransaction);
+
+ if (eitherResourceName.isRight()) {
+ eitherResult = Either.right(eitherResourceName.right().value());
+ return eitherResult;
+ }
+
+ origComponent = eitherResourceName.left().value();
+ }
+
+ String resourceName = origComponent.getName();
+ componentInstance.setComponentName(resourceName);
+ if (componentInstance.getName() == null || componentInstance.getName().isEmpty())
+ componentInstance.setName(resourceName);
+ String logicalName = componentInstanceOperation.createComponentInstLogicalName(resourceInNumber, componentInstance.getName());
+
+ Either<Boolean, ResponseFormat> eitherValidation = validateComponentInstanceName(logicalName, componentInstance, true);
+ if (eitherValidation.isRight()) {
+ eitherResult = Either.right(eitherValidation.right().value());
+ }
+ if (containerComponentType == ComponentTypeEnum.RESOURCE) {
+ Resource resource = (Resource) origComponent;
+ componentInstance.setToscaComponentName(resource.getToscaResourceName());
+ }
+
+ return eitherResult;
+ }
+
+ public Either<ComponentInstance, ResponseFormat> createComponentInstanceOnGraph(String containerComponentParam, org.openecomp.sdc.be.model.Component containerComponent, Component origComponent, ComponentInstance componentInstance, String userId,
+ boolean needLock, boolean inTransaction) {
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentOperation containerOperation = getComponentOperation(containerComponentType);
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+ if (needLock) {
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createComponentInstance");
+
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+ try {
+ resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, componentInstance, userId, containerOperation, inTransaction);
+ return resultOp;
+
+ } finally {
+ if (needLock)
+ unlockComponent(resultOp, containerComponent);
+ }
+
+ }
+
+ private Map<String, String> getExistingEnvVersions(ComponentInstance componentInstance) {
+ if (null == componentInstance.getDeploymentArtifacts())
+ return null;
+ return componentInstance.getDeploymentArtifacts().values()
+ //filter env artifacts
+ .stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.getType()))
+ //map name to version
+ .collect(Collectors.toMap(a -> a.getArtifactName(), a -> a.getArtifactVersion()));
+ }
+
+ private Either<ComponentInstance, ResponseFormat> createComponentInstanceOnGraph(org.openecomp.sdc.be.model.Component containerComponent, Component origComponent, ComponentInstance componentInstance, String userId,
+ ComponentOperation containerOperation, boolean inTransaction) {
+ Either<ComponentInstance, ResponseFormat> resultOp;
+ boolean nameAlreadyExist = true;
+ String resourceInNumber = "";
+ String containerComponentId = containerComponent.getUniqueId();
+ ComponentTypeEnum containerComponentType = containerComponent.getComponentType();
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+ NodeTypeEnum compInstNodeType = getNodeTypeOfComponentInstanceOrigin();
+ while (nameAlreadyExist) {
+
+ Either<String, ResponseFormat> eitherNameLogic = handleNameLogic(origComponent, componentInstance, containerComponent.getComponentType(), containerComponent.getUniqueId(), true, inTransaction);
+ if (eitherNameLogic.isRight()) {
+ return Either.right(eitherNameLogic.right().value());
+ } else {
+ resourceInNumber = eitherNameLogic.left().value();
+ }
+
+ Either<Boolean, StorageOperationStatus> isNameExistStatus = componentInstanceOperation.isComponentInstanceNameExist(containerComponentId, containerNodeType, null, componentInstance.getNormalizedName());
+ if (isNameExistStatus.isRight()) {
+ log.debug("Failed to check if component instance name exists for container component {}", containerComponentId);
+
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND, componentInstance.getName(), containerComponentId));
+ return resultOp;
+ }
+ nameAlreadyExist = isNameExistStatus.left().value();
+
+ }
+
+ Either<ComponentInstance, StorageOperationStatus> result = componentInstanceOperation.createComponentInstance(containerComponentId, containerNodeType, resourceInNumber, componentInstance, compInstNodeType, inTransaction);
+
+ if (result.isRight()) {
+ log.debug("Failed to create entry on graph for component instance {}", componentInstance.getName());
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), "", null));
+ return resultOp;
+ }
+
+ log.debug("Entity on graph is created.");
+ ComponentInstance compInst = result.left().value();
+
+ Map<String, String> existingEnvVersions = getExistingEnvVersions(componentInstance);
+ Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts = addComponentInstanceArtifacts(containerComponent, compInst, userId, inTransaction, existingEnvVersions);
+ if (addComponentInstanceArtifacts.isRight()) {
+ log.debug("Failed to create component instance {}", componentInstance.getName());
+ resultOp = Either.right(addComponentInstanceArtifacts.right().value());
+ return resultOp;
+ }
+
+ resultOp = Either.left(compInst);
+ return resultOp;
+ }
+
+ /**
+ * addResourceInstanceArtifacts - add artifacts (HEAT_ENV) to resource instance The instance artifacts are generated from the resource's artifacts
+ *
+ * @param componentInstance
+ * @param userId
+ * @param existingEnvVersions
+ * @param containerComponentId
+ *
+ * @return
+ */
+ protected Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance componentInstance, String userId, boolean inTransaction,
+ Map<String, String> existingEnvVersions) {
+ log.debug("add artifacts to resource instance");
+
+ ActionStatus status = setResourceArtifactsOnResourceInstance(componentInstance);
+ if (!ActionStatus.OK.equals(status)) {
+ ResponseFormat resultOp = componentsUtils.getResponseFormatForResourceInstance(status, "", null);
+ return Either.right(resultOp);
+ }
+
+ // generate heat_env if necessary
+ Map<String, ArtifactDefinition> componentDeploymentArtifacts = componentInstance.getDeploymentArtifacts();
+ if (componentDeploymentArtifacts == null) {
+ return Either.left(ActionStatus.OK);
+ }
+ Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<String, ArtifactDefinition>(componentDeploymentArtifacts);
+ for (ArtifactDefinition artifact : componentDeploymentArtifacts.values()) {
+ // if (artifact.getArtifactType().equalsIgnoreCase(
+ // ArtifactTypeEnum.HEAT.getType())) {
+ String type = artifact.getArtifactType();
+
+ if (!(type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()))) {
+ continue;
+ }
+
+ if (artifact.checkEsIdExist()) {
+ Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getDeploymentResourceInstanceArtifacts();
+ if (deploymentResourceArtifacts == null) {
+ log.debug("no deployment artifacts are configured for resource instance");
+ break;
+ }
+ Map<String, Object> placeHolderData = (Map<String, Object>) deploymentResourceArtifacts.get(HEAT_ENV_NAME);
+
+ String envLabel = (artifact.getArtifactLabel() + HEAT_ENV_SUFFIX).toLowerCase();
+ Either<ArtifactDefinition, ResponseFormat> createArtifactPlaceHolder = artifactBusinessLogic.createArtifactPlaceHolderInfo(componentInstance.getUniqueId(), envLabel, placeHolderData, userId, ArtifactGroupTypeEnum.DEPLOYMENT,
+ inTransaction);
+ if (createArtifactPlaceHolder.isRight()) {
+ return Either.right(createArtifactPlaceHolder.right().value());
+ }
+ ArtifactDefinition artifactHeatEnv = createArtifactPlaceHolder.left().value();
+
+ artifactHeatEnv.setHeatParamsUpdateDate(System.currentTimeMillis());
+ artifactHeatEnv.setTimeout(0);
+ buildHeatEnvFileName(artifact, artifactHeatEnv, placeHolderData);
+
+ // rbetzer - keep env artifactVersion - changeComponentInstanceVersion flow
+ handleEnvArtifactVersion(artifactHeatEnv, existingEnvVersions);
+ Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact = artifactBusinessLogic.addHeatEnvArtifact(artifactHeatEnv, artifact, componentInstance.getUniqueId(), NodeTypeEnum.ResourceInstance, true);
+ if (addHeatEnvArtifact.isRight()) {
+ log.debug("failed to create heat env artifact on resource instance");
+ return Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(addHeatEnvArtifact.right().value(), false), "", null));
+ }
+
+ ArtifactDefinition artifactDefinition = addHeatEnvArtifact.left().value();
+ if (artifact.getHeatParameters() != null) {
+ List<HeatParameterDefinition> heatEnvParameters = new ArrayList<HeatParameterDefinition>();
+ for (HeatParameterDefinition parameter : artifact.getHeatParameters()) {
+ HeatParameterDefinition heatEnvParameter = new HeatParameterDefinition(parameter);
+ heatEnvParameter.setDefaultValue(parameter.getCurrentValue());
+ heatEnvParameters.add(heatEnvParameter);
+ }
+ artifactDefinition.setHeatParameters(heatEnvParameters);
+ }
+ finalDeploymentArtifacts.put(envLabel, artifactDefinition);
+
+ // audit
+ EnumMap<AuditingFieldsKeysEnum, Object> artifactAuditingFields = artifactBusinessLogic.createArtifactAuditingFields(artifactDefinition, "", artifactDefinition.getUniqueId());
+ artifactAuditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, componentInstance.getName());
+ handleAuditing(AuditingActionEnum.ARTIFACT_UPLOAD, containerComponent, userId, artifactAuditingFields, inTransaction);
+ }
+ // }
+ }
+ componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts);
+ return Either.left(ActionStatus.OK);
+ }
+
+ private void handleAuditing(AuditingActionEnum artifactUpload, org.openecomp.sdc.be.model.Component containerComponent, String userId, EnumMap<AuditingFieldsKeysEnum, Object> artifactAuditingFields, boolean inTransaction) {
+
+ Either<User, ActionStatus> user = userAdmin.getUser(userId, inTransaction);
+ if (user.isRight()) {
+ log.debug("failed to get user properties from graph for audit");
+ return;
+ }
+
+ componentsUtils.auditComponent(componentsUtils.getResponseFormat(ActionStatus.OK), user.left().value(), containerComponent, "", "", AuditingActionEnum.ARTIFACT_UPLOAD, ComponentTypeEnum.RESOURCE_INSTANCE, artifactAuditingFields);
+
+ }
+
+ private void handleEnvArtifactVersion(ArtifactDefinition heatEnvArtifact, Map<String, String> existingEnvVersions) {
+ if (null != existingEnvVersions) {
+ String prevVersion = existingEnvVersions.get(heatEnvArtifact.getArtifactName());
+ if (null != prevVersion) {
+ heatEnvArtifact.setArtifactVersion(prevVersion);
+ }
+ }
+ }
+
+ private void buildHeatEnvFileName(ArtifactDefinition heatArtifact, ArtifactDefinition heatEnvArtifact, Map<String, Object> placeHolderData) {
+ String heatExtension = GeneralUtility.getFilenameExtension(heatArtifact.getArtifactName());
+ String envExtension = (String) placeHolderData.get(ARTIFACT_PLACEHOLDER_FILE_EXTENSION);
+ String fileName = heatArtifact.getArtifactName().replaceAll("." + heatExtension, "." + envExtension);
+ heatEnvArtifact.setArtifactName(fileName);
+ }
+
+ private ActionStatus setResourceArtifactsOnResourceInstance(ComponentInstance resourceInstance) {
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = artifactBusinessLogic.getArtifacts(resourceInstance.getComponentUid(), NodeTypeEnum.Resource, true, ArtifactGroupTypeEnum.DEPLOYMENT);
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<String, ArtifactDefinition>();
+ if (getResourceDeploymentArtifacts.isRight()) {
+ StorageOperationStatus status = getResourceDeploymentArtifacts.right().value();
+ if (!status.equals(StorageOperationStatus.NOT_FOUND)) {
+ log.debug("Failed to fetch resource artifacts. status is {}", status);
+ return componentsUtils.convertFromStorageResponseForResourceInstance(status, true);
+ }
+ } else {
+ deploymentArtifacts = getResourceDeploymentArtifacts.left().value();
+ }
+
+ if (!deploymentArtifacts.isEmpty()) {
+ Map<String, ArtifactDefinition> tempDeploymentArtifacts = new HashMap<String, ArtifactDefinition>(deploymentArtifacts);
+ for (Entry<String, ArtifactDefinition> artifact : deploymentArtifacts.entrySet()) {
+ if (!artifact.getValue().checkEsIdExist()) {
+ tempDeploymentArtifacts.remove(artifact.getKey());
+ }
+ }
+
+ resourceInstance.setDeploymentArtifacts(tempDeploymentArtifacts);
+ }
+
+ return ActionStatus.OK;
+ }
+
+ public Either<ComponentInstance, ResponseFormat> updateComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance) {
+ return updateComponentInstance(containerComponentParam, containerComponentId, componentInstanceId, userId, componentInstance, false, true, true);
+ }
+
+ public Either<ComponentInstance, ResponseFormat> updateComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance, boolean inTransaction,
+ boolean needLock, boolean createNewTransaction) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "update Component Instance", inTransaction);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, inTransaction, createNewTransaction);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+ ComponentTypeEnum instanceType = getComponentType(containerComponentType);
+ Either<Boolean, StorageOperationStatus> validateParentStatus = componentInstanceOperation.validateParent(containerComponentId, componentInstanceId, inTransaction);
+ if (validateParentStatus.isRight()) {
+ log.debug("Failed to get component instance {} on service {}", componentInstanceId, containerComponentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentInstance.getName(), instanceType.getValue().toLowerCase()));
+ return resultOp;
+ }
+ Boolean isPrentValid = validateParentStatus.left().value();
+ if (!isPrentValid) {
+ resultOp = Either.right(
+ componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(), containerComponentId));
+ return resultOp;
+
+ }
+
+ if (needLock) {
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ try {
+
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(componentInstance, inTransaction);
+
+ if (eitherResourceName.isRight()) {
+ resultOp = Either.right(eitherResourceName.right().value());
+ return resultOp;
+ }
+ Component origComponent = eitherResourceName.left().value();
+
+ resultOp = updateComponentInstance(containerComponentId, containerComponentType, origComponent, componentInstanceId, componentInstance, inTransaction);
+ return resultOp;
+
+ } finally {
+ if (needLock)
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ // New Multiple Instance Update API
+ public Either<List<ComponentInstance>, ResponseFormat> updateComponentInstance(String containerComponentParam, String containerComponentId, String userId, List<ComponentInstance> componentInstanceList, boolean needLock,
+ boolean createNewTransaction) {
+
+ Either<List<ComponentInstance>, ResponseFormat> resultOp = null;
+ org.openecomp.sdc.be.model.Component containerComponent = null;
+ try {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "update Component Instance", true);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+
+ ComponentParametersView componentFilter = new ComponentParametersView();
+ componentFilter.disableAll();
+ componentFilter.setIgnoreUsers(false);
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExistsByFilter(containerComponentId, containerComponentType, componentFilter, true);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+
+ containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+
+ ComponentTypeEnum instanceType = getComponentType(containerComponentType);
+
+ for (ComponentInstance componentInstance : componentInstanceList) {
+ Either<Boolean, StorageOperationStatus> validateParentStatus = componentInstanceOperation.validateParent(containerComponentId, componentInstance.getUniqueId(), true);
+ if (validateParentStatus.isRight()) {
+ log.debug("Failed to get component instance {} on service {}", componentInstance.getUniqueId(), containerComponentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentInstance.getName(), instanceType.getValue().toLowerCase()));
+ return resultOp;
+ }
+ Boolean isPrentValid = validateParentStatus.left().value();
+ if (!isPrentValid) {
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(),
+ containerComponentId));
+ return resultOp;
+ }
+ }
+
+ if (needLock) {
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ List<ComponentInstance> updatedList = new ArrayList<>();
+ for (ComponentInstance componentInstance : componentInstanceList) {
+
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(componentInstance, true);
+
+ if (eitherResourceName.isRight()) {
+ resultOp = Either.right(eitherResourceName.right().value());
+ return resultOp;
+ }
+ Component origComponent = eitherResourceName.left().value();
+
+ Either<ComponentInstance, ResponseFormat> resultSingleUpdate = updateComponentInstance(containerComponentId, containerComponentType, origComponent, componentInstance.getUniqueId(), componentInstance, true);
+
+ if (resultSingleUpdate.isRight()) {
+ resultOp = Either.right(resultSingleUpdate.right().value());
+ return resultOp;
+ }
+ updatedList.add(resultSingleUpdate.left().value());
+ }
+
+ resultOp = Either.left(updatedList);
+ return resultOp;
+
+ } finally {
+ if (needLock) {
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+ }
+
+ private ComponentTypeEnum getComponentType(ComponentTypeEnum containerComponentType) {
+ if (ComponentTypeEnum.PRODUCT.equals(containerComponentType)) {
+ return ComponentTypeEnum.SERVICE_INSTANCE;
+ } else {
+ return ComponentTypeEnum.RESOURCE_INSTANCE;
+ }
+ }
+
+ public Either<ComponentInstance, ResponseFormat> updateComponentInstance(String containerComponentParam, org.openecomp.sdc.be.model.Component containerComponent, org.openecomp.sdc.be.model.Component origComponent, String componentInstanceId,
+ ComponentInstance componentInstance, boolean needLock, boolean inTransaction) {
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ if (needLock) {
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ try {
+
+ resultOp = updateComponentInstance(containerComponent.getUniqueId(), containerComponentType, origComponent, componentInstanceId, componentInstance, inTransaction);
+ return resultOp;
+
+ } finally {
+ if (needLock)
+ unlockComponent(resultOp, containerComponent);
+ }
+
+ }
+
+ private Either<ComponentInstance, ResponseFormat> updateComponentInstance(String containerComponentId, ComponentTypeEnum containerComponentType, org.openecomp.sdc.be.model.Component origComponent, String componentInstanceId,
+ ComponentInstance componentInstance, boolean inTransaction) {
+ Either<ComponentInstance, ResponseFormat> resultOp;
+
+ Either<String, ResponseFormat> eitherNameLogic = handleNameLogic(origComponent, componentInstance, containerComponentType, containerComponentId, false, inTransaction);
+ if (eitherNameLogic.isRight()) {
+ return Either.right(eitherNameLogic.right().value());
+ }
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+
+ Either<Boolean, StorageOperationStatus> isNameExistStatus = componentInstanceOperation.isComponentInstanceNameExist(containerComponentId, containerNodeType, componentInstanceId, componentInstance.getNormalizedName());
+ if (isNameExistStatus.isRight()) {
+ log.debug("Failed to get resource instance names for service {}", containerComponentId);
+
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND, componentInstance.getName(), containerComponentId));
+ return resultOp;
+ }
+ Boolean isNameExist = isNameExistStatus.left().value();
+ if (isNameExist) {
+ containerComponentType = getComponentTypeOfComponentInstance();
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName()));
+ return resultOp;
+
+ }
+
+ log.debug("Try to update entry on graph");
+ Either<ComponentInstance, StorageOperationStatus> result = componentInstanceOperation.updateResourceInstance(containerComponentId, containerNodeType, componentInstanceId, componentInstance, inTransaction);
+
+ if (result.isLeft()) {
+ log.debug("Enty on graph is updated.");
+ ComponentInstance resResourceInfo = result.left().value();
+ resultOp = Either.left(resResourceInfo);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to update entry on graph for resource instance {}", componentInstance.getName());
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), false), "", componentInstance.getName()));
+ return resultOp;
+ }
+
+ }
+
+ public Either<ComponentInstance, ResponseFormat> deleteComponentInstance(String containerComponentParam, String containerComponentId, String resourceInstanceId, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Component Instance", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, false, true);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "deleteComponentInstance");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ // validate resource
+ /*
+ * if (!ComponentValidationUtils.canWorkOnComponent(containerComponentId, serviceOperation, userId)) { log.info( "Restricted operation for user {} on service {}", userId, containerComponentId); return Either.right(componentsUtils
+ * .getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); } // lock resource StorageOperationStatus lockStatus = graphLockOperation.lockComponent( containerComponentId, NodeTypeEnum.Service); if (lockStatus != StorageOperationStatus.OK) {
+ * log.debug("Failed to lock service {}", containerComponentId); resultOp = Either.right(componentsUtils .getResponseFormat(componentsUtils .convertFromStorageResponse(lockStatus))); return resultOp; }
+ */
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+ try {
+ resultOp = deleteComponentInstance(containerComponentId, resourceInstanceId, containerComponentType);
+ return resultOp;
+
+ } finally {
+ /*
+ * if (resultOp == null || resultOp.isRight()) { titanGenericDao.rollback(); } else { titanGenericDao.commit(); } graphLockOperation.unlockComponent(containerComponentId, NodeTypeEnum.Service);
+ */
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ private Either<ComponentInstance, ResponseFormat> deleteComponentInstance(String containerComponentId, String resourceInstanceId, ComponentTypeEnum containerComponentType) {
+ Either<ComponentInstance, ResponseFormat> resultOp;
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+ Either<ComponentInstance, StorageOperationStatus> result = componentInstanceOperation.deleteComponentInstance(containerNodeType, containerComponentId, resourceInstanceId, true);
+
+ if (result.isRight()) {
+ log.debug("Failed to delete entry on graph for resourceInstance {}", resourceInstanceId);
+ ActionStatus status = componentsUtils.convertFromStorageResponse(result.right().value(), containerComponentType);
+ // TODO check
+ /*
+ * if (ActionStatus.SERVICE_NOT_FOUND.equals(status)) { resultOp = Either .right(componentsUtils .getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND)); } else {
+ */
+ resultOp = Either.right(componentsUtils.getResponseFormat(status, resourceInstanceId));
+ // }
+ return resultOp;
+ }
+ ComponentInstance resResourceInfo = result.left().value();
+ resultOp = Either.left(resResourceInfo);
+
+ log.debug("Entry on graph is deleted. Exist more connections on this artifact.");
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resResourceInfo.getDeploymentArtifacts();
+ if (deploymentArtifacts != null && !deploymentArtifacts.isEmpty()) {
+ StorageOperationStatus deleteArtifactsIfNotOnGraph = artifactBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(new ArrayList<ArtifactDefinition>(deploymentArtifacts.values()));
+ if (!deleteArtifactsIfNotOnGraph.equals(StorageOperationStatus.OK)) {
+ log.debug("failed to delete artifact payload. status={}", deleteArtifactsIfNotOnGraph.name());
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), resourceInstanceId));
+ }
+
+ }
+ return resultOp;
+ }
+
+ public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
+ return associateRIToRI(componentId, userId, requirementDef, componentTypeEnum, false, true, true);
+ }
+
+ public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction, boolean needLock,
+ boolean createNewTransaction) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "associate Ri To RI", inTransaction);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, inTransaction, createNewTransaction);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+ if (needLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
+
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ try {
+
+ resultOp = associateRIToRIOnGraph(componentId, requirementDef, componentTypeEnum, inTransaction);
+
+ return resultOp;
+
+ } finally {
+ if (needLock)
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRIOnGraph(String componentId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction) {
+
+ log.debug("Try to create entry on graph");
+ Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
+
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> result = componentInstanceOperation.associateResourceInstances(componentId, componentTypeEnum.getNodeType(), requirementDef, inTransaction);
+
+ if (result.isLeft()) {
+ log.debug("Enty on graph is created.");
+ RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
+ resultOp = Either.left(requirementCapabilityRelDef);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to associate node {} with node {}", requirementDef.getFromNode(), requirementDef.getToNode());
+ String fromNameOrId = "";
+ String toNameOrId = "";
+ Either<ComponentInstance, StorageOperationStatus> fromResult = componentInstanceOperation.getResourceInstanceById(requirementDef.getFromNode());
+ Either<ComponentInstance, StorageOperationStatus> toResult = componentInstanceOperation.getResourceInstanceById(requirementDef.getToNode());
+
+ toNameOrId = requirementDef.getFromNode();
+ fromNameOrId = requirementDef.getFromNode();
+ if (fromResult.isLeft()) {
+ fromNameOrId = fromResult.left().value().getName();
+ }
+ if (toResult.isLeft()) {
+ toNameOrId = toResult.left().value().getName();
+ }
+
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRequirement()));
+
+ return resultOp;
+ }
+
+ }
+
+ public Either<RequirementCapabilityRelDef, ResponseFormat> dissociateRIFromRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "dissociate RI From RI", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, false, true);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
+
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ try {
+ log.debug("Try to create entry on graph");
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> result = componentInstanceOperation.dissociateResourceInstances(componentId, componentTypeEnum.getNodeType(), requirementDef, true);
+ if (result.isLeft()) {
+ log.debug("Enty on graph is created.");
+ RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
+ resultOp = Either.left(requirementCapabilityRelDef);
+ return resultOp;
+
+ } else {
+
+ log.debug("Failed to dissocaite node {} from node {}", requirementDef.getFromNode(), requirementDef.getToNode());
+ String fromNameOrId = "";
+ String toNameOrId = "";
+ Either<ComponentInstance, StorageOperationStatus> fromResult = componentInstanceOperation.getResourceInstanceById(requirementDef.getFromNode());
+ Either<ComponentInstance, StorageOperationStatus> toResult = componentInstanceOperation.getResourceInstanceById(requirementDef.getToNode());
+
+ toNameOrId = requirementDef.getFromNode();
+ fromNameOrId = requirementDef.getFromNode();
+ if (fromResult.isLeft()) {
+ fromNameOrId = fromResult.left().value().getName();
+ }
+ if (toResult.isLeft()) {
+ toNameOrId = toResult.left().value().getName();
+ }
+
+ resultOp = Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRequirement()));
+ return resultOp;
+ }
+ } finally {
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ private Either<ComponentInstanceAttribute, ResponseFormat> updateAttributeValue(ComponentInstanceAttribute attribute, String resourceInstanceId) {
+ Either<ComponentInstanceAttribute, StorageOperationStatus> eitherAttribute = componentInstanceOperation.updateAttributeValueInResourceInstance(attribute, resourceInstanceId, true);
+ Either<ComponentInstanceAttribute, ResponseFormat> result;
+ if (eitherAttribute.isLeft()) {
+ log.debug("Attribute value {} was updated on graph.", attribute.getValueUniqueUid());
+ ComponentInstanceAttribute instanceAttribute = eitherAttribute.left().value();
+
+ result = Either.left(instanceAttribute);
+
+ } else {
+ log.debug("Failed to update attribute value {} in resource instance {}", attribute, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(eitherAttribute.right().value());
+
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
+
+ }
+ return result;
+ }
+
+ private Either<ComponentInstanceInput, ResponseFormat> updateInputValue(ComponentInstanceInput input, String resourceInstanceId) {
+ Either<ComponentInstanceInput, StorageOperationStatus> eitherInput = componentInstanceOperation.updateInputValueInResourceInstance(input, resourceInstanceId, true);
+ Either<ComponentInstanceInput, ResponseFormat> result;
+ if (eitherInput.isLeft()) {
+ log.debug("Input value {} was updated on graph.", input.getValueUniqueUid());
+ ComponentInstanceInput instanceInput = eitherInput.left().value();
+
+ result = Either.left(instanceInput);
+
+ } else {
+ log.debug("Failed to update input value {} in resource instance {}", input, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(eitherInput.right().value());
+
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
+
+ }
+ return result;
+ }
+
+ private Either<ComponentInstanceAttribute, ResponseFormat> createAttributeValue(ComponentInstanceAttribute attribute, String resourceInstanceId) {
+
+ Either<ComponentInstanceAttribute, ResponseFormat> result;
+
+ Wrapper<Integer> indexCounterWrapper = new Wrapper<>();
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ validateIncrementCounter(resourceInstanceId, GraphPropertiesDictionary.ATTRIBUTE_COUNTER, indexCounterWrapper, errorWrapper);
+
+ if (!errorWrapper.isEmpty()) {
+ result = Either.right(errorWrapper.getInnerElement());
+ } else {
+ Either<ComponentInstanceAttribute, StorageOperationStatus> eitherAttribute = componentInstanceOperation.addAttributeValueToResourceInstance(attribute, resourceInstanceId, indexCounterWrapper.getInnerElement(), true);
+ if (eitherAttribute.isLeft()) {
+ log.debug("Attribute value was added to resource instance {}", resourceInstanceId);
+ ComponentInstanceAttribute instanceAttribute = eitherAttribute.left().value();
+ result = Either.left(instanceAttribute);
+
+ } else {
+ log.debug("Failed to add attribute value {} to resource instance {}", attribute, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(eitherAttribute.right().value());
+ result = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Create Or Updates Attribute Instance
+ *
+ * @param componentTypeEnum
+ * @param componentId
+ * @param resourceInstanceId
+ * @param attribute
+ * @param userId
+ * @return
+ */
+ public Either<ComponentInstanceAttribute, ResponseFormat> createOrUpdateAttributeValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceAttribute attribute, String userId) {
+ Either<ComponentInstanceAttribute, ResponseFormat> result = null;
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+
+ validateUserExist(userId, "create Or Update Attribute Value", errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ validateComponentTypeEnum(componentTypeEnum, "CreateOrUpdateAttributeValue", errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ validateCanWorkOnComponent(componentId, componentTypeEnum, userId, errorWrapper);
+ }
+ if (errorWrapper.isEmpty()) {
+ validateComponentLock(componentId, componentTypeEnum, errorWrapper);
+ }
+
+ try {
+ if (errorWrapper.isEmpty()) {
+ final boolean isCreate = Objects.isNull(attribute.getValueUniqueUid());
+ if (isCreate) {
+ result = createAttributeValue(attribute, resourceInstanceId);
+ } else {
+ result = updateAttributeValue(attribute, resourceInstanceId);
+ }
+ } else {
+ result = Either.right(errorWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ finally {
+ if (result == null || result.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
+ }
+ }
+
+ public Either<ComponentInstanceProperty, ResponseFormat> createOrUpdatePropertyValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceProperty property, String userId) {
+
+ Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Or Update Property Value", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ if (componentTypeEnum == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertyValue", "invalid component type", ErrorSeverity.INFO);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ return resultOp;
+ }
+
+ IComponentOperation componentOperation = getIComponentOperation(componentTypeEnum);
+
+ if (!ComponentValidationUtils.canWorkOnComponent(componentId, componentOperation, userId)) {
+ log.info("Restricted operation for user {} on service {}", userId, componentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ return resultOp;
+ }
+ // lock resource
+ StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug("Failed to lock service {}", componentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ return resultOp;
+ }
+ try {
+ String propertyValueUid = property.getValueUniqueUid();
+ if (propertyValueUid == null) {
+
+ Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, GraphPropertiesDictionary.PROPERTY_COUNTER, true);
+
+ if (counterRes.isRight()) {
+ log.debug("increaseAndGetResourcePropertyCounter failed resource instance {} property {}", resourceInstanceId, property);
+ StorageOperationStatus status = counterRes.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
+ resultOp = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+ Integer index = counterRes.left().value();
+ Either<ComponentInstanceProperty, StorageOperationStatus> result = componentInstanceOperation.addPropertyValueToResourceInstance(property, resourceInstanceId, index, true);
+
+ if (result.isLeft()) {
+ log.debug("Property value was added to resource instance {}", resourceInstanceId);
+ ComponentInstanceProperty instanceProperty = result.left().value();
+
+ resultOp = Either.left(instanceProperty);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to add property value {} to resource instance {}", property, resourceInstanceId);
+ // TODO: esofer add error
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ return resultOp;
+ }
+
+ } else {
+ Either<ComponentInstanceProperty, StorageOperationStatus> result = componentInstanceOperation.updatePropertyValueInResourceInstance(property, resourceInstanceId, true);
+
+ if (result.isLeft()) {
+ log.debug("Property value {} was updated on graph.", property.getValueUniqueUid());
+ ComponentInstanceProperty instanceProperty = result.left().value();
+
+ resultOp = Either.left(instanceProperty);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to update property value {} in resource instance {}", property, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ return resultOp;
+ }
+ }
+
+ } finally {
+ if (resultOp == null || resultOp.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
+ }
+
+ }
+
+ public Either<ComponentInstanceInput, ResponseFormat> createOrUpdateInputValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceInput inputProperty, String userId) {
+
+ Either<ComponentInstanceInput, ResponseFormat> resultOp = null;
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Or Update Input Value", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ if (componentTypeEnum == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("createOrUpdateInputValue", "invalid component type", ErrorSeverity.INFO);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ return resultOp;
+ }
+
+ IComponentOperation componentOperation = getIComponentOperation(componentTypeEnum);
+
+ if (!ComponentValidationUtils.canWorkOnComponent(componentId, componentOperation, userId)) {
+ log.info("Restricted operation for user {} on service {}", userId, componentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ return resultOp;
+ }
+ // lock resource
+ StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug("Failed to lock service {}", componentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ return resultOp;
+ }
+ try {
+ String propertyValueUid = inputProperty.getValueUniqueUid();
+ if (propertyValueUid == null) {
+
+ Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, GraphPropertiesDictionary.INPUT_COUNTER, true);
+
+ if (counterRes.isRight()) {
+ log.debug("increaseAndGetResourceInputCounter failed resource instance {} inputProperty {}", resourceInstanceId, inputProperty);
+ StorageOperationStatus status = counterRes.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
+ resultOp = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+ Integer index = counterRes.left().value();
+ Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.addInputValueToResourceInstance(inputProperty, resourceInstanceId, index, true);
+
+ if (result.isLeft()) {
+ log.debug("Property value was added to resource instance {}", resourceInstanceId);
+ ComponentInstanceInput instanceProperty = result.left().value();
+
+ resultOp = Either.left(instanceProperty);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to add input value {} to resource instance {}", inputProperty, resourceInstanceId);
+ // TODO: esofer add error
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ return resultOp;
+ }
+
+ } else {
+ Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.updateInputValueInResourceInstance(inputProperty, resourceInstanceId, true);
+
+ if (result.isLeft()) {
+ log.debug("Input value {} was updated on graph.", inputProperty.getValueUniqueUid());
+ ComponentInstanceInput instanceProperty = result.left().value();
+
+ resultOp = Either.left(instanceProperty);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to update property value {} in reosurce instance {}", inputProperty, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ return resultOp;
+ }
+ }
+
+ } finally {
+ if (resultOp == null || resultOp.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
+ }
+
+ }
+
+ public Either<ComponentInstanceProperty, ResponseFormat> deletePropertyValue(ComponentTypeEnum componentTypeEnum, String serviceId, String resourceInstanceId, String propertyValueId, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Property Value", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
+
+ if (componentTypeEnum == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertyValue", "invalid component type", ErrorSeverity.INFO);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ return resultOp;
+ }
+
+ IComponentOperation componentOperation = getIComponentOperation(componentTypeEnum);
+
+ if (!ComponentValidationUtils.canWorkOnComponent(serviceId, componentOperation, userId)) {
+ log.info("Restricted operation for user {} on service {}", userId, serviceId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ return resultOp;
+ }
+ // lock resource
+ StorageOperationStatus lockStatus = graphLockOperation.lockComponent(serviceId, componentTypeEnum.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug("Failed to lock service {}", serviceId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ return resultOp;
+ }
+ try {
+ Either<ComponentInstanceProperty, StorageOperationStatus> result = propertyOperation.removePropertyValueFromResourceInstance(propertyValueId, resourceInstanceId, true);
+
+ if (result.isLeft()) {
+ log.debug("Property value {} was removed from graph.", propertyValueId);
+ ComponentInstanceProperty instanceProperty = result.left().value();
+
+ resultOp = Either.left(instanceProperty);
+ return resultOp;
+
+ } else {
+ log.debug("Failed to remove property value {} in resource instance {}", propertyValueId, resourceInstanceId);
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+
+ resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
+
+ return resultOp;
+ }
+
+ } finally {
+ if (resultOp == null || resultOp.isRight()) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(serviceId, componentTypeEnum.getNodeType());
+ }
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateComponentInstanceName(String resourceInstanceName, ComponentInstance resourceInstance, boolean isCreate) {
+ ComponentTypeEnum containerComponentType = getComponentTypeOfComponentInstance();
+ if (!isCreate) {
+ if (resourceInstanceName == null)
+ return Either.left(true);
+ }
+
+ if (!ValidationUtils.validateStringNotEmpty(resourceInstanceName)) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, containerComponentType.getValue());
+
+ return Either.right(errorResponse);
+ }
+ resourceInstance.setNormalizedName(ValidationUtils.normaliseComponentInstanceName(resourceInstanceName));
+ if (!isCreate) {
+ if (!ValidationUtils.validateResourceInstanceNameLength(resourceInstanceName)) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, containerComponentType.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+
+ return Either.right(errorResponse);
+ }
+ if (!ValidationUtils.validateResourceInstanceName(resourceInstanceName)) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME, containerComponentType.getValue());
+
+ return Either.right(errorResponse);
+ }
+ }
+
+ return Either.left(true);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateComponentInstanceParentState(ComponentTypeEnum containerComponentType, ComponentInstance resourceInstance) {
+ String componentId = resourceInstance.getComponentUid();
+ Either<? extends Component, StorageOperationStatus> eitherResourceResponse = Either.right(StorageOperationStatus.GENERAL_ERROR);
+
+ ComponentTypeEnum componentType = getComponentTypeByParentComponentType(containerComponentType);
+ ComponentOperation componentOperation = getComponentOperation(componentType);
+ if (componentOperation != null)
+ eitherResourceResponse = componentOperation.getComponent(componentId, true);
+
+ Component component = null;
+ ResponseFormat errorResponse = null;
+ if (eitherResourceResponse.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(eitherResourceResponse.right().value(), componentType);
+ errorResponse = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
+ return Either.right(errorResponse);
+ }
+ component = eitherResourceResponse.left().value();
+ LifecycleStateEnum resourceCurrState = component.getLifecycleState();
+ if (resourceCurrState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
+ ActionStatus actionStatus = ActionStatus.ILLEGAL_COMPONENT_STATE;
+ errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().toString(), component.getName(), resourceCurrState.toString());
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ public Either<ComponentInstance, ResponseFormat> changeComponentInstanceVersion(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance newComponentInstance) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "change Component Instance Version", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<ComponentInstance, ResponseFormat> resultOp = null;
+
+ Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
+ if (validateComponentType.isRight()) {
+ return Either.right(validateComponentType.right().value());
+ }
+
+ final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentOperation containerOperation = getComponentOperation(containerComponentType);
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, false, true);
+ if (validateComponentExists.isRight()) {
+ return Either.right(validateComponentExists.right().value());
+ }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+
+ Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
+ if (validateCanWorkOnComponent.isRight()) {
+ return Either.right(validateCanWorkOnComponent.right().value());
+ }
+
+ Either<Boolean, StorageOperationStatus> validateParentStatus = componentInstanceOperation.validateParent(containerComponentId, componentInstanceId, false);
+ if (validateParentStatus.isRight()) {
+ log.debug("Failed to get resource instance {} on service {}", componentInstanceId, containerComponentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND, componentInstanceId));
+ return resultOp;
+ }
+ Boolean isPrentValid = validateParentStatus.left().value();
+ if (!isPrentValid) {
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceId, containerComponentId));
+ return resultOp;
+
+ }
+
+ Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = componentInstanceOperation.getResourceInstanceById(componentInstanceId);
+ if (resourceInstanceStatus.isRight()) {
+ log.debug("Failed to get resource instance {} on service {}", componentInstanceId, containerComponentId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND, componentInstanceId));
+ return resultOp;
+ }
+ ComponentInstance currentResourceInstance = resourceInstanceStatus.left().value();
+
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "changeComponentInstanceVersion");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+
+ try {
+ if (currentResourceInstance.getComponentUid().equals(newComponentInstance.getComponentUid())) {
+ resultOp = Either.left(currentResourceInstance);
+ return resultOp;
+
+ }
+ String resourceId = newComponentInstance.getComponentUid();
+ if (!getCompInstOriginComponentOperation().isComponentExist(resourceId)) {
+ log.debug("resource {} not found.", resourceId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ return resultOp;
+ }
+
+ // esofer - before deleting component instance, we should keep the
+ // groups which holds this instance
+ List<String> groupsToRevert = new ArrayList<>();
+ Either<List<String>, StorageOperationStatus> associatedGroups = groupOperation.getAssociatedGroupsToComponentInstance(componentInstanceId, true);
+ if (associatedGroups.isRight()) {
+ StorageOperationStatus status = associatedGroups.right().value();
+ if (status != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("ChangeComponentInstanceVersion", "Failed to getch groups of current component instance", ErrorSeverity.ERROR);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return resultOp;
+ }
+ } else {
+ List<String> groups = associatedGroups.left().value();
+ groupsToRevert.addAll(groups);
+ }
+ // rbetzer - before deleting component instance, retrieve env artifacts to keep track of artifactVersion
+
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> retrieveEnvArtifacts = componentInstanceOperation.fetchCIEnvArtifacts(componentInstanceId);
+ if (retrieveEnvArtifacts.isLeft())
+ newComponentInstance.setDeploymentArtifacts(retrieveEnvArtifacts.left().value());
+ else if (retrieveEnvArtifacts.right().value() != StorageOperationStatus.OK) {
+ log.debug("falied to fetch instance deployment artifacts {}", componentInstanceId );
+ }
+
+ resultOp = deleteComponentInstance(containerComponentId, componentInstanceId, containerComponentType);
+ if (resultOp.isRight()) {
+
+ log.debug("failed to delete resource instance {}", resourceId);
+
+ return resultOp;
+
+ }
+
+ Either<Component, ResponseFormat> eitherResourceName = getOriginComponentNameFromComponentInstance(newComponentInstance, true);
+
+ if (eitherResourceName.isRight()) {
+ resultOp = Either.right(eitherResourceName.right().value());
+ return resultOp;
+ }
+
+ Component origComponent = eitherResourceName.left().value();
+
+ ComponentInstance resResourceInfo = resultOp.left().value();
+ newComponentInstance.setName(resResourceInfo.getName());
+ newComponentInstance.setPosX(resResourceInfo.getPosX());
+ newComponentInstance.setPosY(resResourceInfo.getPosY());
+ newComponentInstance.setDescription(resResourceInfo.getDescription());
+
+ resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, newComponentInstance, userId, containerOperation, true);
+
+ if (resultOp.isRight()) {
+
+ log.debug("failed to create resource instance {}", resourceId);
+
+ return resultOp;
+
+ }
+
+ newComponentInstance = resultOp.left().value();
+ newComponentInstance.setName(resResourceInfo.getName());
+ resultOp = updateComponentInstance(containerComponentId, containerComponentType, origComponent, newComponentInstance.getUniqueId(), newComponentInstance, true);
+
+ ComponentInstance updatedComponentInstance = resultOp.left().value();
+ if (resultOp.isRight()) {
+ log.debug("failed to create resource instance {}", resourceId);
+ return resultOp;
+ }
+
+ if (false == groupsToRevert.isEmpty()) {
+ StorageOperationStatus associatedGroupsToComponentInstance = groupOperation.associateGroupsToComponentInstance(groupsToRevert, updatedComponentInstance.getUniqueId(), updatedComponentInstance.getName(), true);
+ if (associatedGroupsToComponentInstance != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("ChangeComponentInstanceVersion", "Failed to associate groups to new component instance", ErrorSeverity.ERROR);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return resultOp;
+ }
+ }
+
+ Either<ComponentInstance, StorageOperationStatus> fullResourceInstance = componentInstanceOperation.getFullComponentInstance(resultOp.left().value(), getNodeTypeOfComponentInstanceOrigin());
+ if (fullResourceInstance.isRight()) {
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fullResourceInstance.right().value()), resourceId));
+ return resultOp;
+ }
+ resultOp = Either.left(fullResourceInstance.left().value());
+ return resultOp;
+
+ } finally {
+ unlockComponent(resultOp, containerComponent);
+ }
+ }
+
+ protected abstract Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent);
+
+ protected abstract NodeTypeEnum getNodeTypeOfComponentInstanceOrigin();
+
+ protected abstract ComponentTypeEnum getComponentTypeOfComponentInstance();
+
+ protected abstract ComponentOperation getContainerComponentOperation();
+
+ protected abstract ComponentOperation getCompInstOriginComponentOperation();
+
+ protected void validateIncrementCounter(String resourceInstanceId, GraphPropertiesDictionary counterType, Wrapper<Integer> instaceCounterWrapper, Wrapper<ResponseFormat> errorWrapper) {
+ Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, counterType, true);
+
+ if (counterRes.isRight()) {
+ log.debug("increase And Get {} failed resource instance {}", counterType.name(), resourceInstanceId);
+ StorageOperationStatus status = counterRes.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus));
+ } else {
+ instaceCounterWrapper.setInnerElement(counterRes.left().value());
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java
new file mode 100644
index 0000000000..6cebc7dd53
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java
@@ -0,0 +1,285 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+/**
+ * This class holds the logic of arranging resource instance on the canvas for imported VF
+ *
+ * @author mshitrit
+ *
+ */
+@Component("compositionBusinessLogic")
+public class CompositionBusinessLogic {
+ @Autowired
+ private VFComponentInstanceBusinessLogic vfComponentInstanceBusinessLogic;
+
+ private static final int VFC_CANVAS_ELEMENT_SIZE = 50;
+ private static final int CP_CANVAS_ELEMENT_SIZE = 21;
+ private static final int CANVAS_WIDTH = 1000;
+ private static final int CANVAS_HEIGHT = 700;
+ private static final int SPACE_BETWEEN_ELEMENTS = VFC_CANVAS_ELEMENT_SIZE * 4;
+ private static final double CP_RADIUS_FACTOR = 0.4;
+
+ enum RelativePosition {
+ LEFT, RIGHT, UP, DOWN
+ };
+
+ protected Either<List<ComponentInstance>, ResponseFormat> setPositionsForComponentInstances(Resource resource, String userId) {
+ Either<List<ComponentInstance>, ResponseFormat> result = Either.left(resource.getComponentInstances());
+
+ boolean isNotAllPositionsCalculated = resource.getComponentInstances() == null
+ || resource.getComponentInstances().stream().filter(p -> (p.getPosX() == null || p.getPosX().isEmpty()) || (p.getPosY() == null || p.getPosY().isEmpty())).findAny().isPresent();
+
+ if (isNotAllPositionsCalculated) {
+ // Arrange Icons In Spiral Pattern
+ Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstanceLocations = buildSpiralPatternPositioningForComponentInstances(resource);
+
+ // Set Relative Locations According to Canvas Size
+ componentInstanceLocations.entrySet().stream().forEach(e -> setRelativePosition(e));
+
+ // Update in DB
+ result = vfComponentInstanceBusinessLogic.updateComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME, resource.getUniqueId(), userId, resource.getComponentInstances(), false, false);
+
+ }
+ return result;
+
+ }
+
+ private void setRelativePosition(Entry<ImmutablePair<Double, Double>, ComponentInstance> entry) {
+ int xCenter = CANVAS_WIDTH / 2;
+ int yCenter = CANVAS_HEIGHT / 2;
+
+ ImmutablePair<Double, Double> matrixPosition = entry.getKey();
+ ComponentInstance componentInstance = entry.getValue();
+ componentInstance.setPosX(calculateCompositionPosition(xCenter, matrixPosition.getLeft(), componentInstance));
+ componentInstance.setPosY(calculateCompositionPosition(yCenter, matrixPosition.getRight(), componentInstance));
+ }
+
+ private String calculateCompositionPosition(int center, double relativePosition, ComponentInstance componentInstance) {
+ final double topLeftCanvasPosition = center + relativePosition * CompositionBusinessLogic.SPACE_BETWEEN_ELEMENTS;
+ double offsetedCanvasPosition;
+ switch (componentInstance.getOriginType()) {
+ case CP:
+ offsetedCanvasPosition = topLeftCanvasPosition - CompositionBusinessLogic.CP_CANVAS_ELEMENT_SIZE / 2;
+ break;
+ case VL:
+ offsetedCanvasPosition = topLeftCanvasPosition - CompositionBusinessLogic.CP_CANVAS_ELEMENT_SIZE / 2;
+ break;
+ case VF:
+ offsetedCanvasPosition = topLeftCanvasPosition - CompositionBusinessLogic.VFC_CANVAS_ELEMENT_SIZE / 2;
+ break;
+ case VFC:
+ offsetedCanvasPosition = topLeftCanvasPosition - CompositionBusinessLogic.VFC_CANVAS_ELEMENT_SIZE / 2;
+ break;
+ default:
+ offsetedCanvasPosition = topLeftCanvasPosition - CompositionBusinessLogic.VFC_CANVAS_ELEMENT_SIZE / 2;
+ break;
+ }
+ return String.valueOf(offsetedCanvasPosition);
+ }
+
+ protected Map<ImmutablePair<Double, Double>, ComponentInstance> buildSpiralPatternPositioningForComponentInstances(Resource resource) {
+
+ Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstanceLocations = new HashMap<>();
+
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ componentInstances.addAll(resource.getComponentInstances());
+ Map<ComponentInstance, List<ComponentInstance>> connectededCps = getCpsConnectedToVFC(componentInstances, resource);
+ // Remove all cp that are connected from the list
+ componentInstances.removeAll(connectededCps.values().stream().flatMap(e -> e.stream()).collect(Collectors.toList()));
+
+ buildSpiralPatternForMajorComponents(componentInstanceLocations, componentInstances);
+ buildCirclePatternForCps(componentInstanceLocations, connectededCps);
+
+ return componentInstanceLocations;
+ }
+
+ protected void buildCirclePatternForCps(Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstLocations, Map<ComponentInstance, List<ComponentInstance>> connectedCps) {
+
+ for (Entry<ComponentInstance, List<ComponentInstance>> vfcCpList : connectedCps.entrySet()) {
+ Entry<ImmutablePair<Double, Double>, ComponentInstance> vfcOfTheCps = componentInstLocations.entrySet().stream().filter(p -> p.getValue().getUniqueId().equals(vfcCpList.getKey().getUniqueId())).findAny().get();
+ buildCirclePatternForOneGroupOfCps(vfcOfTheCps.getKey(), vfcCpList.getValue(), componentInstLocations);
+ }
+
+ }
+
+ private void buildCirclePatternForOneGroupOfCps(ImmutablePair<Double, Double> vfcLocation, List<ComponentInstance> cpsGroup, Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstLocations) {
+ final int numberOfCps = cpsGroup.size();
+ double angleBetweenCps = (!cpsGroup.isEmpty()) ? Math.toRadians(360) / numberOfCps : 0;
+ double currentAngle = 0;
+ Double xCenter = vfcLocation.getLeft();
+ Double yCenter = vfcLocation.getRight();
+ for (ComponentInstance currCp : cpsGroup) {
+ double cpXposition = xCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.cos(currentAngle);
+ double cpYposition = yCenter + CompositionBusinessLogic.CP_RADIUS_FACTOR * Math.sin(currentAngle);
+ componentInstLocations.put(new ImmutablePair<Double, Double>(cpXposition, cpYposition), currCp);
+ currentAngle += angleBetweenCps;
+ }
+
+ }
+
+ private void buildSpiralPatternForMajorComponents(Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstanceLocations, List<ComponentInstance> componentInstances) {
+ int elementsCounter = 0;
+ ImmutablePair<Double, Double> currPlacement;
+ ImmutablePair<Double, Double> prevPlacement = null;
+ RelativePosition relationToPrevElement = null;
+ for (ComponentInstance curr : componentInstances) {
+ elementsCounter++;
+ if (elementsCounter == 1) {
+ currPlacement = new ImmutablePair<Double, Double>(0D, 0D);
+ } else if (elementsCounter == 2) {
+ currPlacement = new ImmutablePair<Double, Double>(-1D, 0D);
+ relationToPrevElement = RelativePosition.LEFT;
+ } else {
+ relationToPrevElement = getRelativePositionForCurrentElement(componentInstanceLocations, relationToPrevElement, prevPlacement);
+ currPlacement = getRelativeElementLocation(prevPlacement, relationToPrevElement);
+
+ }
+
+ componentInstanceLocations.put(currPlacement, curr);
+ prevPlacement = currPlacement;
+ }
+ }
+
+ protected Map<ComponentInstance, List<ComponentInstance>> getCpsConnectedToVFC(List<ComponentInstance> allComponentInstances, Resource vf) {
+ Map<ComponentInstance, List<ComponentInstance>> vfcWithItsCps = new HashMap<>();
+ List<RequirementCapabilityRelDef> allRelations = vf.getComponentInstancesRelations();
+ for (ComponentInstance curr : allComponentInstances) {
+ // Filters Only CPs
+ if (curr.getOriginType() == OriginTypeEnum.CP) {
+ // List Of elements the CP is connected to
+ List<RequirementCapabilityRelDef> connectedToList = allRelations.stream().filter(p -> p.getFromNode().equals(curr.getUniqueId()) || p.getToNode().equals(curr.getUniqueId())).collect(Collectors.toList());
+ // Adds Only CPs Which are connected to VFC
+ filterCpConnectedToVFC(allComponentInstances, vfcWithItsCps, curr, connectedToList);
+ }
+ }
+ return vfcWithItsCps;
+ }
+
+ private void filterCpConnectedToVFC(List<ComponentInstance> allComponentInstances, Map<ComponentInstance, List<ComponentInstance>> vfcWithItsCps, ComponentInstance currCP, List<RequirementCapabilityRelDef> connectedToTheCPList) {
+ if (!connectedToTheCPList.isEmpty()) {
+ // Set Of Ids Of components Instances which are connected certain CP
+ Set<String> mateIds = connectedToTheCPList.stream().map(cpRelation -> cpRelation.getFromNode().equals(currCP.getUniqueId()) ? cpRelation.getToNode() : cpRelation.getFromNode()).collect(Collectors.toSet());
+
+ // Vfc Component instance Connected to the CP
+ Optional<ComponentInstance> optionalVfcConnectedToCP = allComponentInstances.stream().
+ // All instances connected to CP
+ filter(p -> mateIds.contains(p.getUniqueId())).
+ // Filter in only VFC connected to the CP
+ filter(p -> p.getOriginType() == OriginTypeEnum.VFC).findAny();
+
+ if (optionalVfcConnectedToCP.isPresent()) {
+ final ComponentInstance vfcWithCps = optionalVfcConnectedToCP.get();
+ if (vfcWithItsCps.containsKey(vfcWithCps)) {
+ vfcWithItsCps.get(vfcWithCps).add(currCP);
+ } else {
+ List<ComponentInstance> cpsList = new ArrayList<>();
+ cpsList.add(currCP);
+ vfcWithItsCps.put(vfcWithCps, cpsList);
+ }
+ }
+ }
+ }
+
+ private RelativePosition getRelativePositionForCurrentElement(Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstanceLocations, RelativePosition relationToPrevElement, ImmutablePair<Double, Double> prevPlacement) {
+ switch (relationToPrevElement) {
+ case LEFT: {
+ boolean isOccupied = isAdjacentElementOccupied(prevPlacement, RelativePosition.UP, componentInstanceLocations);
+ relationToPrevElement = isOccupied ? RelativePosition.LEFT : RelativePosition.UP;
+ break;
+ }
+ case RIGHT: {
+ boolean isOccupied = isAdjacentElementOccupied(prevPlacement, RelativePosition.DOWN, componentInstanceLocations);
+ relationToPrevElement = isOccupied ? RelativePosition.RIGHT : RelativePosition.DOWN;
+ break;
+ }
+ case UP: {
+ boolean isOccupied = isAdjacentElementOccupied(prevPlacement, RelativePosition.RIGHT, componentInstanceLocations);
+ relationToPrevElement = isOccupied ? RelativePosition.UP : RelativePosition.RIGHT;
+ break;
+ }
+ case DOWN: {
+ boolean isOccupied = isAdjacentElementOccupied(prevPlacement, RelativePosition.LEFT, componentInstanceLocations);
+ relationToPrevElement = isOccupied ? RelativePosition.DOWN : RelativePosition.LEFT;
+ break;
+ }
+ default: {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return relationToPrevElement;
+ }
+
+ private boolean isAdjacentElementOccupied(ImmutablePair<Double, Double> currElement, RelativePosition adjacentElementRelationToCurrElement, Map<ImmutablePair<Double, Double>, ComponentInstance> allElements) {
+
+ ImmutablePair<Double, Double> adjacentElementPosition = getRelativeElementLocation(currElement, adjacentElementRelationToCurrElement);
+ return allElements.containsKey(adjacentElementPosition);
+ }
+
+ private ImmutablePair<Double, Double> getRelativeElementLocation(ImmutablePair<Double, Double> currElement, RelativePosition relativeLocation) {
+ ImmutablePair<Double, Double> relativeElementPosition;
+ switch (relativeLocation) {
+
+ case LEFT: {
+ relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft() - 1, currElement.getRight());
+ break;
+ }
+ case RIGHT: {
+ relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft() + 1, currElement.getRight());
+ break;
+ }
+ case UP: {
+ relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft(), currElement.getRight() + 1);
+ break;
+ }
+ case DOWN: {
+ relativeElementPosition = new ImmutablePair<Double, Double>(currElement.getLeft(), currElement.getRight() - 1);
+ break;
+ }
+ default: {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return relativeElementPosition;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
new file mode 100644
index 0000000000..226225a07c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
@@ -0,0 +1,313 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.Date;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ConsumerOperation;
+import org.openecomp.sdc.be.resources.data.ConsumerData;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("ConsumerBusinessLogic")
+public class ConsumerBusinessLogic extends BaseBusinessLogic {
+
+ private static final String CONSUMER_NAME = "Consumer name";
+ private static final String CONSUMER_SALT = "Consumer salt";
+ private static final String CONSUMER_PW = "Consumer password";
+
+ @javax.annotation.Resource
+ private IUserBusinessLogic userAdmin;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ @javax.annotation.Resource
+ private ConsumerOperation consumerOperation;
+
+ @javax.annotation.Resource
+ private IGraphLockOperation graphLockOperation;
+
+ private static Logger log = LoggerFactory.getLogger(ConsumerBusinessLogic.class.getName());
+
+ public Either<ConsumerDefinition, ResponseFormat> createConsumer(User user, ConsumerDefinition consumer) {
+
+ Either<User, ResponseFormat> userValidation = validateUser(user, consumer, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS);
+
+ if (userValidation.isRight()) {
+ return Either.right(userValidation.right().value());
+ }
+ checkFieldsForOverrideAttempt(consumer);
+ user = userValidation.left().value();
+ consumer.setLastModfierAtuid(user.getUserId());
+
+ Either<ConsumerDefinition, ResponseFormat> consumerValidationResponse = validateConsumer(consumer, user, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS);
+ if (consumerValidationResponse.isRight()) {
+ ResponseFormat responseFormat = consumerValidationResponse.right().value();
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ String consumerName = consumer.getConsumerName();
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(consumerName, NodeTypeEnum.ConsumerCredentials);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "createConsumer");
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError("createConsumer", NodeTypeEnum.ConsumerCredentials.getName(), consumerName);
+ log.debug("Failed to lock consumer {} error - {}", consumerName, lockResult);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ try {
+ Either<ConsumerData, StorageOperationStatus> getResponse = consumerOperation.getCredentials(consumerName);
+ if (getResponse.isLeft() && getResponse.left().value() != null) {
+ return updateConsumer(consumer, user, true);
+ }
+
+ Date date = new Date();
+ consumer.setConsumerDetailsLastupdatedtime(date.getTime());
+ consumer.setConsumerLastAuthenticationTime(Long.valueOf(0));
+
+ Either<ConsumerData, StorageOperationStatus> createResponse = consumerOperation.createCredentials(new ConsumerData(consumer));
+
+ if (createResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForConsumer(createResponse.right().value()));
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ log.debug("Consumer created successfully!!!");
+ consumer = new ConsumerDefinition(createResponse.left().value().getConsumerDataDefinition());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.left(consumer);
+ } finally {
+ graphLockOperation.unlockComponent(consumerName, NodeTypeEnum.ConsumerCredentials);
+ }
+ }
+
+ private Either<User, ResponseFormat> validateUser(User user, ConsumerDefinition consumer, AuditingActionEnum auditAction) {
+
+ if (user.getUserId() == null || user.getUserId().trim().isEmpty()) {
+ log.debug("createEcompUser method - user is missing. userId={}", user.getUserId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ log.debug("audit before sending response");
+ componentsUtils.auditConsumerCredentialsEvent(auditAction, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ log.debug("get user from DB");
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId(), false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ log.debug("createEcompUser method - user is not listed. userId={}", user.getUserId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
+ log.debug("audit before sending response");
+ componentsUtils.auditConsumerCredentialsEvent(auditAction, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+
+ user = eitherCreator.left().value();
+ // validate user role
+ log.debug("validate user role");
+ if (!user.getRole().equals(Role.ADMIN.name())) {
+ log.info("role {} is not allowed to perform this action", user.getRole());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("audit before sending response");
+ componentsUtils.auditConsumerCredentialsEvent(auditAction, consumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ return Either.left(user);
+ }
+
+ private Either<ConsumerDefinition, ResponseFormat> validateConsumer(ConsumerDefinition consumer, User user, AuditingActionEnum audatingAction) {
+ Either<ConsumerDefinition, ResponseFormat> validateConsumerName = validateConsumerName(consumer);
+ if (validateConsumerName.isRight()) {
+ return Either.right(validateConsumerName.right().value());
+ }
+ Either<ConsumerDefinition, ResponseFormat> validateConsumerPassword = validateConsumerPassword(consumer);
+ if (validateConsumerPassword.isRight()) {
+ return Either.right(validateConsumerPassword.right().value());
+ }
+ consumer = validateConsumerPassword.left().value();
+ Either<ConsumerDefinition, ResponseFormat> validateEcompUserSalt = validateConsumerSalt(consumer);
+ if (validateEcompUserSalt.isRight()) {
+ return Either.right(validateEcompUserSalt.right().value());
+ }
+ return Either.left(consumer);
+
+ }
+
+ private Either<ConsumerDefinition, ResponseFormat> validateConsumerName(ConsumerDefinition consumer) {
+ String name = consumer.getConsumerName();
+ if (!ValidationUtils.validateStringNotEmpty(name)) {
+ log.debug("Consumer name cannot be empty.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_NAME));
+ }
+ if (!ValidationUtils.validateConsumerName(name)) {
+ log.debug("Consumer name is invalid.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, CONSUMER_NAME));
+ }
+ if (!ValidationUtils.validateLength(name, ValidationUtils.CONSUMER_NAME_MAX_LENGTH)) {
+ log.debug("Consumer name exceeds limit.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, CONSUMER_NAME, String.valueOf(ValidationUtils.CONSUMER_NAME_MAX_LENGTH)));
+ }
+ if (!ValidationUtils.isUTF8Str(name)) {
+ log.debug("Consumer name includes non UTF 8 characters.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, CONSUMER_NAME));
+ }
+
+ return Either.left(consumer);
+ }
+
+ private Either<ConsumerDefinition, ResponseFormat> validateConsumerPassword(ConsumerDefinition consumer) {
+ String password = consumer.getConsumerPassword();
+ if (!ValidationUtils.validateStringNotEmpty(password)) {
+ log.debug("Consumer password cannot be empty.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_PW));
+ }
+ if (password.length() != ValidationUtils.CONSUMER_PASSWORD_LENGTH) {
+ log.debug("Consumer password length is not valid.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_LENGTH, CONSUMER_PW));
+ }
+ consumer.setConsumerPassword(password.toLowerCase());
+ if (!ValidationUtils.validateConsumerPassSalt(consumer.getConsumerPassword())) {
+ log.debug("Consumer password is invalid.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, CONSUMER_PW));
+ }
+
+ return Either.left(consumer);
+ }
+
+ private Either<ConsumerDefinition, ResponseFormat> validateConsumerSalt(ConsumerDefinition consumer) {
+ String salt = consumer.getConsumerSalt();
+ if (!ValidationUtils.validateStringNotEmpty(salt)) {
+ log.debug("Consumer salt cannot be empty.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_SALT));
+ }
+ if (salt.length() != ValidationUtils.CONSUMER_SALT_LENGTH) {
+ log.debug("Consumer salt length is not valid.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_LENGTH, CONSUMER_SALT));
+ }
+ if (!ValidationUtils.validateConsumerPassSalt(salt)) {
+ log.debug("Consumer salt is invalid.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, CONSUMER_SALT));
+ }
+
+ return Either.left(consumer);
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> getConsumer(String consumerId, User user) {
+ ConsumerDefinition tmpConsumer = new ConsumerDefinition();
+ tmpConsumer.setConsumerName(consumerId);
+ // In case of filter (southbound) call
+ if (user != null) {
+ Either<User, ResponseFormat> userValidation = validateUser(user, tmpConsumer, AuditingActionEnum.GET_ECOMP_USER_CREDENTIALS);
+ if (userValidation.isRight()) {
+ return Either.right(userValidation.right().value());
+ }
+ user = userValidation.left().value();
+ }
+ Either<ConsumerData, StorageOperationStatus> getResult = consumerOperation.getCredentials(consumerId);
+ if (getResult.isRight()) {
+ ActionStatus action = componentsUtils.convertFromStorageResponseForConsumer(getResult.right().value());
+ ResponseFormat responseFormat;
+ if (action == ActionStatus.ECOMP_USER_NOT_FOUND) {
+ responseFormat = componentsUtils.getResponseFormat(action, consumerId);
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(action);
+ }
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.GET_ECOMP_USER_CREDENTIALS, tmpConsumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ ConsumerDefinition consumer = new ConsumerDefinition(getResult.left().value().getConsumerDataDefinition());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.GET_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.left(consumer);
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> getConsumer(String consumerId) {
+ return getConsumer(consumerId, null);
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> deleteConsumer(String consumerId, User user) {
+ ConsumerDefinition tmpConsumer = new ConsumerDefinition();
+ tmpConsumer.setConsumerName(consumerId);
+ Either<User, ResponseFormat> userValidation = validateUser(user, tmpConsumer, AuditingActionEnum.DELETE_ECOMP_USER_CREDENTIALS);
+ if (userValidation.isRight()) {
+ return Either.right(userValidation.right().value());
+ }
+ user = userValidation.left().value();
+ Either<ConsumerData, StorageOperationStatus> deleteResult = consumerOperation.deleteCredentials(consumerId);
+ if (deleteResult.isRight()) {
+ ActionStatus action = componentsUtils.convertFromStorageResponseForConsumer(deleteResult.right().value());
+ ResponseFormat responseFormat;
+ if (action == ActionStatus.ECOMP_USER_NOT_FOUND) {
+ responseFormat = componentsUtils.getResponseFormat(action, consumerId);
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(action);
+ }
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.DELETE_ECOMP_USER_CREDENTIALS, tmpConsumer, responseFormat, user);
+ return Either.right(responseFormat);
+ }
+ ConsumerDefinition consumer = new ConsumerDefinition(deleteResult.left().value().getConsumerDataDefinition());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ componentsUtils.auditConsumerCredentialsEvent(AuditingActionEnum.DELETE_ECOMP_USER_CREDENTIALS, consumer, responseFormat, user);
+ return Either.left(consumer);
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> updateConsumer(ConsumerDefinition consumer, User modifier, boolean isCreateRequest) {
+ Either<ConsumerData, StorageOperationStatus> updateResult = consumerOperation.updateCredentials(new ConsumerData(consumer));
+ if (updateResult.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForConsumer(updateResult.right().value()));
+ return Either.right(responseFormat);
+ }
+ consumer = new ConsumerDefinition(updateResult.left().value().getConsumerDataDefinition());
+ return Either.left(consumer);
+ }
+
+ private void checkFieldsForOverrideAttempt(ConsumerDefinition consumer) {
+ if (consumer.getConsumerDetailsLastupdatedtime() != null) {
+ log.info("Consumer Details Last updated time cannot be defined by user. This field will be overridden by the application");
+ }
+ if (consumer.getConsumerLastAuthenticationTime() != null) {
+ log.info("Consumer Last Authentication time cannot be defined by user. This field will be overridden by the application");
+ }
+ if (consumer.getLastModfierAtuid() != null) {
+ log.info("Consumer Last Modifier USER_ID cannot be defined by user. This field will be overridden by the application");
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java
new file mode 100644
index 0000000000..badb257a80
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java
@@ -0,0 +1,265 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CsarValidationUtils {
+
+ private static Logger log = LoggerFactory.getLogger(CsarValidationUtils.class.getName());
+
+ private static final String TOSCA_META_FILE_VERSION = "TOSCA-Meta-File-Version";
+
+ private static final String CSAR_VERSION = "CSAR-Version";
+
+ private static final String CREATED_BY = "Created-By";
+
+ private static final String NEW_LINE_DELM = "\n";
+
+ public final static String TOSCA_METADATA_FILE = "TOSCA-Metadata/TOSCA.meta";
+
+ public static final String TOSCA_META_ENTRY_DEFINITIONS = "Entry-Definitions";
+
+ public final static String[] TOSCA_METADATA_FIELDS = { TOSCA_META_FILE_VERSION, CSAR_VERSION, CREATED_BY, TOSCA_META_ENTRY_DEFINITIONS };
+
+ public final static String ARTIFACTS_METADATA_FILE = "HEAT.meta";
+
+ public final static String ARTIFACTS = "Artifacts/";
+
+ public static final String TOSCA_CSAR_EXTENSION = ".csar";
+
+ public static Either<Boolean, ResponseFormat> validateCsar(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+ Either<Boolean, ResponseFormat> validateStatus = validateIsTOSCAMetadataExist(csar, csarUUID, componentsUtils);
+ if (validateStatus.isRight()) {
+ return Either.right(validateStatus.right().value());
+ }
+ log.trace("TOSCA-Metadata/TOSCA.meta file found, CSAR id {}", csarUUID);
+ return validateTOSCAMetadataFile(csar, csarUUID, componentsUtils);
+
+ }
+
+ public static Either<ImmutablePair<String, String>, ResponseFormat> getToscaYaml(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+ Either<Boolean, ResponseFormat> validateStatus = validateIsTOSCAMetadataExist(csar, csarUUID, componentsUtils);
+ if (validateStatus.isRight()) {
+ return Either.right(validateStatus.right().value());
+ }
+ byte[] toscaMetaBytes = csar.get(TOSCA_METADATA_FILE);
+ Properties props = new Properties();
+ try {
+ props.load(new ByteArrayInputStream(toscaMetaBytes));
+ } catch (IOException e) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file is not in expected key-value form in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+
+ String yamlFileName = props.getProperty(TOSCA_META_ENTRY_DEFINITIONS);
+
+ if (!csar.containsKey(yamlFileName)) {
+ log.debug("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, yamlFileName));
+ }
+
+ log.trace("Found Entry-Definitions property in TOSCA-Metadata/TOSCA.meta, Entry-Definitions: {}, CSAR id: {}", yamlFileName, csarUUID);
+ byte[] yamlFileBytes = csar.get(yamlFileName);
+ if (yamlFileBytes == null) {
+ log.debug("Entry-Definitions {} file not found in csar, csar ID {}", yamlFileName, csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions " + yamlFileName + " file not found in CSAR with id " + csarUUID, "CSAR structure is invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, yamlFileName));
+ }
+
+ String yamlFileContents = new String(yamlFileBytes);
+
+ return Either.left(new ImmutablePair<String, String>(yamlFileName, yamlFileContents));
+ }
+
+ public static Either<ImmutablePair<String, String>, ResponseFormat> getArtifactsMeta(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+
+ if (!csar.containsKey(ARTIFACTS + ARTIFACTS_METADATA_FILE)) {
+ log.debug("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, ARTIFACTS_METADATA_FILE));
+ }
+
+ log.trace("Found Entry-Definitions property in TOSCA-Metadata/TOSCA.meta, Entry-Definitions: {}, CSAR id: {}", ARTIFACTS_METADATA_FILE, csarUUID);
+ byte[] artifactsMetaBytes = csar.get(ARTIFACTS + ARTIFACTS_METADATA_FILE);
+ if (artifactsMetaBytes == null) {
+ log.debug("Entry-Definitions {} file not found in csar, csar ID {}", ARTIFACTS + ARTIFACTS_METADATA_FILE, csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions " + ARTIFACTS + ARTIFACTS_METADATA_FILE + " file not found in CSAR with id " + csarUUID, "CSAR structure is invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, ARTIFACTS + ARTIFACTS_METADATA_FILE));
+ }
+
+ String artifactsFileContents = new String(artifactsMetaBytes);
+
+ return Either.left(new ImmutablePair<String, String>(ARTIFACTS + ARTIFACTS_METADATA_FILE, artifactsFileContents));
+ }
+
+ public static Either<ImmutablePair<String, byte[]>, ResponseFormat> getArtifactsContent(String csarUUID, Map<String, byte[]> csar, String artifactName, ComponentsUtils componentsUtils) {
+ if (!csar.containsKey(ARTIFACTS + artifactName)) {
+ log.debug("Entry-Definitions entry not found in Artifacts/HEAT.meta file, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, ARTIFACTS + artifactName, csarUUID));
+ }
+
+ log.trace("Found Entry-Definitions property in Artifacts/HEAT.meta, Entry-Definitions: {}, CSAR id: {}", ARTIFACTS + artifactName, csarUUID);
+ byte[] artifactFileBytes = csar.get(ARTIFACTS + artifactName);
+ if (artifactFileBytes == null) {
+ log.debug("Entry-Definitions {} file not found in csar, csar ID {}", ARTIFACTS + artifactName, csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions " + ARTIFACTS + artifactName + " file not found in CSAR with id " + csarUUID, "CSAR structure is invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, ARTIFACTS + artifactName, csarUUID));
+ }
+
+ return Either.left(new ImmutablePair<String, byte[]>(artifactName, artifactFileBytes));
+ }
+
+ private static Either<Boolean, ResponseFormat> validateTOSCAMetadataFile(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+
+ byte[] toscaMetaBytes = csar.get(TOSCA_METADATA_FILE);
+ String toscaMetadata = new String(toscaMetaBytes);
+ String[] splited = toscaMetadata.split(NEW_LINE_DELM);
+ if (splited == null || splited.length < TOSCA_METADATA_FIELDS.length) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file is not in expected key-value form in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+ /*
+ * if(splited.length == TOSCA_METADATA_FIELDS.length){ if(!toscaMetadata.endsWith(NEW_LINE_DELM)){ log. debug("TOSCA-Metadata/TOSCA.meta file is not in expected key-value form in csar, csar ID {}" , csarUUID);
+ * BeEcompErrorManager.getInstance(). logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " +csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR); return
+ * Either.right(componentsUtils.getResponseFormat(ActionStatus. CSAR_INVALID_FORMAT, csarUUID)); } }
+ */
+
+ Either<Boolean, ResponseFormat> block_0Status = validateBlock_0(csarUUID, splited, componentsUtils);
+ if (block_0Status.isRight()) {
+ return Either.right(block_0Status.right().value());
+ }
+
+ return Either.left(true);
+
+ }
+
+ private static Either<Boolean, ResponseFormat> validateBlock_0(String csarUUID, String[] splited, ComponentsUtils componentsUtils) {
+ int index = 0;
+ for (String toscaField : TOSCA_METADATA_FIELDS) {
+
+ Properties props = new Properties();
+
+ try {
+ props.load(new ByteArrayInputStream(splited[index].getBytes()));
+ } catch (IOException e) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file is not in expected key-value form in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+ if (!props.containsKey(toscaField)) {
+ log.debug("TOSCA.meta file format is invalid: No new line after block_0 as expected in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+ String value = props.getProperty(toscaField);
+ if (value == null || value.isEmpty()) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file is not in expected key-value form in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+
+ // TOSCA-Meta-File-Version & CSAR-Version : digit.digit - format
+ // validation
+ if (toscaField.equals(TOSCA_META_FILE_VERSION) || toscaField.equals(CSAR_VERSION)) {
+ if (!validateTOSCAMetaProperty(value)) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file contains {} in wrong format (digit.digit), csar ID {}", toscaField, csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not in expected key-value form in CSAR with id " + csarUUID, "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID));
+ }
+ }
+ index++;
+ }
+ return Either.left(true);
+ }
+
+ private static boolean validateTOSCAMetaProperty(String toscaProperty) {
+ final String FLOAT_STRING = "^\\d{1}[.]\\d{1}$";
+ final Pattern FLOAT_PATTERN = Pattern.compile(FLOAT_STRING);
+
+ Matcher floatMatcher = FLOAT_PATTERN.matcher(toscaProperty);
+ return floatMatcher.matches();
+ }
+
+ private static Either<Boolean, ResponseFormat> validateIsTOSCAMetadataExist(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+ if (csar == null || csar.isEmpty()) {
+ log.debug("Error when fetching csar with ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Creating resource from CSAR: fetching CSAR with id " + csarUUID + " failed");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID, csarUUID);
+ return Either.right(responseFormat);
+ }
+ if (!csar.containsKey(TOSCA_METADATA_FILE)) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file not found in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not found in CSAR with id " + csarUUID, "CSAR structure is invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID, csarUUID));
+ }
+ byte[] toscaMetaBytes = csar.get(TOSCA_METADATA_FILE);
+ // Tal && exchanged for ||
+ if (toscaMetaBytes == null || toscaMetaBytes.length == 0) {
+ log.debug("TOSCA-Metadata/TOSCA.meta file not found in csar, csar ID {}", csarUUID);
+ BeEcompErrorManager.getInstance().logInternalDataError("TOSCA-Metadata/TOSCA.meta file not found in CSAR with id " + csarUUID, "CSAR structure is invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID, csarUUID));
+ }
+
+ return Either.left(Boolean.TRUE);
+ }
+
+ public static Either<String, ResponseFormat> getToscaYamlChecksum(Map<String, byte[]> csar, String csarUUID, ComponentsUtils componentsUtils) {
+
+ Either<ImmutablePair<String, String>, ResponseFormat> toscaYamlRes = getToscaYaml(csar, csarUUID, componentsUtils);
+ if (toscaYamlRes.isRight() || toscaYamlRes.left().value() == null || toscaYamlRes.left().value().getRight() == null) {
+ log.debug("Faild to create toscaYamlChecksum for csar, csar ID {}", csarUUID);
+ return Either.right(toscaYamlRes.right().value());
+ }
+
+ String newCheckSum = GeneralUtility.calculateMD5ByByteArray(toscaYamlRes.left().value().getRight().getBytes());
+ return Either.left(newCheckSum);
+
+ }
+
+ public static boolean isCsarPayloadName(String payloadName) {
+ if (payloadName == null)
+ return false;
+ return payloadName.toLowerCase().endsWith(TOSCA_CSAR_EXTENSION);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
new file mode 100644
index 0000000000..e5fba0dff5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
@@ -0,0 +1,255 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("dataTypeImportManager")
+public class DataTypeImportManager {
+
+ public static void main(String[] args) {
+
+ List<PropertyDefinition> properties = new ArrayList<>();
+ PropertyDefinition propertyDefintion = new PropertyDefinition();
+ propertyDefintion.setName("aaa");
+ properties.add(propertyDefintion);
+
+ List<String> allParentsProps = new ArrayList<>();
+ allParentsProps.add("aaa");
+ allParentsProps.add("bbb");
+
+ Set<String> alreadyExistPropsCollection = properties.stream().filter(p -> allParentsProps.contains(p.getName())).map(p -> p.getName()).collect(Collectors.toSet());
+ System.out.println(alreadyExistPropsCollection);
+
+ }
+
+ private static Logger log = LoggerFactory.getLogger(DataTypeImportManager.class.getName());
+ @Resource
+ private PropertyOperation propertyOperation;
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private CommonImportManager commonImportManager;
+
+ public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(String dataTypeYml) {
+ return commonImportManager.createElementTypes(dataTypeYml, elementTypeYml -> createDataTypesFromYml(elementTypeYml), elementTypesList -> createDataTypesByDao(elementTypesList), ElementTypeEnum.DataType);
+ }
+
+ private Either<List<DataTypeDefinition>, ActionStatus> createDataTypesFromYml(String dataTypesYml) {
+
+ return commonImportManager.createElementTypesFromYml(dataTypesYml, (dataTypeName, dataTypeJsonData) -> createDataType(dataTypeName, dataTypeJsonData));
+
+ }
+
+ private Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypesByDao(List<DataTypeDefinition> dataTypesToCreate) {
+
+ return commonImportManager.createElementTypesByDao(dataTypesToCreate, dataType -> validateDataType(dataType), dataType -> new ImmutablePair<>(ElementTypeEnum.DataType, dataType.getName()),
+ dataTypeName -> propertyOperation.getDataTypeByNameWithoutDerived(dataTypeName), dataType -> propertyOperation.addDataType(dataType), (newDataType, oldDataType) -> propertyOperation.updateDataType(newDataType, oldDataType));
+ }
+
+ private Either<ActionStatus, ResponseFormat> validateDataType(DataTypeDefinition dataType) {
+
+ String dataTypeName = dataType.getName();
+ List<PropertyDefinition> properties = dataType.getProperties();
+ if (properties == null) {
+ // At least one parameter should be defined either in the properties
+ // section or at one of the parents
+ String derivedDataType = dataType.getDerivedFromName();
+ // If there are no properties, then we can create a data type if it
+ // is an abstract one or it derives from non abstract data type
+ if ((derivedDataType == null || derivedDataType.isEmpty())) {
+ if (false == isAbstract(dataType.getName())) {
+ if (false == ToscaPropertyType.isScalarType(dataTypeName)) {
+ log.debug("Data type {} must have properties unless it derives from non abstract data type", dataType.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
+
+ return Either.right(responseFormat);
+ }
+ }
+ } else {
+ // if it is not a scalar data type and it derives from abstract
+ // data type, we should reject the request.
+ if (false == ToscaPropertyType.isScalarType(dataTypeName) && true == isAbstract(derivedDataType)) {
+ log.debug("Data type {} which derived from abstract data type must have at least one property", dataType.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
+
+ return Either.right(responseFormat);
+ }
+ }
+ } else {
+ // properties tag cannot be empty
+ if (properties.isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY, dataType, null);
+
+ return Either.right(responseFormat);
+ }
+
+ // check no duplicates
+ Set<String> collect = properties.stream().map(p -> p.getName()).collect(Collectors.toSet());
+ if (collect != null) {
+ if (properties.size() != collect.size()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DUPLICATE_PROPERTY, dataType, null);
+
+ return Either.right(responseFormat);
+ }
+ }
+
+ List<String> propertiesWithSameTypeAsDataType = properties.stream().filter(p -> p.getType().equals(dataType.getName())).map(p -> p.getName()).collect(Collectors.toList());
+ if (propertiesWithSameTypeAsDataType != null && propertiesWithSameTypeAsDataType.isEmpty() == false) {
+ log.debug("The data type {} contains properties with the type {}", dataType.getName(), dataType.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE, dataType, propertiesWithSameTypeAsDataType);
+
+ return Either.right(responseFormat);
+ }
+ }
+
+ String derivedDataType = dataType.getDerivedFromName();
+ if (derivedDataType != null) {
+ Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, true);
+ if (derivedDataTypeByName.isRight()) {
+ StorageOperationStatus status = derivedDataTypeByName.right().value();
+ if (status == StorageOperationStatus.NOT_FOUND) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DERIVED_IS_MISSING, dataType, null);
+
+ return Either.right(responseFormat);
+ } else {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.GENERAL_ERROR, dataType, null);
+
+ return Either.right(responseFormat);
+
+ }
+ } else {
+
+ DataTypeDefinition derivedDataTypeDef = derivedDataTypeByName.left().value();
+ if (properties != null && properties.isEmpty() == false) {
+
+ if (true == isScalarType(derivedDataTypeDef)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_CANNOT_HAVE_PROPERTIES, dataType, null);
+
+ return Either.right(responseFormat);
+ }
+
+ Set<String> allParentsProps = new HashSet<>();
+ do {
+ List<PropertyDefinition> currentParentsProps = derivedDataTypeDef.getProperties();
+ if (currentParentsProps != null) {
+ for (PropertyDefinition propertyDefinition : currentParentsProps) {
+ allParentsProps.add(propertyDefinition.getName());
+ }
+ }
+ derivedDataTypeDef = derivedDataTypeDef.getDerivedFrom();
+ } while (derivedDataTypeDef != null);
+
+ // Check that no property is already defined in one of the
+ // ancestors
+ Set<String> alreadyExistPropsCollection = properties.stream().filter(p -> allParentsProps.contains(p.getName())).map(p -> p.getName()).collect(Collectors.toSet());
+ if (alreadyExistPropsCollection != null && alreadyExistPropsCollection.isEmpty() == false) {
+ List<String> duplicateProps = new ArrayList<>();
+ duplicateProps.addAll(alreadyExistPropsCollection);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR, dataType, duplicateProps);
+
+ return Either.right(responseFormat);
+ }
+
+ }
+ }
+ }
+ return Either.left(ActionStatus.OK);
+ }
+
+ private boolean isAbstract(String dataTypeName) {
+
+ ToscaPropertyType isPrimitiveToscaType = ToscaPropertyType.isValidType(dataTypeName);
+
+ return isPrimitiveToscaType != null && isPrimitiveToscaType.isAbstract() == true;
+
+ }
+
+ private boolean isScalarType(DataTypeDefinition dataTypeDef) {
+
+ boolean isScalar = false;
+ DataTypeDefinition dataType = dataTypeDef;
+
+ while (dataType != null) {
+
+ String name = dataType.getName();
+ if (ToscaPropertyType.isScalarType(name)) {
+ isScalar = true;
+ break;
+ }
+
+ dataType = dataType.getDerivedFrom();
+ }
+
+ return isScalar;
+ }
+
+ private DataTypeDefinition createDataType(String dataTypeName, Map<String, Object> toscaJson) {
+ DataTypeDefinition dataType = new DataTypeDefinition();
+
+ dataType.setName(dataTypeName);
+
+ if (toscaJson != null) {
+ // Description
+ final Consumer<String> descriptionSetter = description -> dataType.setDescription(description);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DESCRIPTION.getElementName(), descriptionSetter);
+ // Derived From
+ final Consumer<String> derivedFromSetter = derivedFrom -> dataType.setDerivedFromName(derivedFrom);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DERIVED_FROM.getElementName(), derivedFromSetter);
+ // Properties
+ commonImportManager.setProperties(toscaJson, (values) -> dataType.setProperties(values));
+
+ setConstraints(toscaJson, dataType);
+ }
+ return dataType;
+ }
+
+ private void setConstraints(Map<String, Object> toscaJson, DataTypeDefinition dataType) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java
new file mode 100644
index 0000000000..9d9425ea85
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java
@@ -0,0 +1,214 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.info.DistributionStatusInfo;
+import org.openecomp.sdc.be.info.DistributionStatusListResponse;
+import org.openecomp.sdc.be.info.DistributionStatusOfServiceInfo;
+import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+@Component("distributionMonitoringBusinessLogic")
+public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
+ private static final String DEPLOYED = "Deployed";
+
+ private static final String ERROR = "Error";
+
+ private static final String DISTRIBUTED = "Distributed";
+
+ private static final String IN_PROGRESS = "In Progress";
+
+ private static Logger log = LoggerFactory.getLogger(ArtifactsBusinessLogic.class.getName());
+
+ // @javax.annotation.Resource
+ // private AuditingDao auditingDao;
+
+ @Autowired
+ private AuditCassandraDao cassandraDao;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ public DistributionMonitoringBusinessLogic() {
+ }
+
+ public Either<DistributionStatusListResponse, ResponseFormat> getListOfDistributionStatus(String did, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get List Of Distribution Status", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ log.trace("getListOfDistributionStatus for did {}", did);
+ Either<List<DistributionStatusEvent>, ActionStatus> distributionStatus = cassandraDao.getListOfDistributionStatuses(did);
+ if (distributionStatus.isRight()) {
+ log.debug("not found distribution statuses for did {} status is {} ", did, distributionStatus.right().value());
+ return Either.right(componentsUtils.getResponseFormat(distributionStatus.right().value(), did));
+ }
+ List<DistributionStatusInfo> distribStatusInfoList = new ArrayList<DistributionStatusInfo>();
+ List<DistributionStatusEvent> distributionStatusEventList = distributionStatus.left().value();
+ if (distributionStatusEventList != null) {
+ for (ESTimeBasedEvent distributionStatusEvent : distributionStatusEventList) {
+ distribStatusInfoList.add(new DistributionStatusInfo(distributionStatusEvent));
+ }
+ }
+
+ DistributionStatusListResponse distributionStatusListResponse = new DistributionStatusListResponse();
+ distributionStatusListResponse.setDistributionStatusList(distribStatusInfoList);
+ log.trace("list statuses for did {} is {} ", did, distribStatusInfoList);
+ return Either.left(distributionStatusListResponse);
+ }
+
+ public Either<DistributionStatusOfServiceListResponce, ResponseFormat> getListOfDistributionServiceStatus(String serviceUuid, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get List Of Distribution Service Status", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ log.trace("getListOfDistributionServiceStatus for serviceUUID {}", serviceUuid);
+ Either<List<? extends AuditingGenericEvent>, ActionStatus> status = cassandraDao.getServiceDistributionStatusesList(serviceUuid);
+ if (status.isRight()) {
+ log.debug("failed to find service distribution statuses. error: {}", status);
+ return Either.right(componentsUtils.getResponseFormat(status.right().value(), serviceUuid));
+ }
+ List<DistributionStatusOfServiceInfo> distribStatusInfoList = new ArrayList<DistributionStatusOfServiceInfo>();
+ List<? extends AuditingGenericEvent> distributionStatusEventList = status.left().value();
+ distribStatusInfoList = handleAuditingDaoResponse(distributionStatusEventList);
+ DistributionStatusOfServiceListResponce distributionStatusListResponse = new DistributionStatusOfServiceListResponce();
+ distributionStatusListResponse.setDistributionStatusOfServiceList(distribStatusInfoList);
+ return Either.left(distributionStatusListResponse);
+ }
+
+ private List<DistributionStatusOfServiceInfo> handleAuditingDaoResponse(List<? extends AuditingGenericEvent> distribStatusInfoList) {
+ List<DistributionStatusOfServiceInfo> reslist = new ArrayList<DistributionStatusOfServiceInfo>();
+ Map<String, List<AuditingGenericEvent>> serviceDidMap = createServiceDidMap(distribStatusInfoList);
+ Set<String> didSet = serviceDidMap.keySet();
+ for (String did : didSet) {
+ DistributionStatusOfServiceInfo distributionStatusOfServiceInfo = new DistributionStatusOfServiceInfo();
+ distributionStatusOfServiceInfo.setDistributionID(did);
+ String dReguestStatus = "";
+ String dNotifyStatus = "";
+ boolean isResult = false;
+ List<? extends AuditingGenericEvent> auditingGenericEventList = serviceDidMap.get(did);
+ ESTimeBasedEvent resAuditingGenericEvent = null;
+ for (AuditingGenericEvent auditingGenericEvent : auditingGenericEventList) {
+ auditingGenericEvent.fillFields();
+
+ String action = (String) auditingGenericEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_ACTION.getDisplayName());
+ Object modifierUserId = auditingGenericEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID.getDisplayName());
+ if (modifierUserId != null) {
+ distributionStatusOfServiceInfo.setUserId((String) modifierUserId);
+ }
+
+ if (action.equals(AuditingActionEnum.DISTRIBUTION_DEPLOY.getName())) {
+
+ isResult = true;
+ resAuditingGenericEvent = auditingGenericEvent;
+ break;
+ } else if (action.equals(AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName())) {
+ dReguestStatus = getStatusFromAuditEvent(auditingGenericEvent);
+ } else if (action.equals(AuditingActionEnum.DISTRIBUTION_NOTIFY.getName())) {
+ dNotifyStatus = getStatusFromAuditEvent(auditingGenericEvent);
+ }
+
+ resAuditingGenericEvent = auditingGenericEvent;
+
+ }
+ distributionStatusOfServiceInfo.setTimestamp((String) resAuditingGenericEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP.getDisplayName()));
+
+ if (!isResult) {
+ if (dReguestStatus.equals(String.valueOf(HttpStatus.SC_OK))) {
+ if (dNotifyStatus.isEmpty()) {
+ distributionStatusOfServiceInfo.setDeployementStatus(IN_PROGRESS);
+
+ } else {
+ if (dNotifyStatus.equals(String.valueOf(HttpStatus.SC_OK)))
+ distributionStatusOfServiceInfo.setDeployementStatus(DISTRIBUTED);
+ else
+ distributionStatusOfServiceInfo.setDeployementStatus(ERROR);
+ }
+ } else
+ distributionStatusOfServiceInfo.setDeployementStatus(ERROR);
+ } else
+ distributionStatusOfServiceInfo.setDeployementStatus(DEPLOYED);
+ reslist.add(distributionStatusOfServiceInfo);
+ }
+
+ return reslist;
+ }
+
+ private String getStatusFromAuditEvent(ESTimeBasedEvent auditingGenericEvent) {
+ String status = "";
+ Object requestStatus = auditingGenericEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_STATUS.getDisplayName());
+ if (requestStatus instanceof String) {
+ status = (String) requestStatus;
+ }
+ return status;
+ }
+
+ private Map<String, List<AuditingGenericEvent>> createServiceDidMap(List<? extends AuditingGenericEvent> distribStatusInfoList) {
+
+ Map<String, List<AuditingGenericEvent>> serviceDidMap = new HashMap<String, List<AuditingGenericEvent>>();
+ for (AuditingGenericEvent auditingGenericEvent : distribStatusInfoList) {
+ List<AuditingGenericEvent> auditingGenericEventList = null;
+ String did = "";
+ auditingGenericEvent.fillFields();
+
+ Object didValue = auditingGenericEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID.getDisplayName());
+ if (didValue != null) {
+ did = (String) didValue;
+ }
+
+ if (!did.isEmpty()) {
+ if (serviceDidMap.containsKey(did)) {
+ auditingGenericEventList = serviceDidMap.get(did);
+ }
+ if (auditingGenericEventList == null) {
+ auditingGenericEventList = new ArrayList();
+
+ }
+ auditingGenericEventList.add(auditingGenericEvent);
+ serviceDidMap.put(did, auditingGenericEventList);
+ }
+ }
+ return serviceDidMap;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
new file mode 100644
index 0000000000..5ebb86f1ba
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
@@ -0,0 +1,1125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
+import org.openecomp.sdc.be.datamodel.utils.NodeTypeConvertUtils;
+import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Product;
+import org.openecomp.sdc.be.model.PropertyScope;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.Tag;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("elementsBusinessLogic")
+public class ElementBusinessLogic extends BaseBusinessLogic {
+
+ private static Logger log = LoggerFactory.getLogger(ElementBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private IElementOperation elementOperation;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ @javax.annotation.Resource
+ private UserBusinessLogic userAdminManager;
+
+ /**
+ *
+ * @param user
+ * @return
+ */
+ public Either<Map<String, List<? extends Component>>, ResponseFormat> getFollowed(User user) {
+ Either<Map<String, List<? extends Component>>, ResponseFormat> response = null;
+ // Getting the role
+ String role = user.getRole();
+ String userId = null;
+ Role currentRole = Role.valueOf(role);
+
+ switch (currentRole) {
+ case DESIGNER:
+ userId = user.getUserId();
+ response = handleDesigner(userId);
+ break;
+
+ case TESTER:
+ userId = user.getUserId();
+ response = handleTester(userId);
+ break;
+
+ case GOVERNOR:
+ userId = user.getUserId();
+ response = handleGovernor(userId);
+ break;
+
+ case OPS:
+ userId = user.getUserId();
+ response = handleOps(userId);
+ break;
+
+ case PRODUCT_STRATEGIST:
+ userId = user.getUserId();
+ response = handleProductStrategist(userId);
+ break;
+
+ case PRODUCT_MANAGER:
+ userId = user.getUserId();
+ response = handleProductManager(userId);
+ break;
+
+ case ADMIN:
+ response = handleAdmin();
+ break;
+
+ default:
+ response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ break;
+ }
+ return response;
+
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleAdmin() {
+ Either<Map<String, List<? extends Component>>, ResponseFormat> response;
+ // userId should stay null
+ Set<LifecycleStateEnum> lifecycleStates = new HashSet<LifecycleStateEnum>();
+ Set<LifecycleStateEnum> lastStateStates = new HashSet<LifecycleStateEnum>();
+ lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
+ response = getFollowedResourcesAndServices(null, lifecycleStates, lastStateStates);
+ return response;
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleDesigner(String userId) {
+ Set<LifecycleStateEnum> lifecycleStates = new HashSet<LifecycleStateEnum>();
+ Set<LifecycleStateEnum> lastStateStates = new HashSet<LifecycleStateEnum>();
+ Either<Map<String, List<? extends Component>>, ResponseFormat> response;
+ lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
+ // more states
+ lastStateStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ response = getFollowedResourcesAndServices(userId, lifecycleStates, lastStateStates);
+ return response;
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleGovernor(String userId) {
+ Either<Map<String, List<? extends Component>>, ResponseFormat> result = handleFollowedCertifiedServices(null);
+ return result;
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleProductStrategist(String userId) {
+ // Should be empty list according to Ella, 13/03/16
+ Map<String, List<? extends Component>> result = new HashMap<String, List<? extends Component>>();
+ result.put("products", new ArrayList<>());
+ return Either.left(result);
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleProductManager(String userId) {
+ Set<LifecycleStateEnum> lifecycleStates = new HashSet<LifecycleStateEnum>();
+ Set<LifecycleStateEnum> lastStateStates = new HashSet<LifecycleStateEnum>();
+ Either<Map<String, List<? extends Component>>, ResponseFormat> response;
+ lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
+ // more states
+ lastStateStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ response = getFollowedProducts(userId, lifecycleStates, lastStateStates);
+ return response;
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleOps(String userId) {
+ Set<DistributionStatusEnum> distStatus = new HashSet<DistributionStatusEnum>();
+ distStatus.add(DistributionStatusEnum.DISTRIBUTION_APPROVED);
+ distStatus.add(DistributionStatusEnum.DISTRIBUTED);
+
+ Either<Map<String, List<? extends Component>>, ResponseFormat> result = handleFollowedCertifiedServices(distStatus);
+ return result;
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleFollowedCertifiedServices(Set<DistributionStatusEnum> distStatus) {
+ Map<String, Object> propertiesToMatch = new HashMap<>();
+ propertiesToMatch.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.CERTIFIED.name());
+
+ Either<Set<Service>, StorageOperationStatus> services = serviceOperation.getCertifiedServicesWithDistStatus(propertiesToMatch, distStatus, false);
+ if (services.isLeft()) {
+ Map<String, List<? extends Component>> result = new HashMap<String, List<? extends Component>>();
+ List<Service> list = new ArrayList<>();
+ list.addAll(services.left().value());
+ result.put("services", list);
+ return Either.left(result);
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(services.right().value())));
+ }
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> handleTester(String userId) {
+ Set<LifecycleStateEnum> lifecycleStates = new HashSet<LifecycleStateEnum>();
+ lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ Either<List<Resource>, StorageOperationStatus> resources = resourceOperation.getTesterFollowed(userId, lifecycleStates, false);
+
+ if (resources.isLeft()) {
+ Either<List<Service>, StorageOperationStatus> services = serviceOperation.getTesterFollowed(userId, lifecycleStates, false);
+ if (services.isLeft()) {
+ Map<String, List<? extends Component>> result = new HashMap<String, List<? extends Component>>();
+ result.put("services", services.left().value());
+ result.put("resources", resources.left().value());
+ return Either.left(result);
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(services.right().value())));
+ }
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resources.right().value())));
+ }
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) {
+ Either<List<Resource>, StorageOperationStatus> resources = resourceOperation.getFollowed(userId, lifecycleStates, lastStateStates, false);
+
+ if (resources.isLeft()) {
+ Either<List<Service>, StorageOperationStatus> services = serviceOperation.getFollowed(userId, lifecycleStates, lastStateStates, false);
+ if (services.isLeft()) {
+ Map<String, List<? extends Component>> result = new HashMap<String, List<? extends Component>>();
+ result.put("services", services.left().value());
+ result.put("resources", resources.left().value());
+ return Either.left(result);
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(services.right().value())));
+ }
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resources.right().value())));
+ }
+ }
+
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> getFollowedProducts(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) {
+ Either<List<Product>, StorageOperationStatus> products = productOperation.getFollowed(userId, lifecycleStates, lastStateStates, false);
+ if (products.isLeft()) {
+ Map<String, List<? extends Component>> result = new HashMap<String, List<? extends Component>>();
+ result.put("products", products.left().value());
+ return Either.left(result);
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(products.right().value())));
+ }
+ }
+
+ /*
+ * New categories flow - start
+ */
+ public Either<List<CategoryDefinition>, ActionStatus> getAllResourceCategories() {
+ return elementOperation.getAllResourceCategories();
+ }
+
+ public Either<List<CategoryDefinition>, ActionStatus> getAllServiceCategories() {
+ return elementOperation.getAllServiceCategories();
+ }
+
+ public Either<CategoryDefinition, ResponseFormat> createCategory(CategoryDefinition category, String componentTypeParamName, String userId) {
+
+ AuditingActionEnum auditingAction = AuditingActionEnum.ADD_CATEGORY;
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ String componentType = (componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue());
+ CategoryTypeEnum categoryType = CategoryTypeEnum.CATEGORY;
+
+ User user = new User();
+ Either<User, ResponseFormat> validateUser = validateUser(userId);
+ if (validateUser.isRight()) {
+ log.debug("Validation of user failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUser.right().value();
+ user = new User();
+ user.setUserId(userId);
+ String currCategoryName = (category == null ? null : category.getName());
+ handleCategoryAuditing(responseFormat, user, currCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ user = validateUser.left().value();
+
+ if (category == null) {
+ log.debug("Category json is invalid");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, user, null, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ String categoryName = category.getName();
+ // For auditing of failures we need the original non-normalized name
+ String origCategoryName = categoryName;
+ if (componentTypeEnum == null) {
+ log.debug("Component type {} is invalid", componentTypeParamName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
+ if (validateUserRole.isRight()) {
+ log.debug("Validation of user role failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUserRole.right().value();
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ if (!ValidationUtils.validateCategoryDisplayNameFormat(categoryName)) {
+ log.debug("Category display name format is invalid, name {}, componentType {}", categoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ categoryName = ValidationUtils.normalizeCategoryName4Display(categoryName);
+
+ if (!ValidationUtils.validateCategoryDisplayNameLength(categoryName)) {
+ log.debug("Category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", categoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ category.setName(categoryName);
+
+ String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
+ category.setNormalizedName(normalizedName);
+
+ NodeTypeEnum nodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, categoryType);
+
+ Either<Boolean, ActionStatus> categoryUniqueEither = elementOperation.isCategoryUniqueForType(nodeType, normalizedName);
+ if (categoryUniqueEither.isRight()) {
+ log.debug("Failed to check category uniqueness, name {}, componentType {}", categoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(categoryUniqueEither.right().value());
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Boolean isCategoryUnique = categoryUniqueEither.left().value();
+ if (!isCategoryUnique) {
+ log.debug("Category is not unique, name {}, componentType {}", categoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<CategoryDefinition, ActionStatus> createCategoryByType = elementOperation.createCategory(category, nodeType);
+ if (createCategoryByType.isRight()) {
+ log.debug("Failed to create category, name {}, componentType {}", categoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
+ handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
+ return Either.right(componentsUtils.getResponseFormat(createCategoryByType.right().value()));
+ }
+ category = createCategoryByType.left().value();
+ log.debug("Created category for component {}, name {}, uniqueId {}", componentType, categoryName, category.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ handleCategoryAuditing(responseFormat, user, category.getName(), auditingAction, componentType);
+ return Either.left(category);
+ }
+
+ public Either<SubCategoryDefinition, ResponseFormat> createSubCategory(SubCategoryDefinition subCategory, String componentTypeParamName, String parentCategoryId, String userId) {
+
+ AuditingActionEnum auditingAction = AuditingActionEnum.ADD_SUB_CATEGORY;
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ String componentType = (componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue());
+ CategoryTypeEnum categoryType = CategoryTypeEnum.SUBCATEGORY;
+ // For auditing
+ String parentCategoryName = parentCategoryId;
+
+ if (subCategory == null) {
+ log.debug("Sub-category json is invalid");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, null, parentCategoryName, null, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ String subCategoryName = subCategory.getName();
+ // For auditing of failures we need the original non-normalized name
+ String origSubCategoryName = subCategoryName;
+
+ User user = new User();
+ /*
+ * if (userId == null) { user.setUserId("UNKNOWN"); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION); handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName,
+ * auditingAction, componentType); return Either.right(responseFormat); }
+ */
+ Either<User, ResponseFormat> validateUser = validateUserExists(userId, "createSubCategory", false);
+ if (validateUser.isRight()) {
+ log.debug("Validation of user failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUser.right().value();
+ user = new User();
+ user.setUserId(userId);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ user = validateUser.left().value();
+
+ if (componentTypeEnum == null) {
+ log.debug("Component type {} is invalid", componentTypeParamName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateComponentType = validateComponentTypeForCategory(componentTypeEnum, categoryType);
+ if (validateComponentType.isRight()) {
+ log.debug("Validation of component type for sub-category failed");
+ ResponseFormat responseFormat = validateComponentType.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
+ if (validateUserRole.isRight()) {
+ log.debug("Validation of user role failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUserRole.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ NodeTypeEnum parentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
+ NodeTypeEnum childNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
+
+ CategoryDefinition categoryDefinition;
+ Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(parentNodeType, parentCategoryId, componentTypeEnum);
+ if (validateCategoryExists.isRight()) {
+ log.debug("Validation of parent category exists failed, parent categoryId {}", parentCategoryId);
+ ResponseFormat responseFormat = validateCategoryExists.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ categoryDefinition = validateCategoryExists.left().value();
+ parentCategoryName = categoryDefinition.getName();
+
+ if (!ValidationUtils.validateCategoryDisplayNameFormat(subCategoryName)) {
+ log.debug("Sub-category display name format is invalid, name {}, componentType {}", subCategoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ subCategoryName = ValidationUtils.normalizeCategoryName4Display(subCategoryName);
+
+ if (!ValidationUtils.validateCategoryDisplayNameLength(subCategoryName)) {
+ log.debug("Sub-category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", subCategoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(subCategoryName);
+ subCategory.setNormalizedName(normalizedName);
+
+ // Uniqueness under this category
+ Either<Boolean, ActionStatus> subCategoryUniqueForCategory = elementOperation.isSubCategoryUniqueForCategory(childNodeType, normalizedName, parentCategoryId);
+ if (subCategoryUniqueForCategory.isRight()) {
+ log.debug("Failed to check sub-category uniqueness, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName, normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForCategory.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Boolean isSubUnique = subCategoryUniqueForCategory.left().value();
+ if (!isSubUnique) {
+ log.debug("Sub-category is not unique for category, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName, normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY, componentType, subCategoryName, parentCategoryName);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ // Setting name of subcategory to fit the similar subcategory name
+ // ignoring cases.
+ // For example if Network-->kUKU exists for service category Network,
+ // and user is trying to create Router-->Kuku for service category
+ // Router,
+ // his subcategory name will be Router-->kUKU.
+ Either<SubCategoryDefinition, ActionStatus> subCategoryUniqueForType = elementOperation.getSubCategoryUniqueForType(childNodeType, normalizedName);
+ if (subCategoryUniqueForType.isRight()) {
+ log.debug("Failed validation of whether similar sub-category exists, normalizedName {} componentType {}", normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForType.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+ SubCategoryDefinition subCategoryDefinition = subCategoryUniqueForType.left().value();
+ if (subCategoryDefinition != null) {
+ subCategoryName = subCategoryDefinition.getName();
+ }
+
+ subCategory.setName(subCategoryName);
+ ///////////////////////////////////////////// Validations end
+
+ Either<SubCategoryDefinition, ActionStatus> createSubCategory = elementOperation.createSubCategory(parentCategoryId, subCategory, childNodeType);
+ if (createSubCategory.isRight()) {
+ log.debug("Failed to create sub-category, name {}, componentType {}", subCategoryName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForType.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ SubCategoryDefinition subCategoryCreated = createSubCategory.left().value();
+ log.debug("Created sub-category for component {}, name {}, uniqueId {}", componentType, subCategoryName, subCategoryCreated.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, subCategoryCreated.getName(), auditingAction, componentType);
+ return Either.left(subCategoryCreated);
+ }
+
+ public Either<GroupingDefinition, ResponseFormat> createGrouping(GroupingDefinition grouping, String componentTypeParamName, String grandParentCategoryId, String parentSubCategoryId, String userId) {
+
+ AuditingActionEnum auditingAction = AuditingActionEnum.ADD_GROUPING;
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ String componentType = (componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue());
+ CategoryTypeEnum categoryType = CategoryTypeEnum.GROUPING;
+ // For auditing
+ String parentCategoryName = grandParentCategoryId;
+ String parentSubCategoryName = parentSubCategoryId;
+
+ User user;
+ Either<User, ResponseFormat> validateUser = validateUserExists(userId, "create Grouping", false);
+ if (validateUser.isRight()) {
+ log.debug("Validation of user failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUser.right().value();
+ user = new User();
+ user.setUserId(userId);
+ String groupingNameForAudit = (grouping == null ? null : grouping.getName());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ user = validateUser.left().value();
+
+ if (grouping == null) {
+ log.debug("Grouping json is invalid");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, null, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ String groupingName = grouping.getName();
+ // For auditing of failures we need the original non-normalized name
+ String origGroupingName = groupingName;
+
+ if (componentTypeEnum == null) {
+ log.debug("Component type {} is invalid", componentTypeParamName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateComponentType = validateComponentTypeForCategory(componentTypeEnum, categoryType);
+ if (validateComponentType.isRight()) {
+ log.debug("Validation of component type for grouping failed");
+ ResponseFormat responseFormat = validateComponentType.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
+ if (validateUserRole.isRight()) {
+ log.debug("Validation of user role failed, userId {}", userId);
+ ResponseFormat responseFormat = validateUserRole.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ NodeTypeEnum grandParentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
+ NodeTypeEnum parentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
+ NodeTypeEnum childNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.GROUPING);
+
+ // Validate category
+ CategoryDefinition categoryDefinition;
+ Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(grandParentNodeType, grandParentCategoryId, componentTypeEnum);
+ if (validateCategoryExists.isRight()) {
+ log.debug("Validation of parent category exists failed, parent categoryId {}", grandParentCategoryId);
+ ResponseFormat responseFormat = validateCategoryExists.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ categoryDefinition = validateCategoryExists.left().value();
+ parentCategoryName = categoryDefinition.getName();
+
+ // Validate subcategory
+ SubCategoryDefinition subCategoryDefinition;
+ Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists = validateSubCategoryExists(parentNodeType, parentSubCategoryId, componentTypeEnum);
+ if (validateSubCategoryExists.isRight()) {
+ log.debug("Validation of parent sub-category exists failed, parent sub-category id {}", parentSubCategoryId);
+ ResponseFormat responseFormat = validateSubCategoryExists.right().value();
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ subCategoryDefinition = validateSubCategoryExists.left().value();
+ parentSubCategoryName = subCategoryDefinition.getName();
+
+ if (!ValidationUtils.validateCategoryDisplayNameFormat(groupingName)) {
+ log.debug("Sub-category display name format is invalid, name {}, componentType {}", groupingName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ groupingName = ValidationUtils.normalizeCategoryName4Display(groupingName);
+
+ if (!ValidationUtils.validateCategoryDisplayNameLength(groupingName)) {
+ log.debug("Grouping display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", groupingName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(groupingName);
+ grouping.setNormalizedName(normalizedName);
+
+ // Uniqueness under this category
+ Either<Boolean, ActionStatus> groupingUniqueForSubCategory = elementOperation.isGroupingUniqueForSubCategory(childNodeType, normalizedName, parentSubCategoryId);
+ if (groupingUniqueForSubCategory.isRight()) {
+ log.debug("Failed to check grouping uniqueness, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName, normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(groupingUniqueForSubCategory.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ Boolean isGroupingUnique = groupingUniqueForSubCategory.left().value();
+ if (!isGroupingUnique) {
+ log.debug("Grouping is not unique for sub-category, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName, normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY, componentType, groupingName, parentSubCategoryName);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ // Setting name of grouping to fit the similar grouping name ignoring
+ // cases.
+ // For example if Network-->kUKU exists for service sub-category
+ // Network, and user is trying to create grouping Router-->Kuku for
+ // service sub-category Router,
+ // his grouping name will be Router-->kUKU.
+ Either<GroupingDefinition, ActionStatus> groupingUniqueForType = elementOperation.getGroupingUniqueForType(childNodeType, normalizedName);
+ if (groupingUniqueForType.isRight()) {
+ log.debug("Failed validation of whether similar grouping exists, normalizedName {} componentType {}", normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(groupingUniqueForType.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+ GroupingDefinition groupingDefinition = groupingUniqueForType.left().value();
+ if (groupingDefinition != null) {
+ groupingName = groupingDefinition.getName();
+ }
+
+ grouping.setName(groupingName);
+ ///////////////////////////////////////////// Validations end
+
+ Either<GroupingDefinition, ActionStatus> createGrouping = elementOperation.createGrouping(parentSubCategoryId, grouping, childNodeType);
+ if (createGrouping.isRight()) {
+ log.debug("Failed to create grouping, name {}, componentType {}", groupingName, componentType);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(createGrouping.right().value());
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
+ return Either.right(responseFormat);
+ }
+
+ GroupingDefinition groupingCreated = createGrouping.left().value();
+ log.debug("Created grouping for component {}, name {}, uniqueId {}", componentType, groupingName, groupingCreated.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingCreated.getName(), auditingAction, componentType);
+ return Either.left(groupingCreated);
+ }
+
+ public Either<List<CategoryDefinition>, ResponseFormat> getAllCategories(String componentType, String userId) {
+ AuditingActionEnum auditingAction = AuditingActionEnum.GET_CATEGORY_HIERARCHY;
+ ResponseFormat responseFormat;
+ User user = new User();
+ if (userId == null) {
+ user.setUserId("UNKNOWN");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ componentsUtils.auditGetCategoryHierarchy(auditingAction, user, componentType, responseFormat);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ResponseFormat> validateUser = validateUserExists(userId, "get All Categories", false);
+ if (validateUser.isRight()) {
+ user.setUserId(userId);
+ log.debug("Validation of user failed, userId {}", userId);
+ responseFormat = validateUser.right().value();
+ componentsUtils.auditGetCategoryHierarchy(auditingAction, user, componentType, responseFormat);
+ return Either.right(responseFormat);
+ }
+ user = validateUser.left().value();
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum == null) {
+ log.debug("Cannot create category for component type {}", componentType);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, "component type");
+ componentsUtils.auditGetCategoryHierarchy(auditingAction, user, componentType, responseFormat);
+ return Either.right(responseFormat);
+ }
+
+ NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
+ Either<List<CategoryDefinition>, ActionStatus> getAllCategoriesByType = elementOperation.getAllCategories(nodeTypeEnum, false);
+ if (getAllCategoriesByType.isRight()) {
+ responseFormat = componentsUtils.getResponseFormat(getAllCategoriesByType.right().value());
+ componentsUtils.auditGetCategoryHierarchy(auditingAction, user, componentType, responseFormat);
+ return Either.right(responseFormat);
+ }
+ List<CategoryDefinition> categories = getAllCategoriesByType.left().value();
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ componentsUtils.auditGetCategoryHierarchy(auditingAction, user, componentType, responseFormat);
+ return Either.left(categories);
+ }
+
+ public Either<CategoryDefinition, ResponseFormat> deleteCategory(String categoryId, String componentTypeParamName, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Category", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ if (componentTypeEnum == null) {
+ log.debug("Cannot create category for component type {}", componentTypeParamName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
+
+ Either<CategoryDefinition, ActionStatus> deleteCategoryByType = elementOperation.deleteCategory(nodeTypeEnum, categoryId);
+ if (deleteCategoryByType.isRight()) {
+ // auditing, logging here...
+ return Either.right(componentsUtils.getResponseFormat(deleteCategoryByType.right().value()));
+ }
+ CategoryDefinition category = deleteCategoryByType.left().value();
+ log.debug("Delete category for component {}, name {}, uniqueId {}", nodeTypeEnum, category.getName(), category.getUniqueId());
+ return Either.left(category);
+ }
+
+ public Either<SubCategoryDefinition, ResponseFormat> deleteSubCategory(String grandParentCategoryId, String parentSubCategoryId, String componentTypeParamName, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Sub Category", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ if (componentTypeEnum == null) {
+ log.debug("Cannot delete sub-category for component type {}", componentTypeParamName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
+
+ Either<SubCategoryDefinition, ActionStatus> deleteSubCategoryByType = elementOperation.deleteSubCategory(nodeTypeEnum, parentSubCategoryId);
+ if (deleteSubCategoryByType.isRight()) {
+ // auditing, logging here...
+ return Either.right(componentsUtils.getResponseFormat(deleteSubCategoryByType.right().value()));
+ }
+ SubCategoryDefinition subCategory = deleteSubCategoryByType.left().value();
+ log.debug("Deleted sub-category for component {}, name {}, uniqueId {}", nodeTypeEnum, subCategory.getName(), subCategory.getUniqueId());
+ return Either.left(subCategory);
+ }
+
+ public Either<GroupingDefinition, ResponseFormat> deleteGrouping(String grandParentCategoryId, String parentSubCategoryId, String groupingId, String componentTypeParamName, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Grouping", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
+ if (componentTypeEnum == null) {
+ log.debug("Cannot delete grouping for component type {}", componentTypeParamName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.GROUPING);
+
+ Either<GroupingDefinition, ActionStatus> deleteGroupingByType = elementOperation.deleteGrouping(nodeTypeEnum, groupingId);
+ if (deleteGroupingByType.isRight()) {
+ // auditing, logging here...
+ return Either.right(componentsUtils.getResponseFormat(deleteGroupingByType.right().value()));
+ }
+ GroupingDefinition deletedGrouping = deleteGroupingByType.left().value();
+ log.debug("Deleted grouping for component {}, name {}, uniqueId {}", nodeTypeEnum, deletedGrouping.getName(), deletedGrouping.getUniqueId());
+ return Either.left(deletedGrouping);
+ }
+
+ private Either<User, ResponseFormat> validateUser(String userId) {
+
+ // validate user exists
+ if (userId == null) {
+ log.debug("User id is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION));
+ }
+
+ Either<User, ActionStatus> userResult = userAdminManager.getUser(userId, false);
+ if (userResult.isRight()) {
+ ResponseFormat responseFormat;
+ if (userResult.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ log.debug("Not authorized user, userId = {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ } else {
+ log.debug("Failed to authorize user, userId = {}", userId);
+ responseFormat = componentsUtils.getResponseFormat(userResult.right().value());
+ }
+
+ return Either.right(responseFormat);
+ }
+ return Either.left(userResult.left().value());
+ // ========================================-
+ }
+
+ private Either<Boolean, ResponseFormat> validateUserRole(User user, ComponentTypeEnum componentTypeEnum) {
+ String role = user.getRole();
+ boolean validAdminAction = (role.equals(Role.ADMIN.name()) && (componentTypeEnum == ComponentTypeEnum.SERVICE || componentTypeEnum == ComponentTypeEnum.RESOURCE));
+ boolean validProductAction = (role.equals(Role.PRODUCT_STRATEGIST.name()) && (componentTypeEnum == ComponentTypeEnum.PRODUCT));
+
+ if (!(validAdminAction || validProductAction)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("User not permitted to perform operation on category, userId = {}, role = {}, componentType = {}", user.getUserId(), role, componentTypeEnum);
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateComponentTypeForCategory(ComponentTypeEnum componentType, CategoryTypeEnum categoryType) {
+ boolean validResourceAction = (componentType == ComponentTypeEnum.RESOURCE && (categoryType == CategoryTypeEnum.CATEGORY || categoryType == CategoryTypeEnum.SUBCATEGORY));
+ boolean validServiceAction = (componentType == ComponentTypeEnum.SERVICE && categoryType == CategoryTypeEnum.CATEGORY);
+ boolean validProductAction = (componentType == ComponentTypeEnum.PRODUCT); // can
+ // be
+ // any
+ // category
+ // type
+
+ if (!(validResourceAction || validServiceAction || validProductAction)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ log.debug("It's not allowed to create category type {} for component type {}", categoryType, componentType);
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ }
+
+ private Either<CategoryDefinition, ResponseFormat> validateCategoryExists(NodeTypeEnum nodeType, String categoryId, ComponentTypeEnum componentType) {
+ Either<CategoryDefinition, ActionStatus> categoryByTypeAndId = elementOperation.getCategory(nodeType, categoryId);
+ if (categoryByTypeAndId.isRight()) {
+ log.debug("Failed to fetch parent category, parent categoryId {}", categoryId);
+ ActionStatus actionStatus = categoryByTypeAndId.right().value();
+ ResponseFormat responseFormat;
+ if (actionStatus == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND) {
+ responseFormat = componentsUtils.getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.CATEGORY.getValue(), "");
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(actionStatus);
+ }
+ return Either.right(responseFormat);
+ }
+ return Either.left(categoryByTypeAndId.left().value());
+ }
+
+ private Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists(NodeTypeEnum nodeType, String subCategoryId, ComponentTypeEnum componentType) {
+ Either<SubCategoryDefinition, ActionStatus> subCategoryByTypeAndId = elementOperation.getSubCategory(nodeType, subCategoryId);
+ if (subCategoryByTypeAndId.isRight()) {
+ log.debug("Failed to fetch parent category, parent categoryId {}", subCategoryId);
+ ActionStatus actionStatus = subCategoryByTypeAndId.right().value();
+ ResponseFormat responseFormat;
+ if (actionStatus == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND) {
+ responseFormat = componentsUtils.getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.SUBCATEGORY.getValue(), "");
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(actionStatus);
+ }
+ return Either.right(responseFormat);
+ }
+ return Either.left(subCategoryByTypeAndId.left().value());
+ }
+
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, AuditingActionEnum auditingAction, String componentType) {
+ componentsUtils.auditCategory(responseFormat, user, category, null, null, auditingAction, componentType);
+ }
+
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory, AuditingActionEnum auditingAction, String componentType) {
+ componentsUtils.auditCategory(responseFormat, user, category, subCategory, null, auditingAction, componentType);
+ }
+
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory, String grouping, AuditingActionEnum auditingAction, String componentType) {
+ componentsUtils.auditCategory(responseFormat, user, category, subCategory, grouping, auditingAction, componentType);
+ }
+
+ /*
+ * New categories flow - end
+ */
+
+ public Either<List<Tag>, ActionStatus> getAllTags(String userId) {
+ Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Tags");
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ return elementOperation.getAllTags();
+ }
+
+ public Either<List<PropertyScope>, ActionStatus> getAllPropertyScopes(String userId) {
+ Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Property Scopes");
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ return elementOperation.getAllPropertyScopes();
+ }
+
+ public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes(String userId) {
+ Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Artifact Types");
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ return elementOperation.getAllArtifactTypes();
+ }
+
+ public Either<Map<String, Object>, ActionStatus> getAllDeploymentArtifactTypes() {
+ return elementOperation.getAllDeploymentArtifactTypes();
+ }
+
+ public Either<Integer, ActionStatus> getDefaultHeatTimeout() {
+ return elementOperation.getDefaultHeatTimeout();
+ }
+
+ public Either<Map<String, List<? extends Component>>, ResponseFormat> getCatalogComponents(String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Catalog Components", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Map<String, List<? extends Component>> resMap = new HashMap<>();
+
+ Either<List<Resource>, StorageOperationStatus> resResources = resourceOperation.getResourceCatalogData(false);
+ if (resResources.isLeft()) {
+ Either<List<Service>, StorageOperationStatus> resServices = serviceOperation.getServiceCatalogData(false);
+ if (resServices.isLeft()) {
+ Either<List<Product>, StorageOperationStatus> resProducts = productOperation.getProductCatalogData(false);
+ if (resProducts.isLeft()) {
+ resMap.put("resources", resResources.left().value());
+ resMap.put("services", resServices.left().value());
+ resMap.put("products", resProducts.left().value());
+ return Either.left(resMap);
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resProducts.right().value())));
+ }
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resServices.right().value())));
+ }
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resResources.right().value())));
+ }
+ }
+
+ public Either<List<? extends Component>, ResponseFormat> getFilteredCatalogComponents(String assetType, Map<FilterKeyEnum, String> filters, String query) {
+ ComponentTypeEnum assetTypeEnum = AssetTypeEnum.convertToComponentTypeEnum(assetType);
+
+ if (query != null) {
+ Optional<NameValuePair> invalidFilter = findInvalidFilter(query, assetTypeEnum);
+ if (invalidFilter.isPresent()) {
+ log.debug("getFilteredAssetList: invalid filter key");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_FILTER_KEY, invalidFilter.get().getName(), FilterKeyEnum.getValidFiltersByAssetType(assetTypeEnum).toString()));
+ }
+ }
+
+ if (filters == null || filters.isEmpty()) {
+ return getCatalogComponentsByAssetType(assetTypeEnum);
+ }
+
+ ComponentOperation componentOperation = getComponentOperation(assetTypeEnum);
+ Either<List<Component>, StorageOperationStatus> result = componentOperation.getFilteredComponents(filters, false);
+
+ if (result.isRight()) {// category hierarchy mismatch or
+ // category/subCategory/distributionStatus not
+ // found
+ List<String> params = getErrorResponseParams(filters, assetTypeEnum);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2)));
+ }
+ if (result.left().value().isEmpty()) {// no assets found for requested
+ // criteria
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.NO_ASSETS_FOUND, assetType, query));
+ }
+ return Either.left(result.left().value());
+ }
+
+ public Either<List<? extends Component>, ResponseFormat> getCatalogComponentsByAssetType(ComponentTypeEnum assetTypeEnum) {
+
+ if (assetTypeEnum == null) {
+ log.debug("getCatalogComponentsByAssetType: Corresponding ComponentTypeEnum not found");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ switch (assetTypeEnum) {
+ case RESOURCE:
+
+ Either<List<Resource>, StorageOperationStatus> resourceCatalogData = resourceOperation.getResourceCatalogDataVFLatestCertifiedAndNonCertified(false);
+ if (resourceCatalogData.isLeft()) {
+ log.debug("getCatalogComponentsByAssetType: Resource fetching successful");
+ return Either.left(resourceCatalogData.left().value());
+ } else {
+ log.debug("getCatalogComponentsByAssetType: Resource fetching failed");
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceCatalogData.right().value())));
+ }
+
+ case SERVICE:
+ Either<List<Service>, StorageOperationStatus> serviceCatalogData = serviceOperation.getServiceCatalogDataLatestCertifiedAndNotCertified(false);
+ if (serviceCatalogData.isLeft()) {
+ log.debug("getCatalogComponentsByAssetType: Service fetching successful");
+ return Either.left(serviceCatalogData.left().value());
+ } else {
+ log.debug("getCatalogComponentsByAssetType: Service fetching failed");
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceCatalogData.right().value())));
+ }
+ /*
+ * case PRODUCT: Either<List<Product>, StorageOperationStatus> resCatalogData = productOperation.getProductCatalogData(false); if(resCatalogData.isLeft()){ log. debug("getCatalogComponentsByAssetType: Product fetching successful" );
+ * return Either.left(resCatalogData.left().value()); }else { log. debug("getCatalogComponentsByAssetType: Product fetching failed" ); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(
+ * resCatalogData.right().value()))); }
+ */
+ default:
+ log.debug("Invalid Asset Type");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+
+ // TODO new story Tal
+ public Either<List<? extends Component>, ResponseFormat> getCatalogComponentsByUuidAndAssetType(String assetType, String uuid) {
+
+ if (assetType == null || assetType == null) {
+ log.debug("getCatalogComponentsByUuidAndAssetType: One of the function parameteres is null");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ ComponentTypeEnum assetTypeEnum = AssetTypeEnum.convertToComponentTypeEnum(assetType);
+
+ if (assetTypeEnum == null) {
+ log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not found");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ switch (assetTypeEnum) {
+
+ case RESOURCE:
+ Either<List<Resource>, StorageOperationStatus> resourceListByUuid = resourceOperation.getLatestResourceByUuid(uuid, false);
+
+ if (resourceListByUuid.isLeft()) {
+ log.debug("getCatalogComponentsByUuidAndAssetType: Resource fetching successful");
+ return Either.left(resourceListByUuid.left().value());
+ }
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(resourceListByUuid.right().value());
+ log.debug("getCatalogComponentsByUuidAndAssetType: Resource fetching failed");
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+
+ case SERVICE:
+ Either<List<Service>, StorageOperationStatus> serviceCatalogData = serviceOperation.getLatestServiceByUuid(uuid, false);
+
+ if (serviceCatalogData.isLeft()) {
+ log.debug("getCatalogComponentsByUuidAndAssetType: Service fetching successful");
+ return Either.left(serviceCatalogData.left().value());
+ }
+
+ log.debug("getCatalogComponentsByUuidAndAssetType: Service fetching failed");
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceCatalogData.right().value())));
+ // case Product is for future US
+ /*
+ * case PRODUCT: Either<List<Product>, StorageOperationStatus> resCatalogData = productOperation.getProductCatalogData(false); if(resCatalogData.isLeft()){ log. debug("getCatalogComponentsByAssetType: Product fetching successful" ); return
+ * Either.left(resCatalogData.left().value()); }else { log. debug("getCatalogComponentsByAssetType: Product fetching failed" ); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(
+ * resCatalogData.right().value()))); }
+ */
+ default:
+ log.debug("Invalid Asset Type");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+
+ public List<String> getAllComponentTypesParamNames() {
+ List<String> paramNames = new ArrayList<>();
+ paramNames.add(ComponentTypeEnum.SERVICE_PARAM_NAME);
+ paramNames.add(ComponentTypeEnum.RESOURCE_PARAM_NAME);
+ paramNames.add(ComponentTypeEnum.PRODUCT_PARAM_NAME);
+ return paramNames;
+ }
+
+ public List<String> getAllSupportedRoles() {
+ Role[] values = Role.values();
+ List<String> roleNames = new ArrayList<>();
+ for (Role role : values) {
+ roleNames.add(role.name());
+ }
+ return roleNames;
+ }
+
+ public Either<Map<String, String>, ActionStatus> getResourceTypesMap() {
+ return elementOperation.getResourceTypesMap();
+ }
+
+ private Optional<NameValuePair> findInvalidFilter(String query, ComponentTypeEnum assetType) {
+ List<NameValuePair> params = URLEncodedUtils.parse(query, StandardCharsets.UTF_8);
+ List<String> validKeys = FilterKeyEnum.getValidFiltersByAssetType(assetType);
+ Predicate<NameValuePair> noMatch = p -> !validKeys.contains(p.getName());
+ return params.stream().filter(noMatch).findAny();
+ }
+
+ private List<String> getErrorResponseParams(Map<FilterKeyEnum, String> filters, ComponentTypeEnum assetType) {
+ List<String> params = new ArrayList<String>();
+ if (1 == filters.size()) {
+ params.add(assetType.getValue().toLowerCase());
+ params.add(filters.keySet().iterator().next().getName());
+ params.add(filters.values().iterator().next());
+ } else {
+ params.add(assetType.getValue());
+ params.add(filters.get(FilterKeyEnum.SUB_CATEGORY));
+ params.add(filters.get(FilterKeyEnum.CATEGORY));
+ }
+ return params;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
new file mode 100644
index 0000000000..3b4528d3a3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
@@ -0,0 +1,1512 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.apache.commons.io.FilenameUtils;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.info.ArtifactDefinitionInfo;
+import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
+import org.openecomp.sdc.be.info.GroupDefinitionInfo;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("groupBusinessLogic")
+public class GroupBusinessLogic extends BaseBusinessLogic {
+
+ public static String INITIAL_VERSION = "1";
+
+ private static final String CREATE_GROUP = "CreateGroup";
+
+ private static final String UPDATE_GROUP = "UpdateGroup";
+
+ private static final String GET_GROUP = "GetGroup";
+
+ private static Logger log = LoggerFactory.getLogger(GroupBusinessLogic.class.getName());
+
+ public GroupBusinessLogic() {
+
+ }
+
+ @javax.annotation.Resource
+ private GroupTypeOperation groupTypeOperation;
+
+ @javax.annotation.Resource
+ private GroupOperation groupOperation;
+
+ /**
+ *
+ * 1. validate user exist
+ *
+ * 2. validate component can be edited
+ *
+ * 3. verify group not already exist
+ *
+ * 4. verify type of group exist
+ *
+ * 5. verify Component instances exist under the component
+ *
+ * 6. verify the component instances type are allowed according to the member types in the group type
+ *
+ * 7. verify the artifacts belongs to the component
+ *
+ * @param componentId
+ * @param userId
+ * @param componentType
+ * @param groupDefinition
+ * @param inTransaction
+ * @return
+ */
+ public Either<GroupDefinition, ResponseFormat> createGroup(String componentId, String userId, ComponentTypeEnum componentType, GroupDefinition groupDefinition, boolean inTransaction) {
+
+ Either<GroupDefinition, ResponseFormat> result = null;
+
+ try {
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, CREATE_GROUP, inTransaction);
+
+ if (validateUserExists.isRight()) {
+ result = Either.right(validateUserExists.right().value());
+ return result;
+ }
+
+ User user = validateUserExists.left().value();
+ // 5. check service/resource existence
+ // 6. check service/resource check out
+ // 7. user is owner of checkout state
+ org.openecomp.sdc.be.model.Component component = null;
+
+ // String realComponentId = componentType ==
+ // ComponentTypeEnum.RESOURCE_INSTANCE ? parentId : componentId;
+ String realComponentId = componentId;
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreComponentInstances(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(realComponentId, componentType, componentParametersView, userId, null, user);
+
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ result = this.createGroup(component, user, componentType, groupDefinition, inTransaction);
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+ }
+
+ private String getComponentTypeForResponse(org.openecomp.sdc.be.model.Component component) {
+ String componentTypeForResponse = "SERVICE";
+ if (component instanceof Resource) {
+ componentTypeForResponse = ((Resource) component).getResourceType().name();
+ }
+ return componentTypeForResponse;
+ }
+
+ /**
+ * Verify that the artifact members belongs to the component
+ *
+ * @param component
+ * @param artifacts
+ * @return
+ */
+ private Either<Boolean, ResponseFormat> verifyArtifactsBelongsToComponent(Component component, List<String> artifacts, String context) {
+
+ if (artifacts == null || true == artifacts.isEmpty()) {
+ return Either.left(true);
+ }
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
+ if (deploymentArtifacts == null || true == deploymentArtifacts.isEmpty()) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(context, "No deployment artifact found under component " + component.getNormalizedName(), ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ List<String> currentArtifacts = deploymentArtifacts.values().stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
+ log.debug("The deployment artifacts of component {} are {}", component.getNormalizedName(), deploymentArtifacts);
+ if (false == currentArtifacts.containsAll(artifacts)) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(context, "Not all artifacts belongs to component " + component.getNormalizedName(), ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return Either.left(true);
+
+ }
+
+ /**
+ * Verify that the artifact members belongs to the component
+ *
+ * @param component
+ * @param artifacts
+ * @return
+ */
+ private Either<List<ArtifactDefinition>, ResponseFormat> getArtifactsBelongsToComponent(Component component, List<String> artifacts, String context) {
+
+ /*
+ * if (artifacts == null || true == artifacts.isEmpty()) { return Either.left(true); }
+ */
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
+ if (deploymentArtifacts == null || true == deploymentArtifacts.isEmpty()) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(context, "No deployment artifact found under component " + component.getNormalizedName(), ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ List<ArtifactDefinition> resultList = new ArrayList();
+
+ for (String artifactId : artifacts) {
+ Optional<ArtifactDefinition> groupArtifactOp = deploymentArtifacts.values().stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny();
+
+ if (groupArtifactOp.isPresent()) {
+ ArtifactDefinition groupArtifact = groupArtifactOp.get();
+ resultList.add(groupArtifact);
+ } else {
+ BeEcompErrorManager.getInstance().logInvalidInputError(context, "Not all artifacts belongs to component " + component.getNormalizedName(), ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+
+ }
+ }
+
+ return Either.left(resultList);
+
+ }
+
+ /**
+ * verify that the members are component instances of the component
+ *
+ * @param component
+ * @param componentType
+ * @param groupMembers
+ * @param memberToscaTypes
+ * @return
+ */
+ private Either<Boolean, ResponseFormat> verifyComponentInstancesAreValidMembers(Component component, ComponentTypeEnum componentType, String groupName, String groupType, Map<String, String> groupMembers, List<String> memberToscaTypes) {
+
+ if (groupMembers == null || true == groupMembers.isEmpty()) {
+ return Either.left(true);
+ }
+
+ if (memberToscaTypes == null || true == memberToscaTypes.isEmpty()) {
+ return Either.left(true);
+ }
+
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ if (componentInstances != null && false == componentInstances.isEmpty()) {
+ Map<String, ComponentInstance> compInstUidToCompInstMap = componentInstances.stream().collect(Collectors.toMap(p -> p.getUniqueId(), p -> p));
+
+ Set<String> allCompInstances = compInstUidToCompInstMap.keySet();
+
+ for (Entry<String, String> groupMember : groupMembers.entrySet()) {
+ String compName = groupMember.getKey();
+ String compUid = groupMember.getValue();
+
+ if (false == allCompInstances.contains(compUid)) {
+ /*
+ * %1 - member name %2 - group name %3 - VF name %4 - component type [VF ]
+ */
+ String componentTypeForResponse = getComponentTypeForResponse(component);
+
+ BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_GROUP, "Not all group members exists under the component", ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, compName, groupName, component.getNormalizedName(), componentTypeForResponse));
+ }
+ }
+
+ ComponentOperation componentOperation = getComponentOperationByParentComponentType(componentType);
+ if (componentOperation instanceof ResourceOperation) {
+ ResourceOperation resourceOperation = (ResourceOperation) componentOperation;
+
+ for (Entry<String, String> groupMember : groupMembers.entrySet()) {
+
+ String componentInstName = groupMember.getKey();
+ String componentInstUid = groupMember.getValue();
+
+ ComponentInstance componentInstance = compInstUidToCompInstMap.get(componentInstUid);
+ String componentUid = componentInstance.getComponentUid();
+ List<String> componentToscaNames = new ArrayList<>();
+ TitanOperationStatus status = resourceOperation.fillResourceDerivedListFromGraph(componentUid, componentToscaNames);
+ if (status != TitanOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logInternalFlowError(CREATE_GROUP, "Cannot find tosca list of component id " + componentUid, ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ log.debug("The tosca names of component id {} are {}", componentUid, memberToscaTypes);
+
+ boolean found = false;
+ for (String memberToscaType : memberToscaTypes) {
+ if (componentToscaNames.contains(memberToscaType)) {
+ found = true;
+ break;
+ }
+ }
+ if (found == false) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_GROUP,
+ "No tosca types from " + memberToscaTypes + " can be found in the tosca list " + componentToscaNames + " of component " + componentInstance.getNormalizedName(), ErrorSeverity.INFO);
+ /*
+ * # %1 - member name # %2 - group name # %3 - group type
+ */
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_INVALID_TOSCA_NAME_OF_COMPONENT_INSTANCE, componentInstName, groupName, groupType));
+ } else {
+ log.debug("Component instance {} fits to one of the required tosca types", componentInstance.getNormalizedName());
+ }
+ }
+ } else {
+ BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_GROUP, "Cannot find tosca list since it is not supported for product", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ return Either.left(true);
+ }
+
+ public ComponentOperation getComponentOperation(NodeTypeEnum componentType) {
+
+ switch (componentType) {
+ case Service:
+ case ResourceInstance:
+ return serviceOperation;
+ case Resource:
+ return resourceOperation;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Update specific group version
+ *
+ * @param groupDefinition
+ * @param inTransaction
+ * @return
+ */
+ public Either<GroupDefinition, StorageOperationStatus> updateGroupVersion(GroupDefinition groupDefinition, boolean inTransaction) {
+ Either<GroupDefinition, StorageOperationStatus> result = null;
+ List<String> groupIdsToUpdateVersion = new ArrayList<>();
+ groupIdsToUpdateVersion.add(groupDefinition.getUniqueId());
+ Either<List<GroupDefinition>, StorageOperationStatus> updateGroupVersion = updateGroupVersion(groupIdsToUpdateVersion, inTransaction);
+ if (updateGroupVersion.isLeft()) {
+ result = Either.left(updateGroupVersion.left().value().get(0));
+ } else {
+ log.debug("Failed to update group version. Status is {} ", updateGroupVersion.right().value());
+ result = Either.right(updateGroupVersion.right().value());
+ }
+ return result;
+ }
+
+ /**
+ * Update list of groups versions
+ *
+ * @param groupsUniqueId
+ * @param inTransaction
+ * @return
+ */
+ public Either<List<GroupDefinition>, StorageOperationStatus> updateGroupVersion(List<String> groupsUniqueId, boolean inTransaction) {
+
+ Either<List<GroupDefinition>, StorageOperationStatus> result = null;
+
+ try {
+
+ result = groupOperation.updateGroupVersion(groupsUniqueId, true);
+
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Update GroupDefinition metadata
+ *
+ * @param componentId
+ * @param user
+ * @param groupId
+ * @param componentType
+ * @param groupUpdate
+ * @param inTransaction
+ * @return
+ */
+ public Either<GroupDefinition, ResponseFormat> updateGroupMetadata(String componentId, User user, String groupUniqueId, ComponentTypeEnum componentType, GroupDefinition groupUpdate, boolean inTransaction) {
+
+ Either<GroupDefinition, ResponseFormat> result = null;
+
+ // Validate user and validate group belongs to component
+ List<GroupDefinition> groups = new ArrayList<>();
+ groups.add(groupUpdate);
+ Either<Component, ResponseFormat> validateGroupsBeforeUpdate = validateGroupsBeforeUpdate(componentId, user.getUserId(), componentType, groups, inTransaction);
+ if (validateGroupsBeforeUpdate.isRight()) {
+ result = Either.right(validateGroupsBeforeUpdate.right().value());
+ return result;
+ }
+ Component component = validateGroupsBeforeUpdate.left().value();
+
+ // Get the GroupDefinition object
+ Either<GroupDefinition, StorageOperationStatus> groupStatus = groupOperation.getGroup(groupUniqueId);
+ if (groupStatus.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(groupStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
+ }
+ GroupDefinition currentGroup = groupStatus.left().value();
+
+ // Validate group type is vfModule
+ if (!currentGroup.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ log.error("Group update metadata: Group type is different then: {}", Constants.DEFAULT_GROUP_VF_MODULE);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_TYPE, groupUpdate.getType());
+ return Either.right(responseFormat);
+ }
+
+ Either<GroupDefinition, ResponseFormat> validationRsponse = validateAndUpdateGroupMetadata(currentGroup, groupUpdate);
+ if (validationRsponse.isRight()) {
+ log.info("Group update metadata: validations field.");
+ return validationRsponse;
+ }
+ GroupDefinition groupToUpdate = validationRsponse.left().value();
+
+ // lock resource
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(componentId, component, "Update GroupDefinition Metadata");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+ try {
+ Either<GroupDefinition, StorageOperationStatus> updateResponse = groupOperation.updateGroupName(groupUniqueId, groupUpdate.getName(), inTransaction);
+ if (updateResponse.isRight()) {
+ titanGenericDao.rollback();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Update GroupDefinition Metadata");
+ BeEcompErrorManager.getInstance().logBeSystemError("Update GroupDefinition Metadata");
+ log.debug("failed to update sevice {}", groupToUpdate.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ titanGenericDao.commit();
+ return Either.left(updateResponse.left().value());
+ } finally {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+ }
+
+ /**
+ * Validate and update GroupDefinition metadata
+ *
+ * @param user
+ * @param currentGroup
+ * @param groupUpdate
+ * @return
+ */
+ private Either<GroupDefinition, ResponseFormat> validateAndUpdateGroupMetadata(GroupDefinition currentGroup, GroupDefinition groupUpdate) {
+ // Check if to update, and update GroupDefinition name.
+ Either<Boolean, ResponseFormat> response = validateAndUpdateGroupName(currentGroup, groupUpdate);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ // Do not allow to update GroupDefinition version directly.
+ String versionUpdated = groupUpdate.getVersion();
+ String versionCurrent = currentGroup.getVersion();
+ if (versionUpdated != null && !versionCurrent.equals(versionUpdated)) {
+ log.info("update Group: recived request to update version to {} the field is not updatable ignoring.", versionUpdated);
+ }
+
+ return Either.left(currentGroup);
+ }
+
+ /**
+ * Validate and update GroupDefinition name
+ *
+ * @param user
+ * @param currentGroup
+ * @param groupUpdate
+ * @return
+ */
+ private Either<Boolean, ResponseFormat> validateAndUpdateGroupName(GroupDefinition currentGroup, GroupDefinition groupUpdate) {
+ String nameUpdated = groupUpdate.getName();
+ String nameCurrent = currentGroup.getName();
+ if (!nameCurrent.equals(nameUpdated)) {
+ Either<Boolean, ResponseFormat> validatNameResponse = validateGroupName(currentGroup.getName(), groupUpdate.getName());
+ if (validatNameResponse.isRight()) {
+ ResponseFormat errorRespons = validatNameResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentGroup.setName(groupUpdate.getName());
+ }
+ return Either.left(true);
+ }
+
+ /**
+ * Validate that group name to update is valid (same as current group name except for middle part). For example: Current group name: MyResource..MyDesc..Module-1 Group to update: MyResource..MyDesc2..Module-1 Verify that only the second part
+ * MyDesc was changed.
+ *
+ * @param currentGroupName
+ * @param groupUpdateName
+ * @return
+ */
+ private Either<Boolean, ResponseFormat> validateGroupName(String currentGroupName, String groupUpdateName) {
+ try {
+ // Check if the group name is in old format.
+ if (Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(groupUpdateName).matches()) {
+ log.error("Group name {} is in old format", groupUpdateName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME, groupUpdateName));
+ }
+
+ // Check that name pats 1 and 3 did not changed (only the second
+ // part can be changed)
+ // But verify before that the current group format is the new one
+ if (!Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(currentGroupName).matches()) {
+ String[] split1 = currentGroupName.split("\\.\\.");
+ String currentResourceName = split1[0];
+ String currentCounter = split1[2];
+
+ String[] split2 = groupUpdateName.split("\\.\\.");
+ String groupUpdateResourceName = split2[0];
+ String groupUpdateCounter = split2[2];
+
+ if (!currentResourceName.equals(groupUpdateResourceName)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentResourceName));
+ }
+
+ if (!currentCounter.equals(groupUpdateCounter)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentCounter));
+ }
+ }
+
+ return Either.left(true);
+ } catch (Exception e) {
+ log.error("Error valiadting group name", e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+
+ /**
+ * associate artifacts to a given group
+ *
+ * @param componentId
+ * @param userId
+ * @param componentType
+ * @param groups
+ * @param shouldLockComp
+ * @param inTransaction
+ * @return
+ */
+ public Either<List<GroupDefinition>, ResponseFormat> associateArtifactsToGroup(String componentId, String userId, ComponentTypeEnum componentType, List<GroupDefinition> groups, boolean shouldLockComp, boolean inTransaction) {
+
+ Either<List<GroupDefinition>, ResponseFormat> result = null;
+
+ if (shouldLockComp == true && inTransaction == true) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("dissociateArtifactsFromGroup", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
+ // Cannot lock component since we are in a middle of another
+ // transaction.
+ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+ }
+
+ Component component = null;
+ try {
+
+ if (groups == null || groups.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.OK));
+ }
+
+ Either<Component, ResponseFormat> validateGroupsBeforeUpdate = validateGroupsBeforeUpdate(componentId, userId, componentType, groups, inTransaction);
+ if (validateGroupsBeforeUpdate.isRight()) {
+ result = Either.right(validateGroupsBeforeUpdate.right().value());
+ return result;
+ }
+
+ component = validateGroupsBeforeUpdate.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "Group - Associate Artifacts");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ List<GroupDefinition> updatedGroups = new ArrayList<>();
+
+ List<GroupDefinition> componentGroups = component.getGroups();
+
+ // per group, associate to it the artifacts
+ for (GroupDefinition groupDefinition : groups) {
+
+ GroupDefinition componentGroup = componentGroups.stream().filter(p -> p.getUniqueId().equals(groupDefinition.getUniqueId())).findFirst().orElse(null);
+ if (componentGroup != null) {
+ List<String> componentArtifacts = componentGroup.getArtifacts();
+ int artifactsSizeInGroup = componentArtifacts == null ? 0 : componentArtifacts.size();
+ if (artifactsSizeInGroup > 0) {
+ List<String> artifactsToAssociate = groupDefinition.getArtifacts();
+
+ // if no artifcats sent
+ if (artifactsToAssociate == null || true == artifactsToAssociate.isEmpty()) {
+ continue;
+ }
+
+ boolean isChanged = componentArtifacts.removeAll(artifactsToAssociate);
+ if (isChanged) {// I.e. At least one artifact is already
+ // associated to the group
+ log.debug("Some of the artifacts already associated to group {}", groupDefinition.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_ARTIFACT_ALREADY_ASSOCIATED, componentGroup.getName()));
+ }
+ }
+ }
+
+ Either<GroupDefinition, StorageOperationStatus> associateArtifactsToGroup = groupOperation.associateArtifactsToGroup(groupDefinition.getUniqueId(), groupDefinition.getArtifacts(), true);
+
+ if (associateArtifactsToGroup.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(associateArtifactsToGroup.right().value());
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ log.debug("Failed to update group {} under component {}, error: {}", groupDefinition.getName(), component.getNormalizedName(), actionStatus.name());
+ return result;
+ }
+ updatedGroups.add(associateArtifactsToGroup.left().value());
+
+ }
+
+ result = Either.left(updatedGroups);
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+ }
+
+ public Either<List<GroupDefinition>, ResponseFormat> associateMembersToGroup(String componentId, String userId, ComponentTypeEnum componentType, List<GroupDefinition> groups, boolean shouldLockComp, boolean inTransaction) {
+
+ Either<List<GroupDefinition>, ResponseFormat> result = null;
+
+ if (shouldLockComp == true && inTransaction == true) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("dissociateArtifactsFromGroup", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
+ // Cannot lock component since we are in a middle of another
+ // transaction.
+ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+ }
+
+ Component component = null;
+ try {
+
+ if (groups == null || groups.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.OK));
+ }
+
+ Either<Component, ResponseFormat> validateGroupsBeforeUpdate = validateGroupsBeforeUpdate(componentId, userId, componentType, groups, inTransaction);
+ if (validateGroupsBeforeUpdate.isRight()) {
+ result = Either.right(validateGroupsBeforeUpdate.right().value());
+ return result;
+ }
+
+ component = validateGroupsBeforeUpdate.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "Group - Associate Members");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ List<GroupDefinition> updatedGroups = new ArrayList<>();
+
+ // per group, associate to it the members
+ for (GroupDefinition groupDefinition : groups) {
+
+ Either<GroupDefinition, StorageOperationStatus> associateMembersToGroup = groupOperation.associateMembersToGroup(groupDefinition.getUniqueId(), groupDefinition.getMembers(), true);
+
+ if (associateMembersToGroup.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(associateMembersToGroup.right().value());
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ log.debug("Failed to update group {} under component {}, error: {}", groupDefinition.getName(), component.getNormalizedName(), actionStatus.name());
+ return result;
+ } else {
+ updatedGroups.add(associateMembersToGroup.left().value());
+ }
+
+ }
+
+ result = Either.left(updatedGroups);
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+ }
+
+ /**
+ * associate artifacts to a given group
+ *
+ * @param componentId
+ * @param userId
+ * @param componentType
+ * @param groups
+ * @param shouldLockComp
+ * @param inTransaction
+ * @return
+ */
+ public Either<GroupDefinitionInfo, ResponseFormat> getGroupWithArtifactsById(ComponentTypeEnum componentType, String componentId, String groupId, String userId, boolean inTransaction) {
+
+ Either<GroupDefinitionInfo, ResponseFormat> result = null;
+
+ // Validate user exist
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, UPDATE_GROUP, true);
+
+ if (validateUserExists.isRight()) {
+ result = Either.right(validateUserExists.right().value());
+ return result;
+ }
+
+ User user = validateUserExists.left().value();
+
+ // Validate component exist
+ org.openecomp.sdc.be.model.Component component = null;
+ String realComponentId = componentId;
+
+ try {
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreComponentInstances(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(realComponentId, componentType, componentParametersView, userId, null, user);
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+
+ // validate we can work on component
+ /*
+ * Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent( component, userId); if (canWork.isRight()) { result = Either.right(canWork.right().value()); return result; }
+ */
+ List<GroupDefinition> groups = component.getGroups();
+ Optional<GroupDefinition> findAny = groups.stream().filter(p -> p.getUniqueId().equals(groupId)).findAny();
+ if (findAny.isPresent()) {
+ GroupDefinition group = findAny.get();
+ Boolean isBase = null;// Constants.IS_BASE;
+ List<GroupProperty> props = group.getProperties();
+ if (props != null && !props.isEmpty()) {
+ Optional<GroupProperty> isBasePropOp = props.stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
+ if (isBasePropOp.isPresent()) {
+ GroupProperty propIsBase = isBasePropOp.get();
+ isBase = Boolean.parseBoolean(propIsBase.getValue());
+
+ } else {
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "failed to find prop isBase " + component.getNormalizedName(), ErrorSeverity.INFO);
+ // return
+ // Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+
+ }
+ }
+
+ List<ArtifactDefinitionInfo> artifacts = new ArrayList();
+ List<String> artifactsIds = group.getArtifacts();
+ if (artifactsIds != null && !artifactsIds.isEmpty()) {
+ Either<List<ArtifactDefinition>, ResponseFormat> getArtifacts = getArtifactsBelongsToComponent(component, artifactsIds, GET_GROUP);
+ if (getArtifacts.isRight()) {
+ log.debug("Faild to find artifacts in group {} under component {}", groupId, component.getUniqueId());
+ // result = Either.right(getArtifacts.right().value());
+ // return result;
+ } else {
+
+ List<ArtifactDefinition> artifactsFromComponent = getArtifacts.left().value();
+ if (artifactsFromComponent != null && !artifactsFromComponent.isEmpty()) {
+ for (ArtifactDefinition artifactDefinition : artifactsFromComponent) {
+ ArtifactDefinitionInfo artifactDefinitionInfo = new ArtifactDefinitionInfo(artifactDefinition);
+ artifacts.add(artifactDefinitionInfo);
+ }
+ }
+ }
+ }
+ GroupDefinitionInfo resultInfo = new GroupDefinitionInfo(group);
+ resultInfo.setIsBase(isBase);
+ if (!artifacts.isEmpty())
+ resultInfo.setArtifacts(artifacts);
+
+ result = Either.left(resultInfo);
+
+ return result;
+
+ } else {
+ log.debug("Faild to find group {} under component {}", groupId, component.getUniqueId());
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "group " + groupId + " not found under component " + component.getUniqueId(), ErrorSeverity.INFO);
+ String componentTypeForResponse = getComponentTypeForResponse(component);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_IS_MISSING, groupId, component.getSystemName(), componentTypeForResponse));
+ return result;
+
+ }
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+
+ }
+
+ /**
+ * @param componentId
+ * @param userId
+ * @param componentType
+ * @param groups
+ * @param inTransaction
+ * @return
+ */
+ private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateGroupsBeforeUpdate(String componentId, String userId, ComponentTypeEnum componentType, List<GroupDefinition> groups, boolean inTransaction) {
+
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> result;
+
+ // Validate user exist
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, UPDATE_GROUP, inTransaction);
+ if (validateUserExists.isRight()) {
+ result = Either.right(validateUserExists.right().value());
+ return result;
+ }
+ User user = validateUserExists.left().value();
+
+ // Validate component exist
+ String realComponentId = componentId;
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreComponentInstances(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(realComponentId, componentType, componentParametersView, userId, null, user);
+
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ org.openecomp.sdc.be.model.Component component = validateComponent.left().value();
+
+ // validate we can work on component
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ // Validate groups exists in the component
+ ResponseFormat validateGroupsInComponent = validateGroupsInComponentByFunc(groups, component, p -> p.getUniqueId());
+ if (validateGroupsInComponent != null) {
+ result = Either.right(validateGroupsInComponent);
+ return result;
+ }
+
+ Set<String> artifacts = new HashSet<>();
+ groups.forEach(p -> {
+ if (p.getArtifacts() != null) {
+ artifacts.addAll(p.getArtifacts());
+ }
+ });
+ // validate all artifacts belongs to the component
+ Either<Boolean, ResponseFormat> verifyArtifactsBelongsToComponent = verifyArtifactsBelongsToComponent(component, new ArrayList<>(artifacts), UPDATE_GROUP);
+ if (verifyArtifactsBelongsToComponent.isRight()) {
+ result = Either.right(verifyArtifactsBelongsToComponent.right().value());
+ return result;
+ }
+
+ return Either.left(component);
+ }
+
+ private ResponseFormat validateGroupsInComponent(List<GroupDefinition> groups, org.openecomp.sdc.be.model.Component component) {
+
+ Function<GroupDefinition, String> getByName = s -> s.getName();
+
+ return validateGroupsInComponentByFunc(groups, component, getByName);
+
+ }
+
+ /**
+ * @param groups
+ * @param component
+ * @param getByParam
+ * - the method to fetch the key of the GroupDefinition(from groups) in order to compare to groups in the component
+ * @return
+ */
+ private ResponseFormat validateGroupsInComponentByFunc(List<GroupDefinition> groups, org.openecomp.sdc.be.model.Component component, Function<GroupDefinition, String> getByParam) {
+ ResponseFormat result = null;
+
+ List<GroupDefinition> currentGroups = component.getGroups();
+
+ boolean found = false;
+ List<String> updatedGroupsName = groups.stream().map(getByParam).collect(Collectors.toList());
+
+ List<String> missingGroupNames = updatedGroupsName;
+
+ if (currentGroups != null && false == currentGroups.isEmpty()) {
+ List<String> currentGroupsName = currentGroups.stream().map(getByParam).collect(Collectors.toList());
+
+ if (currentGroupsName.containsAll(updatedGroupsName)) {
+ found = true;
+ } else {
+ currentGroupsName.removeAll(currentGroupsName);
+ missingGroupNames = currentGroupsName;
+ }
+ }
+ if (false == found) {
+ String componentTypeForResponse = getComponentTypeForResponse(component);
+ String listOfGroups = getAsString(missingGroupNames);
+ result = componentsUtils.getResponseFormat(ActionStatus.GROUP_IS_MISSING, listOfGroups, component.getSystemName(), componentTypeForResponse);
+ return result;
+ }
+
+ return null;
+ }
+
+ public String getAsString(List<String> list) {
+
+ if (list == null || list.isEmpty()) {
+ return "";
+ }
+ StringBuilder builder = new StringBuilder();
+ list.forEach(p -> builder.append(p + ","));
+
+ String result = builder.toString();
+ return result.substring(0, result.length());
+
+ }
+
+ /**
+ * dissociate artifacts from a given group
+ *
+ * @param componentId
+ * @param userId
+ * @param componentType
+ * @param groups
+ * @param shouldLockComp
+ * @param inTransaction
+ * @return
+ */
+ public Either<List<GroupDefinition>, ResponseFormat> dissociateArtifactsFromGroup(String componentId, String userId, ComponentTypeEnum componentType, List<GroupDefinition> groups, boolean shouldLockComp, boolean inTransaction) {
+
+ Either<List<GroupDefinition>, ResponseFormat> result = null;
+
+ if (shouldLockComp == true && inTransaction == true) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("dissociateArtifactsFromGroup", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
+ // Cannot lock component since we are in a middle of another
+ // transaction.
+ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+ }
+
+ Component component = null;
+
+ try {
+
+ if (groups == null || groups.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.OK));
+ }
+
+ Either<Component, ResponseFormat> validateGroupsBeforeUpdate = validateGroupsBeforeUpdate(componentId, userId, componentType, groups, inTransaction);
+ if (validateGroupsBeforeUpdate.isRight()) {
+ result = Either.right(validateGroupsBeforeUpdate.right().value());
+ return result;
+ }
+
+ component = validateGroupsBeforeUpdate.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "Group - Dissociate Artifacts");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ List<GroupDefinition> updatedGroups = new ArrayList<>();
+
+ List<GroupDefinition> componentGroups = component.getGroups();
+ // per group, associate to it the artifacts
+ for (GroupDefinition groupDefinition : groups) {
+
+ GroupDefinition componentGroup = componentGroups.stream().filter(p -> p.getUniqueId().equals(groupDefinition.getUniqueId())).findFirst().orElse(null);
+ if (componentGroup != null) {
+ List<String> componentArtifacts = componentGroup.getArtifacts();
+ int artifactsSizeInGroup = componentArtifacts == null ? 0 : componentArtifacts.size();
+ List<String> artifactsToDissociate = groupDefinition.getArtifacts();
+
+ // if no artifcats sent
+ if (artifactsToDissociate == null || true == artifactsToDissociate.isEmpty()) {
+ continue;
+ }
+
+ if (artifactsSizeInGroup > 0) {
+
+ boolean containsAll = componentArtifacts.containsAll(artifactsToDissociate);
+ if (false == containsAll) { // At least one artifact is
+ // not associated to the
+ // group
+ log.debug("Some of the artifacts already dissociated to group {}", groupDefinition.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_ARTIFACT_ALREADY_DISSOCIATED, componentGroup.getName()));
+ }
+ } else {
+ if (artifactsSizeInGroup == 0) {
+ if (artifactsToDissociate != null && false == artifactsToDissociate.isEmpty()) {
+ log.debug("No artifact is found under the group {}", groupDefinition.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_ARTIFACT_ALREADY_DISSOCIATED, componentGroup.getName()));
+ }
+ }
+ }
+ }
+
+ Either<GroupDefinition, StorageOperationStatus> associateArtifactsToGroup = groupOperation.dissociateArtifactsFromGroup(groupDefinition.getUniqueId(), groupDefinition.getArtifacts(), true);
+
+ if (associateArtifactsToGroup.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(associateArtifactsToGroup.right().value());
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ log.debug("Failed to update group {} under component {}, error: {}", groupDefinition.getName(), component.getNormalizedName(), actionStatus.name());
+ return result;
+ }
+ updatedGroups.add(associateArtifactsToGroup.left().value());
+
+ }
+
+ result = Either.left(updatedGroups);
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+
+ }
+
+ public Either<List<GroupDefinition>, ResponseFormat> createGroups(String componentId, String userId, ComponentTypeEnum componentType, List<GroupDefinition> groupDefinitions, boolean shouldLockComp, boolean inTransaction) {
+
+ Either<List<GroupDefinition>, ResponseFormat> result = null;
+
+ List<GroupDefinition> groups = new ArrayList<>();
+ org.openecomp.sdc.be.model.Component component = null;
+ try {
+
+ if (groupDefinitions != null && false == groupDefinitions.isEmpty()) {
+
+ if (shouldLockComp == true && inTransaction == true) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("createGroups", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
+ // Cannot lock component since we are in a middle of another
+ // transaction.
+ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+ }
+
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, CREATE_GROUP, true);
+ if (validateUserExists.isRight()) {
+ result = Either.right(validateUserExists.right().value());
+ return result;
+ }
+
+ User user = validateUserExists.left().value();
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreComponentInstances(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView, userId, null, user);
+
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "CreateGroups");
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ for (GroupDefinition groupDefinition : groupDefinitions) {
+ Either<GroupDefinition, ResponseFormat> createGroup = this.createGroup(component, user, componentType, groupDefinition, true);
+ if (createGroup.isRight()) {
+ log.debug("Failed to create group {}.", groupDefinition);
+ result = Either.right(createGroup.right().value());
+ return result;
+ }
+ GroupDefinition createdGroup = createGroup.left().value();
+ groups.add(createdGroup);
+ }
+ }
+
+ result = Either.left(groups);
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+
+ }
+
+ public Either<GroupDefinition, ResponseFormat> createGroup(Component component, User user, ComponentTypeEnum componentType, GroupDefinition groupDefinition, boolean inTransaction) {
+
+ Either<GroupDefinition, ResponseFormat> result = null;
+
+ log.debug("Going to create group {}", groupDefinition);
+
+ try {
+
+ // 3. verify group not already exist
+ List<GroupDefinition> groups = component.getGroups();
+ boolean found = false;
+ if (groups != null && false == groups.isEmpty()) {
+
+ GroupDefinition existGroupDef = groups.stream().filter(p -> p.getName().equalsIgnoreCase(groupDefinition.getName())).findFirst().orElse(null);
+
+ found = existGroupDef != null;
+ }
+
+ if (true == found) {
+ String componentTypeForResponse = getComponentTypeForResponse(component);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_ALREADY_EXIST, groupDefinition.getName(), component.getNormalizedName(), componentTypeForResponse));
+ return result;
+ }
+
+ // 4. verify type of group exist
+ String groupType = groupDefinition.getType();
+ if (groupType == null || groupType.isEmpty()) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupDefinition.getName()));
+ return result;
+ }
+ Either<GroupTypeDefinition, StorageOperationStatus> getGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType, true);
+ if (getGroupType.isRight()) {
+ StorageOperationStatus status = getGroupType.right().value();
+ if (status == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_GROUP, "group type " + groupType + " cannot be found", ErrorSeverity.INFO);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_TYPE_IS_INVALID, groupType));
+ return result;
+ } else {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+ }
+
+ // 6. verify the component instances type are allowed according to
+ // the member types in the group type
+ GroupTypeDefinition groupTypeDefinition = getGroupType.left().value();
+
+ Either<Boolean, ResponseFormat> areValidMembers = verifyComponentInstancesAreValidMembers(component, componentType, groupDefinition.getName(), groupType, groupDefinition.getMembers(), groupTypeDefinition.getMembers());
+
+ if (areValidMembers.isRight()) {
+ ResponseFormat responseFormat = areValidMembers.right().value();
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ // 7. verify the artifacts belongs to the component
+ Either<Boolean, ResponseFormat> areValidArtifacts = verifyArtifactsBelongsToComponent(component, groupDefinition.getArtifacts(), CREATE_GROUP);
+ if (areValidArtifacts.isRight()) {
+ ResponseFormat responseFormat = areValidArtifacts.right().value();
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ NodeTypeEnum nodeTypeEnum = componentType.getNodeType();
+
+ // add invariantUUID
+ String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
+ groupDefinition.setInvariantUUID(invariantUUID);
+
+ // add groupUUID
+ String groupUUID = UniqueIdBuilder.generateUUID();
+ groupDefinition.setGroupUUID(groupUUID);
+
+ // add version
+ groupDefinition.setVersion(INITIAL_VERSION);
+
+ // set groupType uid
+ groupDefinition.setTypeUid(groupTypeDefinition.getUniqueId());
+
+ Either<GroupDefinition, StorageOperationStatus> addGroupToGraph = groupOperation.addGroup(nodeTypeEnum, component.getUniqueId(), groupDefinition, true);
+
+ if (addGroupToGraph.isRight()) {
+ StorageOperationStatus storageOperationStatus = addGroupToGraph.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus);
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ log.debug("Failed to create group {} under component {}, error: {}", groupDefinition.getName(), component.getNormalizedName(), actionStatus.name());
+ } else {
+ GroupDefinition groupDefinitionCreated = addGroupToGraph.left().value();
+ result = Either.left(groupDefinitionCreated);
+ }
+
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+
+ }
+
+ public Either<List<GroupDefinition>, ResponseFormat> updateVfModuleGroupNames(String resourceSystemName, List<GroupDefinition> groups, boolean inTransaction) {
+ List<GroupDefinition> updatedGroups = new ArrayList<>();
+ Either<List<GroupDefinition>, ResponseFormat> updateGroupNamesRes = Either.left(updatedGroups);
+ Either<GroupDefinition, StorageOperationStatus> updateGroupNameRes;
+ Either<String, ResponseFormat> validateGenerateGroupNameRes;
+ int counter;
+ for (GroupDefinition group : groups) {
+ if (!group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && !Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(group.getName()).matches()) {
+ continue;
+ }
+ counter = Integer.parseInt(group.getName().split(Constants.MODULE_NAME_DELIMITER)[1]);
+ validateGenerateGroupNameRes = validateGenerateVfModuleGroupName(resourceSystemName, group.getDescription(), counter);
+ if (validateGenerateGroupNameRes.isRight()) {
+ updateGroupNamesRes = Either.right(validateGenerateGroupNameRes.right().value());
+ break;
+ }
+ updateGroupNameRes = groupOperation.updateGroupName(group.getUniqueId(), validateGenerateGroupNameRes.left().value(), inTransaction);
+ if (updateGroupNameRes.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(updateGroupNameRes.right().value());
+ updateGroupNamesRes = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ break;
+ }
+ updatedGroups.add(updateGroupNameRes.left().value());
+ }
+ return updateGroupNamesRes;
+ }
+
+ public Either<Boolean, ResponseFormat> validateGenerateVfModuleGroupNames(List<ArtifactTemplateInfo> allGroups, String resourceSystemName, int startGroupCounter) {
+ Either<Boolean, ResponseFormat> validateGenerateGroupNamesRes = Either.left(true);
+ Collections.sort(allGroups, (art1, art2) -> ArtifactTemplateInfo.compareByGroupName(art1, art2));
+ for (ArtifactTemplateInfo group : allGroups) {
+ Either<String, ResponseFormat> validateGenerateGroupNameRes = validateGenerateVfModuleGroupName(resourceSystemName, group.getDescription(), startGroupCounter++);
+ if (validateGenerateGroupNameRes.isRight()) {
+ validateGenerateGroupNamesRes = Either.right(validateGenerateGroupNameRes.right().value());
+ break;
+ }
+ group.setGroupName(validateGenerateGroupNameRes.left().value());
+ }
+ return validateGenerateGroupNamesRes;
+ }
+
+ /**
+ * Generate module name from resourceName, description and counter
+ *
+ * @param resourceSystemName
+ * @param description
+ * @param groupCounter
+ * @return
+ */
+ private Either<String, ResponseFormat> validateGenerateVfModuleGroupName(String resourceSystemName, String description, int groupCounter) {
+ Either<String, ResponseFormat> validateGenerateGroupNameRes;
+ if (resourceSystemName != null && description != null && Pattern.compile(Constants.MODULE_DESC_PATTERN).matcher(description).matches()) {
+ final String fileName = description.replaceAll("\\.\\.", "\\.");
+ validateGenerateGroupNameRes = Either.left(String.format(Constants.MODULE_NAME_FORMAT, resourceSystemName, FilenameUtils.removeExtension(fileName), groupCounter));
+ } else {
+ validateGenerateGroupNameRes = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME));
+ }
+ return validateGenerateGroupNameRes;
+ }
+
+ public Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNames(Map<String, GroupDefinition> groups, String resourceSystemName) {
+
+ Map<String, GroupDefinition> updatedNamesGroups = new HashMap<>();
+ Either<Map<String, GroupDefinition>, ResponseFormat> result = Either.left(updatedNamesGroups);
+ for (Entry<String, GroupDefinition> groupEntry : groups.entrySet()) {
+ GroupDefinition curGroup = groupEntry.getValue();
+ String groupType = curGroup.getType();
+ String groupName = groupEntry.getKey();
+ int counter;
+ String description;
+ Either<String, ResponseFormat> newGroupNameRes;
+ if (groupType.equals(Constants.DEFAULT_GROUP_VF_MODULE) && !Pattern.compile(Constants.MODULE_NEW_NAME_PATTERN).matcher(groupName).matches()) {
+
+ if (Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(groupEntry.getKey()).matches()) {
+ counter = Integer.parseInt(groupEntry.getKey().split(Constants.MODULE_NAME_DELIMITER)[1]);
+ description = curGroup.getDescription();
+ } else {
+ counter = getNextVfModuleNameCounter(updatedNamesGroups);
+ description = groupName;
+ }
+ newGroupNameRes = validateGenerateVfModuleGroupName(resourceSystemName, description, counter);
+ if (newGroupNameRes.isRight()) {
+ log.debug("Failed to generate new vf module group name. Status is {} ", newGroupNameRes.right().value());
+ result = Either.right(newGroupNameRes.right().value());
+ break;
+ }
+ groupName = newGroupNameRes.left().value();
+ curGroup.setName(groupName);
+ }
+ updatedNamesGroups.put(groupName, curGroup);
+ }
+ return result;
+ }
+
+ public int getNextVfModuleNameCounter(Map<String, GroupDefinition> groups) {
+ int counter = 0;
+ if (groups != null && !groups.isEmpty()) {
+ counter = getNextVfModuleNameCounter(groups.values());
+ }
+ return counter;
+ }
+
+ public int getNextVfModuleNameCounter(Collection<GroupDefinition> groups) {
+ int counter = 0;
+ if (groups != null && !groups.isEmpty()) {
+ List<Integer> counters = groups.stream().filter(group -> Pattern.compile(Constants.MODULE_NEW_NAME_PATTERN).matcher(group.getName()).matches() || Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(group.getName()).matches())
+ .map(group -> Integer.parseInt(group.getName().split(Constants.MODULE_NAME_DELIMITER)[1])).collect(Collectors.toList());
+ counter = (counters == null || counters.isEmpty()) ? 0 : counters.stream().max((a, b) -> Integer.compare(a, b)).get() + 1;
+ }
+ return counter;
+ }
+
+ public Either<List<GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesOnGraph(List<GroupDefinition> groups, String resourceSystemName, boolean inTransaction) {
+ List<GroupDefinition> updatedGroups = new ArrayList<>();
+ Either<List<GroupDefinition>, ResponseFormat> result = Either.left(updatedGroups);
+
+ for (GroupDefinition group : groups) {
+ String groupType = group.getType();
+ String oldGroupName = group.getName();
+ String newGroupName;
+ Either<String, ResponseFormat> newGroupNameRes;
+ Either<GroupDefinition, StorageOperationStatus> updateGroupNameRes;
+ int counter;
+ if (groupType.equals(Constants.DEFAULT_GROUP_VF_MODULE) && Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(oldGroupName).matches()) {
+ counter = Integer.parseInt(group.getName().split(Constants.MODULE_NAME_DELIMITER)[1]);
+ newGroupNameRes = validateGenerateVfModuleGroupName(resourceSystemName, group.getDescription(), counter);
+ if (newGroupNameRes.isRight()) {
+ log.debug("Failed to generate new vf module group name. Status is {} ", newGroupNameRes.right().value());
+ result = Either.right(newGroupNameRes.right().value());
+ break;
+ }
+ newGroupName = newGroupNameRes.left().value();
+ updateGroupNameRes = groupOperation.updateGroupName(group.getUniqueId(), newGroupName, inTransaction);
+ if (updateGroupNameRes.isRight()) {
+ log.debug("Failed to update vf module group name for group {} . Status is {} ", oldGroupName, updateGroupNameRes.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateGroupNameRes.right().value()));
+ result = Either.right(responseFormat);
+ break;
+ }
+ }
+ updatedGroups.add(group);
+ }
+ return result;
+ }
+
+ public Either<List<GroupDefinition>, ResponseFormat> createGroups(Component component, User user, ComponentTypeEnum componentType, List<GroupDefinition> groupDefinitions, boolean inTransaction) {
+
+ List<GroupDefinition> generatedGroups = new ArrayList<>();
+ Either<List<GroupDefinition>, ResponseFormat> result = Either.left(generatedGroups);
+
+ try {
+
+ if (groupDefinitions != null && false == groupDefinitions.isEmpty()) {
+ for (GroupDefinition groupDefinition : groupDefinitions) {
+ Either<GroupDefinition, ResponseFormat> createGroup = this.createGroup(component, user, componentType, groupDefinition, true);
+ if (createGroup.isRight()) {
+ result = Either.right(createGroup.right().value());
+ return result;
+ }
+ GroupDefinition generatedGroup = createGroup.left().value();
+ generatedGroups.add(generatedGroup);
+ }
+ }
+
+ return result;
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
new file mode 100644
index 0000000000..3dee3839b1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("groupTypeImportManager")
+public class GroupTypeImportManager {
+
+ public static void main(String[] args) {
+
+ List<PropertyDefinition> properties = new ArrayList<>();
+ PropertyDefinition propertyDefintion = new PropertyDefinition();
+ propertyDefintion.setName("aaa");
+ properties.add(propertyDefintion);
+
+ List<String> allParentsProps = new ArrayList<>();
+ allParentsProps.add("aaa");
+ allParentsProps.add("bbb");
+
+ Set<String> alreadyExistPropsCollection = properties.stream().filter(p -> allParentsProps.contains(p.getName())).map(p -> p.getName()).collect(Collectors.toSet());
+ System.out.println(alreadyExistPropsCollection);
+
+ }
+
+ private static Logger log = LoggerFactory.getLogger(GroupTypeImportManager.class.getName());
+ @Resource
+ private PropertyOperation propertyOperation;
+ @Resource
+ private IGroupTypeOperation groupTypeOperation;
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private IResourceOperation resourceOperation;
+
+ @Resource
+ private CommonImportManager commonImportManager;
+
+ public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(String groupTypesYml) {
+ return commonImportManager.createElementTypes(groupTypesYml, elementTypeYml -> createGroupTypesFromYml(elementTypeYml), groupTypesList -> createGroupTypesByDao(groupTypesList), ElementTypeEnum.GroupType);
+ }
+
+ private Either<List<GroupTypeDefinition>, ActionStatus> createGroupTypesFromYml(String groupTypesYml) {
+
+ return commonImportManager.createElementTypesFromYml(groupTypesYml, (groupTypeName, groupTypeJsonData) -> createGroupType(groupTypeName, groupTypeJsonData));
+ }
+
+ private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypesByDao(List<GroupTypeDefinition> groupTypesToCreate) {
+ return commonImportManager.createElementTypesByDao(groupTypesToCreate, groupType -> validateGroupType(groupType), groupType -> new ImmutablePair<>(ElementTypeEnum.GroupType, groupType.getType()),
+ groupTypeName -> groupTypeOperation.getLatestGroupTypeByType(groupTypeName), groupType -> groupTypeOperation.addGroupType(groupType), null);
+ }
+
+ private Either<ActionStatus, ResponseFormat> validateGroupType(GroupTypeDefinition groupType) {
+ Either<ActionStatus, ResponseFormat> result = Either.left(ActionStatus.OK);
+ if (groupType.getMembers() != null) {
+ if (groupType.getMembers().isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GROUP_MEMBER_EMPTY, groupType.getType());
+ result = Either.right(responseFormat);
+ } else {
+ for (String member : groupType.getMembers()) {
+ // Verify that such Resource exist
+ Either<org.openecomp.sdc.be.model.Resource, StorageOperationStatus> eitherMemberExist = resourceOperation.getLatestByToscaResourceName(member, false);
+ if (eitherMemberExist.isRight()) {
+ StorageOperationStatus operationStatus = eitherMemberExist.right().value();
+ log.debug("Error when fetching parent resource {}, error: {}", member, operationStatus);
+ ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus);
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("Import GroupType", "resource", member);
+ result = Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, member));
+ break;
+ }
+ }
+
+ }
+ }
+ return result;
+ }
+
+ private GroupTypeDefinition createGroupType(String groupTypeName, Map<String, Object> toscaJson) {
+
+ GroupTypeDefinition groupType = new GroupTypeDefinition();
+
+ if (toscaJson != null) {
+ // Description
+ final Consumer<String> descriptionSetter = description -> groupType.setDescription(description);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DESCRIPTION.getElementName(), descriptionSetter);
+ // Derived From
+ final Consumer<String> derivedFromSetter = derivedFrom -> groupType.setDerivedFrom(derivedFrom);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DERIVED_FROM.getElementName(), derivedFromSetter);
+ // Properties
+ commonImportManager.setProperties(toscaJson, (values) -> groupType.setProperties(values));
+ // Metadata
+ final Consumer<Map<String, String>> metadataSetter = metadata -> groupType.setMetadata(metadata);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.METADATA.getElementName(), metadataSetter);
+ // Members
+ final Consumer<List<String>> membersSetter = members -> groupType.setMembers(members);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.MEMBERS.getElementName(), membersSetter);
+
+ groupType.setType(groupTypeName);
+
+ groupType.setHighestVersion(true);
+
+ groupType.setVersion(ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION);
+ }
+ return groupType;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java
new file mode 100644
index 0000000000..81dfc1a256
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java
@@ -0,0 +1,441 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.servlet.ServletContext;
+
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
+import org.openecomp.sdc.be.components.distribution.engine.UebHealthCheckCall;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.IEsHealthCheckDao;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.WebApplicationContext;
+
+@Component("healthCheckBusinessLogic")
+public class HealthCheckBusinessLogic {
+
+ protected static String BE_HEALTH_LOG_CONTEXT = "be.healthcheck";
+
+ private static Logger healthLogger = LoggerFactory.getLogger(BE_HEALTH_LOG_CONTEXT);
+
+ private static final String BE_HEALTH_CHECK_STR = "beHealthCheck";
+
+ @Resource
+ private TitanGenericDao titanGenericDao;
+
+ @Resource
+ private IEsHealthCheckDao esHealthCheckDao;
+
+ @Resource
+ private DistributionEngineClusterHealth distributionEngineClusterHealth;
+
+ @Autowired
+ private SwitchoverDetector switchoverDetector;
+
+ private static Logger log = LoggerFactory.getLogger(HealthCheckBusinessLogic.class.getName());
+
+ private volatile List<HealthCheckInfo> lastBeHealthCheckInfos = null;
+
+ // private static volatile HealthCheckBusinessLogic instance;
+ //
+ public HealthCheckBusinessLogic() {
+
+ }
+
+ private ScheduledFuture<?> scheduledFuture = null;
+
+ ScheduledExecutorService healthCheckScheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "BE-Health-Check-Task");
+ }
+ });
+
+ HealthCheckScheduledTask healthCheckScheduledTask = null;
+
+ @PostConstruct
+ public void init() {
+
+ lastBeHealthCheckInfos = getBeHealthCheckInfos();
+
+ log.debug("After initializing lastBeHealthCheckInfos :{}", lastBeHealthCheckInfos);
+
+ healthCheckScheduledTask = new HealthCheckScheduledTask();
+
+ if (this.scheduledFuture == null) {
+ this.scheduledFuture = this.healthCheckScheduler.scheduleAtFixedRate(healthCheckScheduledTask, 0, 3, TimeUnit.SECONDS);
+ }
+
+ }
+
+ //
+ // public static HealthCheckBusinessLogic getInstance(){
+ //// if (instance == null){
+ //// instance = init();
+ //// }
+ // return instance;
+ // }
+
+ // private synchronized static HealthCheckBusinessLogic init() {
+ // if (instance == null){
+ // instance = new HealthCheckBusinessLogic();
+ // }
+ // return instance;
+ // }
+
+ private List<HealthCheckInfo> getBeHealthCheckInfos(ServletContext servletContext) {
+
+ List<HealthCheckInfo> healthCheckInfos = new ArrayList<HealthCheckInfo>();
+
+ // BE
+ getBeHealthCheck(servletContext, healthCheckInfos);
+
+ // ES
+ getEsHealthCheck(servletContext, healthCheckInfos);
+
+ // Titan
+ getTitanHealthCheck(servletContext, healthCheckInfos);
+
+ // Distribution Engine
+ getDistributionEngineCheck(servletContext, healthCheckInfos);
+
+ return healthCheckInfos;
+ }
+
+ private List<HealthCheckInfo> getBeHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
+ String appVersion = ExternalConfiguration.getAppVersion();
+ String description = "OK";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.BE, HealthCheckStatus.UP, appVersion, description));
+ return healthCheckInfos;
+ }
+
+ public List<HealthCheckInfo> getTitanHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
+ // Titan health check and version
+ TitanGenericDao titanStatusDao = (TitanGenericDao) getDao(servletContext, TitanGenericDao.class);
+ String description;
+ boolean isTitanUp;
+
+ try {
+ isTitanUp = titanStatusDao.isGraphOpen();
+ } catch (Exception e) {
+ description = "Titan error: " + e.getMessage();
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
+ return healthCheckInfos;
+ }
+ if (isTitanUp) {
+ description = "OK";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.UP, null, description));
+ } else {
+ description = "Titan graph is down";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
+ }
+ return healthCheckInfos;
+ }
+
+ public List<HealthCheckInfo> getEsHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
+
+ // ES health check and version
+ IEsHealthCheckDao esStatusDao = (IEsHealthCheckDao) getDao(servletContext, IEsHealthCheckDao.class);
+ HealthCheckStatus healthCheckStatus;
+ String description;
+
+ try {
+ healthCheckStatus = esStatusDao.getClusterHealthStatus();
+ } catch (Exception e) {
+ healthCheckStatus = HealthCheckStatus.DOWN;
+ description = "ES cluster error: " + e.getMessage();
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
+ return healthCheckInfos;
+ }
+ if (healthCheckStatus.equals(HealthCheckStatus.DOWN)) {
+ description = "ES cluster is down";
+ } else {
+ description = "OK";
+ }
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
+ return healthCheckInfos;
+ }
+
+ public Object getDao(ServletContext servletContext, Class<?> clazz) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(servletContext);
+
+ return webApplicationContext.getBean(clazz);
+ }
+
+ private void getDistributionEngineCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
+
+ DistributionEngineClusterHealth deDao = (DistributionEngineClusterHealth) getDao(servletContext, DistributionEngineClusterHealth.class);
+ HealthCheckInfo healthCheckInfo = deDao.getHealthCheckInfo();
+
+ healthCheckInfos.add(healthCheckInfo);
+
+ }
+
+ public boolean isDistributionEngineUp(ServletContext servletContext) {
+
+ DistributionEngineClusterHealth deDao = (DistributionEngineClusterHealth) getDao(servletContext, DistributionEngineClusterHealth.class);
+ HealthCheckInfo healthCheckInfo = deDao.getHealthCheckInfo();
+ if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN)) {
+ return false;
+ }
+ return true;
+ }
+
+ public List<HealthCheckInfo> getBeHealthCheckInfosStatus() {
+
+ return lastBeHealthCheckInfos;
+
+ }
+
+ private List<HealthCheckInfo> getBeHealthCheckInfos() {
+
+ log.trace("In getBeHealthCheckInfos");
+
+ List<HealthCheckInfo> healthCheckInfos = new ArrayList<HealthCheckInfo>();
+
+ // BE
+ getBeHealthCheck(healthCheckInfos);
+
+ // ES
+ getEsHealthCheck(healthCheckInfos);
+
+ // Titan
+ getTitanHealthCheck(healthCheckInfos);
+
+ // Distribution Engine
+ getDistributionEngineCheck(healthCheckInfos);
+
+ return healthCheckInfos;
+ }
+
+ private List<HealthCheckInfo> getBeHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ String appVersion = ExternalConfiguration.getAppVersion();
+ String description = "OK";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.BE, HealthCheckStatus.UP, appVersion, description));
+ return healthCheckInfos;
+ }
+
+ public List<HealthCheckInfo> getEsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+
+ // ES health check and version
+ HealthCheckStatus healthCheckStatus;
+ String description;
+
+ try {
+ healthCheckStatus = esHealthCheckDao.getClusterHealthStatus();
+ } catch (Exception e) {
+ healthCheckStatus = HealthCheckStatus.DOWN;
+ description = "ES cluster error: " + e.getMessage();
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
+ return healthCheckInfos;
+ }
+ if (healthCheckStatus.equals(HealthCheckStatus.DOWN)) {
+ description = "ES cluster is down";
+ } else {
+ description = "OK";
+ }
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
+ return healthCheckInfos;
+ }
+
+ public List<HealthCheckInfo> getTitanHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ // Titan health check and version
+ String description;
+ boolean isTitanUp;
+
+ try {
+ isTitanUp = titanGenericDao.isGraphOpen();
+ } catch (Exception e) {
+ description = "Titan error: " + e.getMessage();
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
+ return healthCheckInfos;
+ }
+ if (isTitanUp) {
+ description = "OK";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.UP, null, description));
+ } else {
+ description = "Titan graph is down";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
+ }
+ return healthCheckInfos;
+ }
+
+ private void getDistributionEngineCheck(List<HealthCheckInfo> healthCheckInfos) {
+
+ HealthCheckInfo healthCheckInfo = distributionEngineClusterHealth.getHealthCheckInfo();
+
+ healthCheckInfos.add(healthCheckInfo);
+
+ }
+
+ @PreDestroy
+ private void destroy() {
+
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
+ }
+
+ if (healthCheckScheduler != null) {
+ healthCheckScheduler.shutdown();
+ }
+
+ }
+
+ public class HealthCheckScheduledTask implements Runnable {
+
+ List<UebHealthCheckCall> healthCheckCalls = new ArrayList<>();
+
+ public HealthCheckScheduledTask() {
+
+ }
+
+ @Override
+ public void run() {
+
+ healthLogger.trace("Executing BE Health Check Task");
+
+ List<HealthCheckInfo> beHealthCheckInfos = getBeHealthCheckInfos();
+ boolean healthStatus = getAggregateBeStatus(beHealthCheckInfos);
+
+ boolean lastHealthStatus = getAggregateBeStatus(lastBeHealthCheckInfos);
+
+ if (lastHealthStatus != healthStatus) {
+ log.trace("BE Health State Changed to {}. Issuing alarm / recovery alarm...", healthStatus);
+
+ lastBeHealthCheckInfos = beHealthCheckInfos;
+ logAlarm(healthStatus);
+
+ } else {
+ // check if we need to update the status's list in case one of
+ // the statuses was changed
+ if (true == anyStatusChanged(beHealthCheckInfos, lastBeHealthCheckInfos)) {
+ lastBeHealthCheckInfos = beHealthCheckInfos;
+ }
+
+ }
+
+ }
+
+ }
+
+ private void logAlarm(boolean lastHealthState) {
+ if (lastHealthState == true) {
+ BeEcompErrorManager.getInstance().logBeHealthCheckRecovery(BE_HEALTH_CHECK_STR);
+ } else {
+ BeEcompErrorManager.getInstance().logBeHealthCheckError(BE_HEALTH_CHECK_STR);
+ }
+ }
+
+ private boolean getAggregateBeStatus(List<HealthCheckInfo> beHealthCheckInfos) {
+
+ boolean status = true;
+
+ for (HealthCheckInfo healthCheckInfo : beHealthCheckInfos) {
+ if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN) && healthCheckInfo.getHealthCheckComponent() != HealthCheckComponent.DE) {
+ status = false;
+ break;
+ }
+ }
+ return status;
+ }
+
+ public String getSiteMode() {
+ return switchoverDetector.getSiteMode();
+ }
+
+ public boolean anyStatusChanged(List<HealthCheckInfo> beHealthCheckInfos, List<HealthCheckInfo> lastBeHealthCheckInfos) {
+
+ boolean result = false;
+
+ if (beHealthCheckInfos != null && lastBeHealthCheckInfos != null) {
+
+ Map<HealthCheckComponent, HealthCheckStatus> currentValues = beHealthCheckInfos.stream().collect(Collectors.toMap(p -> p.getHealthCheckComponent(), p -> p.getHealthCheckStatus()));
+ Map<HealthCheckComponent, HealthCheckStatus> lastValues = lastBeHealthCheckInfos.stream().collect(Collectors.toMap(p -> p.getHealthCheckComponent(), p -> p.getHealthCheckStatus()));
+
+ if (currentValues != null && lastValues != null) {
+ int currentSize = currentValues.size();
+ int lastSize = lastValues.size();
+
+ if (currentSize != lastSize) {
+ result = true;
+ } else {
+
+ for (Entry<HealthCheckComponent, HealthCheckStatus> entry : currentValues.entrySet()) {
+ HealthCheckComponent key = entry.getKey();
+ HealthCheckStatus value = entry.getValue();
+
+ if (false == lastValues.containsKey(key)) {
+ result = true;
+ break;
+ }
+
+ HealthCheckStatus lastHealthCheckStatus = lastValues.get(key);
+
+ if (value != lastHealthCheckStatus) {
+ result = true;
+ break;
+ }
+ }
+ }
+ } else if (currentValues == null && lastValues == null) {
+ result = false;
+ } else {
+ result = true;
+ }
+
+ } else if (beHealthCheckInfos == null && lastBeHealthCheckInfos == null) {
+ result = false;
+ } else {
+ result = true;
+ }
+
+ return result;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/IDeploymentArtifactTypeConfigGetter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/IDeploymentArtifactTypeConfigGetter.java
new file mode 100644
index 0000000000..68569ebc3b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/IDeploymentArtifactTypeConfigGetter.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.config.Configuration.DeploymentArtifactTypeConfig;
+
+public interface IDeploymentArtifactTypeConfigGetter {
+ DeploymentArtifactTypeConfig getDeploymentArtifactConfig();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
new file mode 100644
index 0000000000..94a7340ff7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -0,0 +1,722 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.heat.HeatParameterType;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.util.GsonFactory;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.representer.Representer;
+import org.yaml.snakeyaml.resolver.Resolver;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import fj.data.Either;
+
+public final class ImportUtils {
+ private ImportUtils() {
+
+ }
+
+ private static CustomResolver customResolver = new CustomResolver();
+
+ private static class CustomResolver extends Resolver {
+ protected void addImplicitResolvers() {
+ // avoid implicit resolvers
+ }
+ }
+
+ public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParamsWithoutImplicitTypes(String heatDecodedPayload, String artifactType) {
+ Map<String, Object> heatData = (Map<String, Object>) new Yaml(new Constructor(), new Representer(), new DumperOptions(), customResolver).load(heatDecodedPayload);
+ return getHeatParameters(heatData, artifactType);
+ }
+
+ public static class Constants {
+
+ public static final String FIRST_CERTIFIED_VERSION_VERSION = "1.0";
+ public static final String FIRST_NON_CERTIFIED_VERSION = "0.1";
+ public static final String VENDOR_NAME = "ATT (Tosca)";
+ public static final String VENDOR_RELEASE = "1.0.0.wd03";
+ public static final LifecycleStateEnum NORMATIVE_TYPE_LIFE_CYCLE = LifecycleStateEnum.CERTIFIED;
+ public static final boolean NORMATIVE_TYPE_HIGHEST_VERSION = true;
+ // public static final String ABSTRACT_CATEGORY = "Generic/Abstract";
+ public static final String ABSTRACT_CATEGORY_NAME = "Generic";
+ public static final String ABSTRACT_SUBCATEGORY = "Abstract";
+ public static final String DEFAULT_ICON = "defaulticon";
+ public static final String INNER_VFC_DESCRIPTION = "Not reusable inner VFC";
+ public static final String USER_DEFINED_RESOURCE_NAMESPACE_PREFIX = "org.openecomp.resource.";
+ public static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList(new String[] { "tosca_simple_yaml_1_0_0", "tosca_simple_profile_for_nfv_1_0_0", "tosca_simple_yaml_1_0" });
+ public static final List<String> TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(new String[] { ".yml", ".yaml", ".csar" });
+ public static final String UI_JSON_PAYLOAD_NAME = "payloadName";
+ public static final String ABSTRACT_NODE = "abstact";
+ }
+
+ public enum ResultStatusEnum {
+ ELEMENT_NOT_FOUND, GENERAL_ERROR, OK, INVALID_PROPERTY_DEFAULT_VALUE, INVALID_PROPERTY_TYPE, INVALID_PROPERTY_VALUE, MISSING_ENTRY_SCHEMA_TYPE
+ }
+
+ public enum ToscaElementTypeEnum {
+ BOOLEAN, STRING, MAP, LIST, ALL
+ }
+
+ public enum ToscaTagNamesEnum {
+ DERIVED_FROM("derived_from"), IS_PASSWORD("is_password"),
+ // Properties
+ PROPERTIES("properties"), TYPE("type"), STATUS("status"), ENTRY_SCHEMA("entry_schema"), REQUIRED("required"), DESCRIPTION("description"), DEFAULT_VALUE("default"), VALUE("value"), CONSTRAINTS("constraints"),
+ // Group Types
+ MEMBERS("members"), METADATA("metadata"),
+ // Policy Types
+ TARGETS("targets"),
+ // Capabilities
+ CAPABILITIES("capabilities"), VALID_SOURCE_TYPES("valid_source_types"),
+ // Requirements
+ REQUIREMENTS("requirements"), NODE("node"), RELATIONSHIP("relationship"), CAPABILITY("capability"), INTERFACES("interfaces"),
+ // Heat env Validation
+ PARAMETERS("parameters"),
+ // Import Validations
+ TOSCA_VERSION("tosca_definitions_version"), TOPOLOGY_TEMPLATE("topology_template"), NODE_TYPES("node_types"), OCCURRENCES("occurrences"), NODE_TEMPLATES("node_templates"), GROUPS("groups"), INPUTS("inputs"),
+ // Attributes
+ ATTRIBUTES("attributes"), LABEL("label"), HIDDEN("hidden"), IMMUTABLE("immutable"), GET_INPUT("get_input");
+
+ private String elementName;
+
+ private ToscaTagNamesEnum(String elementName) {
+ this.elementName = elementName;
+ }
+
+ public String getElementName() {
+ return elementName;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void handleElementNameNotFound(String elementName, Object elementValue, ToscaElementTypeEnum elementType, List<Object> returnedList) {
+ if (elementValue instanceof Map) {
+ ImportUtils.findToscaElements((Map<String, Object>) elementValue, elementName, elementType, returnedList);
+ } else if (elementValue instanceof List) {
+ ImportUtils.findAllToscaElementsInList((List<Object>) elementValue, elementName, elementType, returnedList);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void handleElementNameFound(String elementName, ToscaElementTypeEnum elementType, List<Object> returnedList, Object elementValue) {
+
+ if (elementValue instanceof Boolean) {
+ if (elementType == ToscaElementTypeEnum.BOOLEAN || elementType == ToscaElementTypeEnum.ALL) {
+ returnedList.add(elementValue);
+ }
+ }
+
+ else if (elementValue instanceof String) {
+ if (elementType == ToscaElementTypeEnum.STRING || elementType == ToscaElementTypeEnum.ALL) {
+ returnedList.add(elementValue);
+ }
+ } else if (elementValue instanceof Map) {
+ if (elementType == ToscaElementTypeEnum.MAP || elementType == ToscaElementTypeEnum.ALL) {
+ returnedList.add(elementValue);
+ }
+ ImportUtils.findToscaElements((Map<String, Object>) elementValue, elementName, elementType, returnedList);
+
+ } else if (elementValue instanceof List) {
+ if (elementType == ToscaElementTypeEnum.LIST || elementType == ToscaElementTypeEnum.ALL) {
+ returnedList.add(elementValue);
+ }
+ ImportUtils.findAllToscaElementsInList((List<Object>) elementValue, elementName, elementType, returnedList);
+
+ }
+ // For Integer, Double etc...
+ else if (elementType == ToscaElementTypeEnum.ALL) {
+ if (elementValue != null) {
+ returnedList.add(String.valueOf(elementValue));
+ } else {
+ returnedList.add(elementValue);
+ }
+
+ }
+ }
+
+ private static void findAllToscaElementsInList(List<Object> list, String elementName, ToscaElementTypeEnum elementType, List<Object> returnedList) {
+ Iterator<Object> listItr = list.iterator();
+ while (listItr.hasNext()) {
+ Object elementValue = listItr.next();
+ handleElementNameNotFound(elementName, elementValue, elementType, returnedList);
+ }
+
+ }
+
+ public static Either<Object, ResultStatusEnum> findToscaElement(Map<String, Object> toscaJson, ToscaTagNamesEnum elementName, ToscaElementTypeEnum elementType) {
+ List<Object> foundElements = new ArrayList<>();
+ Either<Object, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ ImportUtils.findToscaElements(toscaJson, elementName.getElementName(), elementType, foundElements);
+ if (foundElements.size() > 0) {
+ returnedElement = Either.left(foundElements.get(0));
+ }
+ return returnedElement;
+
+ }
+
+ /**
+ * Recursively searches for all tosca elements with key equals to elementName and value equals to elementType. <br>
+ * Returns Either element with:<br>
+ * List with all value if values found<br>
+ * Or ELEMENT_NOT_FOUND ActionStatus
+ *
+ * @param toscaJson
+ * @param toscaTagName
+ * @return
+ */
+ public static Either<List<Object>, ResultStatusEnum> findToscaElements(Map<String, Object> toscaJson, String elementName, ToscaElementTypeEnum elementType, List<Object> returnedList) {
+ Either<List<Object>, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ String skipKey = null;
+ if (toscaJson.containsKey(elementName)) {
+ Object elementValue = toscaJson.get(elementName);
+ handleElementNameFound(elementName, elementType, returnedList, elementValue);
+ skipKey = elementName;
+ }
+
+ Iterator<Entry<String, Object>> keyValItr = toscaJson.entrySet().iterator();
+ while (keyValItr.hasNext()) {
+ Entry<String, Object> keyValEntry = keyValItr.next();
+ if (!String.valueOf(keyValEntry.getKey()).equals(skipKey)) {
+ handleElementNameNotFound(elementName, keyValEntry.getValue(), elementType, returnedList);
+ }
+ }
+
+ if (returnedList.size() > 0) {
+ returnedElement = Either.left(returnedList);
+ }
+
+ return returnedElement;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Either<List<T>, ResultStatusEnum> findFirstToscaListElement(Map<String, Object> toscaJson, ToscaTagNamesEnum toscaTagName) {
+ Either<List<T>, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Object, ResultStatusEnum> findFirstToscaElement = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.LIST);
+ if (findFirstToscaElement.isLeft()) {
+ returnedElement = Either.left((List<T>) findFirstToscaElement.left().value());
+ }
+ return returnedElement;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Either<Map<String, T>, ResultStatusEnum> findFirstToscaMapElement(Map<String, Object> toscaJson, ToscaTagNamesEnum toscaTagName) {
+ Either<Map<String, T>, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Object, ResultStatusEnum> findFirstToscaElement = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.MAP);
+ if (findFirstToscaElement.isLeft()) {
+ returnedElement = Either.left((Map<String, T>) findFirstToscaElement.left().value());
+ }
+ return returnedElement;
+
+ }
+
+ public static Either<String, ResultStatusEnum> findFirstToscaStringElement(Map<String, Object> toscaJson, ToscaTagNamesEnum toscaTagName) {
+ Either<String, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Object, ResultStatusEnum> findFirstToscaElements = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.STRING);
+ if (findFirstToscaElements.isLeft()) {
+ returnedElement = Either.left((String) findFirstToscaElements.left().value());
+ }
+ return returnedElement;
+ }
+
+ /**
+ * searches for first Tosca in Json map (toscaJson) boolean element by name (toscaTagName) returns found element or ELEMENT_NOT_FOUND status
+ *
+ * @param toscaJson
+ * @param toscaTagName
+ * @return
+ */
+ public static Either<String, ResultStatusEnum> findFirstToscaBooleanElement(Map<String, Object> toscaJson, ToscaTagNamesEnum toscaTagName) {
+ Either<String, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Object, ResultStatusEnum> findFirstToscaElements = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.BOOLEAN);
+ if (findFirstToscaElements.isLeft()) {
+ returnedElement = Either.left(String.valueOf(findFirstToscaElements.left().value()));
+ }
+ return returnedElement;
+ }
+
+ private static void setPropertyConstraints(Map<String, Object> propertyValue, PropertyDefinition property) {
+ Either<List<Object>, ResultStatusEnum> propertyFieldconstraints = findFirstToscaListElement(propertyValue, ToscaTagNamesEnum.CONSTRAINTS);
+ if (propertyFieldconstraints.isLeft()) {
+ List<Object> jsonConstraintList = propertyFieldconstraints.left().value();
+
+ List<PropertyConstraint> constraintList = new ArrayList<>();
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
+
+ for (Object constraintJson : jsonConstraintList) {
+ PropertyConstraint propertyConstraint = gson.fromJson(gson.toJson(constraintJson), constraintType);
+ constraintList.add(propertyConstraint);
+ }
+ property.setConstraints(constraintList);
+ }
+ }
+
+ public static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) {
+
+ PropertyDefinition propertyDef = new PropertyDefinition();
+ ImportUtils.setField(propertyValue, ToscaTagNamesEnum.TYPE, type -> propertyDef.setType(type));
+ ImportUtils.setPropertyFieldRequired(propertyValue, propertyDef);
+ ImportUtils.setField(propertyValue, ToscaTagNamesEnum.DESCRIPTION, desc -> propertyDef.setDescription(desc));
+
+ Either<Object, ResultStatusEnum> findToscaElement = ImportUtils.findToscaElement(propertyValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ if (findToscaElement.isLeft()) {
+ String propertyJsonStringValue = getPropertyJsonStringValue(findToscaElement.left().value(), propertyDef.getType());
+ propertyDef.setDefaultValue(propertyJsonStringValue);
+ }
+ ImportUtils.setField(propertyValue, ToscaTagNamesEnum.IS_PASSWORD, pass -> propertyDef.setPassword(Boolean.parseBoolean(pass)));
+ ImportUtils.setField(propertyValue, ToscaTagNamesEnum.STATUS, status -> propertyDef.setStatus(status));
+ ImportUtils.setPropertyScheme(propertyValue, propertyDef);
+ ImportUtils.setPropertyConstraints(propertyValue, propertyDef);
+
+ return propertyDef;
+ }
+
+ public static InputDefinition createModuleInput(Map<String, Object> inputValue) {
+
+ InputDefinition inputDef = new InputDefinition();
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.TYPE, type -> inputDef.setType(type));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.REQUIRED, req -> inputDef.setRequired(Boolean.parseBoolean(req)));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.DESCRIPTION, desc -> inputDef.setDescription(desc));
+
+ Either<Object, ResultStatusEnum> findToscaElement = ImportUtils.findToscaElement(inputValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ if (findToscaElement.isLeft()) {
+ String propertyJsonStringValue = getPropertyJsonStringValue(findToscaElement.left().value(), inputDef.getType());
+ inputDef.setDefaultValue(propertyJsonStringValue);
+ }
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.IS_PASSWORD, pass -> inputDef.setPassword(Boolean.parseBoolean(pass)));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.STATUS, status -> inputDef.setStatus(status));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.LABEL, label -> inputDef.setLabel(label));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.HIDDEN, hidden -> inputDef.setHidden(Boolean.parseBoolean(hidden)));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.HIDDEN, immutable -> inputDef.setImmutable(Boolean.parseBoolean(immutable)));
+ ImportUtils.setField(inputValue, ToscaTagNamesEnum.LABEL, label -> inputDef.setLabel(label));
+ ImportUtils.setPropertyScheme(inputValue, inputDef);
+ ImportUtils.setPropertyConstraints(inputValue, inputDef);
+
+ return inputDef;
+ }
+
+ public static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) {
+
+ AttributeDefinition attributeDef = new AttributeDefinition();
+ ImportUtils.setField(attributeMap, ToscaTagNamesEnum.TYPE, type -> attributeDef.setType(type));
+ ImportUtils.setField(attributeMap, ToscaTagNamesEnum.DESCRIPTION, desc -> attributeDef.setDescription(desc));
+ ImportUtils.setField(attributeMap, ToscaTagNamesEnum.STATUS, status -> attributeDef.setStatus(status));
+ Either<Object, ResultStatusEnum> eitherDefaultValue = ImportUtils.findToscaElement(attributeMap, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ if (eitherDefaultValue.isLeft()) {
+ String attributeDefaultValue = getPropertyJsonStringValue(eitherDefaultValue.left().value(), attributeDef.getType());
+ attributeDef.setDefaultValue(attributeDefaultValue);
+ }
+ Either<Object, ResultStatusEnum> eitherValue = ImportUtils.findToscaElement(attributeMap, ToscaTagNamesEnum.VALUE, ToscaElementTypeEnum.ALL);
+ if (eitherValue.isLeft()) {
+ String attributeValue = getPropertyJsonStringValue(eitherValue.left().value(), attributeDef.getType());
+ attributeDef.setValue(attributeValue);
+ }
+ ImportUtils.setAttributeScheme(attributeMap, attributeDef);
+ return attributeDef;
+ }
+
+ private static void setPropertyFieldStatus(Map<String, Object> propertyValue, PropertyDefinition propertyDef) {
+ Either<String, ResultStatusEnum> propertyFieldIsStatus = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.STATUS);
+ if (propertyFieldIsStatus.isLeft()) {
+ propertyDef.setStatus(propertyFieldIsStatus.left().value());
+ }
+
+ }
+
+ private static void setAttributeFieldStatus(Map<String, Object> propertyValue, AttributeDefinition propertyDef) {
+ Either<String, ResultStatusEnum> propertyFieldIsStatus = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.STATUS);
+ if (propertyFieldIsStatus.isLeft()) {
+ propertyDef.setStatus(propertyFieldIsStatus.left().value());
+ }
+
+ }
+
+ private static void setPropertyScheme(Map<String, Object> propertyValue, PropertyDefinition propertyDefinition) {
+ Either<SchemaDefinition, ResultStatusEnum> eitherSchema = getSchema(propertyValue);
+ if (eitherSchema.isLeft()) {
+ SchemaDefinition schemaDef = new SchemaDefinition();
+ schemaDef.setProperty(eitherSchema.left().value().getProperty());
+ propertyDefinition.setSchema(schemaDef);
+ }
+
+ }
+
+ private static void setAttributeScheme(Map<String, Object> propertyValue, AttributeDefinition propertyDefinition) {
+ Either<SchemaDefinition, ResultStatusEnum> eitherSchema = getSchema(propertyValue);
+ if (eitherSchema.isLeft()) {
+ SchemaDefinition schemaDef = new SchemaDefinition();
+ schemaDef.setProperty(eitherSchema.left().value().getProperty());
+ propertyDefinition.setSchema(schemaDef);
+ }
+
+ }
+
+ private static Either<SchemaDefinition, ResultStatusEnum> getSchema(Map<String, Object> propertyValue) {
+ Either<SchemaDefinition, ResultStatusEnum> result = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Object, ResultStatusEnum> propertyFieldEntryScheme = findToscaElement(propertyValue, ToscaTagNamesEnum.ENTRY_SCHEMA, ToscaElementTypeEnum.ALL);
+ if (propertyFieldEntryScheme.isLeft()) {
+ if (propertyFieldEntryScheme.left().value() instanceof String) {
+ String schemaType = (String) propertyFieldEntryScheme.left().value();
+ SchemaDefinition schema = new SchemaDefinition();
+ PropertyDefinition schemeProperty = new PropertyDefinition();
+ schemeProperty.setType(schemaType);
+ schema.setProperty(schemeProperty);
+ result = Either.left(schema);
+
+ } else if (propertyFieldEntryScheme.left().value() instanceof Map) {
+ PropertyDefinition schemeProperty = createModuleProperty((Map<String, Object>) propertyFieldEntryScheme.left().value());
+ SchemaDefinition schema = new SchemaDefinition();
+ schema.setProperty(schemeProperty);
+ result = Either.left(schema);
+
+ }
+
+ }
+ return result;
+ }
+
+ private static void setPropertyFieldIsPassword(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldIsPassword = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.IS_PASSWORD);
+ if (propertyFieldIsPassword.isLeft()) {
+ dataDefinition.setPassword(Boolean.parseBoolean(propertyFieldIsPassword.left().value()));
+ }
+ }
+
+ private static ResultStatusEnum setPropertyFieldDefaultValue(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
+ Either<Object, ResultStatusEnum> propertyFieldDefaultValue = findToscaElement(propertyValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ Gson gson = GsonFactory.getGson();
+ if (propertyFieldDefaultValue.isLeft()) {
+ Object defaultValue = propertyFieldDefaultValue.left().value();
+ String type = dataDefinition.getType();
+ ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(type);
+ // esofer - supporting customized data types. The validation of the
+ // type will be in the creation of the property.
+ // if(innerToscaType == null){
+ // return ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE;
+ // }
+ // customized data types value is represented as json.
+ // Also customized data types which are scalar ones, for example,
+ // data type which derived from integer, their value will be
+ // represented as json.
+ if (innerToscaType == null || innerToscaType.equals(ToscaPropertyType.LIST) || innerToscaType.equals(ToscaPropertyType.MAP)) {
+ String jsonObj = null;
+ if (defaultValue != null) {
+ jsonObj = gson.toJson(defaultValue);
+ }
+
+ dataDefinition.setDefaultValue(jsonObj);
+ } else {
+ dataDefinition.setDefaultValue(String.valueOf(defaultValue));
+ }
+
+ }
+
+ return ResultStatusEnum.OK;
+ }
+
+ private static ResultStatusEnum setAttributeFieldDefaultValue(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ Either<Object, ResultStatusEnum> propertyFieldDefaultValue = findToscaElement(propertyValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ Gson gson = GsonFactory.getGson();
+ if (propertyFieldDefaultValue.isLeft()) {
+ Object defaultValue = propertyFieldDefaultValue.left().value();
+ String type = dataDefinition.getType();
+ ToscaPropertyType innerToscaType = ToscaPropertyType.isValidType(type);
+ // esofer - supporting customized data types. The validation of the
+ // type will be in the creation of the property.
+ // if(innerToscaType == null){
+ // return ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE;
+ // }
+ // customized data types value is represented as json.
+ // Also customized data types which are scalar ones, for example,
+ // data type which derived from integer, their value will be
+ // represented as json.
+ if (innerToscaType == null || innerToscaType.equals(ToscaPropertyType.LIST) || innerToscaType.equals(ToscaPropertyType.MAP)) {
+ String jsonObj = null;
+ if (defaultValue != null) {
+ jsonObj = gson.toJson(defaultValue);
+ }
+
+ dataDefinition.setDefaultValue(jsonObj);
+ } else {
+ dataDefinition.setDefaultValue(String.valueOf(defaultValue));
+ }
+
+ }
+
+ return ResultStatusEnum.OK;
+ }
+
+ public static void setField(Map<String, Object> toscaJson, ToscaTagNamesEnum tagName, Consumer<String> setter) {
+ Either<String, ResultStatusEnum> fieldStringValue = findFirstToscaStringElement(toscaJson, tagName);
+ if (fieldStringValue.isLeft()) {
+ setter.accept(fieldStringValue.left().value());
+ }
+
+ }
+
+ private static void setPropertyFieldDescription(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldDescription = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.DESCRIPTION);
+ if (propertyFieldDescription.isLeft()) {
+ dataDefinition.setDescription(propertyFieldDescription.left().value());
+ }
+ }
+
+ private static void setPropertyFieldRequired(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldRequired = findFirstToscaBooleanElement(propertyValue, ToscaTagNamesEnum.REQUIRED);
+ if (propertyFieldRequired.isLeft()) {
+ dataDefinition.setRequired(Boolean.parseBoolean(propertyFieldRequired.left().value()));
+ }
+ }
+
+ private static void setAttributeFieldType(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldType = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.TYPE);
+ if (propertyFieldType.isLeft()) {
+ dataDefinition.setType(propertyFieldType.left().value());
+ }
+ }
+
+ private static void setPropertyFieldType(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldType = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.TYPE);
+ if (propertyFieldType.isLeft()) {
+ dataDefinition.setType(propertyFieldType.left().value());
+ }
+ }
+
+ private static void setAttributeFieldDescription(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ Either<String, ResultStatusEnum> propertyFieldDescription = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.DESCRIPTION);
+ if (propertyFieldDescription.isLeft()) {
+ dataDefinition.setDescription(propertyFieldDescription.left().value());
+ }
+ }
+
+ public static Either<Map<String, PropertyDefinition>, ResultStatusEnum> getProperties(Map<String, Object> toscaJson) {
+ Function<String, PropertyDefinition> elementGenByName = elementName -> createProperties(elementName);
+ Function<Map<String, Object>, PropertyDefinition> func = map -> createModuleProperty(map);
+
+ return getElements(toscaJson, ToscaTagNamesEnum.PROPERTIES, elementGenByName, func);
+
+ }
+
+ public static Either<Map<String, InputDefinition>, ResultStatusEnum> getInputs(Map<String, Object> toscaJson) {
+ Function<String, InputDefinition> elementGenByName = elementName -> createInputs(elementName);
+ Function<Map<String, Object>, InputDefinition> func = map -> createModuleInput(map);
+
+ return getElements(toscaJson, ToscaTagNamesEnum.INPUTS, elementGenByName, func);
+
+ }
+
+ public static Either<Map<String, AttributeDefinition>, ResultStatusEnum> getAttributes(Map<String, Object> toscaJson) {
+ Function<String, AttributeDefinition> elementGenByName = elementName -> createAttribute(elementName);
+ Function<Map<String, Object>, AttributeDefinition> func = map -> createModuleAttribute(map);
+
+ return getElements(toscaJson, ToscaTagNamesEnum.ATTRIBUTES, elementGenByName, func);
+ }
+
+ public static <ElementDefinition> Either<Map<String, ElementDefinition>, ResultStatusEnum> getElements(Map<String, Object> toscaJson, ToscaTagNamesEnum elementTagName, Function<String, ElementDefinition> elementGenByName,
+ Function<Map<String, Object>, ElementDefinition> func) {
+ Either<Map<String, ElementDefinition>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(toscaJson, elementTagName);
+ if (toscaAttributes.isLeft()) {
+ Map<String, Object> jsonAttributes = toscaAttributes.left().value();
+ Map<String, ElementDefinition> moduleAttributes = new HashMap<>();
+ Iterator<Entry<String, Object>> propertiesNameValue = jsonAttributes.entrySet().iterator();
+ while (propertiesNameValue.hasNext()) {
+ Entry<String, Object> attributeNameValue = propertiesNameValue.next();
+ if (attributeNameValue.getValue() instanceof Map) {
+ @SuppressWarnings("unchecked")
+ ElementDefinition attribute = func.apply((Map<String, Object>) attributeNameValue.getValue());
+ moduleAttributes.put(String.valueOf(attributeNameValue.getKey()), attribute);
+ } else {
+
+ ElementDefinition element = elementGenByName.apply(String.valueOf(attributeNameValue.getValue()));
+
+ moduleAttributes.put(String.valueOf(attributeNameValue.getKey()), element);
+ }
+
+ }
+
+ if (moduleAttributes.size() > 0) {
+ eitherResult = Either.left(moduleAttributes);
+ }
+
+ }
+ return eitherResult;
+
+ }
+
+ private static AttributeDefinition createAttribute(String name) {
+ AttributeDefinition attribute = new AttributeDefinition();
+
+ attribute.setName(name);
+ return attribute;
+ }
+
+ private static PropertyDefinition createProperties(String name) {
+ PropertyDefinition property = new PropertyDefinition();
+ property.setDefaultValue(name);
+ property.setName(name);
+ return property;
+ }
+
+ private static InputDefinition createInputs(String name) {
+ InputDefinition input = new InputDefinition();
+
+ input.setName(name);
+ return input;
+ }
+
+ public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) {
+
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
+ Either<Map<String, Object>, ResultStatusEnum> toscaProperties = findFirstToscaMapElement(heatData, ToscaTagNamesEnum.PARAMETERS);
+ if (toscaProperties.isLeft()) {
+ Map<String, Object> jsonProperties = toscaProperties.left().value();
+ List<HeatParameterDefinition> moduleProperties = new ArrayList<>();
+ Iterator<Entry<String, Object>> propertiesNameValue = jsonProperties.entrySet().iterator();
+ while (propertiesNameValue.hasNext()) {
+ Entry<String, Object> propertyNameValue = propertiesNameValue.next();
+ if (propertyNameValue.getValue() instanceof Map) {
+ if (!artifactType.equals(ArtifactTypeEnum.HEAT_ENV.getType())) {
+ @SuppressWarnings("unchecked")
+ Either<HeatParameterDefinition, ResultStatusEnum> propertyStatus = createModuleHeatParameter((Map<String, Object>) propertyNameValue.getValue());
+ if (propertyStatus.isRight()) {
+ return Either.right(propertyStatus.right().value());
+ }
+ HeatParameterDefinition property = propertyStatus.left().value();
+ property.setName(String.valueOf(propertyNameValue.getKey()));
+ moduleProperties.add(property);
+ } else {
+ addHeatParamDefinition(moduleProperties, propertyNameValue, true);
+ }
+ } else {
+ addHeatParamDefinition(moduleProperties, propertyNameValue, false);
+ }
+
+ }
+
+ if (moduleProperties.size() > 0) {
+ eitherResult = Either.left(moduleProperties);
+ }
+
+ }
+ return eitherResult;
+
+ }
+
+ private static void addHeatParamDefinition(List<HeatParameterDefinition> moduleProperties, Entry<String, Object> propertyNameValue, boolean isJson) {
+ HeatParameterDefinition property = new HeatParameterDefinition();
+ Object value = propertyNameValue.getValue();
+ if (value != null) {
+ property.setDefaultValue(isJson ? new Gson().toJson(value).toString() : StringEscapeUtils.escapeJava(String.valueOf(value)));
+ }
+ property.setName(String.valueOf(propertyNameValue.getKey()));
+ moduleProperties.add(property);
+ }
+
+ private static Either<HeatParameterDefinition, ResultStatusEnum> createModuleHeatParameter(Map<String, Object> propertyValue) {
+ HeatParameterDefinition propertyDef = new HeatParameterDefinition();
+ String type;
+ Either<String, ResultStatusEnum> propertyFieldType = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.TYPE);
+ if (propertyFieldType.isLeft()) {
+ type = propertyFieldType.left().value();
+ propertyDef.setType(type);
+ } else {
+ return Either.right(ResultStatusEnum.INVALID_PROPERTY_TYPE);
+ }
+ Either<String, ResultStatusEnum> propertyFieldDescription = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.DESCRIPTION);
+ if (propertyFieldDescription.isLeft()) {
+ propertyDef.setDescription(propertyFieldDescription.left().value());
+ }
+
+ Either<Object, ResultStatusEnum> propertyFieldDefaultVal = findToscaElement(propertyValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
+ if (propertyFieldDefaultVal.isLeft()) {
+ if (propertyFieldDefaultVal.left().value() == null) {
+ return Either.right(ResultStatusEnum.INVALID_PROPERTY_VALUE);
+ }
+ Object value = propertyFieldDefaultVal.left().value();
+ String defaultValue = type.equals(HeatParameterType.JSON.getType()) ? new Gson().toJson(value).toString() : StringEscapeUtils.escapeJava(String.valueOf(value));
+ propertyDef.setDefaultValue(defaultValue);
+ propertyDef.setCurrentValue(defaultValue);
+ }
+
+ return Either.left(propertyDef);
+ }
+
+ public static String getPropertyJsonStringValue(Object value, String type) {
+ Gson gson = new Gson();
+ if (type == null) {
+ return null;
+ }
+ ToscaPropertyType validType = ToscaPropertyType.isValidType(type);
+ if (validType == null || validType.equals(ToscaPropertyType.MAP) || validType.equals(ToscaPropertyType.LIST)) {
+ return gson.toJson(value);
+ }
+ return value.toString();
+ }
+
+ /**
+ * removes from Json map (toscaJson) first element found by name (elementName) note that this method could update the received argument toscaJson
+ *
+ * @param toscaJson
+ * @param elementName
+ */
+ public static void removeElementFromJsonMap(Map<String, Object> toscaJson, String elementName) {
+ for (Entry<String, Object> entry : toscaJson.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ if (key.equals(elementName)) {
+ toscaJson.remove(elementName);
+ return;
+ } else if (value instanceof Map) {
+ removeElementFromJsonMap((Map<String, Object>) value, elementName);
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InformationDeployedArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InformationDeployedArtifactsBusinessLogic.java
new file mode 100644
index 0000000000..129110e13f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InformationDeployedArtifactsBusinessLogic.java
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import org.apache.commons.codec.binary.Base64;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.Configuration.DeploymentArtifactTypeConfig;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+//Pavel
+//currently NOT IN USE - there are no informational deployed artifacts after US601880
+
+@org.springframework.stereotype.Component("informationDeployedArtifactsBusinessLogic")
+public class InformationDeployedArtifactsBusinessLogic {
+
+ /*
+ * private static Logger log = LoggerFactory.getLogger(InformationDeployedArtifactsBusinessLogic.class. getName());
+ *
+ * @javax.annotation.Resource private ArtifactsBusinessLogic artifactBusinessLogic;
+ *
+ * public boolean isInformationDeployedArtifact(ArtifactDefinition artifactInfo) { log.debug("checking if artifact {} is informationalDeployable", artifactInfo.getArtifactName()); boolean informationDeployedArtifact = false; Map<String,
+ * DeploymentArtifactTypeConfig> resourceInformationalDeployedArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration() .getResourceInformationalDeployedArtifacts(); if( resourceInformationalDeployedArtifacts != null &&
+ * resourceInformationalDeployedArtifacts.containsKey(artifactInfo. getArtifactType())){ if( artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL && artifactInfo.checkEsIdExist()){ informationDeployedArtifact = true;
+ *
+ * } } String message = (informationDeployedArtifact) ? "artifact {} is informationalDeployable" : "artifact {} is not informationalDeployable"; log.debug(message, artifactInfo.getArtifactName()); return informationDeployedArtifact; }
+ *
+ * public Either<Boolean, ResponseFormat> validateArtifact(boolean isCreate, ArtifactDefinition artifactInfo, Component parent, NodeTypeEnum parentType) {
+ *
+ * log.debug("checking if informationalDeployable artifact {} is valid ", artifactInfo.getArtifactName()); Wrapper<ResponseFormat> responseFormatWrapper = new Wrapper<ResponseFormat>(); Map<String, DeploymentArtifactTypeConfig>
+ * resourceInformationalDeployedArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration(). getResourceInformationalDeployedArtifacts();
+ *
+ *
+ * artifactBusinessLogic.validateArtifactTypeExists(responseFormatWrapper, artifactInfo); if( responseFormatWrapper.isEmpty() && isCreate ){ artifactBusinessLogic.validateSingleArtifactType(responseFormatWrapper,
+ * ArtifactTypeEnum.findType(artifactInfo.getArtifactType()), parent, parentType); } if( responseFormatWrapper.isEmpty() ){ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+ * artifactBusinessLogic.validateFileExtension(responseFormatWrapper, () -> resourceInformationalDeployedArtifacts.get(artifactInfo.getArtifactType() ), artifactInfo, parentType, artifactType); }
+ *
+ * if( responseFormatWrapper.isEmpty() ){ validatePayloadContent(responseFormatWrapper, artifactInfo); }
+ *
+ * Either<Boolean, ResponseFormat> response; if( responseFormatWrapper.isEmpty() ){ response = Either.left(true); } else{ response = Either.right(responseFormatWrapper.getInnerElement()); }
+ *
+ * String message = (response.isLeft()) ? "informationalDeployable artifact {} is valid" : "informationalDeployable artifact {} is not valid"; log.debug(message, artifactInfo.getArtifactName()); return response; }
+ *
+ * private void validatePayloadContent(Wrapper<ResponseFormat> responseFormatWrapper, ArtifactDefinition artifactToVerify) { ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactToVerify.getArtifactType()); if( artifactType ==
+ * ArtifactTypeEnum.YANG_XML ){ String rawPayloadData = artifactToVerify.getPayloadData(); String xmlToParse = Base64.isBase64(rawPayloadData) ? new String(org.apache.commons.codec.binary.Base64.decodeBase64(rawPayloadData )) : rawPayloadData;
+ *
+ * boolean isXmlValid = artifactBusinessLogic.isValidXml(xmlToParse.getBytes()); if( !isXmlValid ){ ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus. INVALID_XML,
+ * artifactToVerify.getArtifactType()); responseFormatWrapper.setInnerElement(responseFormat); log.debug("Xml is not valid for artifact : {}", artifactToVerify.getArtifactName()); } } }
+ *
+ *
+ *
+ *
+ * public List<ArtifactDefinition> getInformationalDeployedArtifactsForResourceInstance( ComponentInstance resourceInstance ) { String resourceUid = resourceInstance.getComponentUid(); String resourceName = resourceInstance.getComponentName();
+ * return getInformationalDeployedArtifactsForResource(resourceUid, resourceName); }
+ *
+ * private List<ArtifactDefinition> getInformationalDeployedArtifactsForResource( String resourceUid, String resourceName) { List<ArtifactDefinition> informationalDeployedArtifacts = new ArrayList<ArtifactDefinition>(); log.
+ * debug("checking if informationalDeployable artifacts exist for resource {} " , resourceName); Map<String, DeploymentArtifactTypeConfig> resourceInformationalDeployedArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
+ * .getResourceInformationalDeployedArtifacts();
+ *
+ *
+ * Either<Map<String, ArtifactDefinition>, StorageOperationStatus> eitherArtifacts = artifactBusinessLogic.getArtifacts(resourceUid, NodeTypeEnum.Resource, false, ArtifactGroupTypeEnum.INFORMATIONAL);
+ *
+ * if( eitherArtifacts.isLeft() && resourceInformationalDeployedArtifacts != null ){ Predicate<ArtifactDefinition> predicate = p -> resourceInformationalDeployedArtifacts.containsKey(p.getArtifactType()) && p.checkEsIdExist() &&
+ * p.getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL; informationalDeployedArtifacts = eitherArtifacts.left().value().values().stream().filter( predicate ).collect(Collectors.toList()); }
+ *
+ * if( informationalDeployedArtifacts.isEmpty() ){ log.debug("no informationalDeployable artifacts exist for resource {} ", resourceName); } else{ log. debug("informationalDeployable artifacts found for resource {} are :{}", resourceName,
+ * informationalDeployedArtifacts.toString()); }
+ *
+ *
+ * return informationalDeployedArtifacts; }
+ *
+ * public List<ArtifactDefinition> getAllDeployableArtifacts( Resource resource ){ List<ArtifactDefinition> merged = new ArrayList<ArtifactDefinition>();
+ *
+ * List<ArtifactDefinition> deploymentArtifacts = artifactBusinessLogic.getDeploymentArtifacts(resource, NodeTypeEnum.Resource); merged.addAll(deploymentArtifacts);
+ *
+ * List<ArtifactDefinition> informationalDeployedArtifactsForResource = getInformationalDeployedArtifactsForResource( resource.getUniqueId(), resource.getName()); merged.addAll(informationalDeployedArtifactsForResource);
+ *
+ * return merged; }
+ */
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
new file mode 100644
index 0000000000..7d0624440e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -0,0 +1,526 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.InputsOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.be.resources.data.InputsData;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("inputsBusinessLogic")
+public class InputsBusinessLogic extends BaseBusinessLogic {
+
+ private static final String CREATE_INPUT = "CreateInput";
+
+ private static Logger log = LoggerFactory.getLogger(InputsBusinessLogic.class.getName());
+
+ @Autowired
+ private IResourceOperation resourceOperation = null;
+
+ @javax.annotation.Resource
+ private InputsOperation inputsOperation = null;
+
+ @javax.annotation.Resource
+ private PropertyOperation propertyOperation = null;
+
+ @Autowired
+ private ComponentsUtils componentsUtils;
+
+ /**
+ * associate inputs to a given component with paging
+ *
+ * @param componentId
+ * @param userId
+ * @param fromId
+ * @param amount
+ * @return
+ */
+ public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId, String fromName,
+ int amount) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
+
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<List<InputDefinition>, StorageOperationStatus> inputsEitherRes = inputsOperation
+ .getInputsOfComponent(componentId, fromName, amount);
+ if (inputsEitherRes.isRight()) {
+ if (inputsEitherRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.left(new ArrayList<InputDefinition>());
+ }
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(inputsEitherRes.right().value());
+ log.debug("Failed to get inputs under component {}, error: {}", componentId, actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+
+ }
+
+ return Either.left(inputsEitherRes.left().value());
+
+ }
+
+ /**
+ * associate properties to a given component instance input
+ *
+ * @param instanceId
+ * @param userId
+ * @param inputId
+ * @return
+ */
+
+ public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(
+ String userId, String instanceId, String inputId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<List<ComponentInstanceProperty>, StorageOperationStatus> propertiesEitherRes = inputsOperation
+ .getComponentInstancePropertiesByInputId(instanceId, inputId);
+ if (propertiesEitherRes.isRight()) {
+
+ if (propertiesEitherRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.left(new ArrayList<ComponentInstanceProperty>());
+ }
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(propertiesEitherRes.right().value());
+ log.debug("Failed to get inputs under component {}, error: {}", instanceId, actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+
+ }
+
+ return Either.left(propertiesEitherRes.left().value());
+
+ }
+
+ public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId,
+ String componentId, String inputId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs by input", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<List<ComponentInstanceInput>, StorageOperationStatus> inputsEitherRes = inputsOperation
+ .getComponentInstanceInputsByInputId(componentId, inputId);
+ if (inputsEitherRes.isRight()) {
+
+ if (inputsEitherRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.left(new ArrayList<ComponentInstanceInput>());
+ }
+
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(inputsEitherRes.right().value());
+ log.debug("Failed to get inputs for input under component {}, error: {}", componentId, actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+
+ }
+
+ return Either.left(inputsEitherRes.left().value());
+
+ }
+
+ public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId,
+ ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp,
+ boolean inTransaction) {
+
+ Either<List<InputDefinition>, ResponseFormat> result = null;
+ org.openecomp.sdc.be.model.Component component = null;
+ try {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
+
+ if (resp.isRight()) {
+ result = Either.right(resp.right().value());
+ return result;
+ }
+
+ User user = resp.left().value();
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreUsers(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(
+ componentId, componentType, componentParametersView, userId, null, user);
+
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
+ if (lockComponent.isRight()) {
+ result = Either.right(lockComponent.right().value());
+ return result;
+ }
+ }
+
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(
+ applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ result = Either.right(allDataTypes.right().value());
+ return result;
+ }
+
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+
+ Either<List<InputDefinition>, StorageOperationStatus> createInputsResult = this.inputsOperation
+ .addInputsToComponent(componentId, componentType.getNodeType(), componentInstInputsMapUi,
+ dataTypes);
+
+ if (createInputsResult.isRight()) {
+ ActionStatus actionStatus = componentsUtils
+ .convertFromStorageResponse(createInputsResult.right().value());
+ log.debug("Failed to create inputs under component {}, error: {}", componentId, actionStatus.name());
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+
+ }
+ result = Either.left(createInputsResult.left().value());
+
+ return result;
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+
+ }
+
+ public Either<List<InputDefinition>, ResponseFormat> createInputs(String componentId, String userId,
+ ComponentTypeEnum componentType, List<InputDefinition> inputsDefinitions, boolean shouldLockComp,
+ boolean inTransaction) {
+
+ Either<List<InputDefinition>, ResponseFormat> result = null;
+
+ org.openecomp.sdc.be.model.Component component = null;
+ try {
+
+ if (inputsDefinitions != null && false == inputsDefinitions.isEmpty()) {
+
+ if (shouldLockComp == true && inTransaction == true) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("createGroups",
+ "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
+ // Cannot lock component since we are in a middle of another
+ // transaction.
+ ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus));
+ return result;
+ }
+
+ Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, CREATE_INPUT, true);
+ if (validateUserExists.isRight()) {
+ result = Either.right(validateUserExists.right().value());
+ return result;
+ }
+
+ User user = validateUserExists.left().value();
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(
+ componentId, componentType, inTransaction, false);
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+
+ if (shouldLockComp) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
+ if (lockComponent.isRight()) {
+ return Either.right(lockComponent.right().value());
+ }
+ }
+
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ result = createInputsInGraph(inputsDefinitions, component, user, inTransaction);
+ }
+
+ return result;
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+ // unlock resource
+ if (shouldLockComp && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ }
+
+ }
+
+ }
+
+ public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(List<InputDefinition> inputsDefinitions,
+ org.openecomp.sdc.be.model.Component component, User user, boolean inTransaction) {
+ Either<List<InputDefinition>, ResponseFormat> result;
+ List<InputDefinition> inputs = new ArrayList<InputDefinition>();
+ for (InputDefinition inputDefinition : inputsDefinitions) {
+ // String resourceId, String inputName, InputDefinition
+ // newInputDefinition, String userId, boolean inTransaction
+ Either<InputDefinition, ResponseFormat> createInput = createInput(component, user,
+ component.getComponentType(), inputDefinition.getName(), inputDefinition, inTransaction);
+ if (createInput.isRight()) {
+ log.debug("Failed to create group {}.", createInput);
+ result = Either.right(createInput.right().value());
+ return result;
+ }
+ InputDefinition createdGroup = createInput.left().value();
+ inputs.add(createdGroup);
+ }
+ result = Either.left(inputs);
+ return result;
+ }
+
+ /**
+ * Delete input from service
+ *
+ * @param component
+ * @param user
+ * @param componentType
+ * @param inputId
+ * @param inTransaction
+ * @return
+ */
+ public Either<InputDefinition, ResponseFormat> deleteInput(String componentType, String componentId, String userId, String inputId, boolean inTransaction) {
+
+ if (log.isDebugEnabled())
+ log.debug("Going to delete input id: {}", inputId);
+
+ // Validate user (exists)
+ Either<User, ResponseFormat> userEither = validateUserExists(userId, "Delete input", true);
+ if (userEither.isRight()) {
+ return Either.right(userEither.right().value());
+ }
+
+ // Get component using componentType, componentId
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = serviceOperation.getComponent(componentId, true);
+ if (componentEither.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value())));
+ }
+ org.openecomp.sdc.be.model.Component component = componentEither.left().value();
+
+ // Validate inputId is child of the component
+ // And get the inputDefinition for the response
+ InputDefinition inputDefinition = null;
+ Optional<InputDefinition> optionalInput = component.getInputs().stream().
+ // filter by ID
+ filter(input -> input.getUniqueId().equals(inputId)).
+ // Get the input
+ findAny();
+ if (optionalInput.isPresent()) {
+ inputDefinition = optionalInput.get();
+ } else {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
+ }
+
+ // Lock component
+ Either<Boolean, ResponseFormat> lockResultEither = lockComponent(componentId, component, "deleteInput");
+ if (lockResultEither.isRight()) {
+ ResponseFormat responseFormat = lockResultEither.right().value();
+ return Either.right(responseFormat);
+ }
+
+ // Delete input operations
+ Either<String, StorageOperationStatus> deleteEither = Either.right(StorageOperationStatus.GENERAL_ERROR);
+ try {
+ deleteEither = inputsOperation.deleteInput(inputId);
+ if (deleteEither.isRight()){
+ log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value()), component.getName()));
+ }
+ return Either.left(inputDefinition);
+ } finally {
+ if (deleteEither.isRight()) {
+ log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Component id: {} delete input id: {} success", componentId, inputId);
+ titanGenericDao.commit();
+ }
+ unlockComponent(deleteEither, component);
+ }
+ }
+
+ /**
+ * Create new property on resource in graph
+ *
+ * @param resourceId
+ * @param propertyName
+ * @param newPropertyDefinition
+ * @param userId
+ * @return Either<PropertyDefinition, ActionStatus>
+ */
+
+ private Either<InputDefinition, ResponseFormat> createInput(org.openecomp.sdc.be.model.Component component,
+ User user, ComponentTypeEnum componentType, String inputName, InputDefinition newInputDefinition,
+ boolean inTransaction) {
+
+ Either<InputDefinition, ResponseFormat> result = null;
+ if (log.isDebugEnabled())
+ log.debug("Going to create input {}", newInputDefinition);
+
+ try {
+
+ // verify property not exist in resource
+ List<InputDefinition> resourceProperties = component.getInputs();
+
+ if (resourceProperties != null) {
+ if (inputsOperation.isInputExist(resourceProperties, component.getUniqueId(), inputName)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, ""));
+ }
+ }
+
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(
+ applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ return Either.right(allDataTypes.right().value());
+ }
+
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+
+ // validate input default values
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition,
+ dataTypes);
+ if (defaultValuesValidation.isRight()) {
+ return Either.right(defaultValuesValidation.right().value());
+ }
+ // convert property
+ ToscaPropertyType type = getType(newInputDefinition.getType());
+ PropertyValueConverter converter = type.getConverter();
+ // get inner type
+ String innerType = null;
+ if (newInputDefinition != null) {
+ SchemaDefinition schema = newInputDefinition.getSchema();
+ if (schema != null) {
+ PropertyDataDefinition prop = schema.getProperty();
+ if (prop != null) {
+ innerType = prop.getType();
+ }
+ }
+ String convertedValue = null;
+ if (newInputDefinition.getDefaultValue() != null) {
+ convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType,
+ allDataTypes.left().value());
+ newInputDefinition.setDefaultValue(convertedValue);
+ }
+ }
+
+ // add the new property to resource on graph
+ // need to get StorageOpaerationStatus and convert to ActionStatus
+ // from componentsUtils
+ Either<InputsData, StorageOperationStatus> either = inputsOperation.addInput(inputName, newInputDefinition,
+ component.getUniqueId(), componentType.getNodeType());
+ if (either.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(either.right().value()), component.getName()));
+ }
+ // @TODO commit
+ // inputsOperation.getTitanGenericDao().commit();
+ InputDefinition createdInputyDefinition = inputsOperation
+ .convertInputDataToInputDefinition(either.left().value());
+ createdInputyDefinition.setName(inputName);
+ createdInputyDefinition.setParentUniqueId(component.getUniqueId());
+
+ return Either.left(createdInputyDefinition);
+
+ } finally {
+
+ if (false == inTransaction) {
+
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ titanGenericDao.commit();
+ }
+
+ }
+
+ }
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
new file mode 100644
index 0000000000..780980ba08
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("interfaceLifecycleTypeImportManager")
+public class InterfaceLifecycleTypeImportManager {
+
+ @Resource
+ private IInterfaceLifecycleOperation interfaceLifecycleOperation;
+
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private CommonImportManager commonImportManager;
+
+ private static Logger log = LoggerFactory.getLogger(InterfaceLifecycleTypeImportManager.class.getName());
+
+ public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml) {
+
+ Either<List<InterfaceDefinition>, ActionStatus> interfaces = createLifecyclyTypeFromYml(interfaceLifecycleTypesYml);
+ if (interfaces.isRight()) {
+ ActionStatus status = interfaces.right().value();
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByGroupType(status, null);
+ return Either.right(responseFormat);
+ }
+ return createInterfacesByDao(interfaces.left().value());
+
+ }
+
+ private Either<List<InterfaceDefinition>, ActionStatus> createLifecyclyTypeFromYml(String interfaceLifecycleTypesYml) {
+ return commonImportManager.createElementTypesFromYml(interfaceLifecycleTypesYml, (lifecycleTypeName, lifecycleTypeJsonData) -> createLifecycleType(lifecycleTypeName, lifecycleTypeJsonData));
+
+ }
+
+ private Either<List<InterfaceDefinition>, ResponseFormat> createInterfacesByDao(List<InterfaceDefinition> interfacesToCreate) {
+ List<InterfaceDefinition> createdInterfaces = new ArrayList<>();
+ Either<List<InterfaceDefinition>, ResponseFormat> eitherResult = Either.left(createdInterfaces);
+ Iterator<InterfaceDefinition> interfaceItr = interfacesToCreate.iterator();
+ boolean stopDao = false;
+ while (interfaceItr.hasNext() && !stopDao) {
+ InterfaceDefinition interfaceDef = interfaceItr.next();
+
+ log.info("send interfaceDefinition {} to dao for create", interfaceDef.getType());
+
+ Either<InterfaceDefinition, StorageOperationStatus> dataModelResponse = interfaceLifecycleOperation.createInterfaceType(interfaceDef);
+ if (dataModelResponse.isRight()) {
+ log.info("failed to create interface : {} error: {}", interfaceDef.getType(), dataModelResponse.right().value().name());
+ if (dataModelResponse.right().value() != StorageOperationStatus.SCHEMA_VIOLATION) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForLifecycleType(dataModelResponse.right().value()), interfaceDef.getType());
+ eitherResult = Either.right(responseFormat);
+ stopDao = true;
+ }
+
+ } else {
+ createdInterfaces.add(dataModelResponse.left().value());
+ }
+ if (!interfaceItr.hasNext()) {
+ log.info("lifecycle types were created successfully!!!");
+ }
+ }
+ return eitherResult;
+ }
+
+ private InterfaceDefinition createLifecycleType(String interfaceDefinition, Map<String, Object> toscaJson) {
+ InterfaceDefinition interfaceDef = new InterfaceDefinition();
+ interfaceDef.setType(interfaceDefinition);
+
+ Map<String, Operation> operations = new HashMap<String, Operation>();
+
+ for (Map.Entry<String, Object> entry : toscaJson.entrySet()) {
+ Operation operation = new Operation();
+ Map<String, Object> opProp = (Map<String, Object>) entry.getValue();
+
+ operation.setDescription((String) opProp.get("description"));
+ operations.put(entry.getKey(), operation);
+ }
+ interfaceDef.setOperations(operations);
+ return interfaceDef;
+ }
+
+ public static void setLog(Logger log) {
+ InterfaceLifecycleTypeImportManager.log = log;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java
new file mode 100644
index 0000000000..e9708f50d5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.impl.MonitoringDao;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.common.monitoring.MonitoringEvent;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("monitoringBusinessLogic")
+public class MonitoringBusinessLogic {
+
+ private static Logger log = LoggerFactory.getLogger(MonitoringBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private MonitoringDao monitoringDao;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ public Either<Boolean, ResponseFormat> logMonitoringEvent(MonitoringEvent monitoringEvent) {
+ if (monitoringDao == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ ActionStatus status = monitoringDao.addRecord(monitoringEvent);
+ if (!status.equals(ActionStatus.OK)) {
+ log.warn("Failed to persist monitoring event: {}", status.name());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return Either.left(true);
+ }
+
+ public String getEsHost() {
+
+ String res = monitoringDao.getEsHost();
+ res = res.replaceAll("[\\[\\]]", "");
+ res = res.split(",")[0];
+ res = res.replaceAll("[']", "");
+ res = res.split(":")[0];
+ return res;
+ }
+
+ public String getEsPort() {
+ return monitoringDao.getEsPort();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
new file mode 100644
index 0000000000..1e0670daa2
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
+import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("policyTypeImportManager")
+public class PolicyTypeImportManager {
+
+ @Resource
+ private PropertyOperation propertyOperation;
+ @Resource
+ private IPolicyTypeOperation policyTypeOperation;
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Resource
+ private IResourceOperation resourceOperation;
+ @Autowired
+ protected IGroupOperation groupOperation;
+
+ @Resource
+ private CommonImportManager commonImportManager;
+
+ public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(String groupTypesYml) {
+ return commonImportManager.createElementTypes(groupTypesYml, elementTypeYml -> createPolicyTypesFromYml(elementTypeYml), groupTypesList -> createPolicyTypesByDao(groupTypesList), ElementTypeEnum.PolicyType);
+ }
+
+ private Either<List<PolicyTypeDefinition>, ActionStatus> createPolicyTypesFromYml(String policyTypesYml) {
+
+ return commonImportManager.createElementTypesFromYml(policyTypesYml, (policyTypeName, groupTypeJsonData) -> createPolicyType(policyTypeName, groupTypeJsonData));
+ }
+
+ private Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypesByDao(List<PolicyTypeDefinition> policyTypesToCreate) {
+ return commonImportManager.createElementTypesByDao(policyTypesToCreate, policyType -> validatePolicyType(policyType), policyType -> new ImmutablePair<>(ElementTypeEnum.PolicyType, policyType.getType()),
+ policyTypeName -> policyTypeOperation.getLatestPolicyTypeByType(policyTypeName), policyType -> policyTypeOperation.addPolicyType(policyType), null);
+ }
+
+ private Either<ActionStatus, ResponseFormat> validatePolicyType(PolicyTypeDefinition policyType) {
+ Either<ActionStatus, ResponseFormat> result = Either.left(ActionStatus.OK);
+ if (policyType.getTargets() != null) {
+ if (policyType.getTargets().isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.TARGETS_EMPTY, policyType.getType());
+ result = Either.right(responseFormat);
+ }
+ if (result.isLeft()) {
+ for (String targetName : policyType.getTargets()) {
+ boolean isValid = resourceOperation.getLatestByToscaResourceName(targetName, false).isLeft();
+ if (!isValid) {
+ isValid = groupOperation.isGroupExist(targetName, false);
+ }
+ if (!isValid) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.TARGETS_NON_VALID, policyType.getType(), targetName);
+ result = Either.right(responseFormat);
+ break;
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private PolicyTypeDefinition createPolicyType(String groupTypeName, Map<String, Object> toscaJson) {
+
+ PolicyTypeDefinition policyType = new PolicyTypeDefinition();
+
+ if (toscaJson != null) {
+ // Description
+ final Consumer<String> descriptionSetter = description -> policyType.setDescription(description);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DESCRIPTION.getElementName(), descriptionSetter);
+ // Derived From
+ final Consumer<String> derivedFromSetter = derivedFrom -> policyType.setDerivedFrom(derivedFrom);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.DERIVED_FROM.getElementName(), derivedFromSetter);
+ // Properties
+ commonImportManager.setProperties(toscaJson, (values) -> policyType.setProperties(values));
+ // Metadata
+ final Consumer<Map<String, String>> metadataSetter = metadata -> policyType.setMetadata(metadata);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.METADATA.getElementName(), metadataSetter);
+ // Targets
+ final Consumer<List<String>> targetsSetter = targets -> policyType.setTargets(targets);
+ commonImportManager.setField(toscaJson, ToscaTagNamesEnum.TARGETS.getElementName(), targetsSetter);
+
+ policyType.setType(groupTypeName);
+
+ policyType.setHighestVersion(true);
+
+ policyType.setVersion(ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION);
+ }
+ return policyType;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
new file mode 100644
index 0000000000..3a54513b0b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
@@ -0,0 +1,887 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Product;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ProductOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("productBusinessLogic")
+public class ProductBusinessLogic extends ComponentBusinessLogic {
+
+ private static final String PRODUCT_FULL_NAME = "full";
+ private static final String PRODUCT_ABBREVIATED_NAME = "abbreviated";
+ private static Logger log = LoggerFactory.getLogger(ProductBusinessLogic.class.getName());
+ private static final String INITIAL_VERSION = "0.1";
+ private static List<Role> creationRoles;
+ private static List<Role> updateRoles;
+ private static List<Role> contactsRoles;
+
+ public ProductBusinessLogic() {
+ creationRoles = new ArrayList<>();
+ updateRoles = new ArrayList<>();
+ contactsRoles = new ArrayList<>();
+
+ // only PM is allowed to create/update products
+ creationRoles.add(Role.PRODUCT_MANAGER);
+ updateRoles.add(Role.PRODUCT_MANAGER);
+ // Only PM is allowed to be product contacts
+ contactsRoles.add(Role.PRODUCT_MANAGER);
+ }
+
+ @Autowired
+ private IElementOperation elementDao;
+
+ @Autowired
+ private ProductComponentInstanceBusinessLogic productComponentInstanceBusinessLogic;
+
+ @Autowired
+ private ICacheMangerOperation cacheManagerOperation;
+
+ public Either<Product, ResponseFormat> createProduct(Product product, User user) {
+ AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE;
+ ComponentTypeEnum typeEnum = ComponentTypeEnum.PRODUCT;
+
+ // validate user - should be first to get the maximum auditing info in
+ // case of subsequent failures
+ log.debug("get user from DB");
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "Create Product", product, actionEnum, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ // validate user role
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, product, creationRoles, actionEnum, null);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+
+ if (product == null) {
+ log.debug("Invalid product json. Check product servlet log for createProduct entry params");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, Constants.EMPTY_STRING, Constants.EMPTY_STRING, actionEnum, typeEnum);
+ return Either.right(responseFormat);
+ }
+
+ // warn about non-updatable fields
+ checkUnupdatableProductFields(product);
+
+ Either<Product, ResponseFormat> validateProductResponse = validateProductBeforeCreate(product, user, actionEnum);
+ if (validateProductResponse.isRight()) {
+ return Either.right(validateProductResponse.right().value());
+ }
+
+ log.debug("send product {} to dao for create", product.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(product.getSystemName(), product, "Create Product");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ log.debug("Product name locked is {}, status = {}", product.getSystemName(), lockResult);
+
+ try {
+ Either<Product, StorageOperationStatus> createProductEither = productOperation.createProduct(product);
+
+ if (createProductEither.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(createProductEither.right().value()), product, typeEnum);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, Constants.EMPTY_STRING, Constants.EMPTY_STRING, actionEnum, typeEnum);
+ return Either.right(responseFormat);
+ }
+
+ log.debug("Product created successfully");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, Constants.EMPTY_STRING, Constants.EMPTY_STRING, actionEnum, typeEnum);
+
+ // //Add product to cache
+ Product createdProduct = createProductEither.left().value();
+ // cacheManagerOperation.updateComponentInCache(createdProduct.getUniqueId(),
+ // createdProduct.getLastUpdateDate(), NodeTypeEnum.Product);
+
+ return Either.left(createdProduct);
+
+ } finally {
+ graphLockOperation.unlockComponentByName(product.getSystemName(), product.getUniqueId(), NodeTypeEnum.Product);
+ }
+
+ }
+
+ private void checkUnupdatableProductFields(Product product) {
+ checkComponentFieldsForOverrideAttempt(product);
+ if (product.getNormalizedName() != null) {
+ log.info("NormalizedName cannot be defined by user. This field will be overridden by the application");
+ }
+ }
+
+ private Either<Product, ResponseFormat> validateProductBeforeCreate(Product product, User user, AuditingActionEnum actionEnum) {
+
+ Either<Boolean, ResponseFormat> validateProductFields = validateProductFieldsBeforeCreate(user, product, actionEnum);
+ if (validateProductFields.isRight()) {
+ return Either.right(validateProductFields.right().value());
+ }
+
+ if (product.getIsActive() == null) {
+ log.debug("no isActive value was provided, setting to default: false");
+ product.setIsActive(false);
+ }
+
+ product.setCreatorUserId(user.getUserId());
+
+ // enrich object
+ log.debug("enrich product with version and state");
+ product.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ product.setVersion(INITIAL_VERSION);
+
+ // Generate invariant UUID - must be here and not in operation since it
+ // should stay constant during clone
+ String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
+ product.setInvariantUUID(invariantUUID);
+
+ return Either.left(product);
+ }
+
+ private Either<Boolean, ResponseFormat> validateProductFieldsBeforeCreate(User user, Product product, AuditingActionEnum actionEnum) {
+
+ // To be removed in 1607
+ // See below
+ String oldName = product.getName();
+
+ Either<Boolean, ResponseFormat> componentNameValidation = validateProductNameAndCleanup(user, product, actionEnum);
+ if (componentNameValidation.isRight()) {
+ return componentNameValidation;
+ }
+
+ Either<Boolean, ResponseFormat> componentNameUniquenessValidation = validateComponentNameUnique(user, product, actionEnum);
+ if (componentNameUniquenessValidation.isRight()) {
+ return componentNameUniquenessValidation;
+ }
+
+ // To be removed in 1607 and replaced with generic
+ // validateTagsListAndRemoveDuplicates()
+ // See comments on the validateTagsListAndRemoveDuplicates(user,
+ // product, oldName, actionEnum) function
+ Either<Boolean, ResponseFormat> tagsValidation = validateTagsListAndRemoveDuplicates(user, product, oldName, actionEnum);
+ if (tagsValidation.isRight()) {
+ return tagsValidation;
+ }
+
+ Either<Boolean, ResponseFormat> validateIconResponse = validateIcon(user, product, actionEnum);
+ if (validateIconResponse.isRight()) {
+ return validateIconResponse;
+ }
+
+ Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, product, actionEnum);
+ if (projectCodeValidation.isRight()) {
+ return projectCodeValidation;
+ }
+ Either<Boolean, ResponseFormat> categoryValidation = validateGrouping(user, product, actionEnum);
+ if (categoryValidation.isRight()) {
+ return categoryValidation;
+ }
+
+ Either<Boolean, ResponseFormat> contactsListValidation = validateAndUpdateProductContactsList(user, product, actionEnum);
+ if (contactsListValidation.isRight()) {
+ return contactsListValidation;
+ }
+
+ Either<Boolean, ResponseFormat> productFullNameValidation = validateProductFullNameAndCleanup(user, product, actionEnum);
+ if (productFullNameValidation.isRight()) {
+ return productFullNameValidation;
+ }
+
+ Either<Boolean, ResponseFormat> descValidation = validateDescriptionAndCleanup(user, product, actionEnum);
+ if (descValidation.isRight()) {
+ return descValidation;
+ }
+
+ return Either.left(true);
+ }
+
+ public Either<Map<String, Boolean>, ResponseFormat> validateProductNameExists(String productName, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "validate Product Name Exists", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<Boolean, StorageOperationStatus> dataModelResponse = productOperation.validateComponentNameExists(productName);
+
+ if (dataModelResponse.isLeft()) {
+ Map<String, Boolean> result = new HashMap<>();
+ result.put("isValid", dataModelResponse.left().value());
+ log.debug("validation was successfully performed.");
+ return Either.left(result);
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
+
+ return Either.right(responseFormat);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateProductContactsList(User user, Product product, AuditingActionEnum actionEnum) {
+ List<String> contacts = product.getContacts();
+ if (!ValidationUtils.validateListNotEmpty(contacts)) {
+ log.debug("Contacts list cannot be empty for product {}", product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.EMPTY_PRODUCT_CONTACTS_LIST);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ boolean isProductCreatorInContacts = false;
+ String modifierUserId = user.getUserId();
+ for (String contact : contacts) {
+ if (contact.equals(modifierUserId)) {
+ log.trace("modifier userId found in product contacts");
+ isProductCreatorInContacts = true;
+ // No need to validate for this userId - it's modifier's
+ continue;
+ }
+ if (!ValidationUtils.validateContactId(contact)) {
+ log.debug("Product contacts has invalid userId {} for product {}", contact, product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.PRODUCT.getValue());
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ User contactUser = new User();
+ contactUser.setUserId(contact);
+ Either<User, ResponseFormat> validateUser = validateUserExists(contact, "Create Product", false);
+ if (validateUser.isRight()) {
+ log.debug("Cannot set contact with userId {} as product contact, error: {}", contact, validateUser.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PRODUCT_CONTACT, contact);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ contactUser = validateUser.left().value();
+
+ Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(contactUser, contactsRoles);
+ if (validateUserRole.isRight()) {
+ log.debug("Cannot set contact with userId {} as product contact, error: {}", contact, validateUserRole.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PRODUCT_CONTACT, contact);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ }
+
+ if (!isProductCreatorInContacts) {
+ log.debug("modifier userId {} not found in product contacts - adding it", modifierUserId);
+ contacts.add(modifierUserId);
+ }
+
+ // passed - setting all contacts user ids to lowercase
+ List<String> tempContacts = contacts.stream().map(e -> e.toLowerCase()).collect(Collectors.toList());
+ ValidationUtils.removeDuplicateFromList(tempContacts);
+ product.setContacts(tempContacts);
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateGrouping(User user, Product product, AuditingActionEnum actionEnum) {
+ List<CategoryDefinition> categories = product.getCategories();
+ if (categories == null || categories.isEmpty()) {
+ log.debug("Grouping list is empty for product {}", product.getName());
+ return Either.left(true);
+ }
+ Map<String, Map<String, Set<String>>> nonDuplicatedCategories = new HashMap<String, Map<String, Set<String>>>();
+ // remove duplicated entries
+ for (CategoryDefinition cat : categories) {
+ String catName = cat.getName();
+ if (ValidationUtils.validateStringNotEmpty(catName) == false) {
+ // error missing cat name
+ log.debug("Missing category name for product {}", product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.PRODUCT.getValue());
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ Map<String, Set<String>> catEntry = nonDuplicatedCategories.get(catName);
+ if (catEntry == null) {
+ catEntry = new HashMap<String, Set<String>>();
+ nonDuplicatedCategories.put(catName, catEntry);
+ }
+ List<SubCategoryDefinition> subcategories = cat.getSubcategories();
+ if (subcategories == null || subcategories.isEmpty()) {
+ // error missing subcat for cat
+ log.debug("Missing sub-categories for category {} in product {}", catName, product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ for (SubCategoryDefinition subcat : subcategories) {
+ String subCatName = subcat.getName();
+ if (ValidationUtils.validateStringNotEmpty(subCatName) == false) {
+ // error missing sub cat name for cat
+ log.debug("Missing or empty sub-category for category {} in product {}", catName, product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ Set<String> subcatEntry = catEntry.get(subCatName);
+ if (subcatEntry == null) {
+ subcatEntry = new HashSet<String>();
+ catEntry.put(subCatName, subcatEntry);
+ }
+ List<GroupingDefinition> groupings = subcat.getGroupings();
+ for (GroupingDefinition group : groupings) {
+ String groupName = group.getName();
+ if (ValidationUtils.validateStringNotEmpty(groupName) == false) {
+ // error missing grouping for sub cat name and cat
+ log.debug("Missing or empty groupng name for sub-category {} for category {} in product {}", subCatName, catName, product.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ if (!subcatEntry.contains(groupName)) {
+ subcatEntry.add(groupName);
+ } else {
+ log.debug("Grouping [ {} ] already exist for category [ {} ] and subcategory [ {} ]", groupName, catName, subCatName);
+ }
+ }
+ }
+ } // for end of checking duplicated
+ // validate existence
+ Either<List<CategoryDefinition>, ActionStatus> allProductCategories = elementDao.getAllProductCategories();
+
+ if (allProductCategories.isRight()) {
+ log.debug("No product categories {}", allProductCategories.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(allProductCategories.right().value());
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ boolean catExist;
+ // convert non-duplicated to data modeling format and update in the
+ // input object
+ List<CategoryDefinition> newCatList = new ArrayList<CategoryDefinition>();
+
+ // over all categories from request
+ for (Map.Entry<String, Map<String, Set<String>>> entry : nonDuplicatedCategories.entrySet()) {
+ catExist = false;
+ CategoryDefinition categoryDefinition = null;
+ // over all categories from Titan
+ List<CategoryDefinition> categoriesList = allProductCategories.left().value();
+ if (categoriesList != null) {
+ for (CategoryDefinition catInDb : categoriesList) {
+ if (entry.getKey().equals(catInDb.getName())) {
+ catExist = true;
+ boolean subcatExist;
+ // copy data
+ categoryDefinition = new CategoryDefinition(catInDb);
+ SubCategoryDefinition subCategory = null;
+
+ Map<String, Set<String>> subcats = entry.getValue();
+ for (Map.Entry<String, Set<String>> subcat : subcats.entrySet()) {
+ subcatExist = false;
+ List<SubCategoryDefinition> subcategoriesList = catInDb.getSubcategories();
+ if (subcategoriesList != null) {
+ for (SubCategoryDefinition subcatInDb : subcategoriesList) {
+ if (subcatInDb.getName().equals(subcat.getKey())) {
+ // copy data
+ subCategory = new SubCategoryDefinition(subcatInDb);
+ subcatExist = true;
+ Set<String> grouping = subcat.getValue();
+ boolean groupExist;
+ GroupingDefinition groupingDefinition = null;
+ for (String group : grouping) {
+ groupExist = false;
+ List<GroupingDefinition> groupings = subcatInDb.getGroupings();
+ if (groupings != null) {
+ for (GroupingDefinition groupInDb : groupings) {
+ if (groupInDb.getName().equals(group)) {
+ groupExist = true;
+ groupingDefinition = new GroupingDefinition(groupInDb);
+ }
+ }
+ }
+ if (!groupExist) {
+ // error grouping isn't defined
+ // in Titan
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_GROUP_ASSOCIATION, CategoryTypeEnum.GROUPING.getValue(), group);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ subCategory.addGrouping(groupingDefinition);
+ }
+ }
+ }
+ }
+ if (!subcatExist) {
+ // error sub category isn't defined in Titan
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_GROUP_ASSOCIATION, CategoryTypeEnum.SUBCATEGORY.getValue(), subcat.getKey());
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ categoryDefinition.addSubCategory(subCategory);
+ }
+ }
+ }
+ }
+ if (!catExist) {
+ // error category isn't defined in Titan
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_GROUP_ASSOCIATION, CategoryTypeEnum.CATEGORY.getValue(), entry.getKey());
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ newCatList.add(categoryDefinition);
+ }
+ product.setCategories(newCatList);
+ return Either.left(true);
+ }
+
+ public Either<Product, ResponseFormat> getProduct(String productId, User user) {
+ String ecompErrorContext = "Get product";
+ Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
+ if (validateEmptyResult.isRight()) {
+ return Either.right(validateEmptyResult.right().value());
+ }
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+
+ Either<Product, StorageOperationStatus> storageStatus = productOperation.getComponent(productId, false);
+
+ if (storageStatus.isRight()) {
+ log.debug("failed to get resource by id {}", productId);
+ if (storageStatus.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ // TODO check error
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PRODUCT_NOT_FOUND, ComponentTypeEnum.PRODUCT.getValue()));
+ } else {
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
+ }
+ }
+ return Either.left(storageStatus.left().value());
+ }
+
+ public Either<Product, ResponseFormat> deleteProduct(String productId, User user) {
+ String ecompErrorContext = "Delete product";
+ Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
+ if (validateEmptyResult.isRight()) {
+ return Either.right(validateEmptyResult.right().value());
+ }
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+
+ Either<Product, StorageOperationStatus> storageStatus = productOperation.deleteProduct(productId, false);
+
+ if (storageStatus.isRight()) {
+ log.debug("failed to delete resource by id {}", productId);
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
+ }
+ return Either.left(storageStatus.left().value());
+ }
+
+ private Either<Boolean, ResponseFormat> validateProductFullNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
+ String fullName = product.getFullName();
+ if (!ValidationUtils.validateStringNotEmpty(fullName)) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_FULL_NAME);
+ componentsUtils.auditComponentAdmin(errorResponse, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(errorResponse);
+ }
+
+ fullName = ValidationUtils.removeNoneUtf8Chars(fullName);
+ fullName = ValidationUtils.removeHtmlTags(fullName);
+ fullName = ValidationUtils.normaliseWhitespace(fullName);
+ fullName = ValidationUtils.stripOctets(fullName);
+
+ if (!ValidationUtils.validateProductFullNameLength(fullName)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_FULL_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ if (!ValidationUtils.validateIsEnglish(fullName)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_FULL_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ product.setFullName(fullName);
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateProductNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
+ String name = product.getName();
+ if (!ValidationUtils.validateStringNotEmpty(name)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_ABBREVIATED_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ // Product name is required to have same validation and normalization as
+ // category
+ if (!ValidationUtils.validateCategoryDisplayNameFormat(name)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_ABBREVIATED_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ String normalizedName4Display = ValidationUtils.normalizeCategoryName4Display(name);
+
+ if (!ValidationUtils.validateCategoryDisplayNameLength(normalizedName4Display)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_ABBREVIATED_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+
+ product.setName(normalizedName4Display);
+ String normalizedName4Uniqueness = ValidationUtils.normaliseComponentName(normalizedName4Display);
+ product.setNormalizedName(normalizedName4Uniqueness);
+
+ return Either.left(true);
+ }
+
+ // This is a workaround for a current tag--->product name behaviour, which
+ // will be changed in 1607.
+ // It was agreed with Ella on 23/2/16 that the tag validation of product
+ // will be made against the old product name (before normalization),
+ // and in 1607 US will be defined where UI will no longer pass tag of
+ // component name, and BE will add it by itself after all needed
+ // normalizations.
+ private Either<Boolean, ResponseFormat> validateTagsListAndRemoveDuplicates(User user, Product product, String oldProductName, AuditingActionEnum actionEnum) {
+ List<String> tagsList = product.getTags();
+
+ Either<Boolean, ResponseFormat> validateTags = validateComponentTags(tagsList, oldProductName, ComponentTypeEnum.PRODUCT);
+ if (validateTags.isRight()) {
+ ResponseFormat responseFormat = validateTags.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, product, "", "", actionEnum, ComponentTypeEnum.PRODUCT);
+ return Either.right(responseFormat);
+ }
+ ValidationUtils.removeDuplicateFromList(tagsList);
+ return Either.left(true);
+ }
+
+ @Override
+ public void setDeploymentArtifactsPlaceHolder(org.openecomp.sdc.be.model.Component component, User user) {
+
+ }
+
+ public Either<Product, ResponseFormat> updateProductMetadata(String productId, Product updatedProduct, User user) {
+ ComponentTypeEnum typeEnum = ComponentTypeEnum.PRODUCT;
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "Update Product", updatedProduct, null, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ // validate user role
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, updatedProduct, updateRoles, null, null);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+
+ if (updatedProduct == null) {
+ log.debug("Invalid product json. Check product servlet log for updateProduct entry params");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return Either.right(responseFormat);
+ }
+
+ Either<Product, StorageOperationStatus> storageStatus = productOperation.getComponent(productId, false);
+ if (storageStatus.isRight()) {
+ if (storageStatus.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PRODUCT_NOT_FOUND, ComponentTypeEnum.PRODUCT.name().toLowerCase()));
+ }
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), typeEnum), ""));
+ }
+
+ Product currentProduct = storageStatus.left().value();
+
+ if (!ComponentValidationUtils.canWorkOnComponent(productId, productOperation, user.getUserId())) {
+ log.info("Restricted operation for user {} on product {}", user.getUserId(), currentProduct.getCreatorUserId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ Either<Product, ResponseFormat> validationRsponse = validateAndUpdateProductMetadata(user, currentProduct, updatedProduct);
+ if (validationRsponse.isRight()) {
+ log.info("product update metadata: validations field.");
+ return validationRsponse;
+ }
+
+ Product productToUpdate = validationRsponse.left().value();
+ // lock resource
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(currentProduct.getUniqueId(), currentProduct, "Update Product Metadata");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+ try {
+ Either<Product, StorageOperationStatus> updateResponse = productOperation.updateComponent(productToUpdate, true);
+ if (updateResponse.isRight()) {
+ productOperation.rollback();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Update Product Metadata");
+ log.debug("failed to update product {}", productToUpdate.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ productOperation.commit();
+ return Either.left(updateResponse.left().value());
+ } finally {
+ graphLockOperation.unlockComponent(productId, NodeTypeEnum.Product);
+ }
+ }
+
+ private Either<Product, ResponseFormat> validateAndUpdateProductMetadata(User user, Product currentProduct, Product updatedProduct) {
+
+ boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentProduct.getVersion());
+ Either<Boolean, ResponseFormat> response = validateAndUpdateProductName(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateFullName(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateDescription(user, currentProduct, updatedProduct, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateCategory(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateContactList(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateTags(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateProjectCode(user, currentProduct, updatedProduct);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ if (updatedProduct.getIsActive() != null) {
+ currentProduct.setIsActive(updatedProduct.getIsActive());
+ }
+
+ response = validateAndUpdateIcon(user, currentProduct, updatedProduct, hasBeenCertified);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ String currentInvariantUuid = currentProduct.getInvariantUUID();
+ String updatedInvariantUuid = updatedProduct.getInvariantUUID();
+
+ if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
+ log.warn("Product invariant UUID is automatically set and cannot be updated");
+ updatedProduct.setInvariantUUID(currentInvariantUuid);
+ }
+ return Either.left(currentProduct);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateProductName(User user, Product currentProduct, Product updatedProduct) {
+ String updatedProductName = updatedProduct.getName();
+ String tags = "";
+ String currentProductName = currentProduct.getName();
+ if (updatedProductName != null) {
+ Either<Boolean, ResponseFormat> validatProductNameResponse = validateProductNameAndCleanup(user, updatedProduct, null);
+ if (validatProductNameResponse.isRight()) {
+ ResponseFormat errorRespons = validatProductNameResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ updatedProductName = updatedProduct.getName();
+ if (!currentProductName.equals(updatedProductName)) {
+ Either<Boolean, ResponseFormat> productNameUniquenessValidation = validateComponentNameUnique(user, updatedProduct, null);
+ if (productNameUniquenessValidation.isRight()) {
+ return productNameUniquenessValidation;
+ }
+ currentProduct.setName(updatedProductName);
+ tags = updatedProductName;
+ updatedProductName = ValidationUtils.normalizeCategoryName4Display(updatedProductName);
+ currentProduct.getComponentMetadataDefinition().getMetadataDataDefinition().setNormalizedName(ValidationUtils.normaliseComponentName(updatedProductName));
+ List<String> updatedTags = updatedProduct.getTags();
+ // As discussed with Ella currently (1604) we are not removing
+ // the old name from tags.
+ if (updatedTags == null) {
+ updatedTags = currentProduct.getTags();
+ }
+ updatedTags.add(tags);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateFullName(User user, Product currentProduct, Product updatedProduct) {
+ String updatedProductName = updatedProduct.getFullName();
+ String currentProductName = currentProduct.getFullName();
+ if (updatedProductName != null && !currentProductName.equals(updatedProductName)) {
+ Either<Boolean, ResponseFormat> validatProductNameResponse = validateProductFullNameAndCleanup(user, updatedProduct, null);
+ if (validatProductNameResponse.isRight()) {
+ ResponseFormat errorRespons = validatProductNameResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentProduct.setFullName(updatedProduct.getFullName());
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateCategory(User user, Product currentProduct, Product updatedProduct) {
+ List<CategoryDefinition> categoryUpdated = updatedProduct.getCategories();
+ List<CategoryDefinition> categoryCurrent = currentProduct.getCategories();
+
+ Either<Boolean, ResponseFormat> validatCategoryResponse = validateGrouping(user, updatedProduct, null);
+ if (validatCategoryResponse.isRight()) {
+ ResponseFormat errorResponse = validatCategoryResponse.right().value();
+ return Either.right(errorResponse);
+ }
+
+ categoryUpdated = updatedProduct.getCategories();
+ if (categoryUpdated != null) {
+ currentProduct.setCategories(categoryUpdated);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateContactList(User user, Product currentProduct, Product updatedProduct) {
+ List<String> updatedContacts = updatedProduct.getContacts();
+ List<String> currentContacts = currentProduct.getContacts();
+ if (updatedContacts != null) {
+ if (!(currentContacts.containsAll(updatedContacts) && updatedContacts.containsAll(currentContacts))) {
+ Either<Boolean, ResponseFormat> validatResponse = validateAndUpdateProductContactsList(user, updatedProduct, null);
+ if (validatResponse.isRight()) {
+ ResponseFormat errorRespons = validatResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentProduct.setContacts(updatedProduct.getContacts());
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateTags(User user, Product currentProduct, Product updatedProduct) {
+ List<String> tagsUpdated = updatedProduct.getTags();
+ List<String> tagsCurrent = currentProduct.getTags();
+ if (tagsUpdated != null) {
+ if (!(tagsCurrent.containsAll(tagsUpdated) && tagsUpdated.containsAll(tagsCurrent))) {
+ Either<Boolean, ResponseFormat> validatResponse = validateTagsListAndRemoveDuplicates(user, updatedProduct, currentProduct.getName(), null);
+ if (validatResponse.isRight()) {
+ ResponseFormat errorRespons = validatResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentProduct.setTags(updatedProduct.getTags());
+ }
+ }
+ return Either.left(true);
+ }
+
+ @Override
+ public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
+ // markAsDeleted isnt implemented yet
+ return Either.left(new ArrayList<>());
+ }
+
+ @Override
+ protected boolean validateTagPattern(String tag) {
+ return ValidationUtils.validateCategoryDisplayNameFormat(tag);
+ }
+
+ public Either<Product, ResponseFormat> getProductByNameAndVersion(String productName, String productVersion, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Service By Name And Version", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<Product, StorageOperationStatus> storageStatus = productOperation.getProductByNameAndVersion(productName, productVersion, false);
+ if (storageStatus.isRight()) {
+ log.debug("failed to get service by name {} and version {}", productName, productVersion);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.PRODUCT), productName));
+ }
+ Product product = storageStatus.left().value();
+ return Either.left(product);
+ }
+
+ @Override
+ public ComponentInstanceBusinessLogic getComponentInstanceBL() {
+ return productComponentInstanceBusinessLogic;
+ }
+
+ @Override
+ public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
+ return null;
+ }
+
+ public ICacheMangerOperation getCacheManagerOperation() {
+ return cacheManagerOperation;
+ }
+
+ public void setCacheManagerOperation(ICacheMangerOperation cacheManagerOperation) {
+ this.cacheManagerOperation = cacheManagerOperation;
+ }
+
+ public void setProductOperation(ProductOperation productOperation) {
+ this.productOperation = productOperation;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java
new file mode 100644
index 0000000000..46188012d8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("productComponentInstanceBusinessLogic")
+public class ProductComponentInstanceBusinessLogic extends ComponentInstanceBusinessLogic {
+
+ @Override
+ protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
+ return Either.left(true);
+ }
+
+ @Override
+ protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
+ // TODO Pavel this might be also a resource?
+ return NodeTypeEnum.Service;
+ }
+
+ @Override
+ protected ComponentOperation getContainerComponentOperation() {
+ return productOperation;
+ }
+
+ @Override
+ protected ComponentOperation getCompInstOriginComponentOperation() {
+ return serviceOperation;
+ }
+
+ @Override
+ protected ComponentTypeEnum getComponentTypeOfComponentInstance() {
+ return ComponentTypeEnum.SERVICE_INSTANCE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
new file mode 100644
index 0000000000..1e6b1c1d82
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
@@ -0,0 +1,391 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.servlet.ServletContext;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.be.resources.data.PropertyData;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.WebApplicationContext;
+
+import fj.data.Either;
+
+@Component("propertyBusinessLogic")
+public class PropertyBusinessLogic extends BaseBusinessLogic {
+
+ private static final String CREATE_PROPERTY = "CreateProperty";
+
+ private static Logger log = LoggerFactory.getLogger(PropertyBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private IResourceOperation resourceOperation = null;
+
+ @javax.annotation.Resource
+ private PropertyOperation propertyOperation = null;
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+
+ return webApplicationContext.getBean(class1);
+ }
+
+ public Either<Map<String, DataTypeDefinition>, ResponseFormat> getAllDataTypes() {
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
+ return eitherAllDataTypes;
+ }
+
+ /**
+ * Create new property on resource in graph
+ *
+ * @param resourceId
+ * @param propertyName
+ * @param newPropertyDefinition
+ * @param userId
+ * @return Either<PropertyDefinition, ActionStatus>
+ */
+ public Either<EntryData<String, PropertyDefinition>, ResponseFormat> createProperty(String resourceId, String propertyName, PropertyDefinition newPropertyDefinition, String userId) {
+
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> result = null;
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Property", false);
+ if (resp.isRight()) {
+ result = Either.right(resp.right().value());
+ return result;
+ }
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_PROPERTY, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ log.info("Failed to lock component {}. Error - {}", resourceId, lockResult);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+
+ try {
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ return result;
+ }
+ Resource resource = status.left().value();
+
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ return result;
+ }
+
+ // verify property not exist in resource
+ List<PropertyDefinition> resourceProperties = resource.getProperties();
+
+ if (resourceProperties != null) {
+ if (propertyOperation.isPropertyExist(resourceProperties, resourceId, propertyName)) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, ""));
+ return result;
+ }
+ }
+
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ result = Either.right(allDataTypes.right().value());
+ return result;
+ }
+
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+
+ // validate property default values
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newPropertyDefinition, dataTypes);
+ if (defaultValuesValidation.isRight()) {
+ result = Either.right(defaultValuesValidation.right().value());
+ return result;
+ }
+ // convert property
+ ToscaPropertyType type = getType(newPropertyDefinition.getType());
+ if (type != null) {
+ PropertyValueConverter converter = type.getConverter();
+ // get inner type
+ String innerType = null;
+ if (newPropertyDefinition != null) {
+ SchemaDefinition schema = newPropertyDefinition.getSchema();
+ if (schema != null) {
+ PropertyDataDefinition prop = schema.getProperty();
+ if (prop != null) {
+ innerType = prop.getType();
+ }
+ }
+ String convertedValue = null;
+ if (newPropertyDefinition.getDefaultValue() != null) {
+ convertedValue = converter.convert(newPropertyDefinition.getDefaultValue(), innerType, allDataTypes.left().value());
+ newPropertyDefinition.setDefaultValue(convertedValue);
+ }
+ }
+ }
+
+ // add the new property to resource on graph
+ // need to get StorageOpaerationStatus and convert to ActionStatus
+ // from componentsUtils
+ Either<PropertyData, StorageOperationStatus> either = propertyOperation.addProperty(propertyName, newPropertyDefinition, resourceId);
+ if (either.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(either.right().value()), resource.getName()));
+ return result;
+ }
+
+ PropertyDefinition createdPropertyDefinition = propertyOperation.convertPropertyDataToPropertyDefinition(either.left().value(), propertyName, resourceId);
+ EntryData<String, PropertyDefinition> property = new EntryData<String, PropertyDefinition>(propertyName, createdPropertyDefinition);
+ result = Either.left(property);
+ return result;
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+
+ }
+
+ /**
+ * Get property of resource
+ *
+ * @param resourceId
+ * @param propertyId
+ * @param userId
+ * TODO
+ * @return
+ */
+ public Either<Entry<String, PropertyDefinition>, ResponseFormat> getProperty(String resourceId, String propertyId, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "create Component Instance", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = status.left().value();
+
+ // verify property exist in resource
+ List<PropertyDefinition> properties = resource.getProperties();
+ if (properties == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, ""));
+ }
+ for (PropertyDefinition property : properties) {
+ // esofer - check also that the property belongs to the current
+ // resource
+ if (property.getUniqueId().equals(propertyId) && property.getParentUniqueId().equals(resourceId)) {
+ Map<String, PropertyDefinition> propMap = new HashMap<>();
+ propMap.put(property.getName(), property);
+ return Either.left(propMap.entrySet().iterator().next());
+ }
+ }
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, ""));
+ }
+
+ /**
+ * delete property of resource from graph
+ *
+ * @param resourceId
+ * @param propertyId
+ * @param userId
+ * @return
+ */
+ public Either<EntryData<String, PropertyDefinition>, ResponseFormat> deleteProperty(String resourceId, String propertyId, String userId) {
+
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> result = null;
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "delete Property", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_PROPERTY, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+
+ try {
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ return result;
+ }
+ Resource resource = status.left().value();
+
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ return result;
+ }
+
+ // verify property exist in resource
+ Either<Entry<String, PropertyDefinition>, ResponseFormat> statusGetProperty = getProperty(resourceId, propertyId, userId);
+ if (statusGetProperty.isRight()) {
+ result = Either.right(statusGetProperty.right().value());
+ return result;
+ }
+ String propertyName = statusGetProperty.left().value().getKey();
+
+ // delete property of resource from graph
+ // TODO: need to get StorageOperationStatus
+ Either<PropertyData, StorageOperationStatus> either = propertyOperation.deleteProperty(propertyId);
+ // Either<PropertyData, StorageOperationStatus> either =
+ // propertyOperation.deletePropertyFromGraph(propertyId);
+ if (either.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(either.right().value()), resource.getName()));
+ return result;
+ }
+ // propertyOperation.getTitanGenericDao().commit();
+ PropertyDefinition createdPropertyDefinition = propertyOperation.convertPropertyDataToPropertyDefinition(either.left().value(), propertyName, resourceId);
+ EntryData<String, PropertyDefinition> property = new EntryData<String, PropertyDefinition>(propertyName, createdPropertyDefinition);
+ result = Either.left(property);
+ return result;
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+ }
+
+ /**
+ * update property
+ *
+ * @param resourceId
+ * @param propertyId
+ * @param newPropertyDefinition
+ * @param userId
+ * @return
+ */
+ public Either<EntryData<String, PropertyDefinition>, ResponseFormat> updateProperty(String resourceId, String propertyId, PropertyDefinition newPropertyDefinition, String userId) {
+
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> result = null;
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
+ }
+ Resource resource = status.left().value();
+
+ // verify that resource is checked-out and the user is the last updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_PROPERTY, NodeTypeEnum.Resource.name().toLowerCase(), resourceId);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return result;
+ }
+
+ try {
+
+ // verify property exist in resource
+ Either<Entry<String, PropertyDefinition>, ResponseFormat> statusGetProperty = getProperty(resourceId, propertyId, userId);
+ if (statusGetProperty.isRight()) {
+ result = Either.right(statusGetProperty.right().value());
+ return result;
+ }
+ String propertyName = statusGetProperty.left().value().getKey();
+
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ result = Either.right(allDataTypes.right().value());
+ return result;
+ }
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ // validate property default values
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newPropertyDefinition, dataTypes);
+ if (defaultValuesValidation.isRight()) {
+ result = Either.right(defaultValuesValidation.right().value());
+ return result;
+ }
+
+ // add the new property to resource on graph
+ // TODO: convert TitanOperationStatus to Storgae...
+ Either<PropertyData, StorageOperationStatus> either = propertyOperation.updateProperty(propertyId, newPropertyDefinition, dataTypes);
+ // Either<PropertyData, StorageOperationStatus> either =
+ // propertyOperation.updatePropertyFromGraph(propertyId,
+ // newPropertyDefinition);
+ if (either.isRight()) {
+ log.debug("Problem while updating property with id {}. Reason - {}", propertyId, either.right().value());
+ result = Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(either.right().value()), resource.getName()));
+ return result;
+ // return Either.right(ActionStatus.GENERAL_ERROR);
+ }
+
+ PropertyDefinition createdPropertyDefinition = propertyOperation.convertPropertyDataToPropertyDefinition(either.left().value(), propertyName, resourceId);
+ EntryData<String, PropertyDefinition> property = new EntryData<String, PropertyDefinition>(propertyName, createdPropertyDefinition);
+ result = Either.left(property);
+ return result;
+
+ } finally {
+ commitOrRollback(result);
+ // unlock component
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementsBusinessLogic.java
new file mode 100644
index 0000000000..f8dde98010
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementsBusinessLogic.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("requirementsBusinessLogic")
+public class RequirementsBusinessLogic {
+ private static Logger log = LoggerFactory.getLogger(RequirementsBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentsUtils;
+
+ @javax.annotation.Resource
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @javax.annotation.Resource
+ private IResourceOperation resourceOperation;
+
+ public Either<RequirementDefinition, ResponseFormat> updateRequirement(String resourceId, String requirementId, RequirementDefinition requirementDefinition, String userId) {
+
+ // Get the resource from DB
+ Either<Resource, StorageOperationStatus> status = getResource(resourceId);
+ if (status.isRight()) {
+ log.debug("Couldn't get resource {} from DB", resourceId);
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(status.right().value()), ""));
+ }
+ Resource resource = status.left().value();
+ if (resource == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Requirement Business Logic", resourceId);
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("Requirement Business Logic", ComponentTypeEnum.RESOURCE.getValue(), resourceId);
+ log.debug("Couldn't get resource {} from DB", resourceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ // verify that resource is checked-out and the user is the last updater
+ if (!ComponentValidationUtils.canWorkOnResource(resource, userId)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ // TODO
+ return null;
+ }
+
+ private Either<Resource, StorageOperationStatus> getResource(final String resourceId) {
+
+ log.debug("Get resource with id {}", resourceId);
+ Either<Resource, StorageOperationStatus> status = resourceOperation.getResource(resourceId);
+ if (status.isRight()) {
+ log.debug("Resource with id {} was not found", resourceId);
+ return Either.right(status.right().value());
+ }
+
+ Resource resource = status.left().value();
+ if (resource == null) {
+ log.debug("General Error while get resource with id {}", resourceId);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ return Either.left(resource);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
new file mode 100644
index 0000000000..ddc03e14e8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -0,0 +1,5475 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperation;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
+import org.openecomp.sdc.be.info.MergedArtifactInfo;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GetInputValueInfo;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadCapInfo;
+import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadPropInfo;
+import org.openecomp.sdc.be.model.UploadReqInfo;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.heat.HeatParameterType;
+import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
+import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IHeatParametersOperation;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.InputsOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.utils.CommonBeUtils;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.context.WebApplicationContext;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.representer.Representer;
+import org.yaml.snakeyaml.resolver.Resolver;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("resourceBusinessLogic")
+public class ResourceBusinessLogic extends ComponentBusinessLogic {
+
+ private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
+ public static final String INITIAL_VERSION = "0.1";
+
+ Pattern STR_REPLACE_PATTERN = Pattern.compile("^[ ]*\\{[ ]*" + "str_replace" + "=");
+ Pattern TOKEN_PATTERN = Pattern.compile("[ ]*\\{[ ]*" + "token" + "=");
+ Pattern GET_PROPERTY_PATTERN = Pattern.compile("[ ]*\\{[ ]*" + "get_property" + "=");
+ Pattern CONCAT_PATTERN = Pattern.compile("[ ]*\\{[ ]*" + "concat" + "=");
+
+ private static Logger log = LoggerFactory.getLogger(ResourceBusinessLogic.class.getName());
+
+ public ResourceBusinessLogic() {
+ log.debug("ResourceBusinessLogic started");
+ }
+
+ @Autowired
+ private ICapabilityTypeOperation capabilityTypeOperation = null;
+
+ @Autowired
+ private IInterfaceLifecycleOperation interfaceTypeOperation = null;
+
+ @Autowired
+ private IComponentInstanceOperation componentInstanceOperation;
+
+ @Autowired
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
+
+ @Autowired
+ private IPropertyOperation propertyOperation;
+
+ @Autowired
+ private CsarOperation csarOperation;
+
+ @Autowired
+ private VFComponentInstanceBusinessLogic vfComponentInstanceBusinessLogic;
+
+ @Autowired
+ private ResourceImportManager resourceImportManager;
+
+ @Autowired
+ private GroupBusinessLogic groupBusinessLogic;
+ @Autowired
+ private InputsBusinessLogic inputsBusinessLogic;
+
+ @javax.annotation.Resource
+ private InputsOperation inputOperation;
+
+ @Autowired
+ private GroupOperation groupOperation;
+
+ @Autowired
+ private IHeatParametersOperation heatParametersOperation;
+
+ @Autowired
+ private IArtifactOperation artifactOperation;
+
+ @Autowired
+ private CapabilityInstanceOperation capabilityInstanceOperation;
+
+ @Autowired
+ private CompositionBusinessLogic compositionBusinessLogic;
+
+ @Autowired
+ private ICacheMangerOperation cacheManagerOperation;
+
+ private Gson gson = new Gson();
+
+ public CsarOperation getCsarOperation() {
+ return csarOperation;
+ }
+
+ public void setCsarOperation(CsarOperation csarOperation) {
+ this.csarOperation = csarOperation;
+ }
+
+ public IResourceOperation getResourceOperation() {
+ return this.resourceOperation;
+ }
+
+ public void setResourceOperation(ResourceOperation resourceOperation) {
+ this.resourceOperation = resourceOperation;
+ }
+
+ public LifecycleBusinessLogic getLifecycleBusinessLogic() {
+ return lifecycleBusinessLogic;
+ }
+
+ public void setLifecycleManager(LifecycleBusinessLogic lifecycleBusinessLogic) {
+ this.lifecycleBusinessLogic = lifecycleBusinessLogic;
+ }
+
+ public IElementOperation getElementDao() {
+ return elementDao;
+ }
+
+ public void setElementDao(IElementOperation elementDao) {
+ this.elementDao = elementDao;
+ }
+
+ public IUserBusinessLogic getUserAdmin() {
+ return this.userAdmin;
+ }
+
+ public void setUserAdmin(UserBusinessLogic userAdmin) {
+ this.userAdmin = userAdmin;
+ }
+
+ public ComponentsUtils getComponentsUtils() {
+ return this.componentsUtils;
+ }
+
+ public void setComponentsUtils(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ public ArtifactsBusinessLogic getArtifactsManager() {
+ return artifactsBusinessLogic;
+ }
+
+ public void setArtifactsManager(ArtifactsBusinessLogic artifactsManager) {
+ this.artifactsBusinessLogic = artifactsManager;
+ }
+
+ public void setPropertyOperation(IPropertyOperation propertyOperation) {
+ this.propertyOperation = propertyOperation;
+ }
+
+ public ApplicationDataTypeCache getApplicationDataTypeCache() {
+ return applicationDataTypeCache;
+ }
+
+ public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) {
+ this.applicationDataTypeCache = applicationDataTypeCache;
+ }
+
+ /**
+ * the method returns a list of all the resources that are certified, the returned resources are only abstract or only none abstract according to the given param
+ *
+ * @param getAbstract
+ * @param userId
+ * TODO
+ * @return
+ */
+ public Either<List<Resource>, ResponseFormat> getAllCertifiedResources(boolean getAbstract, HighestFilterEnum highestFilter, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get All Certified Resources", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ IResourceOperation dataModel = getResourceOperation();
+ Boolean isHighest = null;
+ switch (highestFilter) {
+ case ALL:
+ break;
+ case HIGHEST_ONLY:
+ isHighest = true;
+ break;
+ case NON_HIGHEST_ONLY:
+ isHighest = false;
+ break;
+ default:
+ break;
+ }
+
+ Either<List<Resource>, StorageOperationStatus> dataModelResponse = dataModel.getAllCertifiedResources(getAbstract, isHighest);
+
+ if (dataModelResponse.isLeft()) {
+ log.debug("Retrived Resource successfully.");
+ return Either.left(dataModelResponse.left().value());
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
+
+ return Either.right(responseFormat);
+ }
+
+ public Either<Map<String, Boolean>, ResponseFormat> validateResourceNameExists(String resourceName, ResourceTypeEnum resourceTypeEnum, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "validate Resource Name Exists", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ IResourceOperation dataModel = getResourceOperation();
+
+ Either<Boolean, StorageOperationStatus> dataModelResponse = dataModel.validateResourceNameExists(resourceName, resourceTypeEnum);
+
+ if (dataModelResponse.isLeft()) {
+ Map<String, Boolean> result = new HashMap<>();
+ result.put("isValid", dataModelResponse.left().value());
+ log.debug("validation was successfully performed.");
+ return Either.left(result);
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
+
+ return Either.right(responseFormat);
+ }
+
+ public Either<Resource, ResponseFormat> createResource(Resource resource, User user, Map<String, byte[]> csarUIPayload, String payloadName) {
+ Either<Resource, ResponseFormat> createResourceResponse = validateResourceBeforeCreate(resource, user, false);
+ if (createResourceResponse.isRight()) {
+ return createResourceResponse;
+ }
+
+ // Creating resource either by DAO or from CSAR
+ String csarUUID = null;
+ if (payloadName == null) {
+ csarUUID = resource.getCsarUUID();
+ } else {
+ csarUUID = payloadName;
+ }
+ if (csarUUID != null && !csarUUID.isEmpty()) {
+ // check if VF with the same Csar UUID or with he same name already
+ // exists
+ Either<List<ResourceMetadataData>, StorageOperationStatus> validateCsarUuidUniquenessRes = resourceOperation.validateCsarUuidUniqueness(csarUUID);
+ if (validateCsarUuidUniquenessRes.isRight()) {
+ log.debug("Failed to validate uniqueness of CsarUUID {} for resource", csarUUID, resource.getSystemName());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validateCsarUuidUniquenessRes.right().value())));
+ }
+
+ List<ResourceMetadataData> existingResourceRes = validateCsarUuidUniquenessRes.left().value();
+ if (existingResourceRes != null && existingResourceRes.size() > 0) {
+ log.debug("Failed to create resource {}, csarUUID {} already exist for a different VF {}", resource.getSystemName(), csarUUID, existingResourceRes.get(0).getMetadataDataDefinition().getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, existingResourceRes.get(0).getMetadataDataDefinition().getName());
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ return Either.right(errorResponse);
+ }
+
+ log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID);
+ createResourceResponse = createResourceFromCsar(resource, user, AuditingActionEnum.CREATE_RESOURCE, false, Either.left(csarUIPayload), csarUUID);
+ return createResourceResponse;
+ }
+
+ return createResourceByDao(resource, user, AuditingActionEnum.CREATE_RESOURCE, false);
+ }
+
+ public Either<Resource, ResponseFormat> validateAndUpdateResourceFromCsar(Resource resource, User user, Map<String, byte[]> csarUIPayload, String payloadName, String resourceUniqueId) {
+ Either<Resource, ResponseFormat> updateResourceResponse = null;
+ Either<Resource, ResponseFormat> validateResourceResponse = null;
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<ResponseFormat>();
+ String csarUUID = null;
+ String csarVersion = null;
+ if (payloadName == null) {
+ csarUUID = resource.getCsarUUID();
+ csarVersion = resource.getCsarVersion();
+ } else {
+ csarUUID = payloadName;
+ }
+ if (csarUUID != null && !csarUUID.isEmpty()) {
+ Resource oldResource = getResourceByUniqueId(responseWrapper, resourceUniqueId);
+ if (responseWrapper.isEmpty()) {
+ validateCsarUuidMatching(responseWrapper, oldResource, resource, csarUUID, resourceUniqueId, user);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateCsarIsNotAlreadyUsed(responseWrapper, oldResource, resource, csarUUID, user);
+ }
+ if (responseWrapper.isEmpty()) {
+ if (oldResource != null && ValidationUtils.hasBeenCertified(oldResource.getVersion())) {
+ overrideImmutableMetadata(oldResource, resource);
+ }
+ validateResourceResponse = validateResourceBeforeCreate(resource, user, false);
+ if (validateResourceResponse.isRight()) {
+ responseWrapper.setInnerElement(validateResourceResponse.right().value());
+ }
+ }
+ if (responseWrapper.isEmpty()) {
+ String oldCsarVersion = oldResource.getCsarVersion();
+ log.debug("CsarUUID is {} - going to update resource with UniqueId {} from CSAR", csarUUID, resourceUniqueId);
+ // (on boarding flow): If the update includes same csarUUID and
+ // same csarVersion as already in the VF - no need to import the
+ // csar (do only metadata changes if there are).
+ if (csarVersion != null && oldCsarVersion != null && oldCsarVersion.equals(csarVersion)) {
+ updateResourceResponse = updateResourceMetadata(resourceUniqueId, resource, oldResource, user, false);
+ } else {
+ updateResourceResponse = updateResourceFromCsar(oldResource, resource, user, AuditingActionEnum.UPDATE_RESOURCE_METADATA, false, Either.left(csarUIPayload), csarUUID);
+ }
+ }
+ } else {
+ log.debug("Failed to update resource {}, csarUUID or payload name is missing", resource.getSystemName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CSAR_UUID, resource.getName());
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ if (responseWrapper.isEmpty()) {
+ return updateResourceResponse;
+ }
+ return Either.right(responseWrapper.getInnerElement());
+ }
+
+ private void validateCsarIsNotAlreadyUsed(Wrapper<ResponseFormat> responseWrapper, Resource oldResource, Resource resource, String csarUUID, User user) {
+ // (on boarding flow): If the update includes a csarUUID: verify this
+ // csarUUID is not in use by another VF, If it is - use same error as
+ // above:
+ // "Error: The VSP with UUID %1 was already imported for VF %2. Please
+ // select another or update the existing VF." %1 - csarUUID, %2 - VF
+ // name
+ Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = resourceOperation.getLatestResourceByCsarOrName(csarUUID, resource.getSystemName());
+ if (resourceLinkedToCsarRes.isRight()) {
+ if (!StorageOperationStatus.NOT_FOUND.equals(resourceLinkedToCsarRes.right().value())) {
+ log.debug("Failed to find previous resource by CSAR {} and system name {}", csarUUID, resource.getSystemName());
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceLinkedToCsarRes.right().value())));
+ }
+ } else if (!resourceLinkedToCsarRes.left().value().getUniqueId().equals(oldResource.getUniqueId()) && !resourceLinkedToCsarRes.left().value().getName().equals(oldResource.getName())) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, resourceLinkedToCsarRes.left().value().getName());
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", AuditingActionEnum.UPDATE_RESOURCE_METADATA, null);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ private void validateCsarUuidMatching(Wrapper<ResponseFormat> responseWrapper, Resource resource, Resource oldResource, String csarUUID, String resourceUniqueId, User user) {
+ // (on boarding flow): If the update includes csarUUID which is
+ // different from the csarUUID of the VF - fail with
+ // error: "Error: Resource %1 cannot be updated using since it is linked
+ // to a different VSP" %1 - VF name
+ String oldCsarUUID = oldResource.getCsarUUID();
+ if (oldCsarUUID != null && !oldCsarUUID.isEmpty() && !csarUUID.equals(oldCsarUUID)) {
+ log.debug("Failed to update resource with UniqueId {} using Csar {}, since the resource is linked to a different VSP {}", resourceUniqueId, csarUUID, oldCsarUUID);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", AuditingActionEnum.UPDATE_RESOURCE_METADATA, null);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ private Resource getResourceByUniqueId(Wrapper<ResponseFormat> responseWrapper, String resourceUniqueId) {
+ Either<Resource, StorageOperationStatus> oldResourceRes = resourceOperation.getResource(resourceUniqueId);
+ if (oldResourceRes.isRight()) {
+ log.debug("Failed to find previous resource by UniqueId {}, status: {}", resourceUniqueId, oldResourceRes.right().value());
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(oldResourceRes.right().value())));
+ return null;
+ }
+ return oldResourceRes.left().value();
+ }
+
+ private void overrideImmutableMetadata(Resource oldRresource, Resource resource) {
+ resource.setName(oldRresource.getName());
+ resource.setIcon(oldRresource.getIcon());
+ resource.setTags(oldRresource.getTags());
+ resource.setVendorName(oldRresource.getVendorName());
+ resource.setCategories(oldRresource.getCategories());
+ resource.setDerivedFrom(oldRresource.getDerivedFrom());
+ }
+
+ private Either<Resource, ResponseFormat> updateResourceFromCsar(Resource oldRresource, Resource newRresource, User user, AuditingActionEnum updateResource, boolean inTransaction, Either<Map<String, byte[]>, StorageOperationStatus> csarUIPayload,
+ String csarUUID) {
+
+ // check state
+ if (LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.equals(oldRresource.getLifecycleState())) {
+ if (!oldRresource.getLastUpdaterUserId().equals(user.getUserId())) {
+ log.debug("Current user is not last updater, last updater userId: {}, current user userId: {}", oldRresource.getLastUpdaterUserId(), user.getUserId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+ }
+ String lockedResourceId = oldRresource.getUniqueId();
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<ArtifactDefinition>();
+
+ Either<Map<String, byte[]>, StorageOperationStatus> csar = null;
+ if (csarUIPayload != null && csarUIPayload.left() != null && csarUIPayload.left().value() != null) {
+ csar = csarUIPayload;
+ } else {
+ csar = csarOperation.getCsar(csarUUID, user);
+ }
+ if (csar.isRight()) {
+ log.debug("Failed to get csar for casrUUID{} ", csarUUID);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(csar.right().value())));
+ }
+
+ Either<ImmutablePair<String, String>, ResponseFormat> toscaYamlCsarStatus = validateAndParseCsar(newRresource, user, csarUUID, csar);
+ if (toscaYamlCsarStatus.isRight()) {
+ return Either.right(toscaYamlCsarStatus.right().value());
+ }
+ Either<String, ResponseFormat> checksum = CsarValidationUtils.getToscaYamlChecksum(csar.left().value(), csarUUID, componentsUtils);
+ if (checksum.isRight()) {
+ log.debug("Failed to calculate checksum for casrUUID{} error {} ", csarUUID, checksum.right().value());
+ return Either.right(checksum.right().value());
+ }
+ boolean isUpdateYaml = true;
+ if (checksum.left().value().equals(oldRresource.getComponentMetadataDefinition().getMetadataDataDefinition().getImportedToscaChecksum())) {
+ log.debug("The checksums are equals for csarUUID {}, existing checsum is {}, new one is {} ", csarUUID, oldRresource.getComponentMetadataDefinition().getMetadataDataDefinition().getImportedToscaChecksum(), checksum.left().value());
+ if (oldRresource.getLifecycleState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT))
+ isUpdateYaml = false;
+ } else {
+ oldRresource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(checksum.left().value());
+ }
+
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(lockedResourceId, oldRresource, "update Resource From Csar");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+
+ Either<Resource, ResponseFormat> result = null;
+ try {
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> prepareForUpdate = null;
+ Resource preparedResource = null;
+ if (isUpdateYaml) {
+
+ prepareForUpdate = updateExistingResourceByImport(newRresource, oldRresource, user, true, false);
+
+ if (prepareForUpdate.isRight()) {
+ log.debug("Failed to prepare resource for update : {}", prepareForUpdate.right().value());
+ result = Either.right(prepareForUpdate.right().value());
+ return result;
+ }
+ preparedResource = prepareForUpdate.left().value().left;
+ String yamlFileName = toscaYamlCsarStatus.left().value().getKey();
+ String yamlFileContents = toscaYamlCsarStatus.left().value().getValue();
+ log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContents);
+
+ // Either<Map<String, Resource>, ResponseFormat>
+ // parseNodeTypeInfoYamlEither =
+ // createResourcesFromYamlNodeTypesList(yamlFileName,preparedResource,
+ // yamlFileContents, user,false);
+
+ Either<Map<String, Resource>, ResponseFormat> parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, user, yamlFileContents, csar.left().value(), false);
+ if (parseNodeTypeInfoYamlEither.isRight()) {
+ ResponseFormat responseFormat = parseNodeTypeInfoYamlEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, preparedResource, "", "", updateResource, null);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ Either<ParsedToscaYamlInfo, ResponseFormat> uploadComponentInstanceInfoMap = parseResourceInfoFromYaml(yamlFileName, preparedResource, yamlFileContents, user);
+ if (uploadComponentInstanceInfoMap.isRight()) {
+ ResponseFormat responseFormat = uploadComponentInstanceInfoMap.right().value();
+ componentsUtils.auditResource(responseFormat, user, preparedResource, "", "", updateResource, null);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ Map<String, InputDefinition> inputs = uploadComponentInstanceInfoMap.left().value().getInputs();
+ Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(preparedResource, user, inputs, true);
+ if (createInputsOnResource.isRight()) {
+ log.debug("failed to create resource inputs status is {}", createInputsOnResource.right().value());
+ ResponseFormat responseFormat = createInputsOnResource.right().value();
+ componentsUtils.auditResource(createInputsOnResource.right().value(), user, preparedResource, "", "", updateResource, null);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ preparedResource = createInputsOnResource.left().value();
+
+ Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.left().value().getInstances();
+ Either<Resource, ResponseFormat> createResourcesInstancesEither = createResourceInstances(user, yamlFileName, preparedResource, instances, true, false, parseNodeTypeInfoYamlEither.left().value());
+ if (createResourcesInstancesEither.isRight()) {
+ log.debug("failed to create resource instances status is {}", createResourcesInstancesEither.right().value());
+ ResponseFormat responseFormat = createResourcesInstancesEither.right().value();
+ componentsUtils.auditResource(createResourcesInstancesEither.right().value(), user, preparedResource, "", "", updateResource, null);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ preparedResource = createResourcesInstancesEither.left().value();
+
+ createResourcesInstancesEither = createResourceInstancesRelations(user, yamlFileName, preparedResource, instances, true, false);
+ if (createResourcesInstancesEither.isRight()) {
+ log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value());
+ result = Either.right(createResourcesInstancesEither.right().value());
+ return result;
+ }
+
+ preparedResource = createResourcesInstancesEither.left().value();
+
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(uploadComponentInstanceInfoMap.left().value().getGroups(), preparedResource.getSystemName());
+ if (validateUpdateVfGroupNamesRes.isRight()) {
+
+ return Either.right(validateUpdateVfGroupNamesRes.right().value());
+ }
+ // add groups to resource
+ Map<String, GroupDefinition> groups;
+
+ if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
+ groups = validateUpdateVfGroupNamesRes.left().value();
+ } else {
+ groups = uploadComponentInstanceInfoMap.left().value().getGroups();
+ }
+ Either<Resource, ResponseFormat> updatedGroupsOnResource = updateGroupsOnResource(preparedResource, user, groups);
+ if (updatedGroupsOnResource.isRight()) {
+
+ return updatedGroupsOnResource;
+ }
+ preparedResource = updatedGroupsOnResource.left().value();
+
+ } else {
+ Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(oldRresource.getUniqueId(), newRresource, user, oldRresource, false, true);
+ if (dataModelResponse.isRight()) {
+ log.debug("failed to update resource metadata {}", dataModelResponse.right().value());
+ result = Either.right(dataModelResponse.right().value());
+ return result;
+ }
+
+ preparedResource = dataModelResponse.left().value();
+
+ }
+
+ Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleCsarArtifacts(preparedResource, user, csarUUID, csar.left().value(), createdArtifacts, ArtifactOperation.Update, false, true);
+ if (createdCsarArtifactsEither.isRight()) {
+
+ return createdCsarArtifactsEither;
+ }
+ preparedResource = createdCsarArtifactsEither.left().value();
+
+ Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, user.getUserId());
+ result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(preparedResource);
+
+ return result;
+
+ } finally {
+ if (result == null || result.isRight()) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ if (!createdArtifacts.isEmpty()) {
+ StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
+ if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, oldRresource.getName());
+ }
+ log.debug("component and all its artifacts were deleted, id = {}", oldRresource.getName());
+ }
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ log.debug("unlock resource {}", lockedResourceId);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ }
+
+ }
+
+ public Either<Resource, ResponseFormat> createResourceFromCsar(Resource resource, User user, AuditingActionEnum createResource, boolean inTransaction, Either<Map<String, byte[]>, StorageOperationStatus> csarUIPayload, String csarUUID) {
+ log.trace("************* created successfully from YAML, resource TOSCA ");
+
+ Either<Map<String, byte[]>, StorageOperationStatus> csar = null;
+ if (csarUIPayload != null && csarUIPayload.left() != null && csarUIPayload.left().value() != null) {
+ csar = csarUIPayload;
+ } else {
+ csar = csarOperation.getCsar(csarUUID, user);
+ }
+
+ Either<ImmutablePair<String, String>, ResponseFormat> toscaYamlCsarStatus = validateAndParseCsar(resource, user, csarUUID, csar);
+ if (toscaYamlCsarStatus.isRight()) {
+ return Either.right(toscaYamlCsarStatus.right().value());
+ }
+ Either<String, ResponseFormat> toscaYamlChecksum = CsarValidationUtils.getToscaYamlChecksum(csar.left().value(), csarUUID, componentsUtils);
+ if (toscaYamlChecksum.isRight()) {
+ log.debug("Failed to calculate checksum for CSAR {}, error {}", csarUUID, toscaYamlChecksum.right().value());
+ return Either.right(toscaYamlChecksum.right().value());
+ }
+ resource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(toscaYamlChecksum.left().value());
+
+ String yamlFileName = toscaYamlCsarStatus.left().value().getKey();
+ String yamlFileContents = toscaYamlCsarStatus.left().value().getValue();
+ log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContents);
+ Either<Resource, ResponseFormat> createResourceFromYaml = createResourceFromYaml(resource, user, yamlFileContents, yamlFileName, csar.left().value(), csarUUID);
+ if (createResourceFromYaml.isRight()) {
+ log.debug("Couldn't create resource from YAML");
+ return Either.right(createResourceFromYaml.right().value());
+ }
+
+ Resource vfResource = createResourceFromYaml.left().value();
+ log.trace("*************VF Resource created successfully from YAML, resource TOSCA name: {}", vfResource.getToscaResourceName());
+ return Either.left(vfResource);
+ }
+
+ private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Resource resource, User user, String csarUUID, Either<Map<String, byte[]>, StorageOperationStatus> csar) {
+ if (csar.isRight()) {
+ StorageOperationStatus value = csar.right().value();
+ log.debug("Error when fetching csar with ID {}, error: {}", csarUUID, value);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Creating resource from CSAR: fetching CSAR with id " + csarUUID + " failed");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(value), csarUUID);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateCsarStatus = CsarValidationUtils.validateCsar(csar.left().value(), csarUUID, componentsUtils);
+ if (validateCsarStatus.isRight()) {
+ ResponseFormat responseFormat = validateCsarStatus.right().value();
+ log.debug("Error when validate csar with ID {}, error: {}", csarUUID, responseFormat);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Creating resource from CSAR: fetching CSAR with id " + csarUUID + " failed");
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+
+ Either<ImmutablePair<String, String>, ResponseFormat> toscaYamlCsarStatus = CsarValidationUtils.getToscaYaml(csar.left().value(), csarUUID, componentsUtils);
+
+ if (toscaYamlCsarStatus.isRight()) {
+ ResponseFormat responseFormat = toscaYamlCsarStatus.right().value();
+ log.debug("Error when try to get csar toscayamlFile with csar ID {}, error: {}", csarUUID, responseFormat);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Creating resource from CSAR: fetching CSAR with id " + csarUUID + " failed");
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ return toscaYamlCsarStatus;
+ }
+
+ private Either<Resource, ResponseFormat> validateResourceBeforeCreate(Resource resource, User user, boolean inTransaction) {
+ log.trace("validating resource before create");
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "Create Resource", resource, AuditingActionEnum.CREATE_RESOURCE, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user.copyData(eitherCreator.left().value());
+
+ // validate user role
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, resource, new ArrayList<Role>(), AuditingActionEnum.CREATE_RESOURCE, null);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+ // VF "derivedFrom" should be null (or ignored)
+ if (!resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = validateDerivedFromNotEmpty(user, resource, AuditingActionEnum.CREATE_RESOURCE);
+ if (validateDerivedFromNotEmpty.isRight()) {
+ return Either.right(validateDerivedFromNotEmpty.right().value());
+ }
+ }
+ return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction);
+
+ }
+
+ public Either<Resource, ResponseFormat> createResourceFromYaml(Resource resource, User user, String topologyTemplateYaml, String yamlName, Map<String, byte[]> csar, String csarUUID) {
+
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<ArtifactDefinition>();
+ log.trace("************* createResourceFromYaml before parse yaml ");
+ Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceInfoFromYaml(yamlName, resource, topologyTemplateYaml, user);
+ if (parseResourceInfoFromYamlEither.isRight()) {
+ ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ log.trace("************* createResourceFromYaml after parse yaml ");
+ ParsedToscaYamlInfo parsedToscaYamlInfo = parseResourceInfoFromYamlEither.left().value();
+ log.debug("The parsed tosca yaml info is {}", parsedToscaYamlInfo);
+ log.trace("************* createResourceFromYaml before create ");
+ Either<Resource, ResponseFormat> createdResourceResponse = createResourceAndRIsFromYaml(yamlName, resource, user, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, csarUUID, csar, createdArtifacts, topologyTemplateYaml);
+ log.trace("************* createResourceFromYaml after create ");
+ if (createdResourceResponse.isRight()) {
+ ResponseFormat responseFormat = createdResourceResponse.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+
+ return createdResourceResponse;
+
+ }
+
+ public Either<Map<String, Resource>, ResponseFormat> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, String resourceYml, User user, boolean needLock) {
+
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml);
+
+ Either<String, ResultStatusEnum> tosca_version = ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION);
+ if (tosca_version.isRight()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ return Either.right(responseFormat);
+ }
+
+ Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES);
+
+ Map<String, Resource> nodeTypesResources = new HashMap<>();
+ Either<Map<String, Resource>, ResponseFormat> result = Either.left(nodeTypesResources);
+
+ Map<String, Object> mapToConvert = new HashMap<String, Object>();
+ mapToConvert.put(ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), tosca_version.left().value());
+
+ if (eitherNodeTypes.isLeft()) {
+
+ Iterator<Entry<String, Object>> nodesNameValue = eitherNodeTypes.left().value().entrySet().iterator();
+
+ while (nodesNameValue.hasNext()) {
+
+ Entry<String, Object> nodeType = nodesNameValue.next();
+ log.trace("************* Going to create node {}", nodeType.getKey());
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> resourceCreated = this.createNodeTypeResourceFromYaml(yamlName, nodeType, user, mapToConvert, resource, needLock);
+ log.trace("************* finished to create node {}", nodeType.getKey());
+ if (resourceCreated.isRight()) {
+ return Either.right(resourceCreated.right().value());
+ }
+ Resource vfcCreated = resourceCreated.left().value().getLeft();
+
+ nodeTypesResources.put(nodeType.getKey(), vfcCreated);
+ mapToConvert.remove(ToscaTagNamesEnum.NODE_TYPES.getElementName());
+
+ }
+ }
+
+ return result;
+ }
+
+ private String getNodeTypeActualName(String fullName) {
+ String nameWithouNamespacePrefix = fullName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ return nameWithouNamespacePrefix.substring(resourceType.length());
+ }
+
+ private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createNodeTypeResourceFromYaml(String yamlName, Entry<String, Object> nodeNameValue, User user, Map<String, Object> mapToConvert, Resource resourceVf, boolean needLock) {
+
+ Either<UploadResourceInfo, ResponseFormat> resourceMetaData = fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(), user);
+ if (resourceMetaData.isRight()) {
+ return Either.right(resourceMetaData.right().value());
+ }
+
+ // We need to create a Yaml from each node_types in order to create
+ // resource from each node type using import normative flow.
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ Yaml yaml = new Yaml(options);
+
+ Map<String, Object> singleVfc = new HashMap<>();
+
+ String actualName = this.getNodeTypeActualName(nodeNameValue.getKey());
+ if (!actualName.startsWith(ImportUtils.Constants.ABSTRACT_NODE)) {
+ actualName = "." + ImportUtils.Constants.ABSTRACT_NODE + actualName;
+ }
+
+ // Setting tosca name
+ String toscaResourceName = ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + resourceMetaData.left().value().getResourceType().toLowerCase() + '.' + resourceVf.getSystemName() + actualName;
+ singleVfc.put(toscaResourceName, nodeNameValue.getValue());
+ mapToConvert.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), singleVfc);
+
+ String singleVfcYaml = yaml.dumpAsMap(mapToConvert);
+
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ return this.createResourceFromNodeType(singleVfcYaml, resourceMetaData.left().value(), user, true, needLock);
+ }
+
+ public Either<Boolean, ResponseFormat> validateResourceCreationFromNodeType(Resource resource, User creator) {
+
+ Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = this.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
+ if (validateDerivedFromNotEmpty.isRight()) {
+ return Either.right(validateDerivedFromNotEmpty.right().value());
+ }
+ return Either.left(true);
+ }
+
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock) {
+
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR);
+ Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> this.validateResourceCreationFromNodeType(resource, creator);
+ return this.resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock);
+ }
+
+ private Either<UploadResourceInfo, ResponseFormat> fillResourceMetadata(String yamlName, Resource resourceVf, String nodeTypeName, User user) {
+ UploadResourceInfo resourceMetaData = new UploadResourceInfo();
+
+ // validate nodetype name prefix
+ if (!nodeTypeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
+ log.debug("invalid nodeTypeName:{} does not start with {}.", nodeTypeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName);
+ return Either.right(responseFormat);
+ }
+
+ String actualName = this.getNodeTypeActualName(nodeTypeName);
+ String namePrefix = nodeTypeName.replace(actualName, "");
+ String resourceType = namePrefix.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+
+ // if we import from csar, the node_type name can be
+ // org.openecomp.resource.abstract.node_name - in this case we always
+ // create a vfc
+ if (resourceType.equals(Constants.ABSTRACT)) {
+ resourceType = ResourceTypeEnum.VFC.name().toLowerCase();
+ }
+ // validating type
+ if (!ResourceTypeEnum.contains(resourceType.toUpperCase())) {
+ log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(), ResourceTypeEnum.values());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName);
+ return Either.right(responseFormat);
+ }
+
+ // Setting name
+ resourceMetaData.setName(resourceVf.getSystemName() + actualName);
+
+ // Setting type from name
+ String type = resourceType.toUpperCase();
+ resourceMetaData.setResourceType(type);
+
+ resourceMetaData.setDescription(ImportUtils.Constants.INNER_VFC_DESCRIPTION);
+ resourceMetaData.setIcon(ImportUtils.Constants.DEFAULT_ICON);
+ resourceMetaData.setContactId(user.getUserId());
+ resourceMetaData.setVendorName(resourceVf.getVendorName());
+ resourceMetaData.setVendorRelease(resourceVf.getVendorRelease());
+
+ // Setting tag
+ List<String> tags = new ArrayList<>();
+ tags.add(resourceMetaData.getName());
+ resourceMetaData.setTags(tags);
+
+ // Setting category
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
+ SubCategoryDefinition subCategory = new SubCategoryDefinition();
+ subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
+ category.addSubCategory(subCategory);
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ resourceMetaData.setCategories(categories);
+
+ return Either.left(resourceMetaData);
+ }
+
+ private Either<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, User user, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative, String csarUUID,
+ Map<String, byte[]> csar, List<ArtifactDefinition> createdArtifacts, String topologyTemplateYaml) {
+
+ boolean result = true;
+
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource, "Create Resource");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ return Either.right(responseFormat);
+ }
+ log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
+
+ try {
+ log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
+ Either<Resource, ResponseFormat> createResourcesEither = createResourceTransaction(resource, user, actionEnum, isNormative, true);
+ log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
+ if (createResourcesEither.isRight()) {
+ result = false;
+ return createResourcesEither;
+ }
+ resource = createResourcesEither.left().value();
+ // add groups to resource
+ log.trace("************* Going to add inputs from yaml {}", yamlName);
+
+ Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
+ Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(resource, user, inputs, true);
+ if (createInputsOnResource.isRight()) {
+ result = false;
+ return createInputsOnResource;
+ }
+ resource = createInputsOnResource.left().value();
+ log.trace("************* Finish to add inputs from yaml {}", yamlName);
+
+ Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
+ log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
+ createResourcesEither = createRIAndRelationsFromYaml(yamlName, resource, user, uploadComponentInstanceInfoMap, actionEnum, topologyTemplateYaml, csar, csarUUID);
+ log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
+ if (createResourcesEither.isRight()) {
+ result = false;
+ return createResourcesEither;
+ }
+
+ resource = createResourcesEither.left().value();
+ // validate update vf module group names
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName());
+ if (validateUpdateVfGroupNamesRes.isRight()) {
+ result = false;
+ return Either.right(validateUpdateVfGroupNamesRes.right().value());
+ }
+ // add groups to resource
+ Map<String, GroupDefinition> groups;
+ log.trace("************* Going to add groups from yaml {}", yamlName);
+
+ if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
+ groups = validateUpdateVfGroupNamesRes.left().value();
+ } else {
+ groups = parsedToscaYamlInfo.getGroups();
+ }
+ Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource, user, groups);
+ if (createGroupsOnResource.isRight()) {
+ result = false;
+ return createGroupsOnResource;
+ }
+ resource = createGroupsOnResource.left().value();
+ log.trace("************* Finished to add groups from yaml {}", yamlName);
+
+ log.trace("************* Going to add artifacts from yaml {}", yamlName);
+ Either<Resource, ResponseFormat> createdCsarArtifactsEither = this.handleCsarArtifacts(resource, user, csarUUID, csar, createdArtifacts, ArtifactOperation.Create, false, true);
+ log.trace("************* Finished to add artifacts from yaml {}", yamlName);
+ if (createdCsarArtifactsEither.isRight()) {
+ result = false;
+ return createdCsarArtifactsEither;
+ }
+ resource = createdCsarArtifactsEither.left().value();
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ ASDCKpiApi.countCreatedResourcesKPI();
+ return Either.left(resource);
+
+ } finally {
+ if (!result) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ if (!createdArtifacts.isEmpty()) {
+ StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
+ if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, resource.getName());
+ }
+ log.debug("component and all its artifacts were deleted, id = {}", resource.getName());
+ }
+
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
+
+ }
+
+ }
+
+ private Either<Resource, ResponseFormat> createGroupsOnResource(Resource resource, User user, Map<String, GroupDefinition> groups) {
+ if (groups != null && false == groups.isEmpty()) {
+ Either<List<GroupDefinition>, ResponseFormat> mergeGroupsUsingResource = updateGroupMembersUsingResource(groups, resource);
+
+ if (mergeGroupsUsingResource.isRight()) {
+ log.debug("Failed to prepare groups for creation");
+ return Either.right(mergeGroupsUsingResource.right().value());
+ }
+ List<GroupDefinition> groupsAsList = mergeGroupsUsingResource.left().value();
+
+ // Either<List<GroupDefinition>, ResponseFormat> createGroups =
+ // groupBusinessLogic.createGroups(
+ // resource.getUniqueId(), user.getUserId(),
+ // ComponentTypeEnum.RESOURCE, groupsAsList, false,
+ // true);
+ // In this method we assume all instances exists in resource
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource, user, ComponentTypeEnum.RESOURCE, groupsAsList, true);
+ if (createGroups.isRight()) {
+ return Either.right(createGroups.right().value());
+ }
+ } else {
+ return Either.left(resource);
+ }
+
+ Either<Resource, StorageOperationStatus> updatedResource = resourceOperation.getResource(resource.getUniqueId(), true);
+ if (updatedResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource);
+ return Either.right(responseFormat);
+ }
+ return Either.left(updatedResource.left().value());
+ }
+
+ private Either<Resource, ResponseFormat> updateGroupsOnResource(Resource resource, User user, Map<String, GroupDefinition> groups) {
+ if (groups != null && false == groups.isEmpty()) {
+ List<GroupDefinition> groupsFromResource = resource.getGroups();
+ Either<List<GroupDefinition>, ResponseFormat> mergeGroupsUsingResource = updateGroupMembersUsingResource(groups, resource);
+
+ if (mergeGroupsUsingResource.isRight()) {
+ log.debug("Failed to prepare groups for creation");
+ return Either.right(mergeGroupsUsingResource.right().value());
+ }
+ List<GroupDefinition> groupsAsList = mergeGroupsUsingResource.left().value();
+ List<GroupDefinition> groupsToUpdate = new ArrayList<GroupDefinition>();
+ List<GroupDefinition> groupsToDelete = new ArrayList<GroupDefinition>();
+ List<GroupDefinition> groupsToCreate = new ArrayList<GroupDefinition>();
+ if (groupsFromResource != null && !groupsFromResource.isEmpty()) {
+ for (GroupDefinition group : groupsAsList) {
+ Optional<GroupDefinition> op = groupsFromResource.stream().filter(p -> p.getName().equals(group.getName())).findAny();
+ if (op.isPresent()) {
+ GroupDefinition groupToUpdate = op.get();
+ groupToUpdate.setMembers(group.getMembers());
+ groupsToUpdate.add(groupToUpdate);
+ } else {
+ groupsToCreate.add(group);
+ }
+ }
+ for (GroupDefinition group : groupsFromResource) {
+ Optional<GroupDefinition> op = groupsAsList.stream().filter(p -> p.getName().equals(group.getName())).findAny();
+ if (!op.isPresent() && (group.getArtifacts() == null || group.getArtifacts().isEmpty())) {
+
+ groupsToDelete.add(group);
+ }
+
+ }
+ } else
+ groupsToCreate.addAll(groupsAsList);
+
+ if (!groupsToCreate.isEmpty()) {
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource, user, ComponentTypeEnum.RESOURCE, groupsToCreate, true);
+
+ if (createGroups.isRight()) {
+ return Either.right(createGroups.right().value());
+ }
+ }
+
+ if (!groupsToDelete.isEmpty()) {
+ for (GroupDefinition group : groupsToDelete) {
+ Either<GroupDefinition, StorageOperationStatus> deleteGroupEither = groupOperation.deleteGroup(group.getUniqueId(), true);
+ if (deleteGroupEither.isRight()) {
+ StorageOperationStatus storageOperationStatus = deleteGroupEither.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus);
+ log.debug("Failed to delete group {} under component {}, error: {}", group.getUniqueId(), resource.getNormalizedName(), actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+ }
+ }
+ if (groupsToUpdate != null && !groupsToUpdate.isEmpty()) {
+ Either<List<GroupDefinition>, ResponseFormat> assotiateGroupEither = groupBusinessLogic.associateMembersToGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, groupsToUpdate, false, true);
+ if (assotiateGroupEither.isRight()) {
+ log.debug("Failed to associate artifacts to groups. Status is {} ", assotiateGroupEither.right().value());
+ return Either.right(assotiateGroupEither.right().value());
+
+ }
+ List<GroupDefinition> updatedGroups = assotiateGroupEither.left().value();
+ List<String> groupsId = updatedGroups.stream().map(e -> e.getUniqueId()).collect(Collectors.toList());
+
+ Either<List<GroupDefinition>, StorageOperationStatus> updateVersionEither = groupBusinessLogic.updateGroupVersion(groupsId, true);
+ if (updateVersionEither.isRight()) {
+ log.debug("Failed to update groups version. Status is {} ", updateVersionEither.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updateVersionEither.right().value()), resource);
+ return Either.right(responseFormat);
+
+ }
+ }
+
+ } else {
+ return Either.left(resource);
+ }
+
+ Either<Resource, StorageOperationStatus> updatedResource = resourceOperation.getResource(resource.getUniqueId(), true);
+ if (updatedResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource);
+ return Either.right(responseFormat);
+ }
+ return Either.left(updatedResource.left().value());
+ }
+
+ private Either<Resource, ResponseFormat> createInputsOnResource(Resource resource, User user, Map<String, InputDefinition> inputs, boolean inTransaction) {
+ if (inputs != null && false == inputs.isEmpty()) {
+ List<InputDefinition> inputsAsList = new ArrayList<InputDefinition>();
+ for (Entry<String, InputDefinition> entry : inputs.entrySet()) {
+ InputDefinition input = entry.getValue();
+ input.setName(entry.getKey());
+ inputsAsList.add(input);
+ }
+ Either<List<InputDefinition>, ResponseFormat> createGroups = inputsBusinessLogic.createInputsInGraph(inputsAsList, resource, user, inTransaction);
+ if (createGroups.isRight()) {
+ return Either.right(createGroups.right().value());
+ }
+ } else {
+ return Either.left(resource);
+ }
+
+ Either<Resource, StorageOperationStatus> updatedResource = resourceOperation.getResource(resource.getUniqueId(), true);
+ if (updatedResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource);
+ return Either.right(responseFormat);
+ }
+ return Either.left(updatedResource.left().value());
+ }
+
+ private Either<List<GroupDefinition>, ResponseFormat> updateGroupMembersUsingResource(Map<String, GroupDefinition> groups, Resource component) {
+
+ List<GroupDefinition> result = new ArrayList<>();
+
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+
+ if (groups != null) {
+ for (Entry<String, GroupDefinition> entry : groups.entrySet()) {
+ String groupName = entry.getKey();
+
+ GroupDefinition groupDefinition = entry.getValue();
+
+ GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
+ updatedGroupDefinition.setMembers(null);
+
+ // get the members of the group
+ Map<String, String> members = groupDefinition.getMembers();
+ if (members != null) {
+ Set<String> compInstancesNames = members.keySet();
+
+ if (componentInstances == null || true == componentInstances.isEmpty()) {
+ String membersAstString = compInstancesNames.stream().collect(Collectors.joining(","));
+ log.debug("The members {} in group {} cannot be found in component {}. There are no component instances", membersAstString, groupName, component.getNormalizedName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(), getComponentTypeForResponse(component)));
+ }
+ // Find all component instances with the member names
+ Map<String, String> memberNames = componentInstances.stream().collect(Collectors.toMap(ComponentInstance::getName, ComponentInstance::getUniqueId));
+ memberNames.putAll(groups.keySet().stream().collect(Collectors.toMap(g -> g, g -> "")));
+ Map<String, String> relevantInstances = memberNames.entrySet().stream().filter(n -> compInstancesNames.contains(n.getKey())).collect(Collectors.toMap(n -> n.getKey(), n -> n.getValue()));
+
+ if (relevantInstances == null || relevantInstances.size() != compInstancesNames.size()) {
+
+ List<String> foundMembers = new ArrayList<>();
+ if (relevantInstances != null) {
+ foundMembers = relevantInstances.keySet().stream().collect(Collectors.toList());
+ }
+ compInstancesNames.removeAll(foundMembers);
+ String membersAstString = compInstancesNames.stream().collect(Collectors.joining(","));
+ log.debug("The members {} in group {} cannot be found in component {}", membersAstString, groupName, component.getNormalizedName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(), getComponentTypeForResponse(component)));
+ }
+
+ updatedGroupDefinition.setMembers(relevantInstances);
+ }
+
+ result.add(updatedGroupDefinition);
+ }
+ }
+ return Either.left(result);
+ }
+
+ private Either<Resource, ResponseFormat> createRIAndRelationsFromYaml(String yamlName, Resource resource, User user, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap, AuditingActionEnum actionEnum,
+ String topologyTemplateYaml, Map<String, byte[]> csar, String csarUUID) {
+
+ Either<Resource, ResponseFormat> result;
+ Either<Resource, ResponseFormat> createResourcesInstancesEither;
+ log.debug("************* Going to create all nodes {}", yamlName);
+ Either<Map<String, Resource>, ResponseFormat> createdResourcesFromdNodeTypeMap = this.handleNodeTypes(yamlName, resource, user, topologyTemplateYaml, csar, false);
+ log.debug("************* Finished to create all nodes {}", yamlName);
+ if (createdResourcesFromdNodeTypeMap.isRight()) {
+ log.debug("failed to resources from node types status is {}", createdResourcesFromdNodeTypeMap.right().value());
+ return Either.right(createdResourcesFromdNodeTypeMap.right().value());
+ }
+
+ log.debug("************* Going to create all resource instances {}", yamlName);
+ createResourcesInstancesEither = createResourceInstances(user, yamlName, resource, uploadComponentInstanceInfoMap, true, false, createdResourcesFromdNodeTypeMap.left().value());
+
+ log.debug("************* Finished to create all resource instances {}", yamlName);
+ if (createResourcesInstancesEither.isRight()) {
+ log.debug("failed to create resource instances status is {}", createResourcesInstancesEither.right().value());
+ result = createResourcesInstancesEither;
+ return createResourcesInstancesEither;
+ }
+ resource = createResourcesInstancesEither.left().value();
+ log.debug("************* Going to create all relations {}", yamlName);
+ createResourcesInstancesEither = createResourceInstancesRelations(user, yamlName, resource, uploadComponentInstanceInfoMap, true, false);
+
+ log.debug("************* Finished to create all relations {}", yamlName);
+
+ if (createResourcesInstancesEither.isRight()) {
+ log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value());
+ result = createResourcesInstancesEither;
+ return result;
+ } else {
+ resource = createResourcesInstancesEither.left().value();
+ }
+
+ log.debug("************* Going to create positions {}", yamlName);
+ Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, user.getUserId());
+ log.debug("************* Finished to set positions {}", yamlName);
+ result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(resource);
+
+ return result;
+ }
+
+ private Either<Map<String, Resource>, ResponseFormat> handleNodeTypes(String yamlName, Resource resource, User user, String topologyTemplateYaml, Map<String, byte[]> csar, boolean needLock) {
+
+ Map<String, Resource> createdResourcesFromdNodeTypeMap = new HashMap<>();
+ Either<Map<String, Resource>, ResponseFormat> result = Either.left(createdResourcesFromdNodeTypeMap);
+
+ String yamlFileName = Constants.GLOBAL_SUBSTITUTION_TYPE_SERVICE_TEMPLATE;
+
+ if (csar != null && csar.containsKey(yamlFileName)) {
+ byte[] yamlFileBytes = csar.get(yamlFileName);
+ String globalTypesYaml = new String(yamlFileBytes, StandardCharsets.UTF_8);
+ Either<Map<String, Resource>, ResponseFormat> createdNodeTypesFromGlobalTypesTemplateEither = this.createResourcesFromYamlNodeTypesList(yamlFileName, resource, globalTypesYaml, user, needLock);
+ if (createdNodeTypesFromGlobalTypesTemplateEither.isRight()) {
+ ResponseFormat responseFormat = createdNodeTypesFromGlobalTypesTemplateEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ createdResourcesFromdNodeTypeMap.putAll(createdNodeTypesFromGlobalTypesTemplateEither.left().value());
+ }
+
+ Either<Map<String, Resource>, ResponseFormat> createdNodeTypeFromMainTemplateEither = createResourcesFromYamlNodeTypesList(yamlName, resource, topologyTemplateYaml, user, needLock);
+ if (createdNodeTypeFromMainTemplateEither.isRight()) {
+ ResponseFormat responseFormat = createdNodeTypeFromMainTemplateEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+
+ createdResourcesFromdNodeTypeMap.putAll(createdNodeTypeFromMainTemplateEither.left().value());
+
+ // add the created node types to the cache although they are not in the
+ // graph.
+ createdResourcesFromdNodeTypeMap.values().stream().forEach(p -> cacheManagerOperation.storeComponentInCache(p, NodeTypeEnum.Resource));
+
+ return result;
+ }
+
+ private Either<Resource, ResponseFormat> handleCsarArtifacts(Resource resource, User user, String csarUUID, Map<String, byte[]> csar, List<ArtifactDefinition> createdArtifacts, ArtifactOperation artifactOperation, boolean shouldLock,
+ boolean inTransaction) {
+
+ if (csar != null) {
+ String vendorLicenseModelId = null;
+ String vfLicenseModelId = null;
+
+ if (artifactOperation.equals(ArtifactOperation.Update)) {
+ Map<String, ArtifactDefinition> deploymentArtifactsMap = resource.getDeploymentArtifacts();
+ if (deploymentArtifactsMap != null && !deploymentArtifactsMap.isEmpty()) {
+ for (Entry<String, ArtifactDefinition> artifactEntry : deploymentArtifactsMap.entrySet()) {
+ if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL))
+ vendorLicenseModelId = artifactEntry.getValue().getUniqueId();
+ if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL))
+ vfLicenseModelId = artifactEntry.getValue().getUniqueId();
+ }
+ }
+
+ }
+ createOrUpdateLicenseArtifact(resource, user, csarUUID, csar, Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME,
+ Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, shouldLock, inTransaction);
+ createOrUpdateLicenseArtifact(resource, user, csarUUID, csar, Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION,
+ vfLicenseModelId, artifactOperation, shouldLock, inTransaction);
+ Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csar, csarUUID, componentsUtils);
+ if (artifacsMetaCsarStatus.isLeft()) {
+
+ String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
+ String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
+ Either<Resource, ResponseFormat> createArtifactsFromCsar = Either.left(resource);
+ if (artifactOperation.equals(ArtifactOperation.Create))
+ createArtifactsFromCsar = createResourceArtifactsFromCsar(csarUUID, csar, resource, user, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
+ else
+ createArtifactsFromCsar = updateResourceArtifactsFromCsar(csarUUID, csar, resource, user, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
+ if (createArtifactsFromCsar.isRight()) {
+ log.debug("Couldn't create artifacts from artifacts.meta");
+ return Either.right(createArtifactsFromCsar.right().value());
+ }
+
+ resource = createArtifactsFromCsar.left().value();
+ } else {
+ List<GroupDefinition> groupsToDelete = resource.getGroups();
+
+ if (groupsToDelete != null && !groupsToDelete.isEmpty()) {
+ Set<String> artifactsToDelete = new HashSet<String>();
+ for (GroupDefinition group : groupsToDelete) {
+ List<String> artifacts = group.getArtifacts();
+ if (artifacts != null) {
+ artifactsToDelete.addAll(artifacts);
+ Either<GroupDefinition, StorageOperationStatus> deleteGroupEither = groupOperation.deleteGroup(group.getUniqueId(), inTransaction);
+ if (deleteGroupEither.isRight()) {
+ StorageOperationStatus storageOperationStatus = deleteGroupEither.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus);
+ log.debug("Failed to delete group {} under component {}, error: {}", group.getUniqueId(), resource.getNormalizedName(), actionStatus.name());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+ }
+ }
+ for (String artifactId : artifactsToDelete) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE,
+ resource, null, null, shouldLock, inTransaction);
+ if (handleDelete.isRight()) {
+ log.debug("Couldn't delete artifact {}", artifactId);
+ return Either.right(handleDelete.right().value());
+ }
+
+ }
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getResource(resource.getUniqueId(), inTransaction);
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+ resource = eitherGerResource.left().value();
+ }
+ }
+ }
+ return Either.left(resource);
+ }
+
+ private Either<Boolean, ResponseFormat> createOrUpdateLicenseArtifact(Resource resource, User user, String csarUUID, Map<String, byte[]> csar, String artifactFileName, String artifactType, String artifactLabel, String artifactDisplayName,
+ String artifactDescription, String artifactId, ArtifactOperation operation, boolean shouldLock, boolean inTransaction) {
+ byte[] artifactFileBytes = null;
+
+ if (csar.containsKey(Constants.ARTIFACTS + artifactFileName)) {
+ artifactFileBytes = csar.get(Constants.ARTIFACTS + artifactFileName);
+ }
+ Either<Boolean, ResponseFormat> result = Either.left(true);
+ if (operation.equals(ArtifactOperation.Update)) {
+ if (artifactId != null && !artifactId.isEmpty() && artifactFileBytes == null) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null,
+ null, shouldLock, inTransaction);
+ if (handleDelete.isRight()) {
+ result = Either.right(handleDelete.right().value());
+ }
+ return result;
+ }
+
+ if ((artifactId == null || artifactId.isEmpty()) && artifactFileBytes != null) {
+ operation = ArtifactOperation.Create;
+ }
+
+ }
+ if (artifactFileBytes != null) {
+ Map<String, Object> vendorLicenseModelJson = buildJsonForUpdateArtifact(artifactId, artifactFileName, artifactType, artifactLabel, artifactDisplayName, artifactDescription, artifactFileBytes, null);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> vfLicenceArtifactCreateEither = createOrUpdateCsarArtifactFromJson(resource, user, vendorLicenseModelJson, operation, shouldLock, inTransaction);
+
+ if (vfLicenceArtifactCreateEither.isRight()) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + csarUUID, ErrorSeverity.WARNING);
+ return Either.right(vfLicenceArtifactCreateEither.right().value());
+ }
+ }
+ return result;
+ }
+
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> createOrUpdateCsarArtifactFromJson(Resource resource, User user, Map<String, Object> json, ArtifactOperation operation, boolean shoudLock, boolean inTransaction) {
+
+ String jsonStr = gson.toJson(json);
+
+ String origMd5 = GeneralUtility.calculateMD5ByString(jsonStr);
+ ArtifactDefinition artifactDefinitionFromJson = RepresentationUtils.convertJsonToArtifactDefinition(jsonStr, ArtifactDefinition.class);
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = artifactsBusinessLogic.handleArtifactRequest(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, operation,
+ artifactDefinitionFromJson.getUniqueId(), artifactDefinitionFromJson, origMd5, jsonStr, null, null, null, null, shoudLock, inTransaction);
+ if (uploadArtifactToService.isRight())
+ return Either.right(uploadArtifactToService.right().value());
+
+ return Either.left(uploadArtifactToService.left().value());
+ }
+
+ public Either<Resource, ResponseFormat> updateResourceArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdNewArtifacts,
+ boolean shouldLock, boolean inTransaction) {
+
+ Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, user);
+ if (parseResourceInfoFromYamlEither.isRight()) {
+ ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+
+ List<GroupDefinition> groups = resource.getGroups();
+ Map<String, ArtifactDefinition> deplymentArtifact = resource.getDeploymentArtifacts();
+ List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete = new ArrayList<ArtifactDefinition>();
+ if (deplymentArtifact != null && !deplymentArtifact.isEmpty()) {
+ for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
+ createdDeplymentArtifactsAfterDelete.add(entry.getValue());
+ }
+ }
+ int labelCounter = createdDeplymentArtifactsAfterDelete.size();
+
+ if (deplymentArtifact == null || deplymentArtifact.isEmpty()) {
+ if (groups != null && !groups.isEmpty()) {
+ for (GroupDefinition group : groups) {
+ if (group.getArtifacts() != null && !group.getArtifacts().isEmpty()) {
+ log.debug("failed to update artifacts from csar. List of emty but group not empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return Either.right(responseFormat);
+ }
+ }
+ }
+ return createResourceArtifacts(csarUUID, csar, resource, user, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdNewArtifacts, shouldLock, inTransaction);
+ }
+ // find artifacts to delete
+ Set<String> artifactNotInGroupSet = findArtifactsNotInGroupToDelete(groups, createdDeplymentArtifactsAfterDelete);
+
+ // delete all artifacts which not in groups
+ if (!artifactNotInGroupSet.isEmpty()) {
+ for (String artifactId : artifactNotInGroupSet) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null,
+ null, shouldLock, inTransaction);
+ if (handleDelete.isRight()) {
+ return Either.right(handleDelete.right().value());
+ }
+
+ }
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getResource(resource.getUniqueId(), inTransaction);
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+
+ resource = eitherGerResource.left().value();
+ deplymentArtifact = resource.getDeploymentArtifacts();
+
+ createdDeplymentArtifactsAfterDelete.clear();
+ if (deplymentArtifact != null && !deplymentArtifact.isEmpty()) {
+ for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
+ createdDeplymentArtifactsAfterDelete.add(entry.getValue());
+ }
+ }
+ }
+
+ // find master in group
+ Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact = findMasterArtifactInGroup(groups, deplymentArtifact);
+
+ ////////////////////////////////////// create set parsed
+ ////////////////////////////////////// artifacts///////////////////////////////////////////
+ Map<String, List<ArtifactTemplateInfo>> parsedArtifactsMap = parseResourceInfoFromYamlEither.left().value();
+ Collection<List<ArtifactTemplateInfo>> parsedArifactsCollection = parsedArtifactsMap.values();
+ Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup = new HashMap<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>();
+
+ for (List<ArtifactTemplateInfo> parsedGroupTemplateList : parsedArifactsCollection) {
+ for (ArtifactTemplateInfo parsedGroupTemplate : parsedGroupTemplateList) {
+ parsedGroupTemplate.setGroupName("");
+ Set<ArtifactTemplateInfo> parsedArtifactsNames = new HashSet<ArtifactTemplateInfo>();
+ parsedArtifactsNames.add(parsedGroupTemplate);
+ List<ArtifactTemplateInfo> relatedGroupTemplateList = parsedGroupTemplate.getRelatedArtifactsInfo();
+ if (relatedGroupTemplateList != null && !relatedGroupTemplateList.isEmpty()) {
+ createArtifactsGroupSet(parsedGroupTemplateList, parsedArtifactsNames);
+ }
+ parsedGroup.put(parsedGroupTemplate, parsedArtifactsNames);
+ }
+ }
+
+ ///////////////////////////////// find artifacts to
+ ///////////////////////////////// delete////////////////////////////////////////////////////
+
+ Set<ArtifactDefinition> artifactsToDelete = new HashSet<ArtifactDefinition>();
+ Map<String, List<ArtifactDefinition>> groupToDelete = new HashMap<String, List<ArtifactDefinition>>();
+ Map<String, List<String>> dissocArtifactFromGroup = new HashMap<String, List<String>>();
+
+ Set<ArtifactTemplateInfo> jsonMasterArtifacts = parsedGroup.keySet();
+
+ Map<GroupDefinition, MergedArtifactInfo> mergedgroup = mergeGroupInUpdateFlow(groupArtifact, parsedGroup, artifactsToDelete, groupToDelete, jsonMasterArtifacts);
+
+ // find artifacts to delete
+ for (Entry<String, List<ArtifactDefinition>> deleteGroup : groupToDelete.entrySet()) {
+
+ List<ArtifactDefinition> artifacts = deleteGroup.getValue();
+ for (ArtifactDefinition artifact : artifacts) {
+ findArtifactToDelete(parsedGroup, artifactsToDelete, deleteGroup.getKey(), artifact);
+ }
+
+ }
+
+ // Set<String> deletedArtifactsName = new HashSet<String>();
+ Either<List<ArtifactDefinition>, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(resource, user, shouldLock, inTransaction, artifactsToDelete, groupToDelete);
+ if (deletedArtifactsEither.isRight()) {
+ log.debug("Failed to delete artifacts. Status is {} ", deletedArtifactsEither.right().value());
+
+ return Either.right(deletedArtifactsEither.right().value());
+
+ }
+ List<ArtifactDefinition> deletedArtifacts = deletedArtifactsEither.left().value();
+
+ // need to update resource if we updated artifacts
+ if (deletedArtifacts != null && !deletedArtifacts.isEmpty()) {
+ for (ArtifactDefinition deletedArtifact : deletedArtifacts) {
+ ArtifactDefinition artToRemove = null;
+ for (ArtifactDefinition artFromResource : createdDeplymentArtifactsAfterDelete) {
+ if (deletedArtifact.getUniqueId().equalsIgnoreCase(artFromResource.getUniqueId())) {
+ artToRemove = artFromResource;
+ break;
+ }
+ }
+ if (artToRemove != null)
+ createdDeplymentArtifactsAfterDelete.remove(artToRemove);
+
+ }
+ }
+
+ ////////////// dissociate, associate or create
+ ////////////// artifacts////////////////////////////
+ Either<Resource, ResponseFormat> assDissotiateEither = associateAndDissociateArtifactsToGroup(csarUUID, csar, resource, user, createdNewArtifacts, labelCounter, shouldLock, inTransaction, createdDeplymentArtifactsAfterDelete,
+ dissocArtifactFromGroup, mergedgroup, deletedArtifacts);
+
+ if (assDissotiateEither.isRight()) {
+ log.debug("Failed to delete artifacts. Status is {} ", assDissotiateEither.right().value());
+
+ return Either.right(assDissotiateEither.right().value());
+
+ }
+ resource = assDissotiateEither.left().value();
+ groups = resource.getGroups();
+ List<GroupDefinition> groupToUpdate = new ArrayList<>();
+ // update vfModule names
+ Set<GroupDefinition> groupForAssociateWithMembers = mergedgroup.keySet();
+ if (groups != null && !groups.isEmpty()) {
+ Either<List<GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNamesOnGraph(groups, resource.getSystemName(), inTransaction);
+ if (validateUpdateVfGroupNamesRes.isRight()) {
+ return Either.right(validateUpdateVfGroupNamesRes.right().value());
+ }
+ List<GroupDefinition> heatGroups = null;
+
+ // List<IArtifactInfo> collect = resources.stream().flatMap( e ->
+ // e.getArtifacts().stream()).filter(p ->
+ // relevantArtifactTypes.contains(p.getArtifactType()
+ // )).collect(Collectors.toList());
+ // List<GroupDefinition> heatGroups = createdGroups.stream().filter(
+ // e -> e.getProperties().stream().filter(p ->
+ // p.getName().contains(Constants.HEAT_FILE_PROPS))).collect(Collectors.toList());
+ heatGroups = groups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
+ ;
+
+ for (GroupDefinition updatedGroupDef : groupForAssociateWithMembers) {
+ GroupDefinition group = null;
+ Optional<GroupDefinition> opGr = groups.stream().filter(p -> p.getUniqueId().equals(updatedGroupDef.getUniqueId())).findAny();
+ if (opGr.isPresent()) {
+ group = opGr.get();
+ groupToUpdate.add(group);
+ }
+ if (group != null) {
+ Map<String, String> members = new HashMap<String, String>();
+ Set<String> artifactsGroup = new HashSet<String>();
+ artifactsGroup.addAll(group.getArtifacts());
+ associateMembersTToArtifacts(createdNewArtifacts, createdDeplymentArtifactsAfterDelete, heatGroups, artifactsGroup, members);
+ if (!members.isEmpty()) {
+ group.setMembers(members);
+
+ }
+ }
+
+ }
+ if (!groupToUpdate.isEmpty()) {
+ Either<List<GroupDefinition>, ResponseFormat> assotiateGroupEither = groupBusinessLogic.associateMembersToGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, groupToUpdate, false, true);
+ if (assotiateGroupEither.isRight()) {
+ log.debug("Failed to associate artifacts to groups. Status is {} ", assotiateGroupEither.right().value());
+ return Either.right(assotiateGroupEither.right().value());
+
+ }
+ }
+
+ }
+
+ //////////////// create new artifacts in update
+ //////////////// flow////////////////////////////
+ List<ArtifactTemplateInfo> newArtifactsGroup = new ArrayList<ArtifactTemplateInfo>();
+
+ for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
+ ArtifactTemplateInfo parsedArtifactMaster = parsedGroupSetEntry.getKey();
+ boolean isNewGroup = true;
+ for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact.entrySet()) {
+ Map<ArtifactDefinition, List<ArtifactDefinition>> groupArtifacts = groupListEntry.getValue();
+ Set<ArtifactDefinition> group = groupArtifacts.keySet();
+ for (ArtifactDefinition artifactInfo : group) {
+ if (parsedArtifactMaster.getFileName().equalsIgnoreCase(artifactInfo.getArtifactName())) {
+ parsedArtifactMaster.setGroupName(groupListEntry.getKey().getName());
+ isNewGroup = false;
+ }
+ }
+ }
+ if (isNewGroup)
+ newArtifactsGroup.add(parsedArtifactMaster);
+
+ }
+ if (!newArtifactsGroup.isEmpty()) {
+ Collections.sort(newArtifactsGroup, (art1, art2) -> ArtifactTemplateInfo.compareByGroupName(art1, art2));
+ int startGroupCounter = groupBusinessLogic.getNextVfModuleNameCounter(groups);
+ Either<Boolean, ResponseFormat> validateGroupNamesRes = groupBusinessLogic.validateGenerateVfModuleGroupNames(newArtifactsGroup, resource.getSystemName(), startGroupCounter);
+ if (validateGroupNamesRes.isRight()) {
+ return Either.right(validateGroupNamesRes.right().value());
+ }
+ Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+ }
+
+ // updatedGroup
+ if (!groupForAssociateWithMembers.isEmpty()) {
+
+ List<String> groupsId = groupForAssociateWithMembers.stream().map(e -> e.getUniqueId()).collect(Collectors.toList());
+
+ Either<List<GroupDefinition>, StorageOperationStatus> updateVersionEither = groupBusinessLogic.updateGroupVersion(groupsId, true);
+ if (updateVersionEither.isRight()) {
+ log.debug("Failed to update groups version. Status is {} ", updateVersionEither.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(updateVersionEither.right().value()), resource);
+ return Either.right(responseFormat);
+
+ }
+ }
+
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getResource(resource.getUniqueId(), inTransaction);
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(eitherGerResource.left().value());
+
+ }
+
+ private Either<List<ArtifactDefinition>, ResponseFormat> deleteArtifactsInUpdateCsarFlow(Resource resource, User user, boolean shouldLock, boolean inTransaction, Set<ArtifactDefinition> artifactsToDelete,
+ Map<String, List<ArtifactDefinition>> groupToDelete) {
+ List<ArtifactDefinition> deletedArtifacts = new ArrayList<ArtifactDefinition>();
+
+ if (!artifactsToDelete.isEmpty()) {
+ for (ArtifactDefinition artifact : artifactsToDelete) {
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifact.getUniqueId(), user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE,
+ resource, null, null, shouldLock, inTransaction);
+ if (handleDelete.isRight()) {
+ return Either.right(handleDelete.right().value());
+ }
+ deletedArtifacts.add(handleDelete.left().value().left().value());
+
+ }
+ }
+ if (!groupToDelete.isEmpty()) {
+ log.debug("try to delete group");
+ for (Entry<String, List<ArtifactDefinition>> deleteGroup : groupToDelete.entrySet()) {
+ Either<GroupDefinition, StorageOperationStatus> deleteGroupEither = groupOperation.deleteGroup(deleteGroup.getKey(), inTransaction);
+ if (deleteGroupEither.isRight()) {
+ StorageOperationStatus storageOperationStatus = deleteGroupEither.right().value();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus);
+ log.debug("Failed to delete group {} under component {}, error: {}", deleteGroup.getKey(), resource.getNormalizedName(), actionStatus.name());
+
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+
+ }
+ }
+ }
+ return Either.left(deletedArtifacts);
+ }
+
+ private Either<Resource, ResponseFormat> associateAndDissociateArtifactsToGroup(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactDefinition> createdNewArtifacts, int labelCounter, boolean shouldLock,
+ boolean inTransaction, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete, Map<String, List<String>> dissocArtifactFromGroup, Map<GroupDefinition, MergedArtifactInfo> mergedgroup, List<ArtifactDefinition> deletedArtifacts) {
+ Map<GroupDefinition, List<ArtifactTemplateInfo>> artifactsToAssotiate = new HashMap<GroupDefinition, List<ArtifactTemplateInfo>>();
+ Map<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>> artifactsToUpdateMap = new HashMap<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>>();
+ Either<Resource, ResponseFormat> resEither = Either.left(resource);
+ for (Entry<GroupDefinition, MergedArtifactInfo> entry : mergedgroup.entrySet()) {
+ List<ArtifactDefinition> dissArtifactsInGroup = entry.getValue().getListToDissotiateArtifactFromGroup(deletedArtifacts);
+ if (dissArtifactsInGroup != null && !dissArtifactsInGroup.isEmpty()) {
+ List<String> dissList = new ArrayList<String>();
+ for (ArtifactDefinition art : dissArtifactsInGroup) {
+ dissList.add(art.getUniqueId());
+ }
+ dissocArtifactFromGroup.put(entry.getKey().getUniqueId(), dissList);
+ }
+
+ List<ArtifactTemplateInfo> newArtifactsInGroup = entry.getValue().getListToAssociateArtifactToGroup();
+ if (newArtifactsInGroup != null && !newArtifactsInGroup.isEmpty())
+ artifactsToAssotiate.put(entry.getKey(), newArtifactsInGroup);
+
+ List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> artifactsToUpdate = entry.getValue().getListToUpdateArtifactInGroup();
+ if (artifactsToUpdate != null && !artifactsToUpdate.isEmpty())
+ artifactsToUpdateMap.put(entry.getKey(), artifactsToUpdate);
+ }
+
+ // Map<String, Set<String>> dissocArtifactFromGroup = new
+ // HashMap<String, Set<String>>();
+ List<GroupDefinition> dissotiateArtifactsgroups = new ArrayList<GroupDefinition>();
+ for (Entry<String, List<String>> dissotiateEntry : dissocArtifactFromGroup.entrySet()) {
+
+ GroupDefinition dissotiateGroup = new GroupDefinition();
+ dissotiateGroup.setUniqueId(dissotiateEntry.getKey());
+ dissotiateGroup.setArtifacts(dissotiateEntry.getValue());
+ dissotiateArtifactsgroups.add(dissotiateGroup);
+ }
+ if (!dissotiateArtifactsgroups.isEmpty()) {
+ log.debug("try to dissociate artifacts from groups ");
+ Either<List<GroupDefinition>, ResponseFormat> dissotiateGroupEither = groupBusinessLogic.dissociateArtifactsFromGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, dissotiateArtifactsgroups, shouldLock,
+ inTransaction);
+ if (dissotiateGroupEither.isRight()) {
+ log.debug("Failed to dissociate artifacts from groups. Status is {} ", dissotiateGroupEither.right().value());
+ resEither = Either.right(dissotiateGroupEither.right().value());
+ return resEither;
+
+ }
+ }
+
+ if (!artifactsToUpdateMap.isEmpty()) {
+ List<ArtifactDefinition> updatedArtifacts = new ArrayList<ArtifactDefinition>();
+ for (Entry<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>> artifactsToUpdateEntry : artifactsToUpdateMap.entrySet()) {
+ List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> artifactsToUpdateList = artifactsToUpdateEntry.getValue();
+ for (ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo> artifact : artifactsToUpdateList) {
+ Either<ArtifactDefinition, ResponseFormat> updateArtifactEither = updateDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifact.getKey(), artifact.getValue(), updatedArtifacts,
+ artifact.getRight().getRelatedArtifactsInfo(), shouldLock, inTransaction);
+ if (updateArtifactEither.isRight()) {
+ log.debug("failed to update artifacts. status is {}", updateArtifactEither.right().value());
+ resEither = Either.right(updateArtifactEither.right().value());
+ return resEither;
+
+ }
+
+ }
+ }
+
+ }
+
+ List<GroupDefinition> associateArtifactGroup = new ArrayList<GroupDefinition>();
+
+ for (Entry<GroupDefinition, List<ArtifactTemplateInfo>> associateEntry : artifactsToAssotiate.entrySet()) {
+ List<ArtifactTemplateInfo> associatedArtifact = associateEntry.getValue();
+ Set<String> arifactsUids = new HashSet<String>();
+ for (ArtifactTemplateInfo artifactTemplate : associatedArtifact) { // try
+ // to
+ // find
+ // artifact
+ // in
+ // resource
+ boolean isCreate = true;
+ for (ArtifactDefinition createdArtifact : createdDeplymentArtifactsAfterDelete) {
+ if (artifactTemplate.getFileName().equalsIgnoreCase(createdArtifact.getArtifactName())) {
+ arifactsUids.add(createdArtifact.getUniqueId());
+ isCreate = false;
+ break;
+ }
+
+ }
+ if (isCreate) { // check if already created
+ for (ArtifactDefinition createdNewArtifact : createdNewArtifacts) {
+ if (artifactTemplate.getFileName().equalsIgnoreCase(createdNewArtifact.getArtifactName())) {
+ arifactsUids.add(createdNewArtifact.getUniqueId());
+ isCreate = false;
+ break;
+ }
+ }
+ }
+
+ if (isCreate) {
+ Either<ArtifactDefinition, ResponseFormat> createArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, artifactTemplate, createdNewArtifacts, labelCounter, shouldLock, inTransaction);
+ if (createArtifactEither.isRight()) {
+ resEither = Either.right(createArtifactEither.right().value());
+ return resEither;
+ }
+ arifactsUids.add(createArtifactEither.left().value().getUniqueId());
+ }
+
+ }
+ if (arifactsUids.size() > 0) {
+ List<String> artifactsToAssociate = new ArrayList<String>();
+ artifactsToAssociate.addAll(arifactsUids);
+ GroupDefinition assotiateGroup = new GroupDefinition();
+ assotiateGroup.setUniqueId(associateEntry.getKey().getUniqueId());
+ assotiateGroup.setArtifacts(artifactsToAssociate);
+ associateArtifactGroup.add(assotiateGroup);
+
+ }
+ }
+
+ if (!associateArtifactGroup.isEmpty()) {
+
+ log.debug("Try to associate artifacts to groups.");
+
+ Either<List<GroupDefinition>, ResponseFormat> assotiateGroupEither = groupBusinessLogic.associateArtifactsToGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, associateArtifactGroup, shouldLock, inTransaction);
+ if (assotiateGroupEither.isRight()) {
+ log.debug("Failed to associate artifacts to groups. Status is {} ", assotiateGroupEither.right().value());
+ resEither = Either.right(assotiateGroupEither.right().value());
+ return resEither;
+
+ }
+ }
+
+ ComponentParametersView parametersView = new ComponentParametersView();
+ parametersView.disableAll();
+ parametersView.setIgnoreComponentInstances(false);
+ parametersView.setIgnoreUsers(false);
+ parametersView.setIgnoreArtifacts(false);
+ parametersView.setIgnoreGroups(false);
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getComponent(resource.getUniqueId(), parametersView, inTransaction);
+
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ resEither = Either.right(responseFormat);
+ return resEither;
+
+ }
+ resEither = Either.left(eitherGerResource.left().value());
+ return resEither;
+ }
+
+ private Map<GroupDefinition, MergedArtifactInfo> mergeGroupInUpdateFlow(Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact, Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup,
+ Set<ArtifactDefinition> artifactsToDelete, Map<String, List<ArtifactDefinition>> groupToDelete, Set<ArtifactTemplateInfo> jsonMasterArtifacts) {
+ Map<GroupDefinition, MergedArtifactInfo> mergedgroup = new HashMap<GroupDefinition, MergedArtifactInfo>();
+ for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact.entrySet()) {
+ Map<ArtifactDefinition, List<ArtifactDefinition>> createdArtifactMap = groupListEntry.getValue();
+ boolean isNeedToDeleteGroup = true;
+ List<ArtifactDefinition> listToDelete = null;
+ for (ArtifactDefinition maserArtifact : createdArtifactMap.keySet()) {
+ listToDelete = createdArtifactMap.get(maserArtifact);
+ for (ArtifactDefinition artToDelete : listToDelete) {
+ findArtifactToDelete(parsedGroup, artifactsToDelete, groupListEntry.getKey().getUniqueId(), artToDelete);
+ }
+ for (ArtifactTemplateInfo jsonMasterArtifact : jsonMasterArtifacts) {
+ if (maserArtifact.getArtifactName().equalsIgnoreCase(jsonMasterArtifact.getFileName())) {
+ MergedArtifactInfo mergedGroup = new MergedArtifactInfo();
+ mergedGroup.setJsonArtifactTemplate(jsonMasterArtifact);
+ mergedGroup.setCreatedArtifact(createdArtifactMap.get(maserArtifact));
+ mergedgroup.put(groupListEntry.getKey(), mergedGroup);
+ isNeedToDeleteGroup = false;
+
+ }
+ }
+
+ }
+ if (isNeedToDeleteGroup) {
+ groupToDelete.put(groupListEntry.getKey().getUniqueId(), listToDelete);
+ }
+
+ }
+ return mergedgroup;
+ }
+
+ private Set<String> findArtifactsNotInGroupToDelete(List<GroupDefinition> groups, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete) {
+ Set<String> artifactNotInGroupSet = new HashSet<String>();
+ for (ArtifactDefinition artifact : createdDeplymentArtifactsAfterDelete) {
+ boolean needToDelete = true;
+ if (artifact.getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL) || artifact.getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL))
+ continue;
+ if (groups != null) {
+ for (GroupDefinition group : groups) {
+ List<String> groupArtifactIds = group.getArtifacts();
+ if (groupArtifactIds == null || groupArtifactIds.isEmpty()) {
+ continue;
+ }
+ for (String groupArtifactid : groupArtifactIds) {
+ if (groupArtifactid.equalsIgnoreCase(artifact.getUniqueId()))
+ needToDelete = false;
+
+ }
+
+ }
+ }
+ if (needToDelete)
+ artifactNotInGroupSet.add(artifact.getUniqueId());
+ }
+ return artifactNotInGroupSet;
+ }
+
+ private void findArtifactToDelete(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete, String deleteGroupId, ArtifactDefinition artifact) {
+ boolean isNeedToDeleteArtifact = true;
+ for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
+ Set<ArtifactTemplateInfo> artifactsNames = parsedGroupSetEntry.getValue();
+ for (ArtifactTemplateInfo template : artifactsNames) {
+ if (artifact.getArtifactName().equalsIgnoreCase(template.getFileName()) && artifact.getArtifactType().equalsIgnoreCase(template.getType())) {
+ isNeedToDeleteArtifact = false;
+
+ }
+ }
+ }
+ if (isNeedToDeleteArtifact) {
+
+ artifactsToDelete.add(artifact);
+
+ }
+ }
+
+ private Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> findMasterArtifactInGroup(List<GroupDefinition> groups, Map<String, ArtifactDefinition> deplymentArtifact) {
+ Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact = new HashMap<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>>();
+
+ for (GroupDefinition group : groups) {
+ Map<ArtifactDefinition, List<ArtifactDefinition>> gupsMap = new HashMap<ArtifactDefinition, List<ArtifactDefinition>>();
+ List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
+ List<String> artifactsList = group.getArtifacts();
+ if (artifactsList != null && !artifactsList.isEmpty()) {
+
+ ArtifactDefinition masterArtifact = ArtifactUtils.findMasterArtifact(deplymentArtifact, artifacts, artifactsList);
+ if (masterArtifact != null)
+ gupsMap.put(masterArtifact, artifacts);
+ groupArtifact.put(group, gupsMap);
+
+ }
+ }
+ return groupArtifact;
+ }
+
+ private void createArtifactsGroupSet(List<ArtifactTemplateInfo> parsedGroupTemplateList, Set<ArtifactTemplateInfo> parsedArtifactsName) {
+
+ for (ArtifactTemplateInfo parsedGroupTemplate : parsedGroupTemplateList) {
+ parsedArtifactsName.add(parsedGroupTemplate);
+ List<ArtifactTemplateInfo> relatedArtifacts = parsedGroupTemplate.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ createArtifactsGroupSet(relatedArtifacts, parsedArtifactsName);
+ }
+ }
+ }
+
+ public Either<Resource, ResponseFormat> createResourceArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdArtifacts,
+ boolean shouldLock, boolean inTransaction) {
+
+ log.debug("parseResourceArtifactsInfoFromFile start");
+ Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, user);
+ if (parseResourceInfoFromYamlEither.isRight()) {
+ ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ log.debug("parseResourceArtifactsInfoFromFile end");
+
+ log.debug("createResourceArtifacts start");
+ Either<Resource, ResponseFormat> respStatus = createResourceArtifacts(csarUUID, csar, resource, user, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdArtifacts, shouldLock, inTransaction);
+ if (respStatus.isRight()) {
+ return respStatus;
+ }
+ log.debug("createResourceArtifacts end");
+ log.debug("getResource start");
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getResource(resource.getUniqueId(), inTransaction);
+ log.debug("getResource end");
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(eitherGerResource.left().value());
+
+ }
+
+ private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactTemplateInfo> artifactsTemplateList,
+ List<ArtifactDefinition> createdNewArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shouldLock, boolean inTransaction) {
+ Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+ List<GroupDefinition> createdGroups = resource.getGroups();
+ List<GroupDefinition> heatGroups = null;
+ if (createdGroups != null && !createdGroups.isEmpty()) {
+
+ // List<IArtifactInfo> collect = resources.stream().flatMap( e ->
+ // e.getArtifacts().stream()).filter(p ->
+ // relevantArtifactTypes.contains(p.getArtifactType()
+ // )).collect(Collectors.toList());
+ // List<GroupDefinition> heatGroups = createdGroups.stream().filter(
+ // e -> e.getProperties().stream().filter(p ->
+ // p.getName().contains(Constants.HEAT_FILE_PROPS))).collect(Collectors.toList());
+ heatGroups = createdGroups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
+ ;
+ }
+
+ for (ArtifactTemplateInfo groupTemplateInfo : artifactsTemplateList) {
+ String groupName = groupTemplateInfo.getGroupName();
+ Set<String> artifactsGroup = new HashSet<String>();
+
+ resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+
+ Map<String, String> members = new HashMap<String, String>();
+ associateMembersTToArtifacts(createdNewArtifacts, artifactsFromResource, heatGroups, artifactsGroup, members);
+
+ List<String> artifactsList = new ArrayList<String>(artifactsGroup);
+
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName(groupName);
+ groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+ groupDefinition.setArtifacts(artifactsList);
+ if (!members.isEmpty())
+ groupDefinition.setMembers(members);
+
+ List<GroupProperty> properties = new ArrayList<GroupProperty>();
+ GroupProperty prop = new GroupProperty();
+ prop.setName(Constants.IS_BASE);
+ prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
+
+ properties.add(prop);
+ groupDefinition.setProperties(properties);
+ Either<GroupDefinition, ResponseFormat> createGroup = groupBusinessLogic.createGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, groupDefinition, inTransaction);
+ if (createGroup.isRight())
+ return Either.right(createGroup.right().value());
+
+ }
+ return resStatus;
+ }
+
+ private Either<Resource, ResponseFormat> createDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, Set<String> artifactsGroup, ArtifactTemplateInfo artifactTemplateInfo,
+ List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shoudLock, boolean inTransaction) {
+ Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+ String artifactFileName = artifactTemplateInfo.getFileName();
+ String artifactUid = "";
+ boolean alreadyExist = false;
+
+ // check if artifacts already exist
+ if (artifactsFromResource != null && !artifactsFromResource.isEmpty()) {
+ for (ArtifactDefinition artifactFromResource : artifactsFromResource) {
+ if (artifactFromResource.getArtifactName().equals(artifactFileName)) {
+ artifactUid = artifactFromResource.getUniqueId();
+ if (!artifactFromResource.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) {
+ log.debug("Artifact with name {} and type {} already exist with type {}", artifactFileName, artifactTemplateInfo.getType(), artifactFromResource.getArtifactType());
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName, artifactTemplateInfo.getType(), artifactFromResource.getArtifactType()));
+ }
+ alreadyExist = true;
+ break;
+ }
+
+ }
+
+ }
+ if (!alreadyExist) {
+ for (ArtifactDefinition createdArtifact : createdArtifacts) {
+ if (createdArtifact.getArtifactName().equals(artifactFileName)) {
+ artifactUid = createdArtifact.getUniqueId();
+ if (!createdArtifact.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) {
+ log.debug("Artifact with name {} and type {} already exist with type {}", artifactFileName, artifactTemplateInfo.getType(), createdArtifact.getArtifactType());
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName, artifactTemplateInfo.getType(), createdArtifact.getArtifactType()));
+ }
+ alreadyExist = true;
+ break;
+ }
+
+ }
+ }
+ // if not exist need to create
+ if (!alreadyExist) {
+
+ Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ if (newArtifactEither.isRight()) {
+ resStatus = Either.right(newArtifactEither.right().value());
+ return resStatus;
+ }
+ artifactUid = newArtifactEither.left().value().getUniqueId();
+
+ }
+
+ artifactsGroup.add(artifactUid);
+
+ List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null) {
+ for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
+ resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+ }
+ }
+ return resStatus;
+ }
+
+ private Either<Resource, ResponseFormat> createResourceArtifacts(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, Map<String, List<ArtifactTemplateInfo>> artifactsMap, AuditingActionEnum createResource,
+ List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction) {
+
+ Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+
+ Collection<List<ArtifactTemplateInfo>> arifactsCollection = artifactsMap.values();
+
+ for (List<ArtifactTemplateInfo> groupTemplateList : arifactsCollection) {
+ if (groupTemplateList != null) {
+ resStatus = createGroupDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, groupTemplateList, createdArtifacts, 0, shouldLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+ }
+ }
+
+ return resStatus;
+
+ }
+
+ private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactTemplateInfo> artifactsTemplateList, List<ArtifactDefinition> createdArtifacts,
+ int labelCounter, boolean shouldLock, boolean inTransaction) {
+ Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+ List<GroupDefinition> createdGroups = resource.getGroups();
+ List<GroupDefinition> heatGroups = null;
+ if (createdGroups != null && !createdGroups.isEmpty()) {
+
+ // List<IArtifactInfo> collect = resources.stream().flatMap( e ->
+ // e.getArtifacts().stream()).filter(p ->
+ // relevantArtifactTypes.contains(p.getArtifactType()
+ // )).collect(Collectors.toList());
+ // List<GroupDefinition> heatGroups = createdGroups.stream().filter(
+ // e -> e.getProperties().stream().filter(p ->
+ // p.getName().contains(Constants.HEAT_FILE_PROPS))).collect(Collectors.toList());
+ heatGroups = createdGroups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
+ ;
+ }
+ for (ArtifactTemplateInfo groupTemplateInfo : artifactsTemplateList) {
+ String groupName = groupTemplateInfo.getGroupName();
+ Set<String> artifactsGroup = new HashSet<String>();
+
+ log.debug("createDeploymentArtifactsFromCsar start");
+ resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction);
+ log.debug("createDeploymentArtifactsFromCsar end");
+ if (resStatus.isRight())
+ return resStatus;
+
+ Map<String, String> members = new HashMap<String, String>();
+ associateMembersTToArtifacts(createdArtifacts, null, heatGroups, artifactsGroup, members);
+
+ List<String> artifactsList = new ArrayList<String>(artifactsGroup);
+
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName(groupName);
+ groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+ groupDefinition.setArtifacts(artifactsList);
+ if (!members.isEmpty())
+ groupDefinition.setMembers(members);
+ List<GroupProperty> properties = new ArrayList<GroupProperty>();
+ GroupProperty prop = new GroupProperty();
+ prop.setName(Constants.IS_BASE);
+ prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
+
+ properties.add(prop);
+ groupDefinition.setProperties(properties);
+ log.debug("createGroup start");
+ // Either<GroupDefinition, ResponseFormat> createGroup =
+ // groupBusinessLogic.createGroup(resource.getUniqueId(),
+ // user.getUserId(), ComponentTypeEnum.RESOURCE, groupDefinition,
+ // inTransaction);
+ // Ignore validations and get component
+
+ // Since in these groups we handle only artifacts, then no need to
+ // fetch component instances
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreArtifacts(false);
+ componentParametersView.setIgnoreGroups(false);
+ componentParametersView.setIgnoreComponentInstances(false);
+ Either<Resource, StorageOperationStatus> component = resourceOperation.getComponent(resource.getUniqueId(), componentParametersView, inTransaction);
+ if (component.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ Either<GroupDefinition, ResponseFormat> createGroup = groupBusinessLogic.createGroup(component.left().value(), user, ComponentTypeEnum.RESOURCE, groupDefinition, inTransaction);
+ log.debug("createGroup end");
+ if (createGroup.isRight())
+ return Either.right(createGroup.right().value());
+
+ }
+ return resStatus;
+ }
+
+ private void associateMembersTToArtifacts(List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, List<GroupDefinition> heatGroups, Set<String> artifactsGroup, Map<String, String> members) {
+ if (heatGroups != null && !heatGroups.isEmpty()) {
+ for (GroupDefinition heatGroup : heatGroups) {
+ List<GroupProperty> grpoupProps = heatGroup.getProperties();
+ if (grpoupProps != null) {
+ Optional<GroupProperty> op = grpoupProps.stream().filter(p -> p.getName().equals(Constants.HEAT_FILE_PROPS)).findAny();
+ if (op.isPresent()) {
+ GroupProperty prop = op.get();
+ String heatFileNAme = prop.getValue();
+ if (null == heatFileNAme || heatFileNAme.isEmpty())
+ continue;
+ List<ArtifactDefinition> artifacts = new ArrayList();
+ for (String artifactId : artifactsGroup) {
+ Optional<ArtifactDefinition> opArt = createdArtifacts.stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny();
+ if (opArt.isPresent()) {
+ artifacts.add(opArt.get());
+ }
+ if (artifactsFromResource != null) {
+ opArt = artifactsFromResource.stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny();
+ if (opArt.isPresent()) {
+ artifacts.add(opArt.get());
+ }
+ }
+ }
+ Optional<ArtifactDefinition> resOp = artifacts.stream().filter(p -> heatFileNAme.contains(p.getArtifactName())).findAny();
+ if (resOp.isPresent()) {
+ members.putAll(heatGroup.getMembers());
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ private Either<Resource, ResponseFormat> createDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, Set<String> artifactsGroup, ArtifactTemplateInfo artifactTemplateInfo,
+ List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) {
+ Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+ String artifactFileName = artifactTemplateInfo.getFileName();
+ String artifactUid = "";
+ boolean alreadyExist = false;
+
+ // check if artifacts already exist
+ for (ArtifactDefinition createdArtifact : createdArtifacts) {
+ if (createdArtifact.getArtifactName().equals(artifactFileName)) {
+ artifactUid = createdArtifact.getUniqueId();
+ if (!createdArtifact.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) {
+ log.debug("Artifact with name {} and type {} already exist with type {}", artifactFileName, artifactTemplateInfo.getType(), createdArtifact.getArtifactType());
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName, artifactTemplateInfo.getType(), createdArtifact.getArtifactType()));
+ }
+ alreadyExist = true;
+ break;
+ }
+
+ }
+ // if not exist need to create
+ if (!alreadyExist) {
+
+ Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ if (newArtifactEither.isRight()) {
+ resStatus = Either.right(newArtifactEither.right().value());
+ return resStatus;
+ }
+ artifactUid = newArtifactEither.left().value().getUniqueId();
+
+ }
+
+ artifactsGroup.add(artifactUid);
+
+ List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null) {
+ for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
+ resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+ }
+ }
+ return resStatus;
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> createDeploymentArtifact(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts,
+ int labelCounter, boolean shoudLock, boolean inTransaction) {
+ String artifactUid;
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, artifactTemplateInfo.getFileName(), componentsUtils);
+ if (artifactContententStatus.isRight())
+ return Either.right(artifactContententStatus.right().value());
+ labelCounter += createdArtifacts.size();
+
+ Map<String, Object> json = buildJsonForArtifact(artifactTemplateInfo, artifactContententStatus.left().value().getValue(), labelCounter);
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, user, json, ArtifactOperation.Create, shoudLock, inTransaction);
+
+ if (uploadArtifactToService.isRight())
+ return Either.right(uploadArtifactToService.right().value());
+
+ ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
+ if (currentInfo.getHeatParameters() != null) {
+
+ Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(csarUUID, csar, artifactTemplateInfo, currentInfo);
+ if (updateEnvEither.isRight()) {
+ log.debug("failed to update parameters to artifact {}", artifactTemplateInfo.getFileName());
+ return Either.right(updateEnvEither.right().value());
+
+ }
+ artifactUid = updateEnvEither.left().value().getUniqueId();
+ createdArtifacts.add(updateEnvEither.left().value());
+ currentInfo = updateEnvEither.left().value();
+ } else {
+
+ artifactUid = currentInfo.getUniqueId();
+ createdArtifacts.add(currentInfo);
+
+ }
+ return Either.left(currentInfo);
+
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> updateDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo,
+ List<ArtifactDefinition> updatedArtifacts, List<ArtifactTemplateInfo> updatedRequiredArtifacts, boolean shouldLock, boolean inTransaction) {
+
+ Either<ArtifactDefinition, ResponseFormat> resStatus = null;
+ String artifactFileName = artifactTemplateInfo.getFileName();
+ String artifactUid = "";
+
+ // check if artifacts already exist
+ for (ArtifactDefinition updatedArtifact : updatedArtifacts) {
+ if (updatedArtifact.getArtifactName().equals(artifactFileName)) {
+ artifactUid = updatedArtifact.getUniqueId();
+ if (!updatedArtifact.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) {
+ log.debug("Artifact with name {} and type {} already updated with type {}", artifactFileName, artifactTemplateInfo.getType(), updatedArtifact.getArtifactType());
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName, artifactTemplateInfo.getType(), updatedArtifact.getArtifactType()));
+ return resStatus;
+ }
+ resStatus = Either.left(updatedArtifact);
+ return resStatus;
+ }
+
+ }
+
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, artifactTemplateInfo.getFileName(), componentsUtils);
+ if (artifactContententStatus.isRight()) {
+ resStatus = Either.right(artifactContententStatus.right().value());
+ return resStatus;
+ }
+
+ Map<String, Object> json = buildJsonForUpdateArtifact(oldArtifact.getUniqueId(), artifactFileName, oldArtifact.getArtifactType(), oldArtifact.getArtifactLabel(), oldArtifact.getArtifactDisplayName(), oldArtifact.getDescription(),
+ artifactContententStatus.left().value().getRight(), updatedRequiredArtifacts);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, user, json, ArtifactOperation.Update, shouldLock, inTransaction);
+
+ if (uploadArtifactToService.isRight()) {
+ resStatus = Either.right(uploadArtifactToService.right().value());
+ return resStatus;
+ }
+ ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
+
+ Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(csarUUID, csar, artifactTemplateInfo, currentInfo);
+ if (updateEnvEither.isRight()) {
+ log.debug("failed to update parameters to artifact {}", artifactFileName);
+ resStatus = Either.right(updateEnvEither.right().value());
+ return resStatus;
+ }
+
+ artifactUid = updateEnvEither.left().value().getUniqueId();
+ updatedArtifacts.add(updateEnvEither.left().value());
+ resStatus = Either.left(updateEnvEither.left().value());
+
+ return resStatus;
+
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> updateHeatParamsFromCsar(String csarUUID, Map<String, byte[]> csar, ArtifactTemplateInfo artifactTemplateInfo, ArtifactDefinition currentInfo) {
+ Either<ArtifactDefinition, ResponseFormat> resStatus = Either.left(currentInfo);
+ if (artifactTemplateInfo.getEnv() != null && !artifactTemplateInfo.getEnv().isEmpty()) {
+
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactparamsStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, artifactTemplateInfo.getEnv(), componentsUtils);
+ if (artifactparamsStatus.isRight()) {
+ resStatus = Either.right(artifactparamsStatus.right().value());
+ return resStatus;
+ }
+ Either<List<HeatParameterDefinition>, ResponseFormat> propsStatus = extractHeatParameters(ArtifactTypeEnum.HEAT_ENV.getType(), artifactTemplateInfo.getEnv(), artifactparamsStatus.left().value().getValue());
+ if (propsStatus.isRight()) {
+
+ resStatus = Either.right(propsStatus.right().value());
+ return resStatus;
+ }
+ List<HeatParameterDefinition> updatedHeatEnvParams = propsStatus.left().value();
+ List<HeatParameterDefinition> currentHeatEnvParams = currentInfo.getHeatParameters();
+ List<HeatParameterDefinition> newHeatEnvParams = new ArrayList<HeatParameterDefinition>();
+
+ if (updatedHeatEnvParams != null && !updatedHeatEnvParams.isEmpty() && currentHeatEnvParams != null && !currentHeatEnvParams.isEmpty()) {
+
+ String paramName;
+ for (HeatParameterDefinition heatEnvParam : updatedHeatEnvParams) {
+
+ paramName = heatEnvParam.getName();
+ for (HeatParameterDefinition currHeatParam : currentHeatEnvParams) {
+ if (paramName.equalsIgnoreCase(currHeatParam.getName())) {
+
+ String updatedParamValue = heatEnvParam.getCurrentValue();
+ if (updatedParamValue == null)
+ updatedParamValue = heatEnvParam.getDefaultValue();
+ HeatParameterType paramType = HeatParameterType.isValidType(currHeatParam.getType());
+ if (!paramType.getValidator().isValid(updatedParamValue, null)) {
+ ActionStatus status = ActionStatus.INVALID_HEAT_PARAMETER_VALUE;
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, ArtifactTypeEnum.HEAT_ENV.getType(), paramType.getType(), paramName);
+ resStatus = Either.right(responseFormat);
+ return resStatus;
+ }
+ currHeatParam.setCurrentValue(paramType.getConverter().convert(updatedParamValue, null, null));
+ newHeatEnvParams.add(currHeatParam);
+ break;
+ }
+ }
+ }
+ if (!newHeatEnvParams.isEmpty()) {
+ StorageOperationStatus operationStatus = heatParametersOperation.updateHeatParameters(currentHeatEnvParams);
+
+ if (operationStatus != StorageOperationStatus.OK) {
+ log.debug("Failed to update artifact on graph - {}", currentInfo.getUniqueId());
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(operationStatus));
+ resStatus = Either.right(responseFormat);
+ return resStatus;
+ }
+ }
+ }
+
+ }
+ return resStatus;
+ }
+
+ private Either<List<HeatParameterDefinition>, ResponseFormat> extractHeatParameters(String artifactType, String fileName, byte[] content) {
+ // extract heat parameters
+ String heatDecodedPayload = GeneralUtility.isBase64Encoded(content) ? new String(Base64.decodeBase64(content)) : new String(content);
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParamsWithoutImplicitTypes(heatDecodedPayload, artifactType);
+ if (heatParameters.isRight()) {
+ log.debug("File {} is not in expected key-value form in csar ", fileName);
+ BeEcompErrorManager.getInstance().logInternalDataError("File " + fileName + " is not in expected key-value form in csar ", "CSAR internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, fileName));
+
+ }
+ return Either.left(heatParameters.left().value());
+
+ }
+
+ private Map<String, Object> buildJsonForArtifact(ArtifactTemplateInfo artifactTemplateInfo, byte[] artifactContentent, int atrifactLabelCounter) {
+
+ Map<String, Object> json = new HashMap<String, Object>();
+ String artifactName = artifactTemplateInfo.getFileName();
+
+ json.put(Constants.ARTIFACT_NAME, artifactTemplateInfo.getFileName());
+ json.put(Constants.ARTIFACT_TYPE, artifactTemplateInfo.getType());
+ json.put(Constants.ARTIFACT_DESCRIPTION, "created from csar");
+
+ /*
+ * DE250204
+ * There is no need to check if base64 encoding. All files that are inside the CSAR are not encoded and need to encoded. The check for isBase64 is not in cases we get files with extension .cert or .key these files are base64 but if do not
+ * encode them again, when the user download them, the decoded file will return not the encoded file that was upload.
+ */
+ // String encodedPayload = new String(artifactContentent);
+ // boolean isEncoded = GeneralUtility.isBase64Encoded(artifactContentent);
+ // if (!isEncoded) {
+ // log.debug("payload is encoded. perform decode");
+ String encodedPayload = Base64.encodeBase64String(artifactContentent);
+ // }
+ json.put(Constants.ARTIFACT_PAYLOAD_DATA, encodedPayload);
+ String displayName = artifactName;
+ if (artifactName.lastIndexOf(".") > 0)
+ displayName = artifactName.substring(0, artifactName.lastIndexOf("."));
+ json.put(Constants.ARTIFACT_DISPLAY_NAME, displayName);
+ String label = ValidationUtils.normalizeArtifactLabel(artifactTemplateInfo.getType() + atrifactLabelCounter);
+ json.put(Constants.ARTIFACT_LABEL, label);
+ json.put(Constants.ARTIFACT_GROUP_TYPE, ArtifactGroupTypeEnum.DEPLOYMENT.getType());
+ List<ArtifactTemplateInfo> requiredArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
+ json.put(Constants.REQUIRED_ARTIFACTS, (requiredArtifacts == null || requiredArtifacts.isEmpty()) ? new ArrayList<>()
+ : requiredArtifacts.stream().filter(e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e.getType().equals(ArtifactTypeEnum.HEAT_NESTED.getType())).map(e -> e.getFileName()).collect(Collectors.toList()));
+ return json;
+ }
+
+ private Map<String, Object> buildJsonForUpdateArtifact(String artifactId, String artifactName, String artifactType, String label, String displayName, String description, byte[] artifactContentent,
+ List<ArtifactTemplateInfo> updatedRequiredArtifacts) {
+
+ Map<String, Object> json = new HashMap<String, Object>();
+ if (artifactId != null && !artifactId.isEmpty())
+ json.put(Constants.ARTIFACT_ID, artifactId);
+
+ json.put(Constants.ARTIFACT_NAME, artifactName);
+ json.put(Constants.ARTIFACT_TYPE, artifactType);
+ json.put(Constants.ARTIFACT_DESCRIPTION, description);
+
+ String encodedPayload = new String(artifactContentent);
+ // DE250204 - need to encode all.
+ //boolean isEncoded = GeneralUtility.isBase64Encoded(artifactContentent);
+ //if (!isEncoded) {
+ log.debug("payload is encoded. perform decode");
+ encodedPayload = Base64.encodeBase64String(artifactContentent);
+ //}
+
+ json.put(Constants.ARTIFACT_PAYLOAD_DATA, encodedPayload);
+ json.put(Constants.ARTIFACT_DISPLAY_NAME, displayName);
+ json.put(Constants.ARTIFACT_LABEL, label);
+ json.put(Constants.ARTIFACT_GROUP_TYPE, ArtifactGroupTypeEnum.DEPLOYMENT.getType());
+ json.put(Constants.REQUIRED_ARTIFACTS, (updatedRequiredArtifacts == null || updatedRequiredArtifacts.isEmpty()) ? new ArrayList<>()
+ : updatedRequiredArtifacts.stream().filter(e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e.getType().equals(ArtifactTypeEnum.HEAT_NESTED.getType())).map(e -> e.getFileName()).collect(Collectors.toList()));
+ return json;
+ }
+
+ private Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceArtifactsInfoFromFile(Resource resource, String artifactsMetaFile, String artifactFileName, User user) {
+
+ try {
+ JsonObject jsonElement = new JsonObject();
+ jsonElement = gson.fromJson(artifactsMetaFile, jsonElement.getClass());
+
+ JsonElement importStructureElement = jsonElement.get(Constants.IMPORT_STRUCTURE);
+ if (importStructureElement == null || importStructureElement.isJsonNull()) {
+ log.debug("Artifact file is not in expected formatr, fileName {}", artifactFileName);
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
+ }
+
+ Map<String, List<Map<String, Object>>> artifactTemplateMap = new HashMap<String, List<Map<String, Object>>>();
+ artifactTemplateMap = componentsUtils.parseJsonToObject(importStructureElement.toString(), HashMap.class);
+ if (artifactTemplateMap.isEmpty()) {
+ log.debug("Artifact file is not in expected formatr, fileName {}", artifactFileName);
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
+ }
+
+ Set<String> artifactsTypeKeys = artifactTemplateMap.keySet();
+ Map<String, List<ArtifactTemplateInfo>> artifactsMap = new HashMap<String, List<ArtifactTemplateInfo>>();
+ List<ArtifactTemplateInfo> allGroups = new ArrayList<>();
+ for (String artifactsTypeKey : artifactsTypeKeys) {
+
+ List<Map<String, Object>> o = artifactTemplateMap.get(artifactsTypeKey);
+ Either<List<ArtifactTemplateInfo>, ResponseFormat> artifactTemplateInfoListPairStatus = createArtifactTemplateInfoModule(artifactsTypeKey, o);
+ if (artifactTemplateInfoListPairStatus.isRight()) {
+ log.debug("Artifact file is not in expected formatr, fileName {}", artifactFileName);
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected format, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(artifactTemplateInfoListPairStatus.right().value());
+ }
+ List<ArtifactTemplateInfo> artifactTemplateInfoList = artifactTemplateInfoListPairStatus.left().value();
+ if (artifactTemplateInfoList == null) {
+ log.debug("Artifact file is not in expected formatr, fileName {}", artifactFileName);
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected format, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
+
+ }
+ allGroups.addAll(artifactTemplateInfoList);
+ artifactsMap.put(artifactsTypeKey, artifactTemplateInfoList);
+ }
+ int counter = groupBusinessLogic.getNextVfModuleNameCounter(resource.getGroups());
+ Either<Boolean, ResponseFormat> validateGroupNamesRes = groupBusinessLogic.validateGenerateVfModuleGroupNames(allGroups, resource.getSystemName(), counter);
+ if (validateGroupNamesRes.isRight()) {
+ return Either.right(validateGroupNamesRes.right().value());
+ }
+ return Either.left(artifactsMap);
+ } catch (Exception e) {
+ log.debug("Artifact file is not in expected format, fileName {}", artifactFileName);
+ log.debug("failed with exception.", e);
+ BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected format, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
+ }
+
+ }
+
+ private Either<List<ArtifactTemplateInfo>, ResponseFormat> createArtifactTemplateInfoModule(String artifactsTypeKey, List<Map<String, Object>> jsonObject) {
+ List<ArtifactTemplateInfo> artifactTemplateInfoList = new ArrayList<ArtifactTemplateInfo>();
+ for (Map<String, Object> o : jsonObject) {
+ Either<ArtifactTemplateInfo, ResponseFormat> artifacttemplateInfoStatus = ArtifactTemplateInfo.createArtifactTemplateInfoFromJson(componentsUtils, artifactsTypeKey, o, artifactTemplateInfoList, null);
+ if (artifacttemplateInfoStatus.isRight()) {
+ return Either.right(artifacttemplateInfoStatus.right().value());
+ }
+
+ ArtifactTemplateInfo artifacttemplateInfo = artifacttemplateInfoStatus.left().value();
+ if (artifacttemplateInfo != null) {
+ artifactTemplateInfoList.add(artifacttemplateInfo);
+ }
+
+ }
+ return Either.left(artifactTemplateInfoList);
+ }
+
+ private Either<Resource, ResponseFormat> createResourceInstancesRelations(User user, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, boolean inTransaction, boolean needLock) {
+ log.debug("createResourceInstancesRelations try to create relations ");
+ List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
+ if (uploadResInstancesMap == null) {
+ log.debug("UploadComponentInstanceInfo is empty, fileName {}", yamlName);
+ BeEcompErrorManager.getInstance().logInternalDataError("UploadComponentInstanceInfo is emty, fileName {}", yamlName, ErrorSeverity.ERROR);
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return Either.right(responseFormat);
+ }
+
+ if (componentInstancesList == null || componentInstancesList.isEmpty()) {
+ log.debug("componentInstancesList is empty in resource {} ", resource.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("componentInstancesList is empty in resource {} ", resource.getUniqueId(), ErrorSeverity.ERROR);
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return Either.right(responseFormat);
+ }
+
+ Map<String, List<PropertyDefinition>> propertiesListPerResource = new HashMap<>();
+
+ long totalCreateRel = 0;
+ long totalCreatePropVal = 0;
+ Iterator<Entry<String, UploadComponentInstanceInfo>> nodesInfoValue = uploadResInstancesMap.entrySet().iterator();
+ while (nodesInfoValue.hasNext()) {
+ Entry<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoEntry = nodesInfoValue.next();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = uploadComponentInstanceInfoEntry.getValue();
+
+ ComponentInstance currentCompInstance = null;
+ for (ComponentInstance compInstance : componentInstancesList) {
+ if (compInstance.getName().equals(uploadComponentInstanceInfo.getName())) {
+ currentCompInstance = compInstance;
+ break;
+ }
+ }
+
+ if (currentCompInstance == null) {
+ log.debug("component instance with name {} in resource {} ", uploadComponentInstanceInfo.getName(), resource.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("component instance with name " + uploadComponentInstanceInfo.getName() + " in resource {} ", resource.getUniqueId(), ErrorSeverity.ERROR);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return Either.right(responseFormat);
+ }
+ String resourceInstanceId = currentCompInstance.getUniqueId();
+
+ log.debug("************* addPropertyValuesToRi start");
+ long startAddProperty = System.currentTimeMillis();
+
+ ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource, resourceInstanceId, currentCompInstance, yamlName, propertiesListPerResource);
+ log.debug("************* addPropertyValuesToRi end");
+ totalCreatePropVal += (System.currentTimeMillis() - startAddProperty);
+
+ if (addPropertiesValueToRiRes.getStatus() != 200) {
+ return Either.right(addPropertiesValueToRiRes);
+ }
+ Map<String, List<UploadReqInfo>> regMap = uploadComponentInstanceInfo.getRequirements();
+ if (regMap == null)
+ continue;
+ Iterator<Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet().iterator();
+
+ long startAddRelation = System.currentTimeMillis();
+
+ while (nodesRegValue.hasNext()) {
+ Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
+
+ List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
+ for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
+ log.debug("Going to create relation {}", uploadRegInfo.getName());
+ String regName = uploadRegInfo.getName();
+ String nodeCapName = uploadRegInfo.getNode();
+ RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
+ regCapRelDef.setFromNode(resourceInstanceId);
+ log.debug("try to find available requirement {} ", regName);
+ Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance);
+ if (eitherReqStatus.isRight()) {
+ log.debug("failed to find available requirement {} status is {}", regName, eitherReqStatus.right().value());
+ return Either.right(eitherReqStatus.right().value());
+ }
+
+ RequirementDefinition validReq = eitherReqStatus.left().value();
+ List<RequirementAndRelationshipPair> reqAndRelationshipPairList = regCapRelDef.getRelationships();
+ if (reqAndRelationshipPairList == null)
+ reqAndRelationshipPairList = new ArrayList<RequirementAndRelationshipPair>();
+ RequirementAndRelationshipPair reqAndRelationshipPair = new RequirementAndRelationshipPair();
+ reqAndRelationshipPair.setRequirement(regName);
+ reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
+ reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
+
+ ComponentInstance currentCapCompInstance = null;
+ for (ComponentInstance compInstance : componentInstancesList) {
+ if (compInstance.getName().equals(uploadRegInfo.getNode())) {
+ currentCapCompInstance = compInstance;
+ break;
+ }
+ }
+
+ if (currentCapCompInstance == null) {
+ log.debug("component instance with name {} in resource {} ", uploadRegInfo.getNode(), resource.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("component instance with name " + uploadRegInfo.getNode() + " in resource {} ", resource.getUniqueId(), ErrorSeverity.ERROR);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return Either.right(responseFormat);
+ }
+ regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
+ log.debug("try to find aviable Capability req name is {} ", validReq.getName());
+ CapabilityDefinition aviableCapForRel = findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadRegInfo);
+ if (aviableCapForRel == null) {
+ log.debug("aviable capability was not found. req name is {} component instance is {}", validReq.getName(), currentCapCompInstance.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("aviable capability was not found. req name is " + validReq.getName() + " component instance is " + currentCapCompInstance.getUniqueId(), resource.getUniqueId(),
+ ErrorSeverity.ERROR);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return Either.right(responseFormat);
+ }
+ reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
+ reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
+ reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
+ reqAndRelationshipPairList.add(reqAndRelationshipPair);
+ regCapRelDef.setRelationships(reqAndRelationshipPairList);
+ ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL();
+ Either<RequirementCapabilityRelDef, ResponseFormat> eitherRelationRes = componentInstanceBL.associateRIToRIOnGraph(resource.getUniqueId(), regCapRelDef, ComponentTypeEnum.RESOURCE, inTransaction);
+ log.debug("************* finished to create relation {}", uploadRegInfo.getName());
+ if (eitherRelationRes.isRight()) {
+ log.debug("failed to associate ri {} to ri {}", regCapRelDef.getFromNode(), regCapRelDef.getToNode());
+ return Either.right(eitherRelationRes.right().value());
+ }
+
+ }
+
+ }
+ totalCreateRel += (System.currentTimeMillis() - startAddRelation);
+ }
+ /*
+ * List<InputDefinition> inputs = resource.getInputs(); for(InputDefinition input: inputs){ if(input.getProperties() != null){ this.inputOperation.associatePropertiesToInputOnGraph(input. getUniqueId(), input.getProperties()); } }
+ */
+
+ // Either<Resource, StorageOperationStatus> eitherGerResource =
+ // resourceOperation.getResource(resource.getUniqueId(), inTransaction);
+ log.debug("************* create relations took : create {}, add property value {}", totalCreateRel, totalCreatePropVal);
+ log.debug("************* in create relations, getResource start");
+ ComponentParametersView parametersView = new ComponentParametersView();
+ parametersView.disableAll();
+ parametersView.setIgnoreComponentInstances(false);
+ parametersView.setIgnoreUsers(false);
+ parametersView.setIgnoreArtifacts(false);
+ parametersView.setIgnoreGroups(false);
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getComponent(resource.getUniqueId(), parametersView, inTransaction);
+ log.debug("************* in create relations, getResource end");
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(eitherGerResource.left().value());
+ }
+
+ private ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Resource resource, String resourceInstanceId, ComponentInstance currentCompInstance, String yamlName,
+ Map<String, List<PropertyDefinition>> propertiesListPerResource) {
+
+ Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
+ if (propMap != null && propMap.size() > 0) {
+ Map<String, PropertyDefinition> currPropertiesMap = new HashMap<String, PropertyDefinition>();
+ List<PropertyDefinition> propertiesList = new ArrayList<PropertyDefinition>();
+ Integer index = currentCompInstance.getPropertyValueCounter();
+ Integer indexInput = currentCompInstance.getInputValueCounter();
+ List<PropertyDefinition> listFromMap = propertiesListPerResource.get(currentCompInstance.getComponentUid());
+ if (listFromMap != null) {
+ propertiesList = listFromMap;
+ } else {
+ TitanOperationStatus getPropertyRes = ((PropertyOperation) propertyOperation).findAllResourcePropertiesRecursively(currentCompInstance.getComponentUid(), propertiesList);
+ if (!getPropertyRes.equals(TitanOperationStatus.OK)) {
+ log.debug("failed to find properties of resource {} status is {}", currentCompInstance.getComponentUid(), getPropertyRes);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(getPropertyRes)), yamlName);
+ return responseFormat;
+ }
+ propertiesListPerResource.put(currentCompInstance.getComponentUid(), propertiesList);
+ }
+ if (propertiesList.size() > 0) {
+ for (PropertyDefinition prop : propertiesList) {
+ String propName = prop.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ currPropertiesMap.put(propName, prop);
+ }
+ }
+ for (List<UploadPropInfo> propertyList : propMap.values()) {
+ UploadPropInfo propertyInfo = propertyList.get(0);
+ String propName = propertyInfo.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ log.debug("failed to find property {} ", propName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName);
+ return responseFormat;
+ }
+ PropertyDefinition curPropertyDef = currPropertiesMap.get(propName);
+ ComponentInstanceProperty property = null;
+ ComponentInstanceInput inputValue = null;
+ // TODO
+ String value = null;
+ List<GetInputValueInfo> getInputs = null;
+ boolean isValidate = true;
+ if (propertyInfo.getValue() != null) {
+ getInputs = propertyInfo.getGet_input();
+ isValidate = getInputs == null || getInputs.isEmpty();
+ if (isValidate) {
+ value = ImportUtils.getPropertyJsonStringValue(propertyInfo.getValue(), curPropertyDef.getType());
+ } else
+ value = ImportUtils.getPropertyJsonStringValue(propertyInfo.getValue(), ToscaTagNamesEnum.GET_INPUT.getElementName());
+ }
+
+ property = new ComponentInstanceProperty(curPropertyDef, value, null);
+
+ Either<ComponentInstanceProperty, StorageOperationStatus> result = componentInstanceOperation.addPropertyValueToResourceInstance(property, resourceInstanceId, isValidate, index, true);
+ if (result.isRight()) {
+ log.debug("Failed to add property value {} to resource instance {}", property, resourceInstanceId);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
+ return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, currentCompInstance.getName());
+ }
+ Either<Integer, StorageOperationStatus> increaseCounterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, GraphPropertiesDictionary.PROPERTY_COUNTER, true);
+ if (increaseCounterRes.isRight()) {
+ log.debug("Failed to increase resource property counter {} to resource instance {}", property, resourceInstanceId);
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(increaseCounterRes.right().value());
+ return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, currentCompInstance.getName());
+ }
+ index = increaseCounterRes.left().value();
+ if (getInputs != null && !getInputs.isEmpty()) {
+ for (GetInputValueInfo getInput : getInputs) {
+ List<InputDefinition> inputs = resource.getInputs();
+ if (inputs == null || inputs.isEmpty()) {
+ log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ", property, resourceInstanceId);
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+
+ Optional<InputDefinition> optional = inputs.stream().filter(p -> p.getName().equals(getInput.getInputName())).findAny();
+ if (!optional.isPresent()) {
+ log.debug("Failed to find input {} ", getInput.getInputName());
+ // @@TODO error message
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition input = optional.get();
+ TitanOperationStatus status = inputOperation.associatePropertyToInput(resourceInstanceId, input.getUniqueId(), result.left().value(), getInput);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to associate input {} tp property value{} ", getInput.getInputName(), result.left().value().getValueUniqueUid());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName);
+ return responseFormat;
+ }
+ GetInputValueInfo getInputIndex = getInput.getGetInputIndex();
+ if (getInputIndex != null) {
+ optional = inputs.stream().filter(p -> p.getName().equals(getInputIndex.getInputName())).findAny();
+ if (!optional.isPresent()) {
+ log.debug("Failed to find input {} ", getInputIndex.getInputName());
+ // @@TODO error message
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition inputIndex = optional.get();
+ status = inputOperation.associatePropertyToInput(resourceInstanceId, inputIndex.getUniqueId(), result.left().value(), getInputIndex);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to associate input {} tp property value{} ", getInput.getInputName(), result.left().value().getValueUniqueUid());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName);
+ return responseFormat;
+ }
+
+ }
+
+ }
+ }
+
+ }
+ }
+ }
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
+
+ // US740820 Relate RIs according to capability name
+ private CapabilityDefinition findAvailableCapabilityByTypeOrName(RequirementDefinition validReq, ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
+ if (null == uploadReqInfo.getCapabilityName() || validReq.getCapability().equals(uploadReqInfo.getCapabilityName())) {// get
+ // by
+ // capability
+ // type
+ return findAviableCapability(validReq, currentCapCompInstance);
+ }
+ return findAvailableCapability(validReq, currentCapCompInstance, uploadReqInfo);
+ }
+
+ private CapabilityDefinition findAvailableCapability(RequirementDefinition validReq, ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
+ Map<String, List<CapabilityDefinition>> capMap = currentCapCompInstance.getCapabilities();
+ if (!capMap.containsKey(validReq.getCapability())) {
+ return null;
+ }
+ Optional<CapabilityDefinition> capByName = capMap.get(validReq.getCapability()).stream().filter(p -> p.getName().equals(uploadReqInfo.getCapabilityName())).findAny();
+ if (!capByName.isPresent()) {
+ return null;
+ }
+ CapabilityDefinition cap = capByName.get();
+ // TODO temporary fix - remove specific capability node validation -
+ // String reqNode = validReq.getNode();
+ // if (reqNode != null && !reqNode.isEmpty() &&
+ // !cap.getCapabilitySources().contains(reqNode)) {
+ // return null;
+ // }
+ RequirementAndRelationshipPair relationPair = getReqRelPair(cap);
+ Either<Boolean, StorageOperationStatus> eitherStatus = componentInstanceOperation.isAvailableCapabilty(currentCapCompInstance, relationPair);
+ if (eitherStatus.isRight() || eitherStatus.left().value() == false) {
+ return null;
+ }
+ return cap;
+ }
+
+ private RequirementAndRelationshipPair getReqRelPair(CapabilityDefinition cap) {
+ RequirementAndRelationshipPair relationPair = new RequirementAndRelationshipPair();
+ relationPair.setCapabilityUid(cap.getUniqueId());
+ relationPair.setCapability(cap.getName());
+ relationPair.setCapabilityOwnerId(cap.getOwnerId());
+ return relationPair;
+ }
+
+ private CapabilityDefinition findAviableCapability(RequirementDefinition validReq, ComponentInstance currentCapCompInstance) {
+ CapabilityDefinition aviableCapForRel = null;
+ Map<String, List<CapabilityDefinition>> capMap = currentCapCompInstance.getCapabilities();
+ if (capMap.containsKey(validReq.getCapability())) {
+ List<CapabilityDefinition> capList = capMap.get(validReq.getCapability());
+
+ for (CapabilityDefinition cap : capList) {
+ // TODO temporary fix - remove specific capability node
+ // String reqNode = validReq.getNode();
+ // if (reqNode != null && !reqNode.isEmpty()) {
+ // if (!cap.getCapabilitySources().contains(reqNode)) {
+ // continue;
+ // }
+ // }
+
+ RequirementAndRelationshipPair relationPair = getReqRelPair(cap);
+ Either<Boolean, StorageOperationStatus> eitherStatus = componentInstanceOperation.isAvailableCapabilty(currentCapCompInstance, relationPair);
+ if (eitherStatus.isRight() || eitherStatus.left().value() == false)
+ continue;
+ else {
+ aviableCapForRel = cap;
+ break;
+ }
+ }
+ }
+ return aviableCapForRel;
+ }
+
+ private Either<RequirementDefinition, ResponseFormat> findAviableRequiremen(String regName, String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance) {
+ Map<String, List<RequirementDefinition>> comInstRegDefMap = currentCompInstance.getRequirements();
+
+ Iterator<Entry<String, List<RequirementDefinition>>> regListValue = comInstRegDefMap.entrySet().iterator();
+ RequirementDefinition validRegDef = null;
+ while (regListValue.hasNext()) {
+ Entry<String, List<RequirementDefinition>> regInfoEntry = regListValue.next();
+
+ List<RequirementDefinition> comInstRegDefList = regInfoEntry.getValue();
+
+ for (RequirementDefinition comInstRegDef : comInstRegDefList) {
+ if (!regName.equals(comInstRegDef.getName()))
+ continue;
+ RequirementAndRelationshipPair relationPair = new RequirementAndRelationshipPair();
+ relationPair.setRequirementUid(comInstRegDef.getUniqueId());
+ relationPair.setCapability(comInstRegDef.getCapability());
+ relationPair.setRequirementOwnerId(comInstRegDef.getOwnerId());
+ Either<Boolean, StorageOperationStatus> eitherStatus = componentInstanceOperation.isAvailableRequirement(currentCompInstance, relationPair);
+ if (eitherStatus.isLeft() && eitherStatus.left().value() == true) {
+ validRegDef = comInstRegDef;
+ break;
+ }
+ }
+ if (validRegDef != null)
+ break;
+ }
+
+ if (validRegDef == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(responseFormat);
+ }
+ return Either.left(validRegDef);
+ }
+
+ public Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, User user) {
+
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml);
+ Either<Object, ResultStatusEnum> toscaElementEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL);
+ if (toscaElementEither.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
+ return Either.right(responseFormat);
+ }
+
+ Either<Map<String, InputDefinition>, ResponseFormat> createInputsEither = createInputsFromYaml(yamlFileName, mappedToscaTemplate, resource);
+ if (createInputsEither.isRight()) {
+ ResponseFormat responseFormat = createInputsEither.right().value();
+ return Either.right(responseFormat);
+ }
+
+ Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> uploadResInstancesEither = createResourcesInstanceInfoFromYaml(yamlFileName, mappedToscaTemplate, resource);
+ if (uploadResInstancesEither.isRight()) {
+ ResponseFormat responseFormat = uploadResInstancesEither.right().value();
+ return Either.right(responseFormat);
+ }
+
+ Either<Map<String, GroupDefinition>, ResponseFormat> createGroupsFromYaml = createGroupsFromYaml(yamlFileName, mappedToscaTemplate, resource);
+ if (createGroupsFromYaml.isRight()) {
+ ResponseFormat responseFormat = createGroupsFromYaml.right().value();
+ return Either.right(responseFormat);
+ }
+
+ ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
+ parsedToscaYamlInfo.setInputs(createInputsEither.left().value());
+ parsedToscaYamlInfo.setInstances(uploadResInstancesEither.left().value());
+ parsedToscaYamlInfo.setGroups(createGroupsFromYaml.left().value());
+
+ return Either.left(parsedToscaYamlInfo);
+ }
+
+ private Either<Resource, ResponseFormat> createResourceInstances(User user, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, boolean inTransaction, boolean needLock,
+ Map<String, Resource> nodeTypeNamespaceMap) {
+ log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
+ if (uploadResInstancesMap == null || uploadResInstancesMap.isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
+
+ return Either.right(responseFormat);
+
+ }
+ Map<String, Resource> existingnodeTypeMap = new HashMap<String, Resource>();
+ if (nodeTypeNamespaceMap != null && !nodeTypeNamespaceMap.isEmpty()) {
+ nodeTypeNamespaceMap.entrySet().stream().forEach(x -> existingnodeTypeMap.put(x.getValue().getToscaResourceName(), x.getValue()));
+ }
+
+ Iterator<Entry<String, UploadComponentInstanceInfo>> nodesInfoValue = uploadResInstancesMap.entrySet().iterator();
+ while (nodesInfoValue.hasNext()) {
+ log.debug("*************Going to create resource instances {}", yamlName);
+ Entry<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoEntry = nodesInfoValue.next();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = uploadComponentInstanceInfoEntry.getValue();
+
+ // updating type if the type is node type name - we need to take the
+ // updated name
+ log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
+ if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ uploadComponentInstanceInfo.setType(nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
+ }
+
+ Either<Resource, ResponseFormat> eitherResource = validateResourceInstanceBeforeCreate(yamlName, inTransaction, uploadComponentInstanceInfo, existingnodeTypeMap);
+ if (eitherResource.isRight()) {
+ return eitherResource;
+ }
+ Resource refResource = eitherResource.left().value();
+
+ ComponentInstance componentInstance = new ComponentInstance();
+
+ componentInstance.setName(uploadComponentInstanceInfo.getName());
+ componentInstance.setComponentUid(refResource.getUniqueId());
+
+ ComponentTypeEnum containerComponentType = resource.getComponentType();
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+
+ if (containerNodeType.equals(NodeTypeEnum.Resource) && uploadComponentInstanceInfo.getCapabilities() != null) {
+ Either<Map<String, List<CapabilityDefinition>>, ResponseFormat> getValidComponentInstanceCapabilitiesRes = getValidComponentInstanceCapabilities(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
+ if (getValidComponentInstanceCapabilitiesRes.isRight()) {
+ return Either.right(getValidComponentInstanceCapabilitiesRes.right().value());
+ } else {
+ componentInstance.setCapabilities(getValidComponentInstanceCapabilitiesRes.left().value());
+ }
+ }
+ if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ log.debug("createResourceInstances - not found lates version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(responseFormat);
+ }
+ Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
+ ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL();
+ Either<ComponentInstance, ResponseFormat> eitherCreateCI = componentInstanceBL.createComponentInstanceOnGraph(ComponentTypeEnum.RESOURCE_PARAM_NAME, resource, origResource, componentInstance, user.getUserId(), needLock, inTransaction);
+ if (eitherCreateCI.isRight()) {
+ log.debug("createResourceInstances - failed to create resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(eitherCreateCI.right().value());
+ }
+
+ ComponentInstance createdCI = eitherCreateCI.left().value();
+ createdCI.setName(uploadComponentInstanceInfo.getName());
+ /*
+ * updateComponentInstance(String containerComponentParam, org.openecomp.sdc.be.model.Component containerComponent, String componentInstanceId, ComponentInstance componentInstance, boolean inTransaction, boolean needLock)
+ */
+ eitherCreateCI = componentInstanceBL.updateComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME, resource, origResource, createdCI.getUniqueId(), createdCI, needLock, inTransaction);
+ if (eitherCreateCI.isRight()) {
+ log.debug("createResourceInstances - failed to update resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(eitherCreateCI.right().value());
+ }
+ log.debug("*************finished to create and update resource instances {}", uploadComponentInstanceInfo.getName());
+
+ }
+ log.debug("*************Going to get resource {}", resource.getUniqueId());
+ ComponentParametersView parametersView = new ComponentParametersView();
+ parametersView.disableAll();
+ parametersView.setIgnoreComponentInstances(false);
+ parametersView.setIgnoreUsers(false);
+ parametersView.setIgnoreInputs(false); // inputs are read when creating
+ // property values on instances
+ Either<Resource, StorageOperationStatus> eitherGerResource = resourceOperation.getComponent(resource.getUniqueId(), parametersView, inTransaction);
+ log.debug("*************finished to get resource {}", resource.getUniqueId());
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+
+ if (eitherGerResource.left().value().getComponentInstances() == null || eitherGerResource.left().value().getComponentInstances().isEmpty()) {
+
+ log.debug("Error when create resource inctanse from csar. ComponentInstances list empty");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Error when create resource inctanse from csar. ComponentInstances list empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
+ return Either.right(responseFormat);
+
+ }
+
+ return Either.left(eitherGerResource.left().value());
+ }
+
+ private Either<Resource, ResponseFormat> validateResourceInstanceBeforeCreate(String yamlName, boolean inTransaction, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map<String, Resource> nodeTypeNamespaceMap) {
+ log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ Resource refResource = null;
+ if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ refResource = nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType());
+ } else {
+
+ Either<Boolean, StorageOperationStatus> eithervalidateResource = resourceOperation.validateToscaResourceNameExists(uploadComponentInstanceInfo.getType());
+ if ((eithervalidateResource.isRight() && eithervalidateResource.right().value() == StorageOperationStatus.NOT_FOUND) || eithervalidateResource.left().value() == true) {
+ log.debug("validateResourceInstanceBeforeCreate - resource instance with name {} and type not valid", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(responseFormat);
+ }
+ Either<Resource, StorageOperationStatus> findResourceEither = resourceOperation.getLatestCertifiedByToscaResourceName(uploadComponentInstanceInfo.getType(), inTransaction);
+ if (findResourceEither.isRight()) {
+ log.debug("validateResourceInstanceBeforeCreate - not found lates version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
+ return Either.right(responseFormat);
+ }
+ refResource = findResourceEither.left().value();
+ nodeTypeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
+ }
+ String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
+ if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ log.debug("validateResourceInstanceBeforeCreate - component instance of component {} can not be created because the component is in an illegal state {}.", refResource.getName(), componentState);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, refResource.getComponentType().getValue(), refResource.getName(), componentState);
+ return Either.right(responseFormat);
+ }
+ ResourceTypeEnum resourceTypeEnum = refResource.getResourceType();
+ if (resourceTypeEnum == ResourceTypeEnum.VF) {
+ log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", resourceTypeEnum);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(responseFormat);
+ }
+ return Either.left(refResource);
+ }
+
+ private Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> createResourcesInstanceInfoFromYaml(String yamlFileName, Map<String, Object> toscaJson, Resource resource) {
+ Map<String, UploadComponentInstanceInfo> moduleComponentInstances = new HashMap<String, UploadComponentInstanceInfo>();
+ Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> result = Either.left(moduleComponentInstances);
+ Either<Map<String, Object>, ResultStatusEnum> eitherNodesTemlates = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TEMPLATES);
+ if (eitherNodesTemlates.isLeft()) {
+ Map<String, Object> jsonNodeTemplates = eitherNodesTemlates.left().value();
+
+ Iterator<Entry<String, Object>> nodesNameValue = jsonNodeTemplates.entrySet().iterator();
+ while (nodesNameValue.hasNext()) {
+ Entry<String, Object> nodeNameValue = nodesNameValue.next();
+ Either<UploadComponentInstanceInfo, ResponseFormat> eitherNode = createModuleComponentInstanceInfo(nodeNameValue.getValue());
+ if (eitherNode.isRight()) {
+ log.info("error when creating node template:{}, for resource:{}", nodeNameValue.getKey(), resource.getName());
+ return Either.right(eitherNode.right().value());
+ } else {
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = eitherNode.left().value();
+ uploadComponentInstanceInfo.setName(nodeNameValue.getKey());
+ moduleComponentInstances.put(nodeNameValue.getKey(), uploadComponentInstanceInfo);
+ }
+
+ }
+
+ }
+ if (moduleComponentInstances.isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName);
+ return Either.right(responseFormat);
+ }
+
+ return result;
+ }
+
+ private Either<UploadComponentInstanceInfo, ResponseFormat> createModuleComponentInstanceInfo(Object nodeTemplateJson) {
+
+ UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
+ Either<UploadComponentInstanceInfo, ResponseFormat> result = Either.left(nodeTemplateInfo);
+
+ try {
+ if (nodeTemplateJson instanceof String) {
+ String nodeTemplateJsonString = (String) nodeTemplateJson;
+ nodeTemplateInfo.setType(nodeTemplateJsonString);
+ } else if (nodeTemplateJson instanceof Map) {
+ Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) nodeTemplateJson;
+ // Type
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ nodeTemplateInfo.setType((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()));
+ }
+
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.REQUIREMENTS.getElementName())) {
+ Either<Map<String, List<UploadReqInfo>>, ResponseFormat> regResponse = createReqModuleFromYaml(nodeTemplateInfo, nodeTemplateJsonMap);
+ if (regResponse.isRight())
+ return Either.right(regResponse.right().value());
+ if (regResponse.left().value().size() > 0) {
+ nodeTemplateInfo.setRequirements(regResponse.left().value());
+ }
+ }
+
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.CAPABILITIES.getElementName())) {
+ Either<Map<String, List<UploadCapInfo>>, ResponseFormat> eitherCapRes = createCapModuleFromYaml(nodeTemplateInfo, nodeTemplateJsonMap);
+ if (eitherCapRes.isRight())
+ return Either.right(eitherCapRes.right().value());
+ if (eitherCapRes.left().value().size() > 0) {
+ nodeTemplateInfo.setCapabilities(eitherCapRes.left().value());
+ }
+ }
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
+ Either<Map<String, List<UploadPropInfo>>, ResponseFormat> regResponse = createPropModuleFromYaml(nodeTemplateJsonMap);
+ if (regResponse.isRight())
+ return Either.right(regResponse.right().value());
+ if (regResponse.left().value().size() > 0) {
+ nodeTemplateInfo.setProperties(regResponse.left().value());
+ }
+ }
+ } else {
+
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create capability");
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
+ log.debug("error when creating capability, message:{}", e.getMessage(), e);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ }
+
+ return result;
+ }
+
+ private Either<Map<String, List<UploadPropInfo>>, ResponseFormat> createPropModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, List<UploadPropInfo>> moduleProp = new HashMap<String, List<UploadPropInfo>>();
+ Either<Map<String, List<UploadPropInfo>>, ResponseFormat> response = Either.left(moduleProp);
+ Either<Map<String, Object>, ResultStatusEnum> toscaProperties = ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, ToscaTagNamesEnum.PROPERTIES);
+ if (toscaProperties.isLeft()) {
+ Map<String, Object> jsonProperties = toscaProperties.left().value();
+ for (Entry<String, Object> jsonPropObj : jsonProperties.entrySet()) {
+ // Property
+ String propName = jsonPropObj.getKey();
+ Object propValue = jsonPropObj.getValue();
+
+ if (valueContainsPattern(STR_REPLACE_PATTERN, propValue)) {
+ log.debug("Ignore property value {}.", propName);
+ continue;
+ }
+
+ if (valueContainsPattern(TOKEN_PATTERN, propValue)) {
+ log.debug("Ignore property value {}.", propName);
+ continue;
+ }
+ if (valueContainsPattern(GET_PROPERTY_PATTERN, propValue)) {
+ log.debug("Ignore property value {}.", propName);
+ continue;
+ }
+
+ if (valueContainsPattern(CONCAT_PATTERN, propValue)) {
+ log.debug("Ignore property value {}.", propName);
+ continue;
+ }
+
+ UploadPropInfo propertyDef = new UploadPropInfo();
+ propertyDef.setValue(propValue);
+ if (propValue instanceof Map) {
+ if (((Map<String, Object>) propValue).containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ propertyDef.setType(((Map<String, Object>) propValue).get(ToscaTagNamesEnum.TYPE.getElementName()).toString());
+ }
+
+ if (((Map<String, Object>) propValue).containsKey(ToscaTagNamesEnum.GET_INPUT.getElementName())
+ || ImportUtils.getPropertyJsonStringValue(propValue, ToscaPropertyType.MAP.getType()).contains(ToscaTagNamesEnum.GET_INPUT.getElementName())) {
+ createGetInputModuleFromMap(propName, (Map<String, Object>) propValue, propertyDef);
+ }
+
+ if (((Map<String, Object>) propValue).containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
+ propertyDef.setDescription(((Map<String, Object>) propValue).get(ToscaTagNamesEnum.DESCRIPTION.getElementName()).toString());
+ }
+ if (((Map<String, Object>) propValue).containsKey(ToscaTagNamesEnum.DEFAULT_VALUE.getElementName())) {
+ propertyDef.setValue(((Map<String, Object>) propValue).get(ToscaTagNamesEnum.DEFAULT_VALUE.getElementName()));
+ }
+ if (((Map<String, Object>) propValue).containsKey(ToscaTagNamesEnum.IS_PASSWORD.getElementName())) {
+ propertyDef.setPassword(Boolean.getBoolean(((Map<String, Object>) propValue).get(ToscaTagNamesEnum.IS_PASSWORD.getElementName()).toString()));
+ } else {
+ propertyDef.setValue(propValue);
+ }
+ } else if (propValue instanceof List) {
+ List<Object> propValueList = (List<Object>) propValue;
+
+ createInputPropList(propertyDef, propValueList);
+ propertyDef.setValue(propValue);
+ }
+
+ propertyDef.setName(propName);
+ if (moduleProp.containsKey(propName)) {
+ moduleProp.get(propName).add(propertyDef);
+ } else {
+ List<UploadPropInfo> list = new ArrayList<UploadPropInfo>();
+ list.add(propertyDef);
+ moduleProp.put(propName, list);
+ }
+ }
+ }
+ return response;
+ }
+
+ private void createInputPropList(UploadPropInfo propertyDef, List<Object> propValueList) {
+ for (Object objValue : propValueList) {
+
+ if (objValue instanceof Map) {
+ Map<String, Object> objMap = (Map<String, Object>) objValue;
+ Set<String> keys = objMap.keySet();
+ for (String key : keys) {
+ Object value = objMap.get(key);
+ if (value instanceof Map) {
+ createGetInputModuleFromMap(key, (Map<String, Object>) value, propertyDef);
+
+ } else if (value instanceof List) {
+ List<Object> propSubValueList = (List<Object>) value;
+
+ createInputPropList(propertyDef, propSubValueList);
+ }
+
+ }
+
+ } else if (objValue instanceof List) {
+ List<Object> propSubValueList = (List<Object>) objValue;
+
+ createInputPropList(propertyDef, propSubValueList);
+
+ }
+
+ }
+ }
+
+ private void createGetInputModuleFromMap(String propName, Map<String, Object> propValue, UploadPropInfo propertyDef) {
+
+ if (propValue.containsKey(ToscaTagNamesEnum.GET_INPUT.getElementName())) {
+ Object getInput = propValue.get(ToscaTagNamesEnum.GET_INPUT.getElementName());
+ GetInputValueInfo getInputInfo = new GetInputValueInfo();
+ List<GetInputValueInfo> getInputs = propertyDef.getGet_input();
+ if (getInputs == null) {
+ getInputs = new ArrayList<GetInputValueInfo>();
+ }
+ if (getInput instanceof String) {
+
+ getInputInfo.setInputName((String) getInput);
+ getInputInfo.setPropName(propName);
+
+ } else if (getInput instanceof List) {
+ List<Object> getInputList = (List<Object>) getInput;
+ getInputInfo.setPropName(propName);
+ getInputInfo.setInputName((String) getInputList.get(0));
+ if (getInputList.size() >= 1) {
+ Object indexObj = getInputList.get(1);
+ if (indexObj instanceof Integer) {
+ getInputInfo.setIndexValue((Integer) indexObj);
+ } else if (indexObj instanceof Float) {
+ int index = ((Float) indexObj).intValue();
+ getInputInfo.setIndexValue(index);
+ } else if (indexObj instanceof Map && ((Map<String, Object>) indexObj).containsKey(ToscaTagNamesEnum.GET_INPUT.getElementName())) {
+ Object index = ((Map<String, Object>) indexObj).get(ToscaTagNamesEnum.GET_INPUT.getElementName());
+ GetInputValueInfo getInputInfoIndex = new GetInputValueInfo();
+ getInputInfoIndex.setInputName((String) index);
+ getInputInfoIndex.setPropName(propName);
+ getInputInfo.setGetInputIndex(getInputInfoIndex);
+ }
+ getInputInfo.setList(true);
+ }
+
+ }
+ getInputs.add(getInputInfo);
+ propertyDef.setGet_input(getInputs);
+ propertyDef.setValue(propValue);
+ } else {
+ Set<String> keys = propValue.keySet();
+ for (String key : keys) {
+ Object value = propValue.get(key);
+ if (value instanceof Map) {
+ createGetInputModuleFromMap(key, (Map<String, Object>) value, propertyDef);
+
+ } else if (value instanceof List) {
+ List<Object> valueList = (List<Object>) value;
+ for (Object o : valueList) {
+ if (o instanceof Map) {
+ createGetInputModuleFromMap(key, (Map<String, Object>) o, propertyDef);
+
+ }
+ }
+
+ }
+
+ }
+
+ }
+ }
+
+ /*
+ * private boolean valueContainsStrReplace(Object propValue) {
+ *
+ * log.debug("valueContainsStrReplace value is {}", propValue); boolean result = false; if (propValue != null) { log.debug("valueContainsStrReplace value is {}", propValue.getClass()); Matcher matcher =
+ * STR_REPLACE_PATTERN.matcher(propValue.toString()); result = matcher.find(); }
+ *
+ * return result; }
+ *
+ * private boolean valueContainsToken(Object propValue) {
+ *
+ * log.debug("valueContainsToken value is {}", propValue); boolean result = false; if (propValue != null) { log.debug("valueContainsToken value is {}", propValue.getClass()); Matcher matcher = TOKEN_PATTERN.matcher(propValue.toString()); result =
+ * matcher.find(); }
+ *
+ * return result; }
+ */
+
+ private boolean valueContainsPattern(Pattern pattern, Object propValue) {
+
+ log.debug("valueContainsToken value is {}", propValue);
+ boolean result = false;
+ if (propValue != null) {
+ log.debug("valueContainspattern value is {}", propValue.getClass());
+ Matcher matcher = pattern.matcher(propValue.toString());
+ result = matcher.find();
+ }
+
+ return result;
+
+ }
+
+ private Either<Map<String, List<UploadCapInfo>>, ResponseFormat> createCapModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, List<UploadCapInfo>> moduleCap = new HashMap<String, List<UploadCapInfo>>();
+ Either<Map<String, List<UploadCapInfo>>, ResponseFormat> response = Either.left(moduleCap);
+ Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.CAPABILITIES);
+ if (toscaRequirements.isLeft()) {
+ List<Object> jsonCapabilities = toscaRequirements.left().value();
+
+ for (Object jsonCapObj : jsonCapabilities) {
+ // Requirement
+ Map<String, Object> capJsonWrapper = (Map<String, Object>) jsonCapObj;
+ String capName = capJsonWrapper.keySet().iterator().next();
+ Either<UploadCapInfo, ResponseFormat> eitherCap = createModuleNodeTemplateCap(capJsonWrapper.get(capName));
+ if (eitherCap.isRight()) {
+ log.info("error when creating Requirement:{}, for node:{}", capName, nodeTemplateInfo);
+ return Either.right(eitherCap.right().value());
+ } else {
+ UploadCapInfo requirementDef = eitherCap.left().value();
+ requirementDef.setName(capName);
+ if (moduleCap.containsKey(capName)) {
+ moduleCap.get(capName).add(requirementDef);
+ } else {
+ List<UploadCapInfo> list = new ArrayList<UploadCapInfo>();
+ list.add(requirementDef);
+ moduleCap.put(capName, list);
+ }
+
+ }
+ }
+
+ }
+
+ return response;
+ }
+
+ private Either<Map<String, List<UploadReqInfo>>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<String, List<UploadReqInfo>>();
+ Either<Map<String, List<UploadReqInfo>>, ResponseFormat> response = Either.left(moduleRequirements);
+ Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.REQUIREMENTS);
+ if (toscaRequirements.isLeft()) {
+ List<Object> jsonRequirements = toscaRequirements.left().value();
+
+ for (Object jsonRequirementObj : jsonRequirements) {
+ // Requirement
+ Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
+ String requirementName = requirementJsonWrapper.keySet().iterator().next();
+ Either<UploadReqInfo, ResponseFormat> eitherRequirement = createModuleNodeTemplateReg(requirementJsonWrapper.get(requirementName));
+ if (eitherRequirement.isRight()) {
+ log.info("error when creating Requirement:{}, for node:{}", requirementName, nodeTemplateInfo);
+ return Either.right(eitherRequirement.right().value());
+ } else {
+ UploadReqInfo requirementDef = eitherRequirement.left().value();
+ requirementDef.setName(requirementName);
+ if (moduleRequirements.containsKey(requirementName)) {
+ moduleRequirements.get(requirementName).add(requirementDef);
+ } else {
+ List<UploadReqInfo> list = new ArrayList<UploadReqInfo>();
+ list.add(requirementDef);
+ moduleRequirements.put(requirementName, list);
+ }
+
+ }
+ }
+
+ }
+ return response;
+ }
+
+ private Either<UploadCapInfo, ResponseFormat> createModuleNodeTemplateCap(Object capObject) {
+ UploadCapInfo capTemplateInfo = new UploadCapInfo();
+ Either<UploadCapInfo, ResponseFormat> result = Either.left(capTemplateInfo);
+
+ if (capObject instanceof String) {
+ String nodeTemplateJsonString = (String) capObject;
+ capTemplateInfo.setNode(nodeTemplateJsonString);
+ } else if (capObject instanceof Map) {
+ Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) capObject;
+ // Type
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.NODE.getElementName())) {
+ capTemplateInfo.setNode((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.NODE.getElementName()));
+ }
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ capTemplateInfo.setType((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()));
+ }
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
+ Either<List<Object>, ResultStatusEnum> validSourceTypesRes = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.VALID_SOURCE_TYPES);
+ if (validSourceTypesRes.isLeft()) {
+ capTemplateInfo.setValidSourceTypes(validSourceTypesRes.left().value().stream().map(o -> o.toString()).collect(Collectors.toList()));
+ }
+ }
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
+ Either<Map<String, List<UploadPropInfo>>, ResponseFormat> regResponse = createPropModuleFromYaml(nodeTemplateJsonMap);
+ if (regResponse.isRight())
+ return Either.right(regResponse.right().value());
+ if (!regResponse.left().value().isEmpty()) {
+ List<UploadPropInfo> properties = new ArrayList<UploadPropInfo>();
+ regResponse.left().value().values().forEach(list -> properties.addAll(list));
+ if (!properties.isEmpty())
+ capTemplateInfo.setProperties(properties);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private Either<UploadReqInfo, ResponseFormat> createModuleNodeTemplateReg(Object regObject) {
+
+ UploadReqInfo regTemplateInfo = new UploadReqInfo();
+ Either<UploadReqInfo, ResponseFormat> result = Either.left(regTemplateInfo);
+
+ if (regObject instanceof String) {
+ String nodeTemplateJsonString = (String) regObject;
+ regTemplateInfo.setNode(nodeTemplateJsonString);
+ } else if (regObject instanceof Map) {
+ Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) regObject;
+ // Type
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.NODE.getElementName())) {
+ regTemplateInfo.setNode((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.NODE.getElementName()));
+ }
+ // US740820 Relate RIs according to capability name
+ if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.CAPABILITY.getElementName())) {
+ regTemplateInfo.setCapabilityName((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName()));
+ }
+ }
+
+ return result;
+ }
+
+ public Either<Resource, ResponseFormat> propagateStateToCertified(User user, Resource resource, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ Either<Resource, ResponseFormat> result = null;
+
+ // resource updated with checkout. certify the resource
+ if (resource.getLifecycleState().equals(LifecycleStateEnum.CERTIFIED)) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock);
+ result = eitherPopulated.isLeft() ? Either.left(resource) : Either.right(eitherPopulated.right().value());
+ return result;
+ }
+ try {
+ result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFICATION_REQUEST, lifecycleChangeInfo, inTransaction, needLock);
+ if (result.isLeft()) {
+ resource = result.left().value();
+ result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.START_CERTIFICATION, lifecycleChangeInfo, inTransaction, needLock);
+ }
+ if (result.isLeft()) {
+ resource = result.left().value();
+ result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFY, lifecycleChangeInfo, inTransaction, needLock);
+ }
+ return result;
+ } finally {
+ if (result == null || result.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Change LifecycleState - Certify");
+ BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
+ if (inTransaction == false) {
+ log.debug("operation failed. do rollback");
+ titanGenericDao.rollback();
+ }
+ } else if (inTransaction == false) {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ }
+ }
+
+ /**
+ * @deprecated Use {@link #createOrUpdateResourceByImport(Resource,User,boolean, boolean,boolean)} instead
+ */
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, AuditingActionEnum auditingEnum, boolean isNormative, boolean needLock) {
+ return createOrUpdateResourceByImport(resource, user, isNormative, false, needLock);
+ }
+
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock) {
+
+ // check if resource already exist
+ Either<Resource, StorageOperationStatus> latestByName = resourceOperation.getLatestByName(resource.getName(), true);
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> result = null;
+
+ // create
+ if (latestByName.isRight() && latestByName.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+
+ Either<Resource, StorageOperationStatus> latestByToscaName = resourceOperation.getLatestByToscaResourceName(resource.getToscaResourceName(), true);
+ if (latestByToscaName.isRight() && latestByToscaName.right().value().equals(StorageOperationStatus.NOT_FOUND))
+ result = createResourceByImport(resource, user, isNormative, isInTransaction);
+
+ else {
+ StorageOperationStatus status = latestByName.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("Create / Update resource by import", ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ log.debug("resource already exist {}. status={}", resource.getName(), status);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ result = Either.right(responseFormat);
+ }
+
+ }
+
+ // update
+ else if (latestByName.isLeft()) {
+ result = updateExistingResourceByImport(resource, latestByName.left().value(), user, isNormative, needLock);
+ }
+
+ // error
+ else {
+ StorageOperationStatus status = latestByName.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
+ log.debug("failed to get latest version of resource {}. status={}", resource.getName(), status);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(latestByName.right().value()), resource);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ result = Either.right(responseFormat);
+ }
+ return result;
+
+ }
+
+ private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction) {
+ log.debug("resource with name {} does not exist. create new resource", resource.getName());
+ Either<Resource, ResponseFormat> response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction);
+ if (response.isRight()) {
+ return Either.right(response.right().value());
+ }
+ Either<Resource, ResponseFormat> createResponse = createResourceByDao(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isNormative, isInTransaction);
+ if (createResponse.isRight()) {
+ return Either.right(createResponse.right().value());
+ } else {
+ ImmutablePair<Resource, ActionStatus> resourcePair = new ImmutablePair<>(createResponse.left().value(), ActionStatus.CREATED);
+ ASDCKpiApi.countImportResourcesKPI();
+ return Either.left(resourcePair);
+
+ }
+ }
+
+ public boolean isResourceExist(String resourceName) {
+ Either<Resource, StorageOperationStatus> latestByName = resourceOperation.getLatestByName(resourceName, false);
+ return latestByName.isLeft();
+ }
+
+ private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> updateExistingResourceByImport(Resource newResource, Resource oldResource, User user, boolean inTransaction, boolean needLock) {
+ String lockedResourceId = oldResource.getUniqueId();
+ log.debug("found resource: name={}, id={}, version={}, state={}", oldResource.getName(), lockedResourceId, oldResource.getVersion(), oldResource.getLifecycleState());
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> result = null;
+ try {
+ if (needLock) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(lockedResourceId, oldResource, "Update Resource by Import");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+ }
+
+ Either<Resource, ResponseFormat> prepareResourceForUpdate = prepareResourceForUpdate(oldResource, user, inTransaction, false);
+ if (prepareResourceForUpdate.isRight()) {
+ ResponseFormat responseFormat = prepareResourceForUpdate.right().value();
+ log.info("resource {} cannot be updated. reason={}", lockedResourceId, responseFormat.getFormattedMessage());
+ componentsUtils.auditResource(responseFormat, user, newResource, oldResource.getLifecycleState().name(), oldResource.getVersion(), AuditingActionEnum.IMPORT_RESOURCE, null);
+ result = Either.right(prepareResourceForUpdate.right().value());
+ return result;
+ }
+ oldResource = prepareResourceForUpdate.left().value();
+
+ mergeOldResourceMetadataWithNew(oldResource, newResource);
+
+ Either<Boolean, ResponseFormat> validateFieldsResponse = validateResourceFieldsBeforeUpdate(oldResource, newResource, inTransaction);
+ if (validateFieldsResponse.isRight()) {
+ result = Either.right(validateFieldsResponse.right().value());
+ return result;
+ }
+
+ // contact info normalization
+ newResource.setContactId(newResource.getContactId().toLowerCase());
+ // non-updatable fields
+ newResource.setCreatorUserId(user.getUserId());
+ newResource.setCreatorFullName(user.getFullName());
+ newResource.setLastUpdaterUserId(user.getUserId());
+ newResource.setLastUpdaterFullName(user.getFullName());
+ newResource.setUniqueId(oldResource.getUniqueId());
+ newResource.setVersion(oldResource.getVersion());
+ newResource.setInvariantUUID(oldResource.getInvariantUUID());
+ newResource.setLifecycleState(oldResource.getLifecycleState());
+ newResource.setUUID(oldResource.getUUID());
+ newResource.setNormalizedName(oldResource.getNormalizedName());
+ newResource.setSystemName(oldResource.getSystemName());
+ if (oldResource.getCsarUUID() != null) {
+ newResource.setCsarUUID(oldResource.getCsarUUID());
+ }
+ if (oldResource.getImportedToscaChecksum() != null) {
+ newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
+ }
+ newResource.setAbstract(oldResource.isAbstract());
+
+ if (newResource.getDerivedFrom() == null || newResource.getDerivedFrom().isEmpty()) {
+ newResource.setDerivedFrom(oldResource.getDerivedFrom());
+ }
+ // TODO rhalili: handle artifacts here (delete from old resource and
+ // add for new)
+ // TODO rbetzer: remove after migration - in case of resources
+ // created without tosca artifacts - add the placeholders
+ if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
+ setToscaArtifactsPlaceHolders(newResource, user);
+ }
+ Either<Resource, StorageOperationStatus> overrideResource = resourceOperation.overrideResource(newResource, oldResource, true);
+
+ if (overrideResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(overrideResource.right().value()), newResource);
+ componentsUtils.auditResource(responseFormat, user, newResource, newResource.getLifecycleState().name(), newResource.getVersion(), AuditingActionEnum.IMPORT_RESOURCE, null);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ log.debug("Resource updated successfully!!!");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ componentsUtils.auditResource(responseFormat, user, newResource, oldResource.getLifecycleState().name(), oldResource.getVersion(), AuditingActionEnum.IMPORT_RESOURCE, null);
+
+ ImmutablePair<Resource, ActionStatus> resourcePair = new ImmutablePair<>(overrideResource.left().value(), ActionStatus.OK);
+ result = Either.left(resourcePair);
+ return result;
+ } finally {
+ if (result == null || result.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Change LifecycleState - Certify");
+ BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
+ log.debug("operation failed. do rollback");
+ titanGenericDao.rollback();
+ } else if (inTransaction == false) {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ if (needLock == true) {
+ log.debug("unlock resource {}", lockedResourceId);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ }
+ }
+
+ }
+
+ /**
+ * Merge old resource with new. Keep old category and vendor name without change
+ *
+ * @param oldResource
+ * @param newResource
+ */
+ private void mergeOldResourceMetadataWithNew(Resource oldResource, Resource newResource) {
+
+ // keep old category and vendor name without change
+ // merge the rest of the resource metadata
+ if (newResource.getTags() == null || newResource.getTags().isEmpty()) {
+ newResource.setTags(oldResource.getTags());
+ }
+
+ if (newResource.getDescription() == null) {
+ newResource.setDescription(oldResource.getDescription());
+ }
+
+ if (newResource.getVendorRelease() == null) {
+ newResource.setVendorRelease(oldResource.getVendorRelease());
+ }
+
+ if (newResource.getContactId() == null) {
+ newResource.setContactId(oldResource.getContactId());
+ }
+
+ newResource.setCategories(oldResource.getCategories());
+ newResource.setVendorName(oldResource.getVendorName());
+ }
+
+ private Either<Resource, ResponseFormat> prepareResourceForUpdate(Resource latestResource, User user, boolean inTransaction, boolean needLock) {
+
+ Either<Resource, ResponseFormat> result = Either.left(latestResource);
+ // check if user can edit resource
+ if (!ComponentValidationUtils.canWorkOnResource(latestResource, user.getUserId())) {
+ // checkout
+ Either<Resource, ResponseFormat> changeState = lifecycleBusinessLogic.changeState(latestResource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, new LifecycleChangeInfoWithAction("update by import"), inTransaction, needLock);
+ result = changeState;
+ }
+
+ return result;
+ }
+
+ public Either<Resource, ResponseFormat> validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction) {
+
+ Either<Boolean, ResponseFormat> eitherValidation = validateResourceFieldsBeforeCreate(user, getResourceOperation(), resource, actionEnum, inTransaction);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+
+ eitherValidation = validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), resource, actionEnum, inTransaction);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+ eitherValidation = validateLifecycleTypesCreate(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+ eitherValidation = validateResourceType(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setContactId(resource.getContactId().toLowerCase());
+ if (resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(ResourceTypeEnum.VF.name(), resource.getSystemName()));
+ }
+
+ // Generate invariant UUID - must be here and not in operation since it
+ // should stay constant during clone
+ String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
+ resource.setInvariantUUID(invariantUUID);
+
+ return Either.left(resource);
+ }
+
+ private Either<Boolean, ResponseFormat> validateResourceType(User user, Resource resource, AuditingActionEnum actionEnum) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getResourceType() == null) {
+ log.debug("Invalid resource type for resource");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ }
+ return eitherResult;
+ }
+
+ private Either<Boolean, ResponseFormat> validateLifecycleTypesCreate(User user, Resource resource, AuditingActionEnum actionEnum) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getInterfaces() != null && resource.getInterfaces().size() > 0) {
+ log.debug("validate interface lifecycle Types Exist");
+ Iterator<InterfaceDefinition> intItr = resource.getInterfaces().values().iterator();
+ while (intItr.hasNext() && eitherResult.isLeft()) {
+ InterfaceDefinition interfaceDefinition = intItr.next();
+ String intType = interfaceDefinition.getUniqueId();
+ Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation.getInterface(intType);
+ if (eitherCapTypeFound.isRight()) {
+ if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInterfaceMissingError, "Create Resource - validateLifecycleTypesCreate", intType);
+ BeEcompErrorManager.getInstance().logBeGraphObjectMissingError("Create Resource - validateLifecycleTypesCreate", "Interface", intType);
+ log.debug("Lifecycle Type: {} is required by resource: {} but does not exist in the DB", intType, resource.getName());
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateLifecycleTypesCreate");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateLifecycleTypesCreate");
+ log.debug("request to data model failed with error: {}", eitherCapTypeFound.right().value().name());
+ }
+
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_LIFECYCLE_TYPE, intType);
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ }
+
+ }
+ }
+ return eitherResult;
+ }
+
+ private Either<Boolean, ResponseFormat> validateCapabilityTypesCreate(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
+
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getCapabilities() != null && resource.getCapabilities().size() > 0) {
+ log.debug("validate capability Types Exist - capabilities section");
+
+ for (String type : resource.getCapabilities().keySet()) {
+
+ eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, actionEnum, eitherResult, type, inTransaction);
+ if (eitherResult.isRight()) {
+ return Either.right(eitherResult.right().value());
+ }
+ }
+ }
+
+ if (resource.getRequirements() != null && resource.getRequirements().size() > 0) {
+ log.debug("validate capability Types Exist - requirements section");
+
+ for (String type : resource.getRequirements().keySet()) {
+
+ eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, actionEnum, eitherResult, type, inTransaction);
+ if (eitherResult.isRight()) {
+ return Either.right(eitherResult.right().value());
+ }
+ }
+ }
+
+ return eitherResult;
+ }
+
+ private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult, String type,
+ boolean inTransaction) {
+ Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(type, inTransaction);
+ if (eitherCapTypeFound.isRight()) {
+ if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeCapabilityTypeMissingError, "Create Resource - validateCapabilityTypesCreate", type);
+ BeEcompErrorManager.getInstance().logBeGraphObjectMissingError("Create Resource - validateCapabilityTypesCreate", "Capability Type", type);
+ log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB", type, resource.getName());
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateCapabilityTypesCreate");
+ }
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateCapabilityTypesCreate");
+ log.debug("Trying to get capability type {} failed with error: {}", type, eitherCapTypeFound.right().value().name());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, type);
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ }
+ return eitherResult;
+ }
+
+ public Either<Resource, ResponseFormat> createResourceByDao(Resource resource, User user, AuditingActionEnum actionEnum, boolean isNormative) {
+ return createResourceByDao(resource, user, actionEnum, isNormative, false);
+ }
+
+ public Either<Resource, ResponseFormat> createResourceByDao(Resource resource, User user, AuditingActionEnum actionEnum, boolean isNormative, boolean inTransaction) {
+ // create resource
+
+ // lock new resource name in order to avoid creation resource with same
+ // name
+ if (inTransaction == false) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource, "Create Resource");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+
+ log.debug("name is locked {}. status = {}", resource.getSystemName(), lockResult);
+ }
+ try {
+ Either<Resource, ResponseFormat> respStatus = createResourceTransaction(resource, user, actionEnum, isNormative, inTransaction);
+ if (respStatus.isLeft()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ ASDCKpiApi.countCreatedResourcesKPI();
+ } else
+ componentsUtils.auditResource(respStatus.right().value(), user, resource, "", "", actionEnum, null);
+ return respStatus;
+
+ } finally {
+ if (inTransaction == false) {
+ // graphLockOperation.unlockComponent(resource.getSystemName(),
+ // NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
+ }
+ }
+ }
+
+ private Either<Resource, ResponseFormat> createResourceTransaction(Resource resource, User user, AuditingActionEnum actionEnum, boolean isNormative, boolean inTransaction) {
+ // validate resource name uniqueness
+ log.debug("validate resource name");
+ Either<Boolean, ResponseFormat> eitherValidation = validateResourceNameExists(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+
+ log.debug("send resource {} to dao for create", resource.getName());
+
+ createArtifactsPlaceHolderData(resource, user);
+
+ //
+ if (!isNormative) {
+ // enrich object
+ log.debug("enrich resource with creator, version and state");
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setVersion(INITIAL_VERSION);
+ resource.setHighestVersion(true);
+ resource.setAbstract(false);
+ }
+
+ Either<Resource, StorageOperationStatus> dataModelResponse = resourceOperation.createResource(resource, inTransaction);
+
+ // Resource created successfully!!!
+ if (dataModelResponse.isLeft()) {
+ log.debug("Resource created successfully!!!");
+
+ return Either.left(dataModelResponse.left().value());
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), resource);
+
+ return Either.right(responseFormat);
+ }
+
+ private void createArtifactsPlaceHolderData(Resource resource, User user) {
+ // create mandatory artifacts
+
+ // TODO it must be removed after that artifact uniqueId creation will be
+ // moved to ArtifactOperation
+ // String resourceUniqueId =
+ // UniqueIdBuilder.buildResourceUniqueId(resource.getResourceName(),
+ // resource.getResourceVersion());
+
+ setInformationalArtifactsPlaceHolder(resource, user);
+ setDeploymentArtifactsPlaceHolder(resource, user);
+ setToscaArtifactsPlaceHolders(resource, user);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
+ Resource resource = (Resource) component;
+ Map<String, ArtifactDefinition> artifactMap = resource.getDeploymentArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<String, ArtifactDefinition>();
+ }
+ Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getDeploymentResourceArtifacts();
+ if (deploymentResourceArtifacts != null) {
+ Iterator<Entry<String, Object>> iterator = deploymentResourceArtifacts.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Entry<String, Object> currEntry = iterator.next();
+ boolean shouldCreateArtifact = true;
+ Map<String, Object> artifactDetails = (Map<String, Object>) currEntry.getValue();
+ Object object = artifactDetails.get(PLACE_HOLDER_RESOURCE_TYPES);
+ if (object != null) {
+ List<String> artifactTypes = (List<String>) object;
+ if (!artifactTypes.contains(resource.getResourceType().name())) {
+ shouldCreateArtifact = false;
+ continue;
+ }
+ } else {
+ log.info("resource types for artifact placeholder {} were not defined. default is all resources", currEntry.getKey());
+ }
+ if (shouldCreateArtifact) {
+ if (artifactsBusinessLogic != null) {
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(resource.getUniqueId(), currEntry.getKey(), (Map<String, Object>) currEntry.getValue(), user, ArtifactGroupTypeEnum.DEPLOYMENT);
+ if (artifactDefinition != null && !artifactMap.containsKey(artifactDefinition.getArtifactLabel()))
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+ }
+ }
+ }
+ }
+ resource.setDeploymentArtifacts(artifactMap);
+ }
+
+ private void setInformationalArtifactsPlaceHolder(Resource resource, User user) {
+ Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<String, ArtifactDefinition>();
+ }
+ String resourceUniqueId = resource.getUniqueId();
+ List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeResourceCategory();
+ Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getInformationalResourceArtifacts();
+ List<CategoryDefinition> categories = resource.getCategories();
+ boolean isCreateArtifact = true;
+ if (exludeResourceCategory != null) {
+ String category = categories.get(0).getName();
+ for (String exlude : exludeResourceCategory) {
+ if (exlude.equalsIgnoreCase(category)) {
+ isCreateArtifact = false;
+ break;
+ }
+ }
+
+ }
+
+ if (informationalResourceArtifacts != null && isCreateArtifact) {
+ Set<String> keys = informationalResourceArtifacts.keySet();
+ for (String informationalResourceArtifactName : keys) {
+ Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts.get(informationalResourceArtifactName);
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user, ArtifactGroupTypeEnum.INFORMATIONAL);
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+
+ }
+ }
+ resource.setArtifacts(artifactMap);
+ }
+
+ /**
+ * deleteResource
+ *
+ * @param resourceId
+ * @param user
+ * @return
+ */
+ public ResponseFormat deleteResource(String resourceId, User user) {
+ ResponseFormat responseFormat;
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, "Delete Resource", false);
+ if (eitherCreator.isRight()) {
+ return eitherCreator.right().value();
+ }
+
+ Either<Resource, StorageOperationStatus> resourceStatus = resourceOperation.getResource(resourceId);
+ if (resourceStatus.isRight()) {
+ log.debug("failed to get resource {}", resourceId);
+ return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceStatus.right().value()), "");
+ }
+
+ Resource resource = resourceStatus.left().value();
+
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(resourceId, resource, "Mark resource to delete");
+ if (lockResult.isRight()) {
+ result = StorageOperationStatus.GENERAL_ERROR;
+ return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ try {
+
+ result = markComponentToDelete(resource);
+ if (result.equals(StorageOperationStatus.OK)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ } else {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
+ }
+ return responseFormat;
+
+ } finally {
+ if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
+
+ }
+
+ public ResponseFormat deleteResourceByNameAndVersion(String resourceName, String version, User user) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, "Delete Resource", false);
+ if (eitherCreator.isRight()) {
+ return eitherCreator.right().value();
+ }
+
+ // Resource resource = null;
+ List<Resource> resourcesList = null;
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ try {
+
+ Either<List<Resource>, StorageOperationStatus> resourceStatus = resourceOperation.getResourceByNameAndVersion(resourceName, version, true);
+ if (resourceStatus.isRight()) {
+ log.debug("failed to get resource {} version {}", resourceName, version);
+ return componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(resourceStatus.right().value()), resourceName);
+ }
+
+ resourcesList = resourceStatus.left().value();
+
+ } finally {
+ if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resourceName);
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ }
+ for (Resource resource : resourcesList) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(resource.getUniqueId(), resource, "Delete Resource");
+ if (lockResult.isRight()) {
+ result = StorageOperationStatus.GENERAL_ERROR;
+ return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+ try {
+ result = markComponentToDelete(resource);
+ if (!result.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
+ return responseFormat;
+ }
+
+ } finally {
+ if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ log.warn("operation failed. do rollback");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ graphLockOperation.unlockComponent(resource.getUniqueId(), NodeTypeEnum.Resource);
+ }
+ }
+ return responseFormat;
+ }
+
+ public Either<Resource, ResponseFormat> getResource(String resourceId, User user) {
+
+ if (user != null) {
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, "Create Resource", false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ }
+
+ IResourceOperation dataModel = getResourceOperation();
+ Either<Resource, StorageOperationStatus> storageStatus = dataModel.getResource(resourceId);
+
+ if (storageStatus.isRight()) {
+ log.debug("failed to get resource by id {}", resourceId);
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
+ }
+ return Either.left(storageStatus.left().value());
+
+ }
+
+ public Either<List<Resource>, ResponseFormat> getResourceByNameAndVersion(String resourceName, String resourceVersion, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Resource By Name And Version", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<List<Resource>, StorageOperationStatus> getResource = resourceOperation.getResourceByNameAndVersion(resourceName, resourceVersion, false);
+ if (getResource.isRight()) {
+ log.debug("failed to get resource by name {} and version {}", resourceName, resourceVersion);
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(getResource.right().value()), resourceName));
+ }
+ return Either.left(getResource.left().value());
+ }
+
+ /**
+ * updateResourceMetadata
+ *
+ * @param user
+ * - modifier data (userId)
+ * @param inTransaction
+ * TODO
+ * @param resourceIdToUpdate
+ * - the resource identifier
+ * @param newResource
+ *
+ * @return Either<Resource, responseFormat>
+ */
+ public Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, Resource currentResource, User user, boolean inTransaction) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "update Resource Metadata", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ IResourceOperation dataModel = getResourceOperation();
+ log.debug("Get resource with id {}", resourceIdToUpdate);
+ boolean needToUnlock = false;
+ boolean rollbackNeeded = true;
+
+ try {
+ // Either<Resource, StorageOperationStatus> storageStatus =
+ // dataModel.getResource_tx(resourceIdToUpdate, false);
+ if (currentResource == null) {
+ Either<Resource, StorageOperationStatus> storageStatus = dataModel.getResource(resourceIdToUpdate, false);
+ if (storageStatus.isRight()) {
+ return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
+ }
+
+ currentResource = storageStatus.left().value();
+ }
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnResource(currentResource, user.getUserId())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ // lock resource
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceIdToUpdate, NodeTypeEnum.Resource);
+ if (!lockResult.equals(StorageOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "Upload Artifact - lock " + resourceIdToUpdate + ": " + NodeTypeEnum.Resource);
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError("Upload Artifact - lock ", NodeTypeEnum.Resource.getName(), resourceIdToUpdate);
+ log.debug("Failed to lock resource {} error - {}", resourceIdToUpdate, lockResult);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult));
+ return Either.right(responseFormat);
+ }
+
+ needToUnlock = true;
+
+ // critical section starts here
+ // convert json to object
+
+ // Update and updated resource must have a non-empty "derivedFrom"
+ // list
+ // This code is not called from import resources, because of root
+ // VF "derivedFrom" should be null (or ignored)
+ if (!currentResource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ Either<Boolean, ResponseFormat> derivedFromNotEmptyEither = validateDerivedFromNotEmpty(null, newResource, null);
+ if (derivedFromNotEmptyEither.isRight()) {
+ log.debug("for updated resource {}, derived from field is empty", newResource.getName());
+ return Either.right(derivedFromNotEmptyEither.right().value());
+ }
+
+ derivedFromNotEmptyEither = validateDerivedFromNotEmpty(null, currentResource, null);
+ if (derivedFromNotEmptyEither.isRight()) {
+ log.debug("for current resource {}, derived from field is empty", currentResource.getName());
+ return Either.right(derivedFromNotEmptyEither.right().value());
+ }
+ } else {
+ newResource.setDerivedFrom(null);
+ }
+
+ Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, false, true);
+ if (dataModelResponse.isRight()) {
+ log.debug("failed to update resource metadata!!!");
+ rollbackNeeded = true;
+ return Either.right(dataModelResponse.right().value());
+ }
+
+ log.debug("Resource metadata updated successfully!!!");
+ rollbackNeeded = false;
+ return Either.left(dataModelResponse.left().value());
+
+ } finally {
+ if (!inTransaction) {
+ if (rollbackNeeded) {
+ titanGenericDao.rollback();
+ } else {
+ titanGenericDao.commit();
+ }
+ }
+
+ if (needToUnlock) {
+ graphLockOperation.unlockComponent(resourceIdToUpdate, NodeTypeEnum.Resource);
+ }
+ }
+ }
+
+ private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, User user, Resource currentResource, boolean shouldLock, boolean inTransaction) {
+
+ IResourceOperation dataModel = getResourceOperation();
+ Either<Boolean, ResponseFormat> validateResourceFields = validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction);
+ if (validateResourceFields.isRight()) {
+ return Either.right(validateResourceFields.right().value());
+ }
+ // Setting last updater and uniqueId
+ newResource.setContactId(newResource.getContactId().toLowerCase());
+ newResource.setLastUpdaterUserId(user.getUserId());
+ newResource.setUniqueId(resourceIdToUpdate);
+ // Cannot set highest version through UI
+ newResource.setHighestVersion(null);
+ newResource.setCreationDate(currentResource.getCreationDate());
+
+ Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom = processUpdateOfDerivedFrom(currentResource, newResource, user.getUserId(), shouldLock, inTransaction);
+
+ if (processUpdateOfDerivedFrom.isRight()) {
+ log.debug("Couldn't update derived from for resource {}", resourceIdToUpdate);
+ return Either.right(processUpdateOfDerivedFrom.right().value());
+ }
+
+ log.debug("send resource {} to dao for update", newResource.getUniqueId());
+ Either<Resource, StorageOperationStatus> dataModelResponse = dataModel.updateResource(newResource, inTransaction);
+
+ if (dataModelResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), newResource);
+ return Either.right(responseFormat);
+ } else if (dataModelResponse.left().value() == null) {
+ log.debug("No response from updateResource");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return Either.left(dataModelResponse.left().value());
+ }
+
+ /**
+ * validateResourceFieldsBeforeCreate
+ *
+ * @param user
+ * - modifier data (userId)
+ * @param dataModel
+ * - IResourceOperation for resource crud
+ * @param resource
+ * - Resource object to validate
+ * @return Either<Boolean, ErrorResponse>
+ */
+ private Either<Boolean, ResponseFormat> validateResourceFieldsBeforeCreate(User user, IResourceOperation dataModel, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
+ Either<Boolean, ResponseFormat> componentsFieldsValidation = validateComponentFieldsBeforeCreate(user, resource, actionEnum);
+ if (componentsFieldsValidation.isRight()) {
+ return componentsFieldsValidation;
+ }
+
+ // validate name
+
+ /*
+ * log.debug("validate resource name"); Either<Boolean, ResponseFormat> eitherValidation = validateComponentName(user, resource, actionEnum); if (eitherValidation.isRight()) { return eitherValidation; }
+ *
+ * // validate description log.debug("validate description"); eitherValidation = validateDescriptionAndCleanup(user, resource, actionEnum); if (eitherValidation.isRight()) { return eitherValidation; }
+ */
+
+ // validate icon
+ /*
+ * log.debug("validate icon"); eitherValidation = validateIcon(user, resource, actionEnum); if (eitherValidation.isRight()) { return eitherValidation; }
+ */
+
+ // validate tags
+ /*
+ * log.debug("validate tags"); eitherValidation = validateTagsListAndRemoveDuplicates(user, resource, actionEnum); if (eitherValidation.isRight()) { return eitherValidation; }
+ */
+
+ // validate category
+ log.debug("validate category");
+ Either<Boolean, ResponseFormat> eitherValidation = validateCategory(user, resource, actionEnum, inTransaction);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // validate vendor name & release
+ log.debug("validate vendor name");
+ eitherValidation = validateVendorName(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate vendor release");
+ eitherValidation = validateVendorReleaseName(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // validate cost
+ log.debug("validate cost");
+ eitherValidation = validateCost(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // validate licenseType
+ log.debug("validate licenseType");
+ eitherValidation = validateLicenseType(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // validate template (derived from)
+ log.debug("validate derived from");
+ if (resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ resource.setDerivedFrom(null);
+ }
+ eitherValidation = validateDerivedFromExist(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return Either.right(eitherValidation.right().value());
+ }
+
+ // warn about non-updatable fields
+ checkComponentFieldsForOverrideAttempt(resource);
+ String currentCreatorFullName = resource.getCreatorFullName();
+ if (currentCreatorFullName != null) {
+ log.warn("Resource Creator fullname is automatically set and cannot be updated");
+ }
+
+ String currentLastUpdaterFullName = resource.getLastUpdaterFullName();
+ if (currentLastUpdaterFullName != null) {
+ log.warn("Resource LastUpdater fullname is automatically set and cannot be updated");
+ }
+
+ Long currentLastUpdateDate = resource.getLastUpdateDate();
+ if (currentLastUpdateDate != null) {
+ log.warn("Resource last update date is automatically set and cannot be updated");
+ }
+
+ Boolean currentAbstract = resource.isAbstract();
+ if (currentAbstract != null) {
+ log.warn("Resource abstract is automatically set and cannot be updated");
+ }
+
+ return Either.left(true);
+ }
+
+ /**
+ * validateResourceFieldsBeforeUpdate
+ *
+ * @param currentResource
+ * - Resource object to validate
+ * @return Either<Boolean, ErrorResponse>
+ */
+ private Either<Boolean, ResponseFormat> validateResourceFieldsBeforeUpdate(Resource currentResource, Resource updateInfoResource, boolean inTransaction) {
+
+ boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentResource.getVersion());
+
+ // validate resource name
+ log.debug("validate resource name before update");
+ Either<Boolean, ResponseFormat> eitherValidation = validateResourceName(currentResource, updateInfoResource, hasBeenCertified);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // validate description
+ log.debug("validate description before update");
+ eitherValidation = validateDescriptionAndCleanup(null, updateInfoResource, null);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate icon before update");
+ eitherValidation = validateIcon(currentResource, updateInfoResource, hasBeenCertified);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate tags before update");
+ eitherValidation = validateTagsListAndRemoveDuplicates(null, updateInfoResource, null);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate vendor name before update");
+ eitherValidation = validateVendorName(currentResource, updateInfoResource, hasBeenCertified);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate vendor release before update");
+ eitherValidation = validateVendorReleaseName(null, updateInfoResource, null);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate contact info before update");
+ eitherValidation = validateContactId(null, updateInfoResource, null);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate derived before update");
+ eitherValidation = validateDerivedFromDuringUpdate(currentResource, updateInfoResource, hasBeenCertified);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ log.debug("validate category before update");
+ eitherValidation = validateCategory(currentResource, updateInfoResource, hasBeenCertified, inTransaction);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+ // warn about non-updatable fields
+ String currentResourceVersion = currentResource.getVersion();
+ String updatedResourceVersion = updateInfoResource.getVersion();
+
+ if ((updatedResourceVersion != null) && (!updatedResourceVersion.equals(currentResourceVersion))) {
+ log.warn("Resource version is automatically set and cannot be updated");
+ }
+
+ String currentCreatorUserId = currentResource.getCreatorUserId();
+ String updatedCreatorUserId = updateInfoResource.getCreatorUserId();
+
+ if ((updatedCreatorUserId != null) && (!updatedCreatorUserId.equals(currentCreatorUserId))) {
+ log.warn("Resource Creator User id is automatically set and cannot be updated");
+ }
+
+ String currentCreatorFullName = currentResource.getCreatorFullName();
+ String updatedCreatorFullName = updateInfoResource.getCreatorFullName();
+
+ if ((updatedCreatorFullName != null) && (!updatedCreatorFullName.equals(currentCreatorFullName))) {
+ log.warn("Resource Creator fullname is automatically set and cannot be updated");
+ }
+
+ String currentLastUpdaterUserId = currentResource.getLastUpdaterUserId();
+ String updatedLastUpdaterUserId = updateInfoResource.getLastUpdaterUserId();
+
+ if ((updatedLastUpdaterUserId != null) && (!updatedLastUpdaterUserId.equals(currentLastUpdaterUserId))) {
+ log.warn("Resource LastUpdater userId is automatically set and cannot be updated");
+ }
+
+ String currentLastUpdaterFullName = currentResource.getLastUpdaterFullName();
+ String updatedLastUpdaterFullName = updateInfoResource.getLastUpdaterFullName();
+
+ if ((updatedLastUpdaterFullName != null) && (!updatedLastUpdaterFullName.equals(currentLastUpdaterFullName))) {
+ log.warn("Resource LastUpdater fullname is automatically set and cannot be updated");
+ }
+
+ Long currentCreationDate = currentResource.getCreationDate();
+ Long updatedCreationDate = updateInfoResource.getCreationDate();
+
+ if ((updatedCreationDate != null) && (!updatedCreationDate.equals(currentCreationDate))) {
+ log.warn("Resource Creation date is automatically set and cannot be updated");
+ }
+
+ Long currentLastUpdateDate = currentResource.getLastUpdateDate();
+ Long updatedLastUpdateDate = updateInfoResource.getLastUpdateDate();
+
+ if ((updatedLastUpdateDate != null) && (!updatedLastUpdateDate.equals(currentLastUpdateDate))) {
+ log.warn("Resource last update date is automatically set and cannot be updated");
+ }
+
+ LifecycleStateEnum currentLifecycleState = currentResource.getLifecycleState();
+ LifecycleStateEnum updatedLifecycleState = updateInfoResource.getLifecycleState();
+
+ if ((updatedLifecycleState != null) && (!updatedLifecycleState.equals(currentLifecycleState))) {
+ log.warn("Resource lifecycle state date is automatically set and cannot be updated");
+ }
+
+ Boolean currentAbstract = currentResource.isAbstract();
+ Boolean updatedAbstract = updateInfoResource.isAbstract();
+
+ if ((updatedAbstract != null) && (!updatedAbstract.equals(currentAbstract))) {
+ log.warn("Resource abstract is automatically set and cannot be updated");
+ }
+
+ Boolean currentHighestVersion = currentResource.isHighestVersion();
+ Boolean updatedHighestVersion = updateInfoResource.isHighestVersion();
+
+ if ((updatedHighestVersion != null) && (!updatedHighestVersion.equals(currentHighestVersion))) {
+ log.warn("Resource highest version is automatically set and cannot be updated");
+ }
+
+ String currentUuid = currentResource.getUUID();
+ String updatedUuid = updateInfoResource.getUUID();
+
+ if ((updatedUuid != null) && (!updatedUuid.equals(currentUuid))) {
+ log.warn("Resource UUID is automatically set and cannot be updated");
+ }
+
+ ResourceTypeEnum currentResourceType = currentResource.getResourceType();
+ ResourceTypeEnum updatedResourceType = updateInfoResource.getResourceType();
+
+ if ((updatedResourceType != null) && (!updatedResourceType.equals(currentResourceType))) {
+ log.warn("Resource Type cannot be updated");
+
+ }
+ updateInfoResource.setResourceType(currentResource.getResourceType());
+
+ String currentInvariantUuid = currentResource.getInvariantUUID();
+ String updatedInvariantUuid = updateInfoResource.getInvariantUUID();
+
+ if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
+ log.warn("Resource invariant UUID is automatically set and cannot be updated");
+ updateInfoResource.setInvariantUUID(currentInvariantUuid);
+ }
+ return Either.left(true);
+ }
+
+ /*
+ * private Either<Boolean, ResponseFormat> validateResourceName(User user, Resource resource, AuditingActionEnum actionEnum) { log.debug("validate resource name is not empty"); String resourceName = resource.getResourceName();
+ *
+ * if (!ValidationUtils.validateStringNotEmpty(resourceName)) { log.debug("Resource name is empty"); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ * componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null); return Either.right(responseFormat); }
+ *
+ * if (!ValidationUtils.validateResourceNameLength(resourceName)) { log.debug("Resource name is exceeds max length {} ", ValidationUtils.RESOURCE_NAME_MAX_LENGTH); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.
+ * COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.RESOURCE_NAME_MAX_LENGTH); componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null); return Either.right(responseFormat);
+ * }
+ *
+ * if (!ValidationUtils.validateResourceName(resourceName)) { log.debug("Resource name {} has invalid format", resourceName); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME,
+ * ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null); return Either.right(responseFormat); } resource.setNormalizedName(ValidationUtils.normaliseComponentName(
+ * resourceName)); resource.setSystemName(ValidationUtils.convertToSystemName(resourceName)) ;
+ *
+ * return Either.left(true); }
+ */
+
+ private Either<Boolean, ResponseFormat> validateResourceName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ String resourceNameUpdated = updateInfoResource.getName();
+ String resourceNameCurrent = currentResource.getName();
+ if (!resourceNameCurrent.equals(resourceNameUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validateResourceNameResponse = validateComponentName(null, updateInfoResource, null);
+ if (validateResourceNameResponse.isRight()) {
+ ResponseFormat errorResponse = validateResourceNameResponse.right().value();
+ return Either.right(errorResponse);
+ }
+ validateResourceNameResponse = validateResourceNameExists(null, updateInfoResource, null);
+ if (validateResourceNameResponse.isRight()) {
+ ResponseFormat errorResponse = validateResourceNameResponse.right().value();
+ return Either.right(errorResponse);
+ }
+ currentResource.setName(resourceNameUpdated);
+ currentResource.setNormalizedName(ValidationUtils.normaliseComponentName(resourceNameUpdated));
+ currentResource.setSystemName(ValidationUtils.convertToSystemName(resourceNameUpdated));
+
+ } else {
+ log.info("Resource name {} cannot be updated once the resource has been certified once.", resourceNameUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateIcon(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ String iconUpdated = updateInfoResource.getIcon();
+ String iconCurrent = currentResource.getIcon();
+ if (!iconCurrent.equals(iconUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validateIcon = validateIcon(null, updateInfoResource, null);
+ if (validateIcon.isRight()) {
+ ResponseFormat errorResponse = validateIcon.right().value();
+ return Either.right(errorResponse);
+ }
+ } else {
+ log.info("Icon {} cannot be updated once the resource has been certified once.", iconUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateVendorName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ String vendorNameUpdated = updateInfoResource.getVendorName();
+ String vendorNameCurrent = currentResource.getVendorName();
+ if (!vendorNameCurrent.equals(vendorNameUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validateVendorName = validateVendorName(null, updateInfoResource, null);
+ if (validateVendorName.isRight()) {
+ ResponseFormat errorResponse = validateVendorName.right().value();
+ return Either.right(errorResponse);
+ }
+ } else {
+ log.info("Vendor name {} cannot be updated once the resource has been certified once.", vendorNameUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateCategory(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified, boolean inTransaction) {
+ Either<Boolean, ResponseFormat> validateCategoryName = validateCategory(null, updateInfoResource, null, inTransaction);
+ if (validateCategoryName.isRight()) {
+ ResponseFormat errorResponse = validateCategoryName.right().value();
+ return Either.right(errorResponse);
+ }
+ if (hasBeenCertified) {
+ CategoryDefinition currentCategory = currentResource.getCategories().get(0);
+ SubCategoryDefinition currentSubCategory = currentCategory.getSubcategories().get(0);
+ CategoryDefinition updateCategory = updateInfoResource.getCategories().get(0);
+ SubCategoryDefinition updtaeSubCategory = updateCategory.getSubcategories().get(0);
+ if (!currentCategory.getName().equals(updateCategory.getName()) || !currentSubCategory.getName().equals(updtaeSubCategory.getName())) {
+ log.info("Category {} cannot be updated once the resource has been certified once.", currentResource.getCategories());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateDerivedFromDuringUpdate(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+
+ List<String> currentDerivedFrom = currentResource.getDerivedFrom();
+ List<String> updatedDerivedFrom = updateInfoResource.getDerivedFrom();
+ if (currentDerivedFrom == null || currentDerivedFrom.isEmpty() || updatedDerivedFrom == null || updatedDerivedFrom.isEmpty()) {
+ log.trace("Update normative types");
+ return Either.left(true);
+ }
+
+ String derivedFromCurrent = currentDerivedFrom.get(0);
+ String derivedFromUpdated = updatedDerivedFrom.get(0);
+
+ if (!derivedFromCurrent.equals(derivedFromUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validateDerivedFromExistsEither = validateDerivedFromExist(null, updateInfoResource, null);
+ if (validateDerivedFromExistsEither.isRight()) {
+ return validateDerivedFromExistsEither;
+ }
+ } else {
+ log.debug("Derived from cannot be updated once the resource has been certified once.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ } else {
+ // For derived from, we must know whether it was actually changed,
+ // otherwise we must do no action.
+ // Due to changes it inflicts on data model (remove artifacts,
+ // properties...), it's not like a flat field which can be
+ // overwritten if not changed.
+ // So we must indicate that derived from is not changed
+ updateInfoResource.setDerivedFrom(null);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateDerivedFromExist(User user, Resource resource, AuditingActionEnum actionEnum) {
+
+ if (resource.getDerivedFrom() == null || resource.getDerivedFrom().isEmpty()) {
+ return Either.left(true);
+ }
+
+ IResourceOperation resourceOperation = getResourceOperation();
+
+ String templateName = resource.getDerivedFrom().get(0);
+
+ Either<Boolean, StorageOperationStatus> dataModelResponse = resourceOperation.validateToscaResourceNameExists(templateName);
+ if (dataModelResponse.isRight()) {
+ StorageOperationStatus storageStatus = dataModelResponse.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateDerivedFromExist");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateDerivedFromExist");
+ log.debug("request to data model failed with error: {}", storageStatus.name());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource);
+ log.trace("audit before sending response");
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+
+ if (dataModelResponse.left().value()) {
+ log.info("resource template with name {} does not exists", templateName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(true);
+ }
+
+ public Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty(User user, Resource resource, AuditingActionEnum actionEnum) {
+ log.debug("validate resource derivedFrom field");
+ if ((resource.getDerivedFrom() == null) || (resource.getDerivedFrom().isEmpty()) || (resource.getDerivedFrom().get(0)) == null || (resource.getDerivedFrom().get(0).trim().isEmpty())) {
+ log.info("derived from (template) field is missing for the resource");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateResourceNameExists(User user, Resource resource, AuditingActionEnum actionEnum) {
+
+ IResourceOperation resourceOperation = getResourceOperation();
+ Either<Boolean, StorageOperationStatus> resourceOperationResponse = resourceOperation.validateResourceNameExists(resource.getName(), resource.getResourceType());
+ if (resourceOperationResponse.isLeft()) {
+ if (resourceOperationResponse.left().value()) {
+ return Either.left(true);
+ } else {
+ log.debug("resource with name {} already exists", resource.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ return Either.right(errorResponse);
+ }
+ }
+ log.debug("error while validateResourceNameExists for resource: {}", resource.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceOperationResponse.right().value()));
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ return Either.right(errorResponse);
+ }
+
+ /*
+ * private Either<Boolean, ResponseFormat> validateTagsListAndRemoveDuplicates(User user, Resource resource, AuditingActionEnum actionEnum) { List<String> tagsList = resource.getTags();
+ *
+ * Either<Boolean, ResponseFormat> validateTags = validateResourceTags(tagsList, resource.getResourceName()); if (validateTags.isRight()) { ResponseFormat responseFormat = validateTags.right().value();
+ * componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null); return Either.right(responseFormat); } ValidationUtils.removeDuplicateFromList(tagsList); return Either.left(true);
+ *
+ * }
+ *
+ * private Either<Boolean, ResponseFormat> validateResourceTags(List<String> tags, String resourceName) { log.debug("validate resource tags"); boolean includesResourceName = false; int tagListSize = 0; if (tags != null && !tags.isEmpty()) { for
+ * (String tag : tags) { if (!ValidationUtils.validateTagLength(tag)) { log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH); return Either.right(componentsUtils.getResponseFormat(ActionStatus.
+ * COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH)); } if (ValidationUtils.validateComponentNamePattern(tag)) { if (!includesResourceName) { includesResourceName = resourceName.equals(tag); } } else {
+ * log.debug("invalid tag {}", tag); return Either.right(componentsUtils.getResponseFormat(ActionStatus. COMPONENT_INVALID_TAG)); } tagListSize += tag.length() + 1; } if (!includesResourceName) { log.debug( "tags must include resource name");
+ * return Either.right(componentsUtils.getResponseFormat(ActionStatus. COMPONENT_INVALID_TAGS_NO_COMP_NAME)); } if (!ValidationUtils.validateTagListLength(tagListSize)) { log.debug( "overall tags length {}, exceeds limit {}", tagListSize,
+ * ValidationUtils.TAG_LIST_MAX_LENGTH); return Either.right(componentsUtils.getResponseFormat(ActionStatus. COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH)); } return Either.left(true); }
+ *
+ * return Either.right(componentsUtils.getResponseFormat(ActionStatus. COMPONENT_MISSING_TAGS)); }
+ */
+
+ private Either<Boolean, ResponseFormat> validateCategory(User user, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
+
+ List<CategoryDefinition> categories = resource.getCategories();
+ if (categories == null || categories.size() == 0) {
+ log.debug("Resource category is empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+ if (categories.size() > 1) {
+ log.debug("Must be only one category for resource");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue());
+ return Either.right(responseFormat);
+ }
+ CategoryDefinition category = categories.get(0);
+ List<SubCategoryDefinition> subcategories = category.getSubcategories();
+ if (subcategories == null || subcategories.size() == 0) {
+ log.debug("Missinig subcategory for resource");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ return Either.right(responseFormat);
+ }
+ if (subcategories.size() > 1) {
+ log.debug("Must be only one sub ategory for resource");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
+ return Either.right(responseFormat);
+ }
+
+ SubCategoryDefinition subcategory = subcategories.get(0);
+
+ if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ log.debug("Resource category is empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+ if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+ log.debug("Resource category is empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+
+ Either<Boolean, ResponseFormat> validateCategory = validateCategoryListed(category, subcategory, inTransaction);
+ if (validateCategory.isRight()) {
+ ResponseFormat responseFormat = validateCategory.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateCategoryListed(CategoryDefinition category, SubCategoryDefinition subcategory, boolean inTransaction) {
+ if (category != null && subcategory != null) {
+ log.debug("validating resource category {} against valid categories list", category);
+ Either<List<CategoryDefinition>, ActionStatus> categories = elementDao.getAllCategories(NodeTypeEnum.ResourceNewCategory, inTransaction);
+ if (categories.isRight()) {
+ log.debug("failed to retrive resource categories from Titan");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(categories.right().value());
+ return Either.right(responseFormat);
+ }
+ List<CategoryDefinition> categoryList = categories.left().value();
+ for (CategoryDefinition cat : categoryList) {
+ if (cat.getName().equals(category.getName())) {
+ for (SubCategoryDefinition subcat : cat.getSubcategories()) {
+ if (subcat.getName().equals(subcategory.getName())) {
+ return Either.left(true);
+ }
+ }
+ log.debug("SubCategory {} is not part of resource category group. Resource subcategory valid values are {}", subcategory, cat.getSubcategories());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()));
+ }
+ }
+ log.debug("Category {} is not part of resource category group. Resource category valid values are {}", category, categoryList);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()));
+ }
+ return Either.left(false);
+ }
+
+ public Either<Boolean, ResponseFormat> validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
+ String vendorRelease = resource.getVendorRelease();
+
+ log.debug("validate vendor relese name");
+ if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+ log.info("vendor relese name is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validateVendorReleaseResponse = validateVendorReleaseName(vendorRelease);
+ if (validateVendorReleaseResponse.isRight()) {
+ ResponseFormat responseFormat = validateVendorReleaseResponse.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ }
+ return validateVendorReleaseResponse;
+ }
+
+ public Either<Boolean, ResponseFormat> validateVendorReleaseName(String vendorRelease) {
+ if (vendorRelease != null) {
+ if (!ValidationUtils.validateVendorReleaseLength(vendorRelease)) {
+ log.info("vendor release exceds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+
+ if (!ValidationUtils.validateVendorRelease(vendorRelease)) {
+ log.info("vendor release is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_RELEASE);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ return Either.left(false);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateVendorName(User user, Resource resource, AuditingActionEnum actionEnum) {
+ String vendorName = resource.getVendorName();
+ if (!ValidationUtils.validateStringNotEmpty(vendorName)) {
+ log.info("vendor name is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
+ componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validateVendorNameResponse = validateVendorName(vendorName);
+ if (validateVendorNameResponse.isRight()) {
+ ResponseFormat responseFormat = validateVendorNameResponse.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ }
+ return validateVendorNameResponse;
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateVendorName(String vendorName) {
+ if (vendorName != null) {
+ if (!ValidationUtils.validateVendorNameLength(vendorName)) {
+ log.info("vendor name exceds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+
+ if (!ValidationUtils.validateVendorName(vendorName)) {
+ log.info("vendor name is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_NAME);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+
+ }
+ return Either.left(false);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateCost(User user, Resource resource, AuditingActionEnum actionEnum) {
+ String cost = resource.getCost();
+ if (cost != null) {
+
+ if (!ValidationUtils.validateCost(cost)) {
+ log.debug("resource cost is invalid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateLicenseType(User user, Resource resource, AuditingActionEnum actionEnum) {
+ log.debug("validate licenseType");
+ String licenseType = resource.getLicenseType();
+ if (licenseType != null) {
+ List<String> licenseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getLicenseTypes();
+ if (!licenseTypes.contains(licenseType)) {
+ log.debug("License type {} isn't configured");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ if (actionEnum != null) {
+ // In update case, no audit is required
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ }
+ return Either.right(responseFormat);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom(Resource currentResource, Resource updatedResource, String userId, boolean shouldLock, boolean inTransaction) {
+ Either<Operation, ResponseFormat> deleteArtifactByInterface = null;
+ if (updatedResource.getDerivedFrom() != null) {
+ log.debug("Starting derived from update for resource {}", updatedResource.getUniqueId());
+ log.debug("1. Removing interface artifacts from graph");
+ // Remove all interface artifacts of resource
+ String resourceId = updatedResource.getUniqueId();
+ Map<String, InterfaceDefinition> interfaces = currentResource.getInterfaces();
+
+ if (interfaces != null) {
+ Collection<InterfaceDefinition> values = interfaces.values();
+ for (InterfaceDefinition interfaceDefinition : values) {
+ String interfaceType = interfaceTypeOperation.getShortInterfaceName(interfaceDefinition);
+
+ log.trace("Starting interface artifacts removal for interface type {}", interfaceType);
+ Map<String, Operation> operations = interfaceDefinition.getOperations();
+ if (operations != null) {
+ for (Entry<String, Operation> operationEntry : operations.entrySet()) {
+ Operation operation = operationEntry.getValue();
+ ArtifactDefinition implementation = operation.getImplementation();
+ if (implementation != null) {
+ String uniqueId = implementation.getUniqueId();
+ log.debug("Removing interface artifact definition {}, operation {}, interfaceType {}", uniqueId, operationEntry.getKey(), interfaceType);
+ // only thing that transacts and locks here
+ deleteArtifactByInterface = artifactsBusinessLogic.deleteArtifactByInterface(resourceId, interfaceType, operationEntry.getKey(), userId, uniqueId, null, shouldLock, true);
+ if (deleteArtifactByInterface.isRight()) {
+ log.debug("Couldn't remove artifact definition with id {}", uniqueId);
+ if (!inTransaction) {
+ titanGenericDao.rollback();
+ }
+ return Either.right(deleteArtifactByInterface.right().value());
+ }
+ } else {
+ log.trace("No implementation found for operation {} - nothing to delete", operationEntry.getKey());
+ }
+ }
+ } else {
+ log.trace("No operations found for interface type {}", interfaceType);
+ }
+ }
+ }
+ log.debug("2. Removing properties");
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = propertyOperation.deleteAllPropertiesAssociatedToNode(NodeTypeEnum.Resource, resourceId);
+
+ if (findPropertiesOfNode.isRight() && !findPropertiesOfNode.right().value().equals(StorageOperationStatus.OK)) {
+ log.debug("Failed to remove all properties of resource");
+ if (!inTransaction)
+ titanGenericDao.rollback();
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(findPropertiesOfNode.right().value())));
+ }
+
+ } else {
+ log.debug("Derived from wasn't changed during update");
+ }
+
+ if (!inTransaction)
+ titanGenericDao.commit();
+ return Either.left(true);
+
+ }
+
+ /**** Auditing *******************/
+
+ protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+
+ return webApplicationContext.getBean(class1);
+ }
+
+ public ICapabilityTypeOperation getCapabilityTypeOperation() {
+ return capabilityTypeOperation;
+ }
+
+ public void setCapabilityTypeOperation(ICapabilityTypeOperation capabilityTypeOperation) {
+ this.capabilityTypeOperation = capabilityTypeOperation;
+ }
+
+ public Either<Boolean, ResponseFormat> validatePropertiesDefaultValues(Resource resource) {
+ log.debug("validate resource properties default values");
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ List<PropertyDefinition> properties = resource.getProperties();
+ String type = null;
+ String innerType = null;
+ if (properties != null) {
+ for (PropertyDefinition property : properties) {
+ if (!propertyOperation.isPropertyTypeValid(property)) {
+ log.info("Invalid type for property");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
+ eitherResult = Either.right(responseFormat);
+ break;
+ }
+
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ return Either.right(allDataTypes.right().value());
+ }
+
+ type = property.getType();
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes.left().value());
+ innerType = propertyInnerTypeValid.getLeft();
+ if (!propertyInnerTypeValid.getRight().booleanValue()) {
+ log.info("Invalid inner type for property");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
+ eitherResult = Either.right(responseFormat);
+ break;
+ }
+ }
+
+ if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes.left().value())) {
+ log.info("Invalid default value for property");
+ ResponseFormat responseFormat;
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType, property.getDefaultValue());
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
+ }
+ eitherResult = Either.right(responseFormat);
+ break;
+
+ }
+ }
+ }
+ return eitherResult;
+ }
+
+ @Override
+ public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
+ return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
+ }
+
+ @Override
+ public ComponentInstanceBusinessLogic getComponentInstanceBL() {
+ return vfComponentInstanceBusinessLogic;
+ }
+
+ private String getComponentTypeForResponse(Component component) {
+ String componentTypeForResponse = "SERVICE";
+ if (component instanceof Resource) {
+ componentTypeForResponse = ((Resource) component).getResourceType().name();
+ }
+ return componentTypeForResponse;
+ }
+
+ private Either<Map<String, GroupDefinition>, ResponseFormat> createGroupsFromYaml(String yamlFileName, Map<String, Object> toscaJson, Resource resource) {
+
+ Map<String, GroupDefinition> groups = new HashMap<String, GroupDefinition>();
+ Either<Map<String, GroupDefinition>, ResponseFormat> result = Either.left(groups);
+
+ Either<Map<String, Object>, ResultStatusEnum> eitherNodesTemlates = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.GROUPS);
+ if (eitherNodesTemlates.isLeft()) {
+ Map<String, Object> jsonNodeTemplates = eitherNodesTemlates.left().value();
+
+ if (jsonNodeTemplates != null && false == jsonNodeTemplates.isEmpty()) {
+ Iterator<Entry<String, Object>> nodesNameValue = jsonNodeTemplates.entrySet().iterator();
+ while (nodesNameValue.hasNext()) {
+ Entry<String, Object> groupNameValue = nodesNameValue.next();
+
+ String groupName = groupNameValue.getKey();
+ Either<GroupDefinition, ResponseFormat> eitherNode = createGroupInfo(groupName, groupNameValue.getValue());
+ if (eitherNode.isRight()) {
+ String message = "Failed when creating group: " + groupNameValue.getKey() + " for resource:" + resource.getName();
+ BeEcompErrorManager.getInstance().logInternalFlowError("ImportResource", message, ErrorSeverity.INFO);
+ return Either.right(eitherNode.right().value());
+ } else {
+ GroupDefinition groupDefinition = eitherNode.left().value();
+ groups.put(groupName, groupDefinition);
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private Either<Map<String, InputDefinition>, ResponseFormat> createInputsFromYaml(String yamlFileName, Map<String, Object> toscaJson, Resource resource) {
+
+ Either<Map<String, InputDefinition>, ResultStatusEnum> inputs = ImportUtils.getInputs(toscaJson);
+ if (inputs.isRight()) {
+ String message = "Failed when creating inputs: for resource:" + resource.getName();
+ BeEcompErrorManager.getInstance().logInternalFlowError("ImportResource", message, ErrorSeverity.INFO);
+ Map<String, InputDefinition> resultMap = new HashMap();
+ return Either.left(resultMap);
+
+ }
+
+ Either<Map<String, InputDefinition>, ResponseFormat> result = Either.left(inputs.left().value());
+
+ return result;
+ }
+
+ private Either<GroupDefinition, ResponseFormat> createGroupInfo(String groupName, Object groupTemplateJson) {
+
+ GroupDefinition groupInfo = new GroupDefinition();
+ groupInfo.setName(groupName);
+ Either<GroupDefinition, ResponseFormat> result = Either.left(groupInfo);
+
+ try {
+ if (groupTemplateJson != null && groupTemplateJson instanceof Map) {
+ Map<String, Object> groupTemplateJsonMap = (Map<String, Object>) groupTemplateJson;
+ // Type
+ String groupType = null;
+ if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ groupType = (String) groupTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName());
+ groupInfo.setType(groupType);
+ } else {
+ log.debug("The 'type' member is not found under group {}", groupName);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+ }
+
+ if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
+ groupInfo.setDescription((String) groupTemplateJsonMap.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
+ }
+
+ if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.MEMBERS.getElementName())) {
+ Object members = groupTemplateJsonMap.get(ToscaTagNamesEnum.MEMBERS.getElementName());
+ if (members != null) {
+ if (members instanceof List) {
+ Map<String, String> membersLoaded = new HashMap<>();
+ List<?> membersAsList = (List<?>) members;
+ for (Object member : membersAsList) {
+ membersLoaded.put(member.toString(), "");
+ }
+ groupInfo.setMembers(membersLoaded);
+ } else {
+ log.debug("The 'type' member is not found under group {}", groupName);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+ }
+ }
+ }
+
+ if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
+ Object properties = groupTemplateJsonMap.get(ToscaTagNamesEnum.PROPERTIES.getElementName());
+
+ Either<List<GroupProperty>, ResponseFormat> regResponse = createPropertiesValueModuleFromYaml(properties, groupName, groupType);
+ if (regResponse.isRight())
+ return Either.right(regResponse.right().value());
+ if (regResponse.left().value().size() > 0) {
+ groupInfo.setProperties(regResponse.left().value());
+ }
+ }
+
+ } else {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create group");
+ log.debug("error when creating group, message:{}", e.getMessage(), e);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ }
+
+ return result;
+ }
+
+ private Either<List<GroupProperty>, ResponseFormat> createPropertiesValueModuleFromYaml(Object properties, String groupName, String groupType) {
+
+ List<GroupProperty> result = new ArrayList<>();
+
+ if (properties == null) {
+ return Either.left(result);
+ }
+
+ Either<GroupTypeDefinition, StorageOperationStatus> groupTypeRes = groupTypeOperation.getLatestGroupTypeByType(groupType, true);
+
+ if (groupTypeRes.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupType));
+ }
+
+ Map<String, PropertyDefinition> gtProperties = new HashMap<>();
+ GroupTypeDefinition groupTypeDefinition = groupTypeRes.left().value();
+
+ List<PropertyDefinition> propertiesDef = groupTypeDefinition.getProperties();
+
+ if (propertiesDef != null) {
+ gtProperties = propertiesDef.stream().collect(Collectors.toMap(p -> p.getName(), p -> p));
+ }
+
+ if (properties != null) {
+
+ if (properties instanceof Map) {
+
+ Map<String, Object> props = (Map<String, Object>) properties;
+ for (Entry<String, Object> entry : props.entrySet()) {
+
+ String propName = entry.getKey();
+ Object value = entry.getValue();
+
+ PropertyDefinition gtDefinition = gtProperties.get(propName);
+ if (gtDefinition == null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_PROPERTY_NOT_FOUND, propName, groupName, groupType));
+ }
+
+ ToscaPropertyType type = ToscaPropertyType.isValidType(gtDefinition.getType());
+
+ String convertedValue = null;
+ if (value != null) {
+ if (type == null || value instanceof Map || value instanceof List) {
+ convertedValue = gson.toJson(value);
+ } else {
+ convertedValue = value.toString();
+ }
+ }
+
+ GroupProperty groupProperty = new GroupProperty();
+ groupProperty.setValue(convertedValue);
+ groupProperty.setName(propName);
+
+ log.debug("After building group property {}", groupProperty);
+
+ result.add(groupProperty);
+ }
+
+ }
+
+ }
+
+ return Either.left(result);
+ }
+
+ public Either<Resource, ResponseFormat> getLatestResourceFromCsarUuid(String csarUuid, User user) {
+
+ // validate user
+ if (user != null) {
+ Either<User, ResponseFormat> userValidation = validateUserExists(user, "Get resource from csar UUID", false);
+ if (userValidation.isRight()) {
+ return Either.right(userValidation.right().value());
+ }
+ }
+
+ // get resource from csar uuid
+ Either<Resource, StorageOperationStatus> either = resourceOperation.getLatestResourceByCsarOrName(csarUuid, "");
+ if (either.isRight()) {
+ ResponseFormat resp = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_FROM_CSAR_NOT_FOUND, csarUuid);
+ return Either.right(resp);
+ }
+
+ return Either.left(either.left().value());
+ }
+
+ @Override
+ public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
+ return null;
+ }
+
+ private Either<Map<String, List<CapabilityDefinition>>, ResponseFormat> getValidComponentInstanceCapabilities(Map<String, List<CapabilityDefinition>> defaultCapabilities, Map<String, List<UploadCapInfo>> uploadedCapabilities) {
+ ResponseFormat responseFormat;
+ Map<String, List<CapabilityDefinition>> validCapabilitiesMap = new HashMap<>();
+
+ for (Entry<String, List<UploadCapInfo>> uploadedCapabilitiesEntry : uploadedCapabilities.entrySet()) {
+ String capabilityType = uploadedCapabilitiesEntry.getValue().get(0).getType();
+ if (!defaultCapabilities.containsKey(capabilityType)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType);
+ return Either.right(responseFormat);
+ } else {
+ CapabilityDefinition delaultCapability = defaultCapabilities.get(capabilityType).get(0);
+ Either<Boolean, String> validationRes = validateUniquenessUpdateUploadedComponentInstanceCapability(delaultCapability, uploadedCapabilitiesEntry.getValue().get(0));
+ if (validationRes.isRight()) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, validationRes.right().value());
+ return Either.right(responseFormat);
+ }
+ List<CapabilityDefinition> validCapabilityList = new ArrayList<>();
+ validCapabilityList.add(delaultCapability);
+ validCapabilitiesMap.put(uploadedCapabilitiesEntry.getKey(), validCapabilityList);
+ }
+ }
+ return Either.left(validCapabilitiesMap);
+ }
+
+ private Either<Boolean, String> validateUniquenessUpdateUploadedComponentInstanceCapability(CapabilityDefinition defaultCapability, UploadCapInfo uploadedCapability) {
+ List<ComponentInstanceProperty> validProperties = new ArrayList<>();
+ Map<String, PropertyDefinition> defaultProperties = defaultCapability.getProperties().stream().collect(Collectors.toMap(PropertyDefinition::getName, Function.identity()));
+ List<UploadPropInfo> uploadedProperties = uploadedCapability.getProperties();
+ for (UploadPropInfo property : uploadedProperties) {
+ String propertyName = property.getName().toLowerCase();
+ String propertyType = property.getType();
+ ComponentInstanceProperty validProperty;
+ if (defaultProperties.containsKey(propertyName)) {
+ if (propertyType != null && !defaultProperties.get(propertyName).getType().equals(propertyType)) {
+ return Either.right(propertyName);
+ }
+ }
+ validProperty = new ComponentInstanceProperty();
+ validProperty.setName(propertyName);
+ if (property.getValue() != null)
+ validProperty.setValue(property.getValue().toString());
+ validProperty.setDescription(property.getDescription());
+ validProperty.setPassword(property.isPassword());
+ validProperties.add(validProperty);
+ }
+ defaultCapability.setProperties(validProperties);
+ return Either.left(true);
+ }
+
+ public ICacheMangerOperation getCacheManagerOperation() {
+ return cacheManagerOperation;
+ }
+
+ public void setCacheManagerOperation(ICacheMangerOperation cacheManagerOperation) {
+ this.cacheManagerOperation = cacheManagerOperation;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
new file mode 100644
index 0000000000..329481a546
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -0,0 +1,921 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.WebApplicationContext;
+import org.yaml.snakeyaml.Yaml;
+
+import fj.data.Either;
+
+@Component("resourceImportManager")
+public class ResourceImportManager {
+
+ private ServletContext servletContext;
+
+ @Autowired
+ private IAuditingManager auditingManager;
+
+ @Autowired
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @Autowired
+ private IGraphLockOperation graphLockOperation;
+
+ @Autowired
+ protected ComponentsUtils componentsUtils;
+
+ @Autowired
+ protected ResourceOperation resourceOperation;
+
+ @Autowired
+ protected CapabilityTypeOperation capabilityTypeOperation;
+
+ private ResponseFormatManager responseFormatManager;
+
+ private static Logger log = LoggerFactory.getLogger(ResourceImportManager.class.getName());
+
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
+
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
+ lifecycleChangeInfo.setUserRemarks("certification on import");
+ Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+
+ return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock);
+ }
+
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function<Resource, Either<Boolean, ResponseFormat>> validationFunction,
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock) {
+ Resource resource = new Resource();
+ ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<Resource, ActionStatus>(resource, ActionStatus.CREATED);
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
+
+ String latestCertifiedResourceId = null;
+ try {
+ setConstantMetaData(resource);
+ setMetaDataFromJson(resourceMetaData, resource);
+
+ Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource, isInTransaction);
+ if (validateResourceFromYaml.isRight()) {
+ ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
+ auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
+ return Either.right(validationErrorResponse);
+
+ }
+
+ Either<Boolean, ResponseFormat> isValidResource = validationFunction.apply(resource);
+ if (isValidResource.isLeft()) {
+ // The flag createNewVersion if false doesn't create new version
+ if (!createNewVersion) {
+ Either<Resource, StorageOperationStatus> latestByName = resourceOperation.getLatestByName(resource.getName(), isInTransaction);
+ if (latestByName.isLeft()) {
+ return Either.right(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource));
+ }
+ }
+
+ response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock);
+ if (response.isLeft()) {
+ resource = response.left().value().left;
+ latestCertifiedResourceId = getLatestCertifiedResourceId(resource);
+ Either<Resource, ResponseFormat> certificationResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock);
+ if (certificationResponse.isRight()) {
+ response = Either.right(certificationResponse.right().value());
+ } else {
+ responsePair = new ImmutablePair<Resource, ActionStatus>(certificationResponse.left().value(), response.left().value().right);
+ response = Either.left(responsePair);
+ }
+ }
+ } else {
+ ResponseFormat validationErrorResponse = isValidResource.right().value();
+ auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
+ response = Either.right(validationErrorResponse);
+ }
+
+ } catch (RuntimeException e) {
+ ResponseFormat exceptionResponse = handleImportResourceExecption(resourceMetaData, creator, true, e);
+ response = Either.right(exceptionResponse);
+ } finally {
+ if (latestCertifiedResourceId != null && needLock) {
+ log.debug("unlock resource {}", latestCertifiedResourceId);
+ graphLockOperation.unlockComponent(latestCertifiedResourceId, NodeTypeEnum.Resource);
+ }
+ }
+
+ return response;
+ }
+
+ private String getLatestCertifiedResourceId(Resource resource) {
+ Map<String, String> allVersions = resource.getAllVersions();
+ Double latestCertifiedVersion = 0.0;
+ if (allVersions != null) {
+ for (String version : allVersions.keySet()) {
+ Double dVersion = Double.valueOf(version);
+ if ((dVersion > latestCertifiedVersion) && (version.endsWith(".0"))) {
+ latestCertifiedVersion = dVersion;
+ }
+ }
+ return allVersions.get(String.valueOf(latestCertifiedVersion));
+ } else {
+ return null;
+ }
+ }
+
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isReusable, boolean isInTransaction) {
+
+ Resource resource = new Resource();
+ ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<Resource, ActionStatus>(resource, ActionStatus.CREATED);
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
+
+ try {
+ setMetaDataFromJson(resourceMetaData, resource);
+
+ Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource, isInTransaction);
+ if (validateResourceFromYaml.isRight()) {
+ ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
+ auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
+ return Either.right(validationErrorResponse);
+
+ }
+
+ // currently import VF isn't supported. In future will be supported
+ // import VF only with CSER file!!
+ if (ResourceTypeEnum.VF.equals(resource.getResourceType())) {
+ log.debug("Now import VF isn't supported. It will be supported in future with CSER file only");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = resourceBusinessLogic.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
+ if (validateDerivedFromNotEmpty.isRight()) {
+ return Either.right(validateDerivedFromNotEmpty.right().value());
+ }
+
+ Either<Boolean, ResponseFormat> validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+
+ if (validatePropertiesTypes.isLeft()) {
+ response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true);
+ } else {
+ ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value();
+ auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
+ response = Either.right(validationErrorResponse);
+ }
+
+ } catch (RuntimeException e) {
+ ResponseFormat exceptionResponse = handleImportResourceExecption(resourceMetaData, creator, false, e);
+ response = Either.right(exceptionResponse);
+ }
+
+ return response;
+
+ }
+
+ private Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource, boolean inTransaction) {
+ @SuppressWarnings("unchecked")
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ Map<String, Object> toscaJsonAll = (Map<String, Object>) new Yaml().load(resourceYml);
+ Map<String, Object> toscaJson = toscaJsonAll;
+
+ // Checks if exist and builds the node_types map
+ if (toscaJsonAll.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName())) {
+ toscaJson = new HashMap<String, Object>();
+ toscaJson.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(ToscaTagNamesEnum.NODE_TYPES.getElementName()));
+ }
+ // Derived From
+ Either<Resource, ResponseFormat> setDerivedFrom = setDerivedFrom(toscaJson, resource, inTransaction);
+ if (setDerivedFrom.isRight()) {
+ return Either.right(setDerivedFrom.right().value());
+ }
+ Resource parentResource = setDerivedFrom.left().value();
+ setToscaResourceName(toscaJson, resource);
+ setAttributes(toscaJson, resource);
+ eitherResult = setCapabilities(toscaJson, resource, parentResource);
+ if (eitherResult.isRight())
+ return eitherResult;
+ setProperties(toscaJson, resource);
+ eitherResult = setRequirements(toscaJson, resource, parentResource);
+ if (eitherResult.isRight())
+ return eitherResult;
+ setInterfaceLifecycle(toscaJson, resource);
+
+ return eitherResult;
+ }
+
+ private void setToscaResourceName(Map<String, Object> toscaJson, Resource resource) {
+ Either<Map<String, Object>, ResultStatusEnum> toscaElement = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TYPES);
+ if (toscaElement.isLeft() || toscaElement.left().value().size() == 1) {
+ String toscaResourceName = toscaElement.left().value().keySet().iterator().next();
+ resource.setToscaResourceName(toscaResourceName);
+ }
+ }
+
+ private void setInterfaceLifecycle(Map<String, Object> toscaJson, Resource resource) {
+ Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.INTERFACES);
+ if (toscaInterfaces.isLeft()) {
+ Map<String, Object> jsonInterfaces = toscaInterfaces.left().value();
+ Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<String, InterfaceDefinition>();
+ Iterator<Entry<String, Object>> interfacesNameValue = jsonInterfaces.entrySet().iterator();
+ while (interfacesNameValue.hasNext()) {
+ Entry<String, Object> interfaceNameValue = interfacesNameValue.next();
+ Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue.getValue());
+ if (eitherInterface.isRight()) {
+ log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName());
+ } else {
+ moduleInterfaces.put(interfaceNameValue.getKey(), eitherInterface.left().value());
+ }
+
+ }
+ if (moduleInterfaces.size() > 0) {
+ resource.setInterfaces(moduleInterfaces);
+ }
+ }
+ }
+
+ private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(Object interfaceJson) {
+ InterfaceDefinition interf = new InterfaceDefinition();
+ Either<InterfaceDefinition, ResultStatusEnum> result = Either.left(interf);
+
+ try {
+ if (interfaceJson instanceof String) {
+ String requirementJsonString = (String) interfaceJson;
+ interf.setType(requirementJsonString);
+ } else if (interfaceJson instanceof Map) {
+ Map<String, Object> requirementJsonMap = (Map<String, Object>) interfaceJson;
+ if (requirementJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ String type = (String) requirementJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName());
+ interf.setType(type);
+ interf.setUniqueId(type.toLowerCase());
+ }
+ } else {
+ result = Either.right(ResultStatusEnum.GENERAL_ERROR);
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource- create interface");
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface");
+ log.debug("error when creating interface, message:{}", e.getMessage(), e);
+ result = Either.right(ResultStatusEnum.GENERAL_ERROR);
+ }
+
+ return result;
+ }
+
+ private Either<Boolean, ResponseFormat> setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(toscaJson, ToscaTagNamesEnum.REQUIREMENTS);
+ if (toscaRequirements.isLeft()) {
+ List<Object> jsonRequirements = toscaRequirements.left().value();
+ Map<String, List<RequirementDefinition>> moduleRequirements = new HashMap<String, List<RequirementDefinition>>();
+ // Checking for name duplication
+ Set<String> reqNames = new HashSet<>();
+ // Getting flattened list of capabilities of parent node - cap name
+ // to cap type
+ Either<Map<String, String>, ResponseFormat> reqName2Type = getReqName2Type(parentResource);
+ if (reqName2Type.isRight()) {
+ ResponseFormat responseFormat = reqName2Type.right().value();
+ log.debug("Error during setting requirements of imported resource: {}", responseFormat);
+ return Either.right(responseFormat);
+ }
+ Map<String, String> reqName2TypeMap = reqName2Type.left().value();
+ for (Object jsonRequirementObj : jsonRequirements) {
+ // Requirement
+ Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
+ String requirementName = requirementJsonWrapper.keySet().iterator().next();
+ String reqNameLowerCase = requirementName.toLowerCase();
+ if (reqNames.contains(reqNameLowerCase)) {
+ log.debug("More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", reqNameLowerCase);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase));
+ }
+ reqNames.add(reqNameLowerCase);
+ Either<RequirementDefinition, ResponseFormat> eitherRequirement = createRequirementFromImportFile(requirementJsonWrapper.get(requirementName));
+ if (eitherRequirement.isRight()) {
+ log.info("error when creating Requirement:{}, for resource:{}", requirementName, resource.getName());
+ return Either.right(eitherRequirement.right().value());
+ }
+ RequirementDefinition requirementDef = eitherRequirement.left().value();
+ requirementDef.setName(requirementName);
+ if (moduleRequirements.containsKey(requirementDef.getCapability())) {
+ moduleRequirements.get(requirementDef.getCapability()).add(requirementDef);
+ } else {
+ List<RequirementDefinition> list = new ArrayList<RequirementDefinition>();
+ list.add(requirementDef);
+ moduleRequirements.put(requirementDef.getCapability(), list);
+ }
+
+ // Validating against req/cap of "derived from" node
+ Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef.getCapability(), requirementDef.getName());
+ if (validateVsParentCap.isRight()) {
+ return Either.right(validateVsParentCap.right().value());
+ }
+ if (!validateVsParentCap.left().value()) {
+ log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResource.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef.getName().toLowerCase(), parentResource.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ if (moduleRequirements.size() > 0) {
+ resource.setRequirements(moduleRequirements);
+ }
+
+ }
+ return eitherResult;
+
+ }
+
+ private Either<RequirementDefinition, ResponseFormat> createRequirementFromImportFile(Object requirementJson) {
+ RequirementDefinition requirement = new RequirementDefinition();
+ Either<RequirementDefinition, ResponseFormat> result = Either.left(requirement);
+
+ try {
+ if (requirementJson instanceof String) {
+ String requirementJsonString = (String) requirementJson;
+ requirement.setCapability(requirementJsonString);
+ } else if (requirementJson instanceof Map) {
+ Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
+ if (requirementJsonMap.containsKey(ToscaTagNamesEnum.CAPABILITY.getElementName())) {
+ requirement.setCapability((String) requirementJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName()));
+ }
+
+ if (requirementJsonMap.containsKey(ToscaTagNamesEnum.NODE.getElementName())) {
+ requirement.setNode((String) requirementJsonMap.get(ToscaTagNamesEnum.NODE.getElementName()));
+ }
+
+ if (requirementJsonMap.containsKey(ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
+ requirement.setRelationship((String) requirementJsonMap.get(ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
+ }
+ if (requirementJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+ List<Object> occurrencesList = (List) requirementJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName());
+ Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
+ if (validateAndSetOccurrencesStatus.isRight()) {
+ result = Either.right(validateAndSetOccurrencesStatus.right().value());
+ return result;
+ }
+ if (validateAndSetOccurrencesStatus.left().value() == true) {
+ requirement.setMinOccurrences(occurrencesList.get(0).toString());
+ requirement.setMaxOccurrences(occurrencesList.get(1).toString());
+ }
+
+ }
+ } else {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create Requirement");
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create Requirement");
+ log.debug("error when creating requirement, message:{}", e.getMessage(), e);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ }
+
+ return result;
+ }
+
+ private ResultStatusEnum setProperties(Map<String, Object> toscaJson, Resource resource) {
+ Map<String, Object> reducedToscaJson = new HashMap<>(toscaJson);
+ ImportUtils.removeElementFromJsonMap(reducedToscaJson, "capabilities");
+ ResultStatusEnum result = ResultStatusEnum.OK;
+ Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(reducedToscaJson);
+ if (properties.isLeft()) {
+ List<PropertyDefinition> propertiesList = new ArrayList<>();
+ Map<String, PropertyDefinition> value = properties.left().value();
+ if (value != null) {
+ for (Entry<String, PropertyDefinition> entry : value.entrySet()) {
+ String name = entry.getKey();
+ PropertyDefinition propertyDefinition = entry.getValue();
+ propertyDefinition.setName(name);
+ propertiesList.add(propertyDefinition);
+ }
+ }
+ resource.setProperties(propertiesList);
+ } else {
+ result = properties.right().value();
+ }
+ return result;
+ }
+
+ private ResultStatusEnum setAttributes(Map<String, Object> toscaJson, Resource resource) {
+ ResultStatusEnum result = ResultStatusEnum.OK;
+ Either<Map<String, AttributeDefinition>, ResultStatusEnum> attributes = ImportUtils.getAttributes(toscaJson);
+ if (attributes.isLeft()) {
+ List<AttributeDefinition> attributeList = new ArrayList<>();
+ Map<String, AttributeDefinition> value = attributes.left().value();
+ if (value != null) {
+ for (Entry<String, AttributeDefinition> entry : value.entrySet()) {
+ String name = entry.getKey();
+ AttributeDefinition attributeDef = entry.getValue();
+ attributeDef.setName(name);
+ attributeList.add(attributeDef);
+ }
+ }
+ resource.setAttributes(attributeList);
+ } else {
+ result = attributes.right().value();
+ }
+ return result;
+ }
+
+ private Either<Resource, ResponseFormat> setDerivedFrom(Map<String, Object> toscaJson, Resource resource, boolean inTransaction) {
+ Either<String, ResultStatusEnum> toscaDerivedFromElement = ImportUtils.findFirstToscaStringElement(toscaJson, ToscaTagNamesEnum.DERIVED_FROM);
+ Resource derivedFromResource = null;
+ if (toscaDerivedFromElement.isLeft()) {
+ String derivedFrom = toscaDerivedFromElement.left().value();
+ log.debug("Derived from TOSCA name is {}", derivedFrom);
+ resource.setDerivedFrom(Arrays.asList(new String[] { derivedFrom }));
+ Either<Resource, StorageOperationStatus> latestByToscaResourceName = resourceOperation.getLatestByToscaResourceName(derivedFrom, inTransaction);
+ if (latestByToscaResourceName.isRight()) {
+ StorageOperationStatus operationStatus = latestByToscaResourceName.right().value();
+ if (operationStatus.equals(StorageOperationStatus.NOT_FOUND)) {
+ operationStatus = StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND;
+ }
+ log.debug("Error when fetching parent resource {}, error: {}", derivedFrom, operationStatus);
+ ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus);
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom);
+ return Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, derivedFrom));
+ }
+ derivedFromResource = latestByToscaResourceName.left().value();
+ }
+ return Either.left(derivedFromResource);
+ }
+
+ private Either<Boolean, ResponseFormat> setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ Either<Map<String, Object>, ResultStatusEnum> toscaCapabilities = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.CAPABILITIES);
+ if (toscaCapabilities.isLeft()) {
+ Map<String, Object> jsonCapabilities = toscaCapabilities.left().value();
+ Map<String, List<CapabilityDefinition>> moduleCapabilities = new HashMap<String, List<CapabilityDefinition>>();
+ Iterator<Entry<String, Object>> capabilitiesNameValue = jsonCapabilities.entrySet().iterator();
+ Set<String> capNames = new HashSet<>();
+ // Getting flattened list of capabilities of parent node - cap name
+ // to cap type
+ Either<Map<String, String>, ResponseFormat> capName2Type = getCapName2Type(parentResource);
+ if (capName2Type.isRight()) {
+ ResponseFormat responseFormat = capName2Type.right().value();
+ log.debug("Error during setting capabilities of imported resource: {}", responseFormat);
+ return Either.right(responseFormat);
+ }
+ Map<String, String> capName2TypeMap = capName2Type.left().value();
+ while (capabilitiesNameValue.hasNext()) {
+ Entry<String, Object> capabilityNameValue = capabilitiesNameValue.next();
+
+ // Validating that no req/cap duplicates exist in imported YAML
+ String capNameLowerCase = capabilityNameValue.getKey().toLowerCase();
+ if (capNames.contains(capNameLowerCase)) {
+ log.debug("More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", capNameLowerCase);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase));
+ }
+ capNames.add(capNameLowerCase);
+
+ Either<CapabilityDefinition, ResponseFormat> eitherCapability = createCapabilityFromImportFile(capabilityNameValue.getValue());
+ if (eitherCapability.isRight()) {
+ log.debug("error when creating capability:{}, for resource:{}", capabilityNameValue.getKey(), resource.getName());
+ return Either.right(eitherCapability.right().value());
+ }
+
+ CapabilityDefinition capabilityDef = eitherCapability.left().value();
+ capabilityDef.setName(capabilityNameValue.getKey());
+ if (moduleCapabilities.containsKey(capabilityDef.getType())) {
+ moduleCapabilities.get(capabilityDef.getType()).add(capabilityDef);
+ } else {
+ List<CapabilityDefinition> list = new ArrayList<CapabilityDefinition>();
+ list.add(capabilityDef);
+ moduleCapabilities.put(capabilityDef.getType(), list);
+ }
+
+ // Validating against req/cap of "derived from" node
+ Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef.getType(), capabilityDef.getName());
+ if (validateVsParentCap.isRight()) {
+ return Either.right(validateVsParentCap.right().value());
+ }
+ if (!validateVsParentCap.left().value()) {
+ // Here parentResource is for sure not null, so it's
+ // null-safe
+ log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResource.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef.getName().toLowerCase(), parentResource.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ if (moduleCapabilities.size() > 0) {
+ resource.setCapabilities(moduleCapabilities);
+ }
+ }
+
+ return eitherResult;
+
+ }
+
+ private Either<Map<String, String>, ResponseFormat> getCapName2Type(Resource parentResource) {
+ Map<String, String> capName2type = new HashMap<>();
+ if (parentResource != null) {
+ Map<String, List<CapabilityDefinition>> capabilities = parentResource.getCapabilities();
+ if (capabilities != null) {
+ for (List<CapabilityDefinition> capDefinitions : capabilities.values()) {
+ for (CapabilityDefinition capDefinition : capDefinitions) {
+ String nameLowerCase = capDefinition.getName().toLowerCase();
+ if (capName2type.get(nameLowerCase) != null) {
+ String parentResourceName = parentResource.getName();
+ log.debug("Resource with name {} has more than one capability with name {}, ignoring case", parentResourceName, nameLowerCase);
+ BeEcompErrorManager.getInstance().logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more capabilities with name " + nameLowerCase, ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ capName2type.put(nameLowerCase, capDefinition.getType());
+ }
+ }
+ }
+ }
+ return Either.left(capName2type);
+ }
+
+ private Either<Map<String, String>, ResponseFormat> getReqName2Type(Resource parentResource) {
+ Map<String, String> reqName2type = new HashMap<>();
+ if (parentResource != null) {
+ Map<String, List<RequirementDefinition>> requirements = parentResource.getRequirements();
+ if (requirements != null) {
+ for (List<RequirementDefinition> reqDefinitions : requirements.values()) {
+ for (RequirementDefinition reqDefinition : reqDefinitions) {
+ String nameLowerCase = reqDefinition.getName().toLowerCase();
+ if (reqName2type.get(nameLowerCase) != null) {
+ String parentResourceName = parentResource.getName();
+ log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", parentResourceName, nameLowerCase);
+ BeEcompErrorManager.getInstance().logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more requirements with name " + nameLowerCase, ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ reqName2type.put(nameLowerCase, reqDefinition.getCapability());
+ }
+ }
+ }
+ }
+ return Either.left(reqName2type);
+ }
+
+ private Either<Boolean, ResponseFormat> validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
+ String capNameLowerCase = reqCapName.toLowerCase();
+ log.trace("Validating capability {} vs parent resource", capNameLowerCase);
+ String parentCapType = parentCapName2Type.get(capNameLowerCase);
+ if (parentCapType != null) {
+ if (childCapabilityType.equals(parentCapType)) {
+ log.debug("Capability with name {} is of same type {} for imported resource and its parent - this is OK", capNameLowerCase, childCapabilityType);
+ return Either.left(true);
+ }
+ Either<Boolean, StorageOperationStatus> capabilityTypeDerivedFrom = capabilityTypeOperation.isCapabilityTypeDerivedFrom(childCapabilityType, parentCapType);
+ if (capabilityTypeDerivedFrom.isRight()) {
+ log.debug("Couldn't check whether imported resource capability derives from its parent's capability");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom.right().value()));
+ return Either.right(responseFormat);
+ }
+ return Either.left(capabilityTypeDerivedFrom.left().value());
+ }
+ return Either.left(true);
+ }
+
+ private Either<CapabilityDefinition, ResponseFormat> createCapabilityFromImportFile(Object capabilityJson) {
+
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ Either<CapabilityDefinition, ResponseFormat> result = Either.left(capabilityDefinition);
+
+ try {
+ if (capabilityJson instanceof String) {
+ String capabilityJsonString = (String) capabilityJson;
+ capabilityDefinition.setType(capabilityJsonString);
+ } else if (capabilityJson instanceof Map) {
+ Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
+ // Type
+ if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ capabilityDefinition.setType((String) capabilityJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()));
+ }
+ // ValidSourceTypes
+ if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
+ capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName()));
+ }
+ // ValidSourceTypes
+ if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
+ capabilityDefinition.setDescription((String) capabilityJsonMap.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
+ }
+ if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+ List<Object> occurrencesList = (List) capabilityJsonMap.get(ToscaTagNamesEnum.OCCURRENCES.getElementName());
+ Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
+ if (validateAndSetOccurrencesStatus.isRight()) {
+ result = Either.right(validateAndSetOccurrencesStatus.right().value());
+ return result;
+ }
+ if (validateAndSetOccurrencesStatus.left().value() == true) {
+ capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
+ capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
+ }
+ }
+ if (capabilityJsonMap.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
+
+ Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
+ if (propertiesRes.isRight()) {
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
+ return result;
+ } else {
+ propertiesRes.left().value().entrySet().stream().forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
+ List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left().value().values().stream().map(p -> new ComponentInstanceProperty(p, p.getDefaultValue(), null)).collect(Collectors.toList());
+ capabilityDefinition.setProperties(capabilityProperties);
+ }
+ }
+ } else {
+
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create capability");
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
+ log.debug("error when creating capability, message:{}", e.getMessage(), e);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ }
+
+ return result;
+ }
+
+ private ResponseFormat handleImportResourceExecption(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e) {
+ String payloadName = (resourceMetaData != null) ? resourceMetaData.getPayloadName() : "";
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource " + payloadName);
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource " + payloadName);
+
+ log.debug("Error when importing resource from payload:{} Exception text: {}", payloadName, e.getMessage(), e);
+ ResponseFormat errorResponseWrapper = getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ auditErrorImport(resourceMetaData, user, errorResponseWrapper, isNormative);
+ return errorResponseWrapper;
+ }
+
+ private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, boolean isNormative) {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, AuditingActionEnum.IMPORT_RESOURCE.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceMetaData.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, ComponentTypeEnum.RESOURCE.getValue());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, user.getUserId());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, errorResponseWrapper.getStatus());
+ String message = "";
+ if (errorResponseWrapper.getMessageId() != null) {
+ message = errorResponseWrapper.getMessageId() + ": ";
+ }
+ message += errorResponseWrapper.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, user.getFirstName() + " " + user.getLastName());
+
+ String version, lifeCycleState;
+ if (isNormative) {
+ version = Constants.FIRST_CERTIFIED_VERSION_VERSION;
+ lifeCycleState = LifecycleStateEnum.CERTIFIED.name();
+ } else {
+ version = "";
+ lifeCycleState = LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name();
+
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, version);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, lifeCycleState);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TOSCA_NODE_TYPE, "");
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ private void setMetaDataFromJson(UploadResourceInfo resourceMetaData, Resource resource) {
+ resource.setTags(resourceMetaData.getTags());
+ List<CategoryDefinition> categories = resourceMetaData.getCategories();
+ resource.setCategories(categories);
+ resource.setDescription(resourceMetaData.getDescription());
+ resource.setIcon(resourceMetaData.getResourceIconPath());
+ resource.setName(resourceMetaData.getName());
+ if (categories != null && !categories.isEmpty()) {
+ CategoryDefinition categoryDef = categories.get(0);
+ resource.setAbstract(false);
+ if (categoryDef != null && categoryDef.getName() != null && categoryDef.getName().equals(Constants.ABSTRACT_CATEGORY_NAME)) {
+ SubCategoryDefinition subCategoryDef = categoryDef.getSubcategories().get(0);
+ if (subCategoryDef != null && subCategoryDef.getName().equals(Constants.ABSTRACT_SUBCATEGORY)) {
+ resource.setAbstract(true);
+ }
+ }
+ }
+ resource.setContactId(resourceMetaData.getContactId());
+ resource.setCreatorUserId(resourceMetaData.getContactId());
+
+ if (resourceMetaData.getVendorName() != null) {
+ resource.setVendorName(resourceMetaData.getVendorName());
+ }
+
+ if (resourceMetaData.getVendorRelease() != null) {
+ resource.setVendorRelease(resourceMetaData.getVendorRelease());
+ }
+
+ resource.setResourceType(ResourceTypeEnum.valueOf(resourceMetaData.getResourceType()));
+
+ }
+
+ private void setConstantMetaData(Resource resource) {
+ resource.setVersion(ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION);
+ ;
+ resource.setLifecycleState(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE);
+ resource.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
+ resource.setVendorName(ImportUtils.Constants.VENDOR_NAME);
+ resource.setVendorRelease(ImportUtils.Constants.VENDOR_RELEASE);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateOccurrences(List<Object> occurrensesList) {
+
+ if (!ValidationUtils.validateListNotEmpty(occurrensesList)) {
+ log.debug("Occurrenses list empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+
+ if (occurrensesList.size() < 2) {
+ log.debug("Occurrenses list size not 2");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+ Object minObj = occurrensesList.get(0);
+ Object maxObj = occurrensesList.get(1);
+ Integer minOccurrences = null;
+ Integer maxOccurrences = null;
+ if (minObj instanceof Integer)
+ minOccurrences = (Integer) minObj;
+ else {
+ log.debug("Invalid occurrenses format. low_bound occurrense must be Integer {}", minObj);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+ if (minOccurrences < 0) {
+ log.debug("Invalid occurrenses format.low_bound occurrense negative {}", minOccurrences);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+
+ if (maxObj instanceof String) {
+ if (maxObj.equals("UNBOUNDED")) {
+ return Either.left(true);
+ } else {
+ log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+ } else {
+ if (maxObj instanceof Integer)
+ maxOccurrences = (Integer) maxObj;
+ else {
+ log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+
+ if (maxOccurrences <= 0 || maxOccurrences < minOccurrences) {
+ log.debug("Invalid occurrenses format. min occurrence is {}. Max occurrence is {}", minOccurrences, maxOccurrences);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
+ return Either.right(responseFormat);
+ }
+ }
+
+ return Either.left(true);
+
+ }
+
+ public void init(ServletContext servletContext) {
+ if (this.servletContext == null) {
+ synchronized (this) {
+ if (this.servletContext == null) {
+ this.servletContext = servletContext;
+ responseFormatManager = ResponseFormatManager.getInstance();
+ resourceBusinessLogic = getResourceBL(servletContext);
+ }
+ }
+ }
+ }
+
+ public boolean isResourceExist(String resourceName) {
+ return resourceBusinessLogic.isResourceExist(resourceName);
+ }
+
+ private ResourceBusinessLogic getResourceBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(org.openecomp.sdc.common.api.Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ResourceBusinessLogic resourceBl = webApplicationContext.getBean(ResourceBusinessLogic.class);
+ return resourceBl;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public IAuditingManager getAuditingManager() {
+ return auditingManager;
+ }
+
+ public ResponseFormatManager getResponseFormatManager() {
+ return responseFormatManager;
+ }
+
+ public void setResponseFormatManager(ResponseFormatManager responseFormatManager) {
+ this.responseFormatManager = responseFormatManager;
+ }
+
+ public ResourceBusinessLogic getResourceBusinessLogic() {
+ return resourceBusinessLogic;
+ }
+
+ public void setResourceBusinessLogic(ResourceBusinessLogic resourceBusinessLogic) {
+ this.resourceBusinessLogic = resourceBusinessLogic;
+ }
+
+ public Logger getLog() {
+ return log;
+ }
+
+ public static void setLog(Logger log) {
+ ResourceImportManager.log = log;
+ }
+
+ public IGraphLockOperation getGraphLockOperation() {
+ return graphLockOperation;
+ }
+
+ public void setGraphLockOperation(IGraphLockOperation graphLockOperation) {
+ this.graphLockOperation = graphLockOperation;
+ }
+
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public void setAuditingManager(IAuditingManager auditingManager) {
+ this.auditingManager = auditingManager;
+ }
+
+ public void setResourceOperation(ResourceOperation resourceOperation) {
+ this.resourceOperation = resourceOperation;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java
new file mode 100644
index 0000000000..e8c0bf3d8a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.ErrorConfiguration;
+import org.openecomp.sdc.be.config.ErrorInfo;
+import org.openecomp.sdc.be.config.ErrorInfo.ErrorInfoType;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.OkResponseInfo;
+import org.openecomp.sdc.exception.PolicyException;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.exception.ServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResponseFormatManager {
+
+ private volatile static ResponseFormatManager instance;
+ private static ConfigurationManager configurationManager;
+ private static Logger log = LoggerFactory.getLogger(ResponseFormatManager.class.getName());
+
+ public static ResponseFormatManager getInstance() {
+ if (instance == null) {
+
+ instance = init();
+ }
+ return instance;
+ }
+
+ private static synchronized ResponseFormatManager init() {
+ if (instance == null) {
+ instance = new ResponseFormatManager();
+ configurationManager = ConfigurationManager.getConfigurationManager();
+ }
+ return instance;
+ }
+
+ public ResponseFormat getResponseFormat(ActionStatus responseEnum, String... variables) {
+ ErrorConfiguration errorConfiguration = configurationManager.getErrorConfiguration();
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(responseEnum.name());
+ if (errorInfo == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.EcompErrorNotFound, "ResponseFormatManager", responseEnum.name());
+ log.debug("failed to locate {} in error configuration", responseEnum.name());
+ errorInfo = errorConfiguration.getErrorInfo(ActionStatus.GENERAL_ERROR.name());
+ }
+ ResponseFormat errorResponseWrapper = new ResponseFormat(errorInfo.getCode());
+ String errorMessage = errorInfo.getMessage();
+ String errorMessageId = errorInfo.getMessageId();
+ ErrorInfoType errorInfoType = errorInfo.getErrorInfoType();
+ if (errorInfoType.equals(ErrorInfoType.SERVICE_EXCEPTION)) {
+ errorResponseWrapper.setServiceException(new ServiceException(errorMessageId, errorMessage, variables));
+ } else if (errorInfoType.equals(ErrorInfoType.POLICY_EXCEPTION)) {
+ errorResponseWrapper.setPolicyException(new PolicyException(errorMessageId, errorMessage, variables));
+ } else if (errorInfoType.equals(ErrorInfoType.OK)) {
+ errorResponseWrapper.setOkResponseInfo(new OkResponseInfo(errorMessageId, errorMessage, variables));
+ }
+ return errorResponseWrapper;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
new file mode 100644
index 0000000000..6bbe88f30c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -0,0 +1,1768 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
+import org.openecomp.sdc.be.components.distribution.engine.INotificationData;
+import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GroupTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.DistributionTransitionEnum;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
+import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("serviceBusinessLogic")
+public class ServiceBusinessLogic extends ComponentBusinessLogic {
+
+ private static final String STATUS_SUCCESS_200 = "200";
+
+ private static final String STATUS_DEPLOYED = "DEPLOYED";
+
+ @Autowired
+ private IElementOperation elementDao;
+
+ @Autowired
+ private IDistributionEngine distributionEngine;
+
+ // @Autowired
+ // private AuditingDao auditingDao;
+
+ @Autowired
+ private AuditCassandraDao auditCassandraDao;
+
+ @Autowired
+ private ServiceComponentInstanceBusinessLogic serviceComponentInstanceBusinessLogic;
+
+ @Autowired
+ private ICacheMangerOperation cacheManagerOperation;
+
+ private static Logger log = LoggerFactory.getLogger(ServiceBusinessLogic.class.getName());
+ private static final String INITIAL_VERSION = "0.1";
+
+ public ServiceBusinessLogic() {
+ log.debug("ServiceBusinessLogic started");
+ }
+
+ public Either<Service, ResponseFormat> changeServiceDistributionState(String serviceId, String state, LifecycleChangeInfoWithAction commentObj, User user) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "change Service Distribution State", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ log.debug("check request state");
+ Either<DistributionTransitionEnum, ResponseFormat> validateEnum = validateTransitionEnum(state, user);
+ if (validateEnum.isRight()) {
+ return Either.right(validateEnum.right().value());
+ }
+ DistributionTransitionEnum distributionTransition = validateEnum.left().value();
+ AuditingActionEnum auditAction = (distributionTransition == DistributionTransitionEnum.APPROVE ? AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_APPROV : AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REJECT);
+ Either<String, ResponseFormat> commentResponse = validateComment(commentObj, user, auditAction);
+ if (commentResponse.isRight()) {
+ return Either.right(commentResponse.right().value());
+ }
+ String comment = commentResponse.left().value();
+
+ Either<Service, ResponseFormat> validateService = validateServiceDistributionChange(user, serviceId, auditAction, comment);
+ if (validateService.isRight()) {
+ return Either.right(validateService.right().value());
+ }
+ Service service = validateService.left().value();
+ DistributionStatusEnum initState = service.getDistributionStatus();
+
+ Either<User, ResponseFormat> validateUser = validateUserDistributionChange(user, service, auditAction, comment);
+ if (validateUser.isRight()) {
+ return Either.right(validateUser.right().value());
+ }
+ user = validateUser.left().value();
+
+ // lock resource
+ /*
+ * StorageOperationStatus lockResult = graphLockOperation.lockComponent(serviceId, NodeTypeEnum.Service); if (!lockResult.equals(StorageOperationStatus.OK)) { BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.
+ * BeFailedLockObjectError, "ChangeServiceDistributionState"); log.debug("Failed to lock service {} error - {}", serviceId, lockResult); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR,
+ * service.getVersion(), service.getServiceName());
+ *
+ * createAudit(user, auditAction, comment, service, responseFormat); return Either.right(componentsUtils.getResponseFormat(ActionStatus. GENERAL_ERROR)); }
+ */
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "ChangeServiceDistributionState");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ createAudit(user, auditAction, comment, service, responseFormat);
+ return Either.right(responseFormat);
+ }
+
+ try {
+
+ DistributionStatusEnum newState;
+ if (distributionTransition == DistributionTransitionEnum.APPROVE) {
+ newState = DistributionStatusEnum.DISTRIBUTION_APPROVED;
+ } else {
+ newState = DistributionStatusEnum.DISTRIBUTION_REJECTED;
+ }
+ Either<Service, StorageOperationStatus> result = serviceOperation.updateDestributionStatus(service, user, newState);
+ if (result.isRight()) {
+ titanGenericDao.rollback();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "ChangeServiceDistributionState");
+ BeEcompErrorManager.getInstance().logBeSystemError("ChangeServiceDistributionState");
+ log.debug("service {} is change destribuation status failed", service.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, service.getVersion(), service.getName());
+ createAudit(user, auditAction, comment, service, responseFormat);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ titanGenericDao.commit();
+ Service updatedService = result.left().value();
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS, updatedService.getDistributionStatus().name());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, initState.name());
+ createAudit(user, auditAction, comment, updatedService, responseFormat, auditingFields);
+ return Either.left(result.left().value());
+
+ } finally {
+ graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
+ }
+
+ }
+
+ public Either<List<Map<String, Object>>, ResponseFormat> getComponentAuditRecords(String componentVersion, String componentUUID, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Component Audit Records", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<List<Map<String, Object>>, ActionStatus> result;
+ try {
+
+ // Certified Version
+ if (componentVersion.endsWith(".0")) {
+ Either<List<ResourceAdminEvent>, ActionStatus> eitherAuditingForCertified = auditCassandraDao.getByServiceInstanceId(componentUUID);
+ if (eitherAuditingForCertified.isLeft()) {
+ result = Either.left(getAuditingFieldsList(eitherAuditingForCertified.left().value()));
+ } else {
+ result = Either.right(eitherAuditingForCertified.right().value());
+ }
+ }
+ // Uncertified Version
+ else {
+ result = getAuditRecordsForUncertifiedComponent(componentUUID, componentVersion);
+ }
+ } catch (Exception e) {
+ log.debug("get Audit Records failed with exception {}", e);
+ result = Either.right(ActionStatus.GENERAL_ERROR);
+ }
+
+ if (result.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(result.right().value()));
+ } else {
+ return Either.left(result.left().value());
+ }
+
+ }
+
+ private Either<List<Map<String, Object>>, ActionStatus> getAuditRecordsForUncertifiedComponent(String componentUUID, String componentVersion) {
+ // First Query
+ Either<List<ResourceAdminEvent>, ActionStatus> eitherprevVerAudit = auditCassandraDao.getAuditByServiceIdAndPrevVersion(componentUUID, componentVersion);
+
+ if (eitherprevVerAudit.isRight()) {
+ return Either.right(eitherprevVerAudit.right().value());
+ }
+
+ // Second Query
+ Either<List<ResourceAdminEvent>, ActionStatus> eitherCurrVerAudit = auditCassandraDao.getAuditByServiceIdAndCurrVersion(componentUUID, componentVersion);
+ if (eitherCurrVerAudit.isRight()) {
+ return Either.right(eitherCurrVerAudit.right().value());
+ }
+
+ List<Map<String, Object>> prevVerAuditList = getAuditingFieldsList(eitherprevVerAudit.left().value());
+ List<Map<String, Object>> currVerAuditList = getAuditingFieldsList(eitherCurrVerAudit.left().value());
+
+ List<Map<String, Object>> duplicateElements = new ArrayList<Map<String, Object>>();
+ duplicateElements.addAll(prevVerAuditList);
+ duplicateElements.retainAll(currVerAuditList);
+
+ List<Map<String, Object>> joinedNonDuplicatedList = new ArrayList<Map<String, Object>>();
+ joinedNonDuplicatedList.addAll(prevVerAuditList);
+ joinedNonDuplicatedList.removeAll(duplicateElements);
+ joinedNonDuplicatedList.addAll(currVerAuditList);
+
+ return Either.left(joinedNonDuplicatedList);
+ }
+
+ private List<Map<String, Object>> getAuditingFieldsList(List<? extends AuditingGenericEvent> prevVerAuditList) {
+
+ List<Map<String, Object>> prevVerAudit = new ArrayList<Map<String, Object>>();
+ for (AuditingGenericEvent auditEvent : prevVerAuditList) {
+ auditEvent.fillFields();
+ prevVerAudit.add(auditEvent.getFields());
+ }
+ return prevVerAudit;
+ }
+
+ /**
+ * createService
+ *
+ * @param service
+ * - Service
+ * @param user
+ * - modifier data (userId)
+ * @return Either<Service, responseFormat>
+ */
+ public Either<Service, ResponseFormat> createService(Service service, User user) {
+
+ // get user details
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "Create Service", service, AuditingActionEnum.CREATE_RESOURCE, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ // validate user role
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, new ArrayList<Role>(), AuditingActionEnum.CREATE_RESOURCE, null);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+ service.setCreatorUserId(user.getUserId());
+
+ // warn on overridden fields
+ checkFieldsForOverideAttampt(service);
+ // enrich object
+ log.debug("enrich service with version and state");
+ service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setVersion(INITIAL_VERSION);
+ service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+
+ Either<Service, ResponseFormat> createServiceResponse = validateServiceBeforeCreate(service, user, AuditingActionEnum.CREATE_RESOURCE);
+ if (createServiceResponse.isRight()) {
+ return createServiceResponse;
+ }
+ return createServiceByDao(service, AuditingActionEnum.CREATE_RESOURCE, serviceOperation, user);
+ }
+
+ private void checkFieldsForOverideAttampt(Service service) {
+ checkComponentFieldsForOverrideAttempt(service);
+ if ((service.getDistributionStatus() != null)) {
+ log.info("Distribution Status cannot be defined by user. This field will be overridden by the application");
+ }
+ }
+
+ private Either<Service, ResponseFormat> createServiceByDao(Service service, AuditingActionEnum actionEnum, IServiceOperation dataModel, User user) {
+ log.debug("send service {} to dao for create", service.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(service.getSystemName(), service, "Create Service");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, service, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+ }
+
+ log.debug("System name locked is {}, status = {}", service.getSystemName(), lockResult);
+
+ try {
+
+ createMandatoryArtifactsData(service, user);
+ createServiceApiArtifactsData(service, user);
+ setToscaArtifactsPlaceHolders(service, user);
+
+ Either<Service, StorageOperationStatus> dataModelResponse = dataModel.createService(service);
+
+ // service created successfully!!!
+ if (dataModelResponse.isLeft()) {
+ log.debug("Service created successfully!!!");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditComponentAdmin(responseFormat, user, service, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ ASDCKpiApi.countCreatedServicesKPI();
+
+ Service createdService = dataModelResponse.left().value();
+ // //add service to cache
+ // cacheManagerOperation.updateComponentInCache(createdService.getUniqueId(),
+ // createdService.getLastUpdateDate(), NodeTypeEnum.Service);
+
+ return Either.left(dataModelResponse.left().value());
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), service, ComponentTypeEnum.SERVICE);
+ log.debug("audit before sending response");
+ componentsUtils.auditComponentAdmin(responseFormat, user, service, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+
+ } finally {
+ graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service);
+ }
+ }
+
+ private void createServiceApiArtifactsData(Service service, User user) {
+ // create mandatory artifacts
+
+ // TODO it must be removed after that artifact uniqueId creation will be
+ // moved to ArtifactOperation
+ // String serviceUniqueId =
+ // UniqueIdBuilder.buildServiceUniqueId(service.getComponentMetadataDefinition().getMetadataDataDefinition().getName(),
+ // service.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion());
+ String serviceUniqueId = service.getUniqueId();
+ Map<String, ArtifactDefinition> artifactMap = service.getArtifacts();
+ if (artifactMap == null)
+ artifactMap = new HashMap<String, ArtifactDefinition>();
+
+ Map<String, Object> serviceApiArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceApiArtifacts();
+ List<String> exludeServiceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeServiceCategory();
+
+ List<CategoryDefinition> categories = service.getCategories();
+ boolean isCreateArtifact = true;
+ if (categories != null && exludeServiceCategory != null && !exludeServiceCategory.isEmpty()) {
+ for (String exlude : exludeServiceCategory) {
+ if (exlude.equalsIgnoreCase(categories.get(0).getName())) {
+ isCreateArtifact = false;
+ break;
+ }
+ }
+
+ }
+
+ if (serviceApiArtifacts != null && isCreateArtifact) {
+ Set<String> keys = serviceApiArtifacts.keySet();
+ for (String serviceApiArtifactName : keys) {
+ Map<String, Object> artifactInfoMap = (Map<String, Object>) serviceApiArtifacts.get(serviceApiArtifactName);
+ ArtifactDefinition artifactDefinition = createArtifactDefinition(serviceUniqueId, serviceApiArtifactName, artifactInfoMap, user, true);
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.SERVICE_API);
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+ }
+
+ service.setArtifacts(artifactMap);
+ }
+ }
+
+ private Either<Service, ResponseFormat> validateServiceBeforeCreate(Service service, User user, AuditingActionEnum actionEnum) {
+
+ Either<Boolean, ResponseFormat> validationResponse = validateServiceFieldsBeforeCreate(user, service, actionEnum);
+ if (validationResponse.isRight()) {
+ return Either.right(validationResponse.right().value());
+ }
+ service.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ service.setContactId(service.getContactId().toLowerCase());
+
+ // Generate invariant UUID - must be here and not in operation since it
+ // should stay constant during clone
+ String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
+ service.setInvariantUUID(invariantUUID);
+
+ return Either.left(service);
+ }
+
+ private Either<Boolean, ResponseFormat> validateServiceFieldsBeforeCreate(User user, Service service, AuditingActionEnum actionEnum) {
+ Either<Boolean, ResponseFormat> componentsFieldsValidation = validateComponentFieldsBeforeCreate(user, service, actionEnum);
+ if (componentsFieldsValidation.isRight()) {
+ return componentsFieldsValidation;
+ }
+
+ // validate service name uniqueness
+ log.debug("validate service name uniqueness");
+ Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum);
+ if (serviceNameUniquenessValidation.isRight()) {
+ return serviceNameUniquenessValidation;
+ }
+
+ // validate category
+ log.debug("validate category");
+ Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum);
+ if (categoryValidation.isRight()) {
+ return categoryValidation;
+ }
+
+ log.debug("validate projectName");
+ Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, service, actionEnum);
+ if (projectCodeValidation.isRight()) {
+ return projectCodeValidation;
+ }
+
+ return Either.left(true);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateServiceCategory(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate Service category");
+
+ if (service.getCategories() == null || service.getCategories().size() == 0) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, service, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(errorResponse);
+ }
+
+ Either<Boolean, ResponseFormat> validatCategory = validateServiceCategory(service.getCategories());
+ if (validatCategory.isRight()) {
+ ResponseFormat responseFormat = validatCategory.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, service, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(true);
+ }
+
+ public Either<Map<String, Boolean>, ResponseFormat> validateServiceNameExists(String serviceName, String userId) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "validate Service Name Exists", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ Either<Boolean, StorageOperationStatus> dataModelResponse = serviceOperation.validateServiceNameExists(serviceName);
+
+ if (dataModelResponse.isLeft()) {
+ Map<String, Boolean> result = new HashMap<>();
+ result.put("isValid", dataModelResponse.left().value());
+ log.debug("validation was successfully performed.");
+ return Either.left(result);
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
+
+ return Either.right(responseFormat);
+ }
+
+ public void setElementDao(IElementOperation elementDao) {
+ this.elementDao = elementDao;
+ }
+
+ public void setServiceOperation(ServiceOperation serviceOperation) {
+ this.serviceOperation = serviceOperation;
+ }
+
+ public void setCassandraAuditingDao(AuditCassandraDao auditingDao) {
+ this.auditCassandraDao = auditingDao;
+ }
+
+ /*
+ * public void setUserAdmin(UserAdminBuisinessLogic userAdmin) { this.userAdmin = userAdmin; }
+ *
+ * public void setComponentsUtils(ComponentsUtils componentsUtils) { this.componentsUtils = componentsUtils; }
+ *
+ * public void setGraphLockOperation(IGraphLockOperation graphLockOperation) { this.graphLockOperation = graphLockOperation; }
+ */
+
+ public ArtifactsBusinessLogic getArtifactBl() {
+ return artifactsBusinessLogic;
+ }
+
+ public void setArtifactBl(ArtifactsBusinessLogic artifactBl) {
+ this.artifactsBusinessLogic = artifactBl;
+ }
+
+ public Either<Service, ResponseFormat> updateServiceMetadata(String serviceId, Service serviceUpdate, User user) {
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "updateServiceMetadata", serviceUpdate, null, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ // validate user role
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, serviceUpdate, new ArrayList<Role>(), null, null);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+
+ Either<Service, StorageOperationStatus> storageStatus = serviceOperation.getService(serviceId);
+ if (storageStatus.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
+ }
+
+ Service currentService = storageStatus.left().value();
+
+ if (!ComponentValidationUtils.canWorkOnService(currentService.getUniqueId(), serviceOperation, user.getUserId())) {
+ log.info("Restricted operation for user {} on service {}", user.getUserId(), currentService.getCreatorUserId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+
+ Either<Service, ResponseFormat> validationRsponse = validateAndUpdateServiceMetadata(user, currentService, serviceUpdate);
+ if (validationRsponse.isRight()) {
+ log.info("service update metadata: validations field.");
+ return validationRsponse;
+ }
+ Service serviceToUpdate = validationRsponse.left().value();
+ // lock resource
+
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, currentService, "Update Service Metadata");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+ try {
+ Either<Service, StorageOperationStatus> updateResponse = serviceOperation.updateService(serviceToUpdate, true);
+ if (updateResponse.isRight()) {
+ titanGenericDao.rollback();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Update Service Metadata");
+ BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
+ log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ titanGenericDao.commit();
+ return Either.left(updateResponse.left().value());
+ } finally {
+ graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
+ }
+ }
+
+ private Either<Service, ResponseFormat> validateAndUpdateServiceMetadata(User user, Service currentService, Service serviceUpdate) {
+
+ boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentService.getVersion());
+ Either<Boolean, ResponseFormat> response = validateAndUpdateCategory(user, currentService, serviceUpdate, hasBeenCertified, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ String creatorUserIdUpdated = serviceUpdate.getCreatorUserId();
+ String creatorUserIdCurrent = currentService.getCreatorUserId();
+ if (creatorUserIdUpdated != null && !creatorUserIdCurrent.equals(creatorUserIdUpdated)) {
+ log.info("update srvice: recived request to update creatorUserId to {} the field is not updatable ignoring.", creatorUserIdUpdated);
+ }
+
+ String creatorFullNameUpdated = serviceUpdate.getCreatorFullName();
+ String creatorFullNameCurrent = currentService.getCreatorFullName();
+ if (creatorFullNameUpdated != null && !creatorFullNameCurrent.equals(creatorFullNameUpdated)) {
+ log.info("update srvice: recived request to update creatorFullName to {} the field is not updatable ignoring.", creatorFullNameUpdated);
+ }
+
+ String lastUpdaterUserIdUpdated = serviceUpdate.getLastUpdaterUserId();
+ String lastUpdaterUserIdCurrent = currentService.getLastUpdaterUserId();
+ if (lastUpdaterUserIdUpdated != null && !lastUpdaterUserIdCurrent.equals(lastUpdaterUserIdUpdated)) {
+ log.info("update srvice: recived request to update lastUpdaterUserId to {} the field is not updatable ignoring.", lastUpdaterUserIdUpdated);
+ }
+
+ String lastUpdaterFullNameUpdated = serviceUpdate.getLastUpdaterFullName();
+ String lastUpdaterFullNameCurrent = currentService.getLastUpdaterFullName();
+ if (lastUpdaterFullNameUpdated != null && !lastUpdaterFullNameCurrent.equals(lastUpdaterFullNameUpdated)) {
+ log.info("update srvice: recived request to update lastUpdaterFullName to {} the field is not updatable ignoring.", lastUpdaterFullNameUpdated );
+ }
+
+ response = validateAndUpdateServiceName(user, currentService, serviceUpdate, hasBeenCertified, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ DistributionStatusEnum distributionStatusUpdated = serviceUpdate.getDistributionStatus();
+ DistributionStatusEnum distributionStatusCurrent = currentService.getDistributionStatus();
+ if (distributionStatusUpdated != null && !distributionStatusUpdated.name().equals((distributionStatusCurrent != null ? distributionStatusCurrent.name() : null))) {
+ log.info("update srvice: recived request to update distributionStatus to {} the field is not updatable ignoring.", distributionStatusUpdated);
+ }
+
+ if (serviceUpdate.getProjectCode() != null) {
+ response = validateAndUpdateProjectCode(user, currentService, serviceUpdate, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+ }
+
+ response = validateAndUpdateIcon(user, currentService, serviceUpdate, hasBeenCertified, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ Long creationDateUpdated = serviceUpdate.getCreationDate();
+ Long creationDateCurrent = currentService.getCreationDate();
+ if (creationDateUpdated != null && !creationDateCurrent.equals(creationDateUpdated)) {
+ log.info("update srvice: recived request to update creationDate to {} the field is not updatable ignoring.", creationDateUpdated);
+ }
+
+ String versionUpdated = serviceUpdate.getVersion();
+ String versionCurrent = currentService.getVersion();
+ if (versionUpdated != null && !versionCurrent.equals(versionUpdated)) {
+ log.info("update srvice: recived request to update version to {} the field is not updatable ignoring.", versionUpdated);
+ }
+
+ response = validateAndUpdateDescription(user, currentService, serviceUpdate, hasBeenCertified, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateTags(user, currentService, serviceUpdate, hasBeenCertified, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateContactId(user, currentService, serviceUpdate, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ Long lastUpdateDateUpdated = serviceUpdate.getLastUpdateDate();
+ Long lastUpdateDateCurrent = currentService.getLastUpdateDate();
+ if (lastUpdateDateUpdated != null && !lastUpdateDateCurrent.equals(lastUpdateDateUpdated)) {
+ log.info("update srvice: recived request to update lastUpdateDate to {} the field is not updatable ignoring.", lastUpdateDateUpdated);
+ }
+
+ LifecycleStateEnum lifecycleStateUpdated = serviceUpdate.getLifecycleState();
+ LifecycleStateEnum lifecycleStateCurrent = currentService.getLifecycleState();
+ if (lifecycleStateUpdated != null && !lifecycleStateCurrent.name().equals(lifecycleStateUpdated.name())) {
+ log.info("update srvice: recived request to update lifecycleState to {} the field is not updatable ignoring.", lifecycleStateUpdated);
+ }
+
+ Boolean isHighestVersionUpdated = serviceUpdate.isHighestVersion();
+ Boolean isHighestVersionCurrent = currentService.isHighestVersion();
+ if (isHighestVersionUpdated != null && !isHighestVersionCurrent.equals(isHighestVersionUpdated)) {
+ log.info("update srvice: recived request to update isHighestVersion to {} the field is not updatable ignoring.", isHighestVersionUpdated);
+ }
+
+ String uuidUpdated = serviceUpdate.getUUID();
+ String uuidCurrent = currentService.getUUID();
+ if (!uuidCurrent.equals(uuidUpdated)) {
+ log.info("update srvice: recived request to update uuid to {} the field is not updatable ignoring.", uuidUpdated);
+ }
+
+ String currentInvariantUuid = currentService.getInvariantUUID();
+ String updatedInvariantUuid = serviceUpdate.getInvariantUUID();
+
+ if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
+ log.warn("Product invariant UUID is automatically set and cannot be updated");
+ serviceUpdate.setInvariantUUID(currentInvariantUuid);
+ }
+ return Either.left(currentService);
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateContactId(User user, Service currentService, Service serviceUpdate, AuditingActionEnum audatingAction) {
+ String contactIdUpdated = serviceUpdate.getContactId();
+ String contactIdCurrent = currentService.getContactId();
+ if (!contactIdCurrent.equals(contactIdUpdated)) {
+ Either<Boolean, ResponseFormat> validatContactId = validateContactId(user, serviceUpdate, audatingAction);
+ if (validatContactId.isRight()) {
+ ResponseFormat errorRespons = validatContactId.right().value();
+ return Either.right(errorRespons);
+ }
+ currentService.setContactId(contactIdUpdated.toLowerCase());
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateTags(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ List<String> tagsUpdated = serviceUpdate.getTags();
+ List<String> tagsCurrent = currentService.getTags();
+ if (tagsUpdated == null || tagsUpdated.isEmpty()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS);
+ componentsUtils.auditComponentAdmin(responseFormat, user, serviceUpdate, "", "", audatingAction, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+ }
+
+ if (!(tagsCurrent.containsAll(tagsUpdated) && tagsUpdated.containsAll(tagsCurrent))) {
+ Either<Boolean, ResponseFormat> validatResponse = validateTagsListAndRemoveDuplicates(user, serviceUpdate, audatingAction);
+ if (validatResponse.isRight()) {
+ ResponseFormat errorRespons = validatResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentService.setTags(tagsUpdated);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ String descriptionUpdated = serviceUpdate.getDescription();
+ String descriptionCurrent = currentService.getDescription();
+ if (!descriptionCurrent.equals(descriptionUpdated)) {
+ Either<Boolean, ResponseFormat> validateDescriptionResponse = validateDescriptionAndCleanup(user, serviceUpdate, audatingAction);
+ if (validateDescriptionResponse.isRight()) {
+ ResponseFormat errorRespons = validateDescriptionResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentService.setDescription(serviceUpdate.getDescription());
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateProjectCode(User user, Service currentService, Service serviceUpdate, AuditingActionEnum audatingAction) {
+ String projectCodeUpdated = serviceUpdate.getProjectCode();
+ String projectCodeCurrent = currentService.getProjectCode();
+ if (!projectCodeCurrent.equals(projectCodeUpdated)) {
+ Either<Boolean, ResponseFormat> validatProjectCodeResponse = validateProjectCode(user, serviceUpdate, audatingAction);
+ if (validatProjectCodeResponse.isRight()) {
+ ResponseFormat errorRespons = validatProjectCodeResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentService.setProjectCode(projectCodeUpdated);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ String iconUpdated = serviceUpdate.getIcon();
+ String iconCurrent = currentService.getIcon();
+ if (!iconCurrent.equals(iconUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validatIconResponse = validateIcon(user, serviceUpdate, audatingAction);
+ if (validatIconResponse.isRight()) {
+ ResponseFormat errorRespons = validatIconResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ currentService.setIcon(iconUpdated);
+ } else {
+ log.info("icon {} cannot be updated once the service has been certified once.", iconUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_ICON_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateServiceName(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ String serviceNameUpdated = serviceUpdate.getName();
+ String serviceNameCurrent = currentService.getName();
+ if (!serviceNameCurrent.equals(serviceNameUpdated)) {
+ if (!hasBeenCertified) {
+ Either<Boolean, ResponseFormat> validatServiceNameResponse = validateComponentName(user, serviceUpdate, audatingAction);
+ if (validatServiceNameResponse.isRight()) {
+ ResponseFormat errorRespons = validatServiceNameResponse.right().value();
+ return Either.right(errorRespons);
+ }
+
+ Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, serviceUpdate, audatingAction);
+ if (serviceNameUniquenessValidation.isRight()) {
+ return serviceNameUniquenessValidation;
+ }
+ currentService.setName(serviceNameUpdated);
+ currentService.getComponentMetadataDefinition().getMetadataDataDefinition().setNormalizedName(ValidationUtils.normaliseComponentName(serviceNameUpdated));
+ currentService.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName(ValidationUtils.convertToSystemName(serviceNameUpdated));
+
+ } else {
+ log.info("service name {} cannot be updated once the service has been certified once.", serviceNameUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NAME_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateCategory(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ List<CategoryDefinition> categoryUpdated = serviceUpdate.getCategories();
+ List<CategoryDefinition> categoryCurrent = currentService.getCategories();
+ Either<Boolean, ResponseFormat> validatCategoryResponse = validateServiceCategory(user, serviceUpdate, audatingAction);
+ if (validatCategoryResponse.isRight()) {
+ ResponseFormat errorRespons = validatCategoryResponse.right().value();
+ return Either.right(errorRespons);
+ }
+ if (!categoryCurrent.get(0).getName().equals(categoryUpdated.get(0).getName())) {
+ if (!hasBeenCertified) {
+ currentService.setCategories(categoryUpdated);
+ } else {
+ log.info("category {} cannot be updated once the service has been certified once.", categoryUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CATEGORY_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+
+ }
+
+ public Either<Boolean, ResponseFormat> validateServiceCategory(List<CategoryDefinition> list) {
+ if (list != null) {
+ if (list.size() > 1) {
+ log.debug("Must be only one category for service");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
+ return Either.right(responseFormat);
+ }
+ CategoryDefinition category = list.get(0);
+ if (category.getSubcategories() != null) {
+ log.debug("Subcategories cannot be defined for service");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
+ return Either.right(responseFormat);
+ }
+ if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ log.debug("Resource category is empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ return Either.right(responseFormat);
+ }
+
+ log.debug("validating service category {} against valid categories list", list);
+ Either<List<CategoryDefinition>, ActionStatus> categorys = elementDao.getAllServiceCategories();
+ if (categorys.isRight()) {
+ log.debug("failed to retrive service categories from Titan");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(categorys.right().value());
+ return Either.right(responseFormat);
+ }
+ List<CategoryDefinition> categoryList = categorys.left().value();
+ for (CategoryDefinition value : categoryList) {
+ if (value.getName().equals(category.getName())) {
+ return Either.left(true);
+ }
+ }
+ log.debug("Category {} is not part of service category group. Service category valid values are {}", list, categoryList);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()));
+ }
+ return Either.left(false);
+ }
+
+ public ResponseFormat deleteService(String serviceId, User user) {
+ ResponseFormat responseFormat;
+ String ecompErrorContext = "delete service";
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
+ if (eitherCreator.isRight()) {
+ return eitherCreator.right().value();
+ }
+ user = eitherCreator.left().value();
+
+ Either<Service, StorageOperationStatus> serviceStatus = serviceOperation.getService(serviceId);
+ if (serviceStatus.isRight()) {
+ log.debug("failed to get service {}", serviceId);
+ return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceStatus.right().value()), "");
+ }
+
+ Service service = serviceStatus.left().value();
+
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
+ if (lockResult.isRight()) {
+ result = StorageOperationStatus.GENERAL_ERROR;
+ return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ try {
+
+ result = markComponentToDelete(service);
+ if (result.equals(StorageOperationStatus.OK)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ } else {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, service.getName());
+ }
+ return responseFormat;
+
+ } finally {
+ if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ log.warn("operation failed. do rollback");
+ BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
+ }
+ }
+
+ public ResponseFormat deleteServiceByNameAndVersion(String serviceName, String version, User user) {
+ ResponseFormat responseFormat;
+ String ecompErrorContext = "delete service";
+ Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
+ if (validateEmptyResult.isRight()) {
+ return validateEmptyResult.right().value();
+ }
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
+ if (eitherCreator.isRight()) {
+ return eitherCreator.right().value();
+ }
+ user = eitherCreator.left().value();
+
+ Either<Service, ResponseFormat> getResult = getServiceByNameAndVersion(serviceName, version, user.getUserId());
+ if (getResult.isRight()) {
+ return getResult.right().value();
+ }
+ Service service = getResult.left().value();
+
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
+ if (lockResult.isRight()) {
+ result = StorageOperationStatus.GENERAL_ERROR;
+ return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+
+ try {
+ result = markComponentToDelete(service);
+ if (result.equals(StorageOperationStatus.OK)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ } else {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, service.getName());
+ }
+ return responseFormat;
+
+ } finally {
+ if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ log.warn("operation failed. do rollback");
+ BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("operation success. do commit");
+ titanGenericDao.commit();
+ }
+ graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
+ }
+ }
+
+ public Either<Service, ResponseFormat> getService(String serviceId, User user) {
+ String ecompErrorContext = "Get service";
+ Either<User, ResponseFormat> validateEmptyResult = validateUserNotEmpty(user, ecompErrorContext);
+ if (validateEmptyResult.isRight()) {
+ return Either.right(validateEmptyResult.right().value());
+ }
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(user, ecompErrorContext, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ Either<Service, StorageOperationStatus> storageStatus = serviceOperation.getService(serviceId);
+ if (storageStatus.isRight()) {
+ log.debug("failed to get service by id {}", serviceId);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), serviceId));
+ }
+ // Service service =
+ // createServiceApiArtifactLIst(storageStatus.left().value());
+ Service service = storageStatus.left().value();
+ return Either.left(service);
+ }
+
+ public Either<Service, ResponseFormat> getServiceByNameAndVersion(String serviceName, String serviceVersion, String userId) {
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "get Service By Name And Version", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+ Either<Service, StorageOperationStatus> storageStatus = serviceOperation.getServiceByNameAndVersion(serviceName, serviceVersion, null, false);
+ if (storageStatus.isRight()) {
+ log.debug("failed to get service by name {} and version {}", serviceName, serviceVersion);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), serviceName));
+ }
+ Service service = storageStatus.left().value();
+ return Either.left(service);
+ }
+
+ private void createMandatoryArtifactsData(Service service, User user) {
+ // create mandatory artifacts
+
+ // TODO it must be removed after that artifact uniqueId creation will be
+ // moved to ArtifactOperation
+ // String serviceUniqueId =
+ // UniqueIdBuilder.buildServiceUniqueId(service.getComponentMetadataDefinition().getMetadataDataDefinition().getName(),
+ // service.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion());
+ String serviceUniqueId = service.getUniqueId();
+ Map<String, ArtifactDefinition> artifactMap = service.getArtifacts();
+ if (artifactMap == null)
+ artifactMap = new HashMap<String, ArtifactDefinition>();
+
+ Map<String, Object> informationalServiceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getInformationalServiceArtifacts();
+ List<String> exludeServiceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeServiceCategory();
+
+ String category = service.getCategories().get(0).getName();
+ boolean isCreateArtifact = true;
+ if (category != null && exludeServiceCategory != null && !exludeServiceCategory.isEmpty()) {
+ for (String exlude : exludeServiceCategory) {
+ if (exlude.equalsIgnoreCase(category)) {
+ isCreateArtifact = false;
+ break;
+ }
+ }
+
+ }
+
+ if (informationalServiceArtifacts != null && isCreateArtifact) {
+ Set<String> keys = informationalServiceArtifacts.keySet();
+ for (String informationalServiceArtifactName : keys) {
+ Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalServiceArtifacts.get(informationalServiceArtifactName);
+ ArtifactDefinition artifactDefinition = createArtifactDefinition(serviceUniqueId, informationalServiceArtifactName, artifactInfoMap, user, false);
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+
+ }
+
+ service.setArtifacts(artifactMap);
+ }
+ }
+
+ private ArtifactDefinition createArtifactDefinition(String serviceId, String logicalName, Map<String, Object> artifactInfoMap, User user, Boolean isServiceApi) {
+
+ ArtifactDefinition artifactInfo = artifactsBusinessLogic.createArtifactPlaceHolderInfo(serviceId, logicalName, artifactInfoMap, user, ArtifactGroupTypeEnum.INFORMATIONAL);
+
+ if (isServiceApi) {
+ artifactInfo.setMandatory(false);
+ artifactInfo.setServiceApi(true);
+ }
+ return artifactInfo;
+ }
+
+ private Either<DistributionTransitionEnum, ResponseFormat> validateTransitionEnum(String distributionTransition, User user) {
+ DistributionTransitionEnum transitionEnum = null;
+
+ transitionEnum = DistributionTransitionEnum.getFromDisplayName(distributionTransition);
+ if (transitionEnum == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Change Service Distribution");
+ BeEcompErrorManager.getInstance().logBeSystemError("Change Service Distribution");
+ log.info("state operation is not valid. operations allowed are: {}", DistributionTransitionEnum.valuesAsString());
+ ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(error);
+ }
+
+ return Either.left(transitionEnum);
+ }
+
+ private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction comment, User user, AuditingActionEnum auditAction) {
+ String data = comment.getUserRemarks();
+
+ if (data == null || data.trim().isEmpty()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "Change Service Distribution");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Change Service Distribution");
+ log.debug("user comment cannot be empty or null.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ data = ValidationUtils.removeNoneUtf8Chars(data);
+ data = ValidationUtils.removeHtmlTags(data);
+ data = ValidationUtils.normaliseWhitespace(data);
+ data = ValidationUtils.stripOctets(data);
+
+ if (!ValidationUtils.validateLength(data, ValidationUtils.COMMENT_MAX_LENGTH)) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "Change Service Distribution");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Change Service Distribution");
+ log.debug("user comment exceeds limit.");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, "comment", String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
+ }
+ if (!ValidationUtils.validateIsEnglish(data)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ return Either.left(data);
+ }
+
+ private Either<Service, ResponseFormat> validateServiceDistributionChange(User user, String serviceId, AuditingActionEnum auditAction, String comment) {
+ Either<Service, StorageOperationStatus> storageStatus = serviceOperation.getService(serviceId);
+ if (storageStatus.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceId);
+ createAudit(user, auditAction, comment, responseFormat);
+ return Either.right(responseFormat);
+ }
+ Service service = storageStatus.left().value();
+
+ if (service.getLifecycleState() != LifecycleStateEnum.CERTIFIED) {
+ log.info("service {} is not available for distribution. Should be in certified state", service.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION, service.getVersion(), service.getName());
+ createAudit(user, auditAction, comment, service, responseFormat);
+ return Either.right(responseFormat);
+ }
+ return Either.left(service);
+ }
+
+ private Either<User, ResponseFormat> validateUserDistributionChange(User user, Service service, AuditingActionEnum auditAction, String comment) {
+ log.debug("get user from DB");
+ /*
+ * Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId());s if (eitherCreator.isRight() || eitherCreator.left().value() == null) { BeEcompErrorManager.getInstance().processEcompError(EcompErrorName. BeUserMissingError,
+ * "Activate Distribution", user.getUserId()); log. debug("changeServiceDistributionState method - user is not listed. userId=" + user.getUserId()); ResponseFormat responseFormat =
+ * componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND); createAudit(user, auditAction, comment, responseFormat); return Either.right(responseFormat); } user = eitherCreator.left().value(); log.debug("validate user role"); if
+ * (!validateUserTemp(user, Role.ADMIN, Role.GOVERNOR)) { log.info("role {} is not allowed to perform this action", user.getRole()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ * createAudit(user, auditAction, comment, service, responseFormat); return Either.right(responseFormat); }
+ */
+ // get user details
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "Activate Distribution", service, auditAction, false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ // validate user role
+ List<Role> roles = new ArrayList<>();
+ roles.add(Role.ADMIN);
+ roles.add(Role.GOVERNOR);
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, roles, auditAction, comment);
+ if (validateRes.isRight()) {
+ return Either.right(validateRes.right().value());
+ }
+ return Either.left(user);
+ }
+
+ private void createAudit(User user, AuditingActionEnum auditAction, String comment, ResponseFormat responseFormat) {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+
+ createAudit(user, auditAction, comment, null, responseFormat, auditingFields);
+ }
+
+ private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, ResponseFormat responseFormat) {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS, component.getDistributionStatus().name());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, component.getDistributionStatus().name());
+ createAudit(user, auditAction, comment, component, component.getLifecycleState().name(), component.getVersion(), responseFormat, auditingFields);
+ }
+
+ private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, ResponseFormat responseFormat, EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ log.debug("audit before sending response");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, comment);
+ componentsUtils.auditComponent(responseFormat, user, component, null, null, auditAction, ComponentTypeEnum.SERVICE, auditingFields);
+ }
+
+ private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, String prevState, String prevVersion, ResponseFormat responseFormat, EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ log.debug("audit before sending response");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, comment);
+ componentsUtils.auditComponent(responseFormat, user, component, prevState, prevVersion, auditAction, ComponentTypeEnum.SERVICE, auditingFields);
+ }
+
+ public Either<Service, ResponseFormat> activateDistribution(String serviceId, String envName, User modifier, HttpServletRequest request) {
+
+ Either<User, ResponseFormat> eitherCreator = validateUserExists(modifier.getUserId(), "activate Distribution", false);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+
+ User user = eitherCreator.left().value();
+
+ Either<Service, ResponseFormat> result = null;
+ ResponseFormat response = null;
+ Service updatedService = null;
+ String did = ThreadLocalsHolder.getUuid();
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, did);
+ // DE194021
+ String configuredEnvName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
+ if (configuredEnvName != null && false == envName.equals(configuredEnvName)) {
+ log.trace("Update environment name to be {} instead of {}", configuredEnvName, envName);
+ envName = configuredEnvName;
+ }
+ // DE194021
+
+ ServletContext servletContext = request.getSession().getServletContext();
+ boolean isDistributionEngineUp = getHealthCheckBL(servletContext).isDistributionEngineUp(request.getSession().getServletContext()); // DE
+ if (!isDistributionEngineUp) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Distribution Engine is DOWN");
+ BeEcompErrorManager.getInstance().logBeSystemError("Distribution Engine is DOWN");
+ log.debug("Distribution Engine is DOWN");
+ response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(response);
+ }
+
+ Either<Service, StorageOperationStatus> serviceRes = serviceOperation.getService(serviceId);
+ if (serviceRes.isRight()) {
+ log.debug("failed retrieving service");
+ response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceRes.right().value(), ComponentTypeEnum.SERVICE), serviceId);
+ componentsUtils.auditComponent(response, user, null, null, null, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE, auditingFields);
+ return Either.right(response);
+ }
+ Service service = serviceRes.left().value();
+ String dcurrStatus = service.getDistributionStatus().name();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, dcurrStatus);
+
+ Either<INotificationData, StorageOperationStatus> readyForDistribution = distributionEngine.isReadyForDistribution(service, did, envName);
+ if (readyForDistribution.isLeft()) {
+ INotificationData notificationData = readyForDistribution.left().value();
+ StorageOperationStatus notifyServiceResponse = distributionEngine.notifyService(did, service, notificationData, envName, user.getUserId(), user.getFullName());
+ if (notifyServiceResponse == StorageOperationStatus.OK) {
+ Either<Service, ResponseFormat> updateStateRes = updateDistributionStatusForActivation(service, user, DistributionStatusEnum.DISTRIBUTED);
+ if (updateStateRes.isLeft() && updateStateRes.left().value() != null) {
+ updatedService = updateStateRes.left().value();
+ dcurrStatus = updatedService.getDistributionStatus().name();
+ } else {
+ // The response is not relevant
+ updatedService = service;
+ }
+ ASDCKpiApi.countActivatedDistribution();
+ response = componentsUtils.getResponseFormat(ActionStatus.OK);
+ result = Either.left(updatedService);
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Activate Distribution - send notification");
+ BeEcompErrorManager.getInstance().logBeSystemError("Activate Distribution - send notification");
+ log.debug("distributionEngine.notifyService response is: {}", notifyServiceResponse);
+ response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ result = Either.right(response);
+ }
+ } else {
+ StorageOperationStatus distEngineValidationResponse = readyForDistribution.right().value();
+ response = componentsUtils.getResponseFormatByDE(componentsUtils.convertFromStorageResponse(distEngineValidationResponse), service.getName(), envName);
+ result = Either.right(response);
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS, dcurrStatus);
+ componentsUtils.auditComponent(response, user, service, null, null, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE, auditingFields);
+ return result;
+ }
+
+ // convert to private after deletion of temp url
+ public Either<Service, ResponseFormat> updateDistributionStatusForActivation(Service service, User user, DistributionStatusEnum state) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "update Distribution Status For Activation", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ String serviceId = service.getUniqueId();
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "updateDistributionStatusForActivation");
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
+ }
+ try {
+ Either<Service, StorageOperationStatus> result = serviceOperation.updateDestributionStatus(service, user, state);
+ if (result.isRight()) {
+ titanGenericDao.rollback();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "updateDistributionStatusForActivation");
+ BeEcompErrorManager.getInstance().logBeSystemError("updateDistributionStatusForActivation");
+ log.debug("service {} change distribution status failed", serviceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ titanGenericDao.commit();
+ return Either.left(result.left().value());
+ } finally {
+ graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
+ }
+ }
+
+ public Either<Service, ResponseFormat> markDistributionAsDeployed(String serviceId, String did, User user) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(), "mark Distribution As Deployed", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ log.debug("mark distribution deployed");
+
+ AuditingActionEnum auditAction = AuditingActionEnum.DISTRIBUTION_DEPLOY;
+ Either<Service, StorageOperationStatus> getServiceResponse = serviceOperation.getService(serviceId);
+ if (getServiceResponse.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeServiceMissingError, "markDistributionAsDeployed", serviceId);
+ BeEcompErrorManager.getInstance().logBeComponentMissingError("markDistributionAsDeployed", ComponentTypeEnum.SERVICE.getValue(), serviceId);
+ log.debug("service {} not found", serviceId);
+ ResponseFormat responseFormat = auditDeployError(did, user, auditAction, null, componentsUtils.convertFromStorageResponse(getServiceResponse.right().value(), ComponentTypeEnum.SERVICE), "");
+
+ return Either.right(responseFormat);
+ }
+
+ Service service = getServiceResponse.left().value();
+
+ Either<User, ResponseFormat> validateRoleForDeploy = validateRoleForDeploy(did, user, auditAction, service);
+ if (validateRoleForDeploy.isRight()) {
+ return Either.right(validateRoleForDeploy.right().value());
+ }
+ user = validateRoleForDeploy.left().value();
+
+ return checkDistributionAndDeploy(did, user, auditAction, service);
+
+ }
+
+ public Either<Service, ResponseFormat> generateVfModuleArtifacts(Service service, User modifier, boolean shouldLock) {
+ Function<ComponentInstance, List<ArtifactGenerator<ArtifactDefinition>>> artifactTaskGeneratorCreator = ri ->
+ // Only one VF Module Artifact per instance - add it to a list of one
+ Arrays.asList(new VfModuleArtifacGenerator(modifier, ri, service, shouldLock));
+
+ return generateDeploymentArtifacts(service, modifier, artifactTaskGeneratorCreator);
+
+ }
+
+ private List<GroupDefinition> collectGroupsForCompInstance(ComponentInstance currVF, Wrapper<ResponseFormat> responseWrapper) {
+ List<GroupDefinition> relevantGroups = new ArrayList<>();
+ Either<List<GroupDefinition>, StorageOperationStatus> eitherGroups = groupOperation.getAllGroups(currVF.getComponentUid(), NodeTypeEnum.Resource);
+
+ if (eitherGroups.isRight()) {
+ final StorageOperationStatus storageStatus = eitherGroups.right().value();
+ if (storageStatus != StorageOperationStatus.NOT_FOUND && storageStatus != StorageOperationStatus.OK) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageStatus);
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus));
+ }
+
+ } else {
+ relevantGroups = eitherGroups.left().value().stream().filter(p -> GroupTypeEnum.VF_MODULE.getGroupTypeName().equals(p.getType())).collect(Collectors.toList());
+ }
+ return relevantGroups;
+ }
+
+ private ArtifactDefinition getVfModuleArtifactForCompInstance(ComponentInstance currVF, Service service, User modifier, List<GroupDefinition> groupsForCurrVF, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper) {
+ ArtifactDefinition vfModuleAertifact = null;
+
+ Optional<ArtifactDefinition> optionalVfModuleArtifact = currVF.getDeploymentArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())).findAny();
+ if (optionalVfModuleArtifact.isPresent()) {
+ vfModuleAertifact = optionalVfModuleArtifact.get();
+ } else {
+ Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact = createVfModuleArtifact(modifier, currVF, service, payloadWrapper.getInnerElement());
+ if (createVfModuleArtifact.isLeft()) {
+ vfModuleAertifact = createVfModuleArtifact.left().value();
+ } else {
+ responseWrapper.setInnerElement(createVfModuleArtifact.right().value());
+ }
+ }
+ return vfModuleAertifact;
+ }
+
+ private void fillVfModuleHeatEnvPayload(List<GroupDefinition> groupsForCurrVF, ComponentInstance currVFInstance, Wrapper<String> payloadWrapper) {
+ // Converts GroupDefinition to VfModuleArtifactPayload which is the
+ // format used in the payload
+
+ List<VfModuleArtifactPayload> vfModulePayloadForCurrVF = groupsForCurrVF.stream().map(group -> new VfModuleArtifactPayload(group)).collect(Collectors.toList());
+ Collections.sort(vfModulePayloadForCurrVF, (art1, art2) -> VfModuleArtifactPayload.compareByGroupName(art1, art2));
+ // Update Payload With Heat Env
+ vfModulePayloadForCurrVF.stream().forEach(e -> addHeatEnvArtifactsToVFModulePayload(e, currVFInstance));
+
+ final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ String vfModulePayloadString = gson.toJson(vfModulePayloadForCurrVF);
+ payloadWrapper.setInnerElement(vfModulePayloadString);
+
+ }
+
+ private void addHeatEnvArtifactsToVFModulePayload(VfModuleArtifactPayload vfModulePayload, ComponentInstance currVFInstance) {
+ List<String> originalModuleArtifacts = vfModulePayload.getArtifacts();
+ if (!MapUtils.isEmpty(currVFInstance.getDeploymentArtifacts()) && !CollectionUtils.isEmpty(originalModuleArtifacts)) {
+
+ final Collection<ArtifactDefinition> depInsArtifacts = currVFInstance.getDeploymentArtifacts().values();
+ // All Heat_ENV
+ List<ArtifactDefinition> heatEnvArtifacts = depInsArtifacts.stream().filter(art -> art.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.getType())).collect(Collectors.toList());
+ // Unique Id Of Artifacts In the vf module
+ List<String> moduleArtUniqueId = depInsArtifacts.stream().filter(art -> originalModuleArtifacts.contains(art.getArtifactUUID())).map(art -> art.getUniqueId()).collect(Collectors.toList());
+ // Collect Only Heat Artifatcs that are Generated from artifacts in
+ // the module
+ List<String> relevantHeatEnvUUID = heatEnvArtifacts.stream().filter(heatEnv -> moduleArtUniqueId.contains(heatEnv.getGeneratedFromId())).map(heatEnv -> heatEnv.getArtifactUUID()).collect(Collectors.toList());
+
+ List<String> fullArtifactList = new ArrayList<>();
+ fullArtifactList.addAll(originalModuleArtifacts);
+ fullArtifactList.addAll(relevantHeatEnvUUID);
+
+ vfModulePayload.setArtifacts(fullArtifactList);
+ }
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> generateVfModuleArtifact(User modifier, ComponentInstance currVFInstance, Service service, boolean shouldLock) {
+ ArtifactDefinition vfModuleAertifact = null;
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
+ Wrapper<String> payloadWrapper = new Wrapper<>();
+ List<GroupDefinition> groupsForCurrVF = collectGroupsForCompInstance(currVFInstance, responseWrapper);
+ if (responseWrapper.isEmpty()) {
+ fillVfModuleHeatEnvPayload(groupsForCurrVF, currVFInstance, payloadWrapper);
+ }
+ if (responseWrapper.isEmpty()) {
+ vfModuleAertifact = getVfModuleArtifactForCompInstance(currVFInstance, service, modifier, groupsForCurrVF, payloadWrapper, responseWrapper);
+ }
+ if (responseWrapper.isEmpty() && vfModuleAertifact != null) {
+ vfModuleAertifact = fillVfModulePayload(modifier, currVFInstance, vfModuleAertifact, shouldLock, payloadWrapper, responseWrapper);
+ }
+
+ Either<ArtifactDefinition, ResponseFormat> result;
+ if (responseWrapper.isEmpty()) {
+ result = Either.left(vfModuleAertifact);
+ } else {
+ result = Either.right(responseWrapper.getInnerElement());
+ }
+
+ return result;
+ }
+
+ private ArtifactDefinition fillVfModulePayload(User modifier, ComponentInstance currVF, ArtifactDefinition vfModuleAertifact, boolean shouldLock, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper) {
+ ArtifactDefinition result = null;
+ final Either<Resource, StorageOperationStatus> eitherResource = resourceOperation.getResource(currVF.getComponentUid());
+ if (eitherResource.isRight()) {
+ responseWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(eitherResource.right().value())));
+ } else {
+ Resource resource = eitherResource.left().value();
+ Either<ArtifactDefinition, ResponseFormat> eitherPayload = artifactsBusinessLogic.generateArtifactPayload(vfModuleAertifact, resource, currVF.getName(), modifier, shouldLock, () -> System.currentTimeMillis(),
+ () -> Either.left(artifactsBusinessLogic.createEsArtifactData(vfModuleAertifact, payloadWrapper.getInnerElement().getBytes(StandardCharsets.UTF_8))));
+ if (eitherPayload.isLeft()) {
+ result = eitherPayload.left().value();
+ } else {
+ responseWrapper.setInnerElement(eitherPayload.right().value());
+ }
+ }
+
+ return result;
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact(User modifier, ComponentInstance currVF, Service service, String vfModulePayloadString) {
+
+ ArtifactDefinition vfModuleArtifactDefinition = new ArtifactDefinition();
+
+ vfModuleArtifactDefinition.setDescription("Auto-generated VF Modules information artifact");
+ vfModuleArtifactDefinition.setArtifactDisplayName("Vf Modules Metadata");
+ vfModuleArtifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType());
+ vfModuleArtifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ vfModuleArtifactDefinition.setArtifactLabel("vfModulesMetadata");
+ vfModuleArtifactDefinition.setTimeout(0);
+ vfModuleArtifactDefinition.setArtifactName(currVF.getNormalizedName() + "_modules.json");
+ vfModuleArtifactDefinition.setPayloadData(vfModulePayloadString);
+
+ Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent = artifactOperation.addArifactToComponent(vfModuleArtifactDefinition, currVF.getUniqueId(), NodeTypeEnum.ResourceInstance, true, true);
+
+ Either<ArtifactDefinition, ResponseFormat> result;
+ if (addArifactToComponent.isLeft()) {
+ result = Either.left(addArifactToComponent.left().value());
+ } else {
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArifactToComponent.right().value())));
+ }
+
+ return result;
+ }
+
+ public Either<Service, ResponseFormat> generateHeatEnvArtifacts(Service service, User modifier, boolean shouldLock) {
+
+ Function<ComponentInstance, List<ArtifactGenerator<ArtifactDefinition>>> artifactTaskGeneratorCreator = resourceInstance ->
+ // Get All Deployment Artifacts
+ service.getComponentInstances().stream().filter(ri -> ri != null && ri == resourceInstance).filter(ri -> ri.getDeploymentArtifacts() != null).flatMap(ri -> ri.getDeploymentArtifacts().values().stream()).
+ // Filter in Only Heat Env
+ filter(depArtifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(depArtifact.getArtifactType())).
+ // Create ArtifactGenerator from those Artifacts
+ map(depArtifact -> new HeatEnvArtifactGenerator(depArtifact, service, resourceInstance.getName(), modifier, shouldLock)).collect(Collectors.toList());
+
+ return generateDeploymentArtifacts(service, modifier, artifactTaskGeneratorCreator);
+
+ }
+
+ private <CallVal> Either<Service, ResponseFormat> generateDeploymentArtifacts(Service service, User modifier, Function<ComponentInstance, List<ArtifactGenerator<CallVal>>> artifactTaskGeneratorCreator) {
+
+ List<Future<Either<CallVal, ResponseFormat>>> allFutures = new ArrayList<>();
+
+ // Get Flat List of (Callable) ArtifactGenerator for all the RI in the
+ // service
+ if (service.getComponentInstances() != null) {
+ List<ArtifactGenerator<CallVal>> artifactGenList = service.getComponentInstances().stream().flatMap(ri -> artifactTaskGeneratorCreator.apply(ri).stream()).collect(Collectors.toList());
+ if (artifactGenList != null && !artifactGenList.isEmpty()) {
+ ExecutorService executor = Executors.newFixedThreadPool(artifactGenList.size());
+
+ artifactGenList.stream().forEach(e -> allFutures.add(executor.submit(e)));
+
+ boolean isSuccess = true;
+ ResponseFormat firstError = null;
+ for (Future<Either<CallVal, ResponseFormat>> entry : allFutures) {
+ try {
+ Either<CallVal, ResponseFormat> actionStatus = entry.get(20, TimeUnit.SECONDS);
+ if (actionStatus.isRight()) {
+ isSuccess = false;
+ if (firstError == null) {
+ firstError = actionStatus.right().value();
+ }
+ log.debug("Failed to generate artifact error : {}", actionStatus.right().value());
+ }
+ } catch (Exception e) {
+ log.debug("Failed to collect result from artifact generator ", e);
+ isSuccess = false;
+ firstError = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+ }
+ executor.shutdown();
+ if (!isSuccess) {
+ return Either.right(firstError);
+ }
+ }
+
+ }
+ return Either.left(service);
+ }
+
+ abstract class ArtifactGenerator<CallVal> implements Callable<Either<CallVal, ResponseFormat>> {
+
+ }
+
+ class HeatEnvArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> {
+ ArtifactDefinition artifactDefinition;
+ Service service;
+ String resourceInstanceName;
+ User modifier;
+ boolean shouldLock;
+
+ HeatEnvArtifactGenerator(ArtifactDefinition artifactDefinition, Service service, String resourceInstanceName, User modifier, boolean shouldLock) {
+ this.artifactDefinition = artifactDefinition;
+ this.service = service;
+ this.resourceInstanceName = resourceInstanceName;
+ this.modifier = modifier;
+ this.shouldLock = shouldLock;
+ }
+
+ @Override
+ public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
+ return artifactsBusinessLogic.generateHeatEnvArtifact(artifactDefinition, service, resourceInstanceName, modifier, shouldLock);
+ }
+
+ public ArtifactDefinition getArtifactDefinition() {
+ return artifactDefinition;
+ }
+
+ }
+
+ class VfModuleArtifacGenerator extends ArtifactGenerator<ArtifactDefinition> {
+ private User user;
+ private ComponentInstance componentInstance;
+ private Service service;
+ boolean shouldLock;
+
+ @Override
+ public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
+ return generateVfModuleArtifact(user, componentInstance, service, shouldLock);
+ }
+
+ private VfModuleArtifacGenerator(User user, ComponentInstance componentInstance, Service service, boolean shouldLock) {
+ super();
+ this.user = user;
+ this.componentInstance = componentInstance;
+ this.service = service;
+ this.shouldLock = shouldLock;
+ }
+
+ }
+
+ private synchronized Either<Service, ResponseFormat> checkDistributionAndDeploy(String did, User user, AuditingActionEnum auditAction, Service service) {
+ boolean isDeployed = isDistributionDeployed(did, service);
+ if (isDeployed) {
+ return Either.left(service);
+ }
+ Either<Boolean, ResponseFormat> distributionSuccess = checkDistributionSuccess(did, user, auditAction, service);
+ if (distributionSuccess.isRight()) {
+ return Either.right(distributionSuccess.right().value());
+ }
+
+ log.debug("mark distribution {} as deployed - success", did);
+ componentsUtils.auditServiceDistributionDeployed(auditAction, service.getName(), service.getVersion(), service.getUUID(), did, STATUS_DEPLOYED, "OK", user);
+ return Either.left(service);
+ }
+
+ private boolean isDistributionDeployed(String did, Service service) {
+ Either<List<DistributionDeployEvent>, ActionStatus> alreadyDeployed = auditCassandraDao.getDistributionDeployByStatus(did, AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), STATUS_DEPLOYED);
+
+ boolean isDeployed = false;
+ if (alreadyDeployed.isLeft() && !alreadyDeployed.left().value().isEmpty()) {
+ // already deployed
+ log.debug("distribution {} is already deployed", did);
+ isDeployed = true;
+ }
+ return isDeployed;
+ }
+
+ protected Either<Boolean, ResponseFormat> checkDistributionSuccess(String did, User user, AuditingActionEnum auditAction, Service service) {
+
+ log.trace("checkDistributionSuccess");
+ // get all "DRequest" records for this distribution
+ // Either<List<ESTimeBasedEvent>, ActionStatus> distRequestsResponse =
+ // auditingDao.getListOfDistributionByAction(did,
+ // AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(), "",
+ // ResourceAdminEvent.class);
+ Either<List<ResourceAdminEvent>, ActionStatus> distRequestsResponse = auditCassandraDao.getDistributionRequest(did, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName());
+ if (distRequestsResponse.isRight()) {
+ ResponseFormat error = auditDeployError(did, user, auditAction, service, distRequestsResponse.right().value());
+ return Either.right(error);
+ }
+
+ List<ResourceAdminEvent> distributionRequests = distRequestsResponse.left().value();
+ if (distributionRequests.isEmpty()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionMissingError, "markDistributionAsDeployed", did);
+ BeEcompErrorManager.getInstance().logBeDistributionMissingError("markDistributionAsDeployed", did);
+ log.info("distribution {} is not found", did);
+ ResponseFormat error = auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_NOT_FOUND);
+ return Either.right(error);
+ }
+ boolean isRequestSucceeded = false;
+ for (ResourceAdminEvent event : distributionRequests) {
+ String eventStatus = event.getStatus();
+ if (eventStatus != null && eventStatus.equals(STATUS_SUCCESS_200)) {
+ isRequestSucceeded = true;
+ break;
+ }
+ }
+
+ // get all "DNotify" records for this distribution
+ // Either<List<ESTimeBasedEvent>, ActionStatus>
+ // distNotificationsResponse =
+ // auditingDao.getListOfDistributionByAction(did,
+ // AuditingActionEnum.DISTRIBUTION_NOTIFY.getName(), "",
+ // DistributionNotificationEvent.class);
+ Either<List<DistributionNotificationEvent>, ActionStatus> distNotificationsResponse = auditCassandraDao.getDistributionNotify(did, AuditingActionEnum.DISTRIBUTION_NOTIFY.getName());
+ if (distNotificationsResponse.isRight()) {
+ ResponseFormat error = auditDeployError(did, user, auditAction, service, distNotificationsResponse.right().value());
+ return Either.right(error);
+ }
+
+ List<DistributionNotificationEvent> distributionNotifications = distNotificationsResponse.left().value();
+ boolean isNotificationsSucceeded = false;
+ for (DistributionNotificationEvent event : distributionNotifications) {
+ String eventStatus = event.getStatus();
+ if (eventStatus != null && eventStatus.equals(STATUS_SUCCESS_200)) {
+ isNotificationsSucceeded = true;
+ break;
+ }
+ }
+
+ // if request failed OR there are notifications that failed
+ if (!(isRequestSucceeded && isNotificationsSucceeded)) {
+
+ log.info("distribution {} has failed", did);
+ ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
+ auditDeployError(did, user, auditAction, service, ActionStatus.DISTRIBUTION_REQUESTED_FAILED, did);
+ return Either.right(error);
+ }
+ return Either.left(true);
+ }
+
+ private ResponseFormat auditDeployError(String did, User user, AuditingActionEnum auditAction, Service service, ActionStatus status, String... params) {
+
+ ResponseFormat error = componentsUtils.getResponseFormat(status, params);
+ String message = "";
+ if (error.getMessageId() != null) {
+ message = error.getMessageId() + ": ";
+ }
+ message += error.getFormattedMessage();
+
+ if (service != null) {
+ componentsUtils.auditServiceDistributionDeployed(auditAction, service.getName(), service.getVersion(), service.getUUID(), did, error.getStatus().toString(), message, user);
+ } else {
+ componentsUtils.auditServiceDistributionDeployed(auditAction, "", "", "", did, error.getStatus().toString(), message, user);
+ }
+ return error;
+ }
+
+ private Either<User, ResponseFormat> validateRoleForDeploy(String did, User user, AuditingActionEnum auditAction, Service service) {
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId(), false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUserMissingError, "Deploy Service", user.getUserId());
+ BeEcompErrorManager.getInstance().logBeUserMissingError("Deploy Service", user.getUserId());
+ log.debug("validateRoleForDeploy method - user is not listed. userId={}", user.getUserId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, user.getUserId());
+ auditDeployError(did, user, auditAction, service, ActionStatus.USER_NOT_FOUND);
+ return Either.right(responseFormat);
+ }
+ user = eitherCreator.left().value();
+ log.debug("validate user role");
+ List<Role> roles = new ArrayList<>();
+ roles.add(Role.ADMIN);
+ roles.add(Role.OPS);
+ Either<Boolean, ResponseFormat> validateRes = validateUserRole(user, service, roles, auditAction, null);
+ if (validateRes.isRight()) {
+ log.info("role {} is not allowed to perform this action", user.getRole());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ auditDeployError(did, user, auditAction, service, ActionStatus.RESTRICTED_OPERATION);
+ return Either.right(responseFormat);
+ }
+ return Either.left(user);
+
+ }
+
+ @Override
+ public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
+ return deleteMarkedComponents(ComponentTypeEnum.SERVICE);
+ }
+
+ private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ HealthCheckBusinessLogic healthCheckBl = webApplicationContext.getBean(HealthCheckBusinessLogic.class);
+ return healthCheckBl;
+ }
+
+ @Override
+ public ComponentInstanceBusinessLogic getComponentInstanceBL() {
+ return serviceComponentInstanceBusinessLogic;
+ }
+
+ @Override
+ public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
+
+ Either<User, ResponseFormat> resp = validateUserExists(userId, "Get Component Instances", false);
+ if (resp.isRight()) {
+ return Either.right(resp.right().value());
+ }
+
+ ComponentOperation componentOperation = getComponentOperation(componentTypeEnum);
+
+ Either<List<ComponentInstance>, StorageOperationStatus> componentInstancesResponse = componentOperation.getAllComponentInstncesMetadata(componentId, componentTypeEnum.getNodeType());
+ if (componentInstancesResponse.isRight()) {
+
+ if (componentInstancesResponse.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.left(new ArrayList<ComponentInstance>());
+ }
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentInstancesResponse.right().value()));
+ return Either.right(responseFormat);
+ }
+
+ List<ComponentInstance> componentInstances = componentInstancesResponse.left().value();
+ componentInstances = componentInstances.stream().filter(instance -> instance.getOriginType().equals(OriginTypeEnum.VF)).collect(Collectors.toList());
+
+ return Either.left(componentInstances);
+ }
+
+ public ICacheMangerOperation getCacheManagerOperation() {
+ return cacheManagerOperation;
+ }
+
+ public void setCacheManagerOperation(ICacheMangerOperation cacheManagerOperation) {
+ this.cacheManagerOperation = cacheManagerOperation;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java
new file mode 100644
index 0000000000..c42cf004ff
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("serviceComponentInstanceBusinessLogic")
+public class ServiceComponentInstanceBusinessLogic extends ComponentInstanceBusinessLogic {
+
+ @Override
+ protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
+ return Either.left(true);
+ }
+
+ @Override
+ protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
+ return NodeTypeEnum.Resource;
+ }
+
+ @Override
+ protected ComponentOperation getContainerComponentOperation() {
+ return serviceOperation;
+ }
+
+ @Override
+ protected ComponentOperation getCompInstOriginComponentOperation() {
+ return resourceOperation;
+ }
+
+ @Override
+ protected ComponentTypeEnum getComponentTypeOfComponentInstance() {
+ return ComponentTypeEnum.RESOURCE_INSTANCE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java
new file mode 100644
index 0000000000..3e42897c79
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("vfComponentInstanceBusinessLogic")
+public class VFComponentInstanceBusinessLogic extends ComponentInstanceBusinessLogic {
+
+ private static Logger log = LoggerFactory.getLogger(VFComponentInstanceBusinessLogic.class.getName());
+
+ @Override
+ protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
+ Resource resource = (Resource) containerComponent;
+ ResourceTypeEnum resourceType = resource.getResourceType();
+ if (ResourceTypeEnum.VF != resourceType) {
+ log.debug("Cannot attach resource instances to container resource of type {}", resourceType);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, resourceType.getValue()));
+ }
+ return Either.left(true);
+ }
+
+ @Override
+ protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
+ return NodeTypeEnum.Resource;
+ }
+
+ @Override
+ protected ComponentOperation getContainerComponentOperation() {
+ return resourceOperation;
+ }
+
+ @Override
+ protected ComponentOperation getCompInstOriginComponentOperation() {
+ return resourceOperation;
+ }
+
+ @Override
+ protected ComponentTypeEnum getComponentTypeOfComponentInstance() {
+ return ComponentTypeEnum.RESOURCE_INSTANCE;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java
new file mode 100644
index 0000000000..445b3a9750
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java
@@ -0,0 +1,209 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CertificationChangeTransition extends LifeCycleTransition {
+
+ private static Logger log = LoggerFactory.getLogger(CertificationChangeTransition.class.getName());
+
+ private LifecycleStateEnum nextState;
+ private LifeCycleTransitionEnum name;
+ private AuditingActionEnum auditingAction;
+ private ArtifactsBusinessLogic artifactsManager;
+
+ public CertificationChangeTransition(LifeCycleTransitionEnum name, ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+ super(componentUtils, lifecycleOperation);
+
+ this.name = name;
+
+ // authorized roles
+ Role[] certificationChangeRoles = { Role.ADMIN, Role.TESTER };
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(certificationChangeRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(certificationChangeRoles));
+ // TODO to be later defined for product
+
+ switch (this.name) {
+ case CERTIFY:
+ this.auditingAction = AuditingActionEnum.CERTIFICATION_SUCCESS_RESOURCE;
+ this.nextState = LifecycleStateEnum.CERTIFIED;
+ break;
+ case FAIL_CERTIFICATION:
+ this.auditingAction = AuditingActionEnum.FAIL_CERTIFICATION_RESOURCE;
+ nextState = LifecycleStateEnum.NOT_CERTIFIED_CHECKIN;
+ break;
+ case CANCEL_CERTIFICATION:
+ this.auditingAction = AuditingActionEnum.CANCEL_CERTIFICATION_RESOURCE;
+ nextState = LifecycleStateEnum.READY_FOR_CERTIFICATION;
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return name;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return auditingAction;
+ }
+
+ public ArtifactsBusinessLogic getArtifactsManager() {
+ return artifactsManager;
+ }
+
+ public void setArtifactsManager(ArtifactsBusinessLogic artifactsManager) {
+ this.artifactsManager = artifactsManager;
+ }
+
+ private ResponseFormat formatCertificationError(Component component, StorageOperationStatus response, ComponentTypeEnum componentType) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Change LifecycleState - Certify failed on graph");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Change LifecycleState - Certify failed on graph");
+ log.debug("certification change failed on graph");
+
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return responseFormat;
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before certification change. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ if (!oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ return Either.left(true);
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+
+ log.info("start performing certification change for resource {}", component.getUniqueId());
+ Either<? extends Component, ResponseFormat> result = null;
+ NodeTypeEnum nodeType = componentType.getNodeType();
+
+ try {
+ Either<? extends Component, StorageOperationStatus> certificationChangeResult = Either.right(StorageOperationStatus.GENERAL_ERROR);
+ if (nextState.equals(LifecycleStateEnum.CERTIFIED)) {
+ certificationChangeResult = lifeCycleOperation.certifyComponent(nodeType, component, modifier, owner, true);
+ } else {
+ certificationChangeResult = lifeCycleOperation.cancelOrFailCertification(nodeType, component, modifier, owner, nextState, true);
+ }
+
+ if (certificationChangeResult.isRight()) {
+ ResponseFormat responseFormat = formatCertificationError(component, certificationChangeResult.right().value(), componentType);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ if (nextState.equals(LifecycleStateEnum.CERTIFIED)) {
+ Either<Boolean, StorageOperationStatus> deleteOldComponentVersions = lifeCycleOperation.deleteOldComponentVersions(nodeType, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(),
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getUUID(), true);
+ if (deleteOldComponentVersions.isRight()) {
+ ResponseFormat responseFormat = formatCertificationError(component, deleteOldComponentVersions.right().value(), componentType);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ }
+
+ result = Either.left(certificationChangeResult.left().value());
+ return result;
+ } finally {
+ if (result == null || result.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Change LifecycleState");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Change LifecycleState");
+ if (inTransaction == false) {
+ log.debug("operation failed. do rollback");
+ lifeCycleOperation.getResourceOperation().getTitanGenericDao().rollback();
+ }
+ } else {
+ if (inTransaction == false) {
+ log.debug("operation success. do commit");
+ lifeCycleOperation.getResourceOperation().getTitanGenericDao().commit();
+ }
+ }
+ }
+
+ }
+
+ public StorageOperationStatus deleteOldVersion(List<ArtifactDefinition> artifactsToDelete, Resource resourceToDelete) {
+ ResourceOperation resourceOperation = lifeCycleOperation.getResourceOperation();
+
+ Either<List<ArtifactDefinition>, StorageOperationStatus> artifactsRes = resourceOperation.getComponentArtifactsForDelete(resourceToDelete.getUniqueId(), NodeTypeEnum.Resource, true);
+ if (artifactsRes.isRight()) {
+ return artifactsRes.right().value();
+ }
+ Either<Resource, StorageOperationStatus> deleteResourceRes = resourceOperation.deleteResource(resourceToDelete.getUniqueId(), true);
+ if (deleteResourceRes.isRight()) {
+ return deleteResourceRes.right().value();
+ }
+ artifactsToDelete.addAll(artifactsRes.left().value());
+
+ return StorageOperationStatus.OK;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
new file mode 100644
index 0000000000..69a9cbdb24
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
@@ -0,0 +1,409 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+
+import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CertificationRequestTransition extends LifeCycleTransition {
+
+ private static Logger log = LoggerFactory.getLogger(CertificationRequestTransition.class.getName());
+
+ private ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder;
+ private ResourceOperation resourceOperation;
+ private CapabilityOperation capabilityOperation;
+ private ServiceBusinessLogic serviceBusinessLogic;
+ private ToscaExportHandler toscaExportUtils;
+
+ public CertificationRequestTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation, ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder, ServiceBusinessLogic serviceBusinessLogic,
+ CapabilityOperation capabilityOperation, ToscaExportHandler toscaExportUtils) {
+ super(componentUtils, lifecycleOperation);
+
+ // authorized roles
+ Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
+ // Role[] productCheckoutRoles = {Role.ADMIN, Role.PRODUCT_MANAGER,
+ // Role.PRODUCT_STRATEGIST};
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles));
+ // TODO to be later defined for product
+ // addAuthorizedRoles(ComponentTypeEnum.PRODUCT,
+ // Arrays.asList(productCheckoutRoles));
+
+ this.serviceDistributionArtifactsBuilder = serviceDistributionArtifactsBuilder;
+ if (lifeCycleOperation != null)
+ this.resourceOperation = lifeCycleOperation.getResourceOperation();
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ this.capabilityOperation = capabilityOperation;
+ this.toscaExportUtils = toscaExportUtils;
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return LifeCycleTransitionEnum.CERTIFICATION_REQUEST;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return AuditingActionEnum.CERTIFICATION_REQUEST_RESOURCE;
+ }
+
+ protected Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified(Component component) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+
+ List<ComponentInstance> resourceInstance = component.getComponentInstances();
+ if (resourceInstance != null) {
+ Optional<ComponentInstance> nonCertifiedRIOptional = resourceInstance.stream().filter(p -> !ValidationUtils.validateCertifiedVersion(p.getComponentVersion())).findAny();
+ // Uncertified Resource Found
+ if (nonCertifiedRIOptional.isPresent()) {
+ ComponentInstance nonCertifiedRI = nonCertifiedRIOptional.get();
+ ResponseFormat resFormat = getRelevantResponseFormatUncertifiedRI(nonCertifiedRI, component.getComponentType());
+ eitherResult = Either.right(resFormat);
+ }
+ }
+ return eitherResult;
+ }
+
+ private ResponseFormat getRelevantResponseFormatUncertifiedRI(ComponentInstance nonCertifiedRI, ComponentTypeEnum componentType) {
+
+ ResponseFormat responseFormat;
+ Either<Resource, StorageOperationStatus> eitherResource = resourceOperation.getResource(nonCertifiedRI.getComponentUid());
+ if (eitherResource.isRight()) {
+
+ responseFormat = componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ } else {
+ ActionStatus actionStatus;
+ Resource resource = eitherResource.left().value();
+ Either<List<Resource>, StorageOperationStatus> status = resourceOperation.findLastCertifiedResourceByUUID(resource);
+
+ if (ValidationUtils.validateMinorVersion(nonCertifiedRI.getComponentVersion())) {
+ if (status.isRight() || status.left().value() == null || status.left().value().isEmpty()) {
+ actionStatus = ActionStatus.VALIDATED_RESOURCE_NOT_FOUND;
+ } else {
+ actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
+ }
+ } else {
+ if (status.isRight() || status.left().value() == null || status.left().value().isEmpty())
+ actionStatus = ActionStatus.FOUND_LIST_VALIDATED_RESOURCES;
+ else {
+ actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
+ }
+
+ }
+ String compType = (componentType == ComponentTypeEnum.RESOURCE) ? "VF" : "service";
+ responseFormat = componentUtils.getResponseFormat(actionStatus, compType, resource.getName());
+ }
+ return responseFormat;
+ }
+
+ private Either<ActionStatus, Map<String, ArtifactDefinition>> validateMandatoryArtifactsSupplied(Map<String, ArtifactDefinition> artifacts) {
+
+ if (artifacts == null || true == artifacts.isEmpty()) {
+ return Either.left(ActionStatus.OK);
+ }
+
+ Map<String, ArtifactDefinition> invalidArtifacts = new HashMap<String, ArtifactDefinition>();
+ for (Entry<String, ArtifactDefinition> artifact : artifacts.entrySet()) {
+
+ ArtifactDefinition artifactDefinition = artifact.getValue();
+ if (true == artifactDefinition.getMandatory()) {
+ String artifactEsId = artifactDefinition.getEsId();
+ if (artifactEsId == null || true == artifactEsId.isEmpty()) {
+ invalidArtifacts.put(artifact.getKey(), artifactDefinition);
+ }
+ }
+ }
+
+ if (true == invalidArtifacts.isEmpty()) {
+ return Either.left(ActionStatus.OK);
+ } else {
+ return Either.right(invalidArtifacts);
+ }
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+
+ log.debug("start performing certification request for resource {}", component.getUniqueId());
+
+ // Either<ActionStatus, Map<String, ArtifactDefinition>>
+ // validateMandatoryArtifacts =
+ // validateMandatoryArtifactsSupplied(component.getArtifacts());
+ // log.debug("After checking mandatory artifacts were populated. Result
+ // is " + validateMandatoryArtifacts);
+ // if (validateMandatoryArtifacts.isRight()) {
+ // ResponseFormat responseFormat = componentUtils
+ // .getResponseFormatByMissingArtifacts(
+ // componentType,
+ // validateMandatoryArtifacts.right().value());
+ // return Either.right(responseFormat);
+ // }
+ ActionStatus actionStatus = null;
+ ResponseFormat responseFormat = null;
+
+ if (componentType == ComponentTypeEnum.SERVICE || (componentType == ComponentTypeEnum.RESOURCE && ((Resource) component).getResourceType() == ResourceTypeEnum.VF)) {
+
+ Either<Boolean, ResponseFormat> statusCert = validateAllResourceInstanceCertified(component);
+ if (statusCert.isRight()) {
+ return Either.right(statusCert.right().value());
+ }
+
+ statusCert = validateConfiguredAtomicReqCapSatisfied(component);
+ if (statusCert.isRight()) {
+ return Either.right(statusCert.right().value());
+ }
+ }
+ if (componentType == ComponentTypeEnum.SERVICE) {
+ Either<Boolean, StorageOperationStatus> status = validateDeloymentArtifactSupplied((Service) component);
+ if (status.isRight()) {
+ StorageOperationStatus operationStatus = status.right().value();
+ actionStatus = componentUtils.convertFromStorageResponse(operationStatus);
+ } else {
+ Boolean isDeploymentArtifactExists = status.left().value();
+ if (isDeploymentArtifactExists == null || isDeploymentArtifactExists.booleanValue() == false) {
+ actionStatus = ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND;
+ } else {
+ Either<Service, ResponseFormat> generateHeatEnvResult = serviceBusinessLogic.generateHeatEnvArtifacts((Service) component, modifier, shouldLock);
+ if (generateHeatEnvResult.isRight()) {
+ return Either.right(generateHeatEnvResult.right().value());
+ }
+ Either<Service, ResponseFormat> generateVfModuleResult = serviceBusinessLogic.generateVfModuleArtifacts((Service) component, modifier, shouldLock);
+ if (generateVfModuleResult.isRight()) {
+ return Either.right(generateVfModuleResult.right().value());
+ }
+ }
+ }
+
+ if (actionStatus != null) {
+ responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return Either.right(responseFormat);
+ }
+
+ }
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = componentBl.populateToscaArtifacts(component, modifier, true, inTransaction, shouldLock);
+ if (eitherPopulated != null && eitherPopulated.isRight()) {
+ return Either.right(eitherPopulated.right().value());
+ }
+
+ NodeTypeEnum nodeType = (componentType.equals(ComponentTypeEnum.SERVICE)) ? NodeTypeEnum.Service : NodeTypeEnum.Resource;
+ Either<? extends Component, StorageOperationStatus> certificationRequestResult = lifeCycleOperation.requestCertificationComponent(nodeType, component, modifier, owner, inTransaction);
+ if (certificationRequestResult.isRight()) {
+ log.debug("checkout failed on graph");
+ StorageOperationStatus response = certificationRequestResult.right().value();
+ actionStatus = componentUtils.convertFromStorageResponse(response);
+
+ if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
+ actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
+ }
+ responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(certificationRequestResult.left().value());
+ }
+
+ private Either<Boolean, ResponseFormat> validateConfiguredAtomicReqCapSatisfied(Component component) {
+ log.debug("Submit for testing validation - Start validating configured req/cap satisfied for inner atomic instances, component id:{}", component.getUniqueId());
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ if (componentInstances != null) {
+ // Prepare relationships data structures
+ // Better make it list than set in case we need to count req/cap
+ // occurrences in the future
+ Map<String, List<String>> reqName2Ids = new HashMap<>();
+ Map<String, List<String>> capName2Ids = new HashMap<>();
+ parseRelationsForReqCapVerification(component, reqName2Ids, capName2Ids);
+ Map<String, Set<String>> requirementsToFulfillBeforeCert = configurationManager.getConfiguration().getRequirementsToFulfillBeforeCert();
+ Map<String, Set<String>> capabilitiesToConsumeBeforeCert = configurationManager.getConfiguration().getCapabilitiesToConsumeBeforeCert();
+ for (ComponentInstance compInst : componentInstances) {
+ String compInstId = compInst.getUniqueId();
+ OriginTypeEnum originType = compInst.getOriginType();
+ if (originType == null) {
+ log.error("Origin type is not set for component instance {} - it shouldn't happen. Skipping this component instance...", compInst.getUniqueId());
+ continue;
+ }
+ String compInstType = originType.getValue();
+ // Validating configured requirements fulfilled
+ if (null != requirementsToFulfillBeforeCert) {
+ Set<String> reqToFulfillForType = requirementsToFulfillBeforeCert.get(compInstType);
+ if (reqToFulfillForType != null) {
+ for (String reqNameToFulfill : reqToFulfillForType) {
+ List<String> reqNameList = reqName2Ids.get(reqNameToFulfill);
+ if (reqNameList == null || !reqNameList.contains(compInstId)) {
+ log.debug("Requirement {} wasn't fulfilled for component instance {} of type {}", reqNameToFulfill, compInstId, compInstType);
+ ComponentTypeEnum componentType = component.getComponentType();
+ String compParam = (componentType == ComponentTypeEnum.RESOURCE) ? "VF" : componentType.getValue().toLowerCase();
+ ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION, component.getName(), compParam, originType.getDisplayValue(), compInst.getName(), "requirement",
+ reqNameToFulfill, "fulfilled");
+ return Either.right(responseFormat);
+ }
+ }
+ }
+ }
+ // Validating configured capabilities consumed
+ if (null != capabilitiesToConsumeBeforeCert) {
+ Set<String> capToConsumeForType = capabilitiesToConsumeBeforeCert.get(compInstType);
+ if (capToConsumeForType != null) {
+ for (String capNameToConsume : capToConsumeForType) {
+ List<String> capNameList = capName2Ids.get(capNameToConsume);
+ if (capNameList == null || !capNameList.contains(compInstId)) {
+ log.debug("Capability {} wasn't consumed for component instance {} of type {}", capNameToConsume, compInstId, compInstType);
+ ComponentTypeEnum componentType = component.getComponentType();
+ String compParam = (componentType == ComponentTypeEnum.RESOURCE) ? "VF" : componentType.getValue().toLowerCase();
+ ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION, component.getName(), compParam, originType.getDisplayValue(), compInst.getName(), "capability",
+ capNameToConsume, "consumed");
+ return Either.right(responseFormat);
+ }
+ }
+ }
+ }
+ }
+ }
+ log.debug("Submit for testing validation - validating configured req/cap satisfied for inner atomic instances finished successfully, component id:{}", component.getUniqueId());
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> parseRelationsForReqCapVerification(Component component, Map<String, List<String>> reqName2Ids, Map<String, List<String>> capName2Ids) {
+ log.debug("Submit for testing validation - Preparing relations for inner atomic instances validation");
+ List<RequirementCapabilityRelDef> componentInstancesRelations = component.getComponentInstancesRelations();
+ if (componentInstancesRelations != null) {
+ for (RequirementCapabilityRelDef reqCapRelDef : componentInstancesRelations) {
+ List<RequirementAndRelationshipPair> relationships = reqCapRelDef.getRelationships();
+ if (relationships != null) {
+ for (RequirementAndRelationshipPair reqRelPair : relationships) {
+ String capUniqueId = reqRelPair.getCapabilityUid();
+ Either<CapabilityDefinition, StorageOperationStatus> capability = capabilityOperation.getCapability(capUniqueId);
+ if (capability.isRight()) {
+ log.error("Couldn't fetch capability by id {}", capUniqueId);
+ return Either.right(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ String reqCapType = capability.left().value().getType();
+ String capabilityOwnerId = reqRelPair.getCapabilityOwnerId();
+ String requirementOwnerId = reqRelPair.getRequirementOwnerId();
+ // Update req
+ List<String> reqIds = reqName2Ids.get(reqCapType);
+ if (reqIds == null) {
+ reqIds = new ArrayList<>();
+ reqName2Ids.put(reqCapType, reqIds);
+ }
+ reqIds.add(requirementOwnerId);
+ // Update cap
+ List<String> capIds = capName2Ids.get(reqCapType);
+ if (capIds == null) {
+ capIds = new ArrayList<>();
+ capName2Ids.put(reqCapType, capIds);
+ }
+ capIds.add(capabilityOwnerId);
+ }
+ }
+ }
+ log.debug("Parsed req for validation: {}, parsed cap for validation: {}", reqName2Ids, capName2Ids);
+ } else {
+ log.debug("There are no relations found for component {}", component.getUniqueId());
+ }
+ return Either.left(true);
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before certification request. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ // case of "atomic" checkin and certification request - modifier must be
+ // the owner
+ if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ // other states
+ if (oldState.equals(LifecycleStateEnum.CERTIFIED)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CERTIFIED, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+ if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+ if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ return Either.left(true);
+ }
+
+ private Either<Boolean, StorageOperationStatus> validateDeloymentArtifactSupplied(Service service) {
+
+ Either<Boolean, StorageOperationStatus> serviceContainsDeploymentArtifacts = this.serviceDistributionArtifactsBuilder.isServiceContainsDeploymentArtifacts(service);
+
+ return serviceContainsDeploymentArtifacts;
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java
new file mode 100644
index 0000000000..28227285f1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.Arrays;
+
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CheckinTransition extends LifeCycleTransition {
+
+ private static Logger log = LoggerFactory.getLogger(CheckinTransition.class.getName());
+
+ public CheckinTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+ super(componentUtils, lifecycleOperation);
+
+ // authorized roles
+ Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
+ Role[] productCheckoutRoles = { Role.ADMIN, Role.PRODUCT_MANAGER };
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.PRODUCT, Arrays.asList(productCheckoutRoles));
+
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return LifeCycleTransitionEnum.CHECKIN;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return AuditingActionEnum.CHECKIN_RESOURCE;
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+ log.debug("start performing checkin for {} {}", componentType.name(), component.getUniqueId());
+
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ Either<? extends Component, StorageOperationStatus> checkinResourceResult = lifeCycleOperation.checkinComponent(nodeType, component, modifier, owner, inTransaction);
+ if (checkinResourceResult.isRight()) {
+ log.debug("checkout failed on graph");
+ StorageOperationStatus response = checkinResourceResult.right().value();
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
+
+ if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
+ actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
+ }
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(checkinResourceResult.left().value());
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before checkin. component name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ if (!oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION) && !oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CHECKED_IN, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ return Either.left(true);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java
new file mode 100644
index 0000000000..a4e6bdb86c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.Arrays;
+
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CheckoutTransition extends LifeCycleTransition {
+
+ private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
+
+ private static Logger log = LoggerFactory.getLogger(CheckoutTransition.class.getName());
+
+ public CheckoutTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+ super(componentUtils, lifecycleOperation);
+
+ // authorized roles
+ Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
+ Role[] productCheckoutRoles = { Role.ADMIN, Role.PRODUCT_MANAGER };
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.PRODUCT, Arrays.asList(productCheckoutRoles));
+
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return LifeCycleTransitionEnum.CHECKOUT;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return AuditingActionEnum.CHECKOUT_RESOURCE;
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+
+ log.debug("start performing {} for resource {}", getName().name(), component.getUniqueId());
+
+ if (componentBl != null)
+ componentBl.setDeploymentArtifactsPlaceHolder(component, modifier);
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ Either<? extends Component, StorageOperationStatus> checkoutResourceResult = lifeCycleOperation.checkoutComponent(nodeType, component, modifier, owner, inTransaction);
+
+ if (checkoutResourceResult.isRight()) {
+ log.debug("checkout failed on graph");
+ StorageOperationStatus response = checkoutResourceResult.right().value();
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
+
+ if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
+ actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
+ }
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(checkoutResourceResult.left().value());
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before checkout. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ // Disabled as of 1604 patch after discussing with Ella/Eli/Michael
+
+ /*
+ * if (componentType == ComponentTypeEnum.PRODUCT){ Either<Boolean, ResponseFormat> productContactsEither = productContactsValidation((Product)component, modifier); if (productContactsEither.isRight()){ return productContactsEither; } }
+ */
+
+ // check resource is not locked by another user
+ if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CHECKOUT_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION)) {
+ if (!modifier.getRole().equals(Role.DESIGNER.name()) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+ }
+ return Either.left(true);
+ }
+
+ /*
+ * private Either<Boolean, ResponseFormat> productContactsValidation(Product product, User modifier) { // validate user Either<Boolean, ResponseFormat> eitherResponse = Either.left(true); String role = modifier.getRole(); if
+ * (UserRoleEnum.PRODUCT_MANAGER.getName().equals(role) || UserRoleEnum.PRODUCT_STRATEGIST.getName().equals(role)){ String userId = modifier.getUserId(); if (!product.getContacts().contains(userId)){ log.
+ * debug("User with userId {} cannot checkout product. userId not found in product contacts list" , userId); ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION); return Either.right(responseFormat);
+ * } else { log. trace("Found user userId {} in product contacts - checkout request validated" ); } } return eitherResponse; }
+ */
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java
new file mode 100644
index 0000000000..49d94dc80b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifeCycleTransition.java
@@ -0,0 +1,160 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public abstract class LifeCycleTransition {
+
+ protected ConfigurationManager configurationManager;
+ protected ILifecycleOperation lifeCycleOperation;
+ protected ComponentsUtils componentUtils;
+
+ protected Map<ComponentTypeEnum, List<Role>> authorizedRoles;
+
+ protected LifeCycleTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+
+ // configurationManager = (ConfigurationManager)
+ // context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
+ // lifeCycleOperation = LifecycleOperation.getInstance();
+ this.configurationManager = ConfigurationManager.getConfigurationManager();
+ this.lifeCycleOperation = lifecycleOperation;
+ this.componentUtils = componentUtils;
+ this.authorizedRoles = new HashMap<>();
+
+ }
+
+ public abstract LifeCycleTransitionEnum getName();
+
+ public abstract AuditingActionEnum getAuditingAction();
+
+ public ConfigurationManager getConfigurationManager() {
+ return configurationManager;
+ }
+
+ public void setConfigurationManager(ConfigurationManager configurationManager) {
+ this.configurationManager = configurationManager;
+ }
+
+ public ILifecycleOperation getLifeCycleOperation() {
+ return lifeCycleOperation;
+ }
+
+ public void setLifeCycleOperation(ILifecycleOperation lifeCycleOperation) {
+ this.lifeCycleOperation = lifeCycleOperation;
+ }
+
+ public List<Role> getAuthorizedRoles(ComponentTypeEnum componentType) {
+ return authorizedRoles.get(componentType);
+ }
+
+ public void addAuthorizedRoles(ComponentTypeEnum componentType, List<Role> authorizedRoles) {
+ this.authorizedRoles.put(componentType, authorizedRoles);
+ }
+
+ //
+ // public Either<? extends Component, ResponseFormat>
+ // changeState(ComponentTypeEnum componentType, Component component,
+ // ComponentBusinessLogic componentBl, User modifier, User owner){
+ // return changeState(componentType, component, componentBl, modifier,
+ // owner, false);
+ // }
+
+ public abstract Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean needLock, boolean inTransaction);
+
+ public abstract Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo);
+
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState) {
+
+ return this.validateBeforeTransition(component, componentType, modifier, owner, oldState, null);
+ }
+
+ /**
+ * getComponentOwner
+ *
+ * @param resource
+ * @return
+ */
+ protected Either<User, ResponseFormat> getComponentOwner(Component component, ComponentTypeEnum componentType) {
+
+ return getComponentOwner(component, componentType, false);
+ }
+
+ protected Either<User, ResponseFormat> getComponentOwner(Component component, ComponentTypeEnum componentType, boolean inTransaction) {
+
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ Either<User, StorageOperationStatus> resourceOwnerResult = getLifeCycleOperation().getComponentOwner(component.getUniqueId(), nodeType, inTransaction);
+ if (resourceOwnerResult.isRight()) {
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(componentUtils.convertFromStorageResponse(resourceOwnerResult.right().value()), component, componentType);
+ return Either.right(responseFormat);
+ }
+ return Either.left(resourceOwnerResult.left().value());
+ }
+
+ /**
+ * isUserValidForRequest
+ *
+ * @param modifier
+ * @param action
+ * TODO
+ * @return
+ */
+ protected Either<Boolean, ResponseFormat> userRoleValidation(User modifier, ComponentTypeEnum componentType, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+
+ // validate user
+ if (getAuthorizedRoles(componentType).contains(Role.valueOf(modifier.getRole()))) {
+ return Either.left(true);
+ }
+
+ // this is only when creating vfc/cp when import vf from csar - when we
+ // create resources from node type, we create need to change the state
+ // to certified
+ if (lifecycleChangeInfo != null && lifecycleChangeInfo.getAction() != null && lifecycleChangeInfo.getAction() == LifecycleChanceActionEnum.CREATE_FROM_CSAR) {
+ return Either.left(true);
+ }
+
+ ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ return Either.right(responseFormat);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
new file mode 100644
index 0000000000..27709bb332
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
@@ -0,0 +1,572 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+
+import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
+import org.openecomp.sdc.be.model.operations.impl.ProductOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("lifecycleBusinessLogic")
+public class LifecycleBusinessLogic {
+
+ private static final String COMMENT = "comment";
+
+ @Autowired
+ private IGraphLockOperation graphLockOperation = null;
+
+ @Autowired
+ private ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Autowired
+ private ResourceOperation resourceOperation;
+
+ @Autowired
+ private ServiceOperation serviceOperation;
+
+ @Autowired
+ private ProductOperation productOperation;
+
+ @Autowired
+ private CapabilityOperation capabilityOperation;
+
+ private static Logger log = LoggerFactory.getLogger(LifecycleBusinessLogic.class.getName());
+
+ @javax.annotation.Resource
+ private ComponentsUtils componentUtils;
+
+ @javax.annotation.Resource
+ private ILifecycleOperation lifecycleOperation;
+ @javax.annotation.Resource
+ ArtifactsBusinessLogic artifactsManager;
+
+ @javax.annotation.Resource
+ private ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder;
+
+ @javax.annotation.Resource
+ private ServiceBusinessLogic serviceBusinessLogic;
+
+ @javax.annotation.Resource
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @javax.annotation.Resource
+ private ProductBusinessLogic productBusinessLogic;
+
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+
+ @Autowired
+ ICacheMangerOperation cacheManagerOperation;
+
+ private Map<String, LifeCycleTransition> stateTransitions;
+ private static volatile boolean isInitialized = false;
+
+ @PostConstruct
+ public void init() {
+ // init parameters
+ if (!isInitialized) {
+ synchronized (this) {
+ if (!isInitialized) {
+ initStateOperations();
+ isInitialized = true;
+ }
+ }
+ }
+ }
+
+ private void initStateOperations() {
+ stateTransitions = new HashMap<String, LifeCycleTransition>();
+
+ LifeCycleTransition checkoutOp = new CheckoutTransition(componentUtils, lifecycleOperation);
+ stateTransitions.put(checkoutOp.getName().name(), checkoutOp);
+
+ UndoCheckoutTransition undoCheckoutOp = new UndoCheckoutTransition(componentUtils, lifecycleOperation);
+ undoCheckoutOp.setArtifactsBusinessLogic(artifactsBusinessLogic);
+ stateTransitions.put(undoCheckoutOp.getName().name(), undoCheckoutOp);
+
+ LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation);
+ stateTransitions.put(checkinOp.getName().name(), checkinOp);
+
+ LifeCycleTransition certificationRequest = new CertificationRequestTransition(componentUtils, lifecycleOperation, serviceDistributionArtifactsBuilder, serviceBusinessLogic, capabilityOperation, toscaExportUtils);
+ stateTransitions.put(certificationRequest.getName().name(), certificationRequest);
+
+ LifeCycleTransition startCertification = new StartCertificationTransition(componentUtils, lifecycleOperation);
+ stateTransitions.put(startCertification.getName().name(), startCertification);
+
+ LifeCycleTransition failCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.FAIL_CERTIFICATION, componentUtils, lifecycleOperation);
+ stateTransitions.put(failCertification.getName().name(), failCertification);
+
+ LifeCycleTransition cancelCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.CANCEL_CERTIFICATION, componentUtils, lifecycleOperation);
+ stateTransitions.put(cancelCertification.getName().name(), cancelCertification);
+
+ CertificationChangeTransition successCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentUtils, lifecycleOperation);
+ successCertification.setArtifactsManager(artifactsBusinessLogic);
+ stateTransitions.put(successCertification.getName().name(), successCertification);
+ }
+
+ public LifeCycleTransition getLifecycleTransition(LifeCycleTransitionEnum transitionEnum) {
+ return stateTransitions.get(transitionEnum.name());
+ }
+
+ public Either<Service, ResponseFormat> changeServiceState(String serviceId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) {
+ return (Either<Service, ResponseFormat>) changeComponentState(ComponentTypeEnum.SERVICE, serviceId, modifier, transitionEnum, changeInfo, inTransaction, needLock);
+ }
+
+ // TODO: rhalili - should use changeComponentState when possible
+ public Either<Resource, ResponseFormat> changeState(String resourceId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) {
+ return (Either<Resource, ResponseFormat>) changeComponentState(ComponentTypeEnum.RESOURCE, resourceId, modifier, transitionEnum, changeInfo, inTransaction, needLock);
+
+ // LifeCycleTransition lifeCycleTransition =
+ // stateTransitions.get(transitionEnum.name());
+ // if (lifeCycleTransition == null) {
+ // log.debug("state operation is not valid. operations allowed are: {}",
+ // LifeCycleTransitionEnum.valuesAsString());
+ // ResponseFormat error =
+ // componentUtils.getInvalidContentErrorAndAudit(modifier,
+ // AuditingActionEnum.CHECKOUT_RESOURCE);
+ // return Either.right(error);
+ // }
+ //
+ // Either<Resource, ResponseFormat> operationResult;
+ // Resource resource = null;
+ // boolean needToUnlockResource = false;
+ //
+ // log.debug("get resource from graph");
+ // ResponseFormat errorResponse;
+ // Either<Resource, ResponseFormat> eitherResourceResponse =
+ // getResourceForChange(resourceId, modifier, lifeCycleTransition);
+ // if (eitherResourceResponse.isRight()) {
+ // return eitherResourceResponse;
+ // }
+ // resource = eitherResourceResponse.left().value();
+ // String resourceCurrVersion = resource.getResourceVersion();
+ // LifecycleStateEnum resourceCurrState = resource.getLifecycleState();
+ //
+ // if (inTransaction == false) {
+ // // lock resource
+ // Either<Boolean, ResponseFormat> eitherLockResource =
+ // lockResource(resource);
+ // if (eitherLockResource.isRight()) {
+ // errorResponse = eitherLockResource.right().value();
+ // componentUtils.auditResource(errorResponse, modifier, resource,
+ // resourceCurrState.name(), resourceCurrVersion,
+ // lifeCycleTransition.getAuditingAction(), null);
+ // return Either.right(errorResponse);
+ // }
+ // needToUnlockResource = true;
+ // }
+ //
+ // try {
+ // Either<Boolean, ResponseFormat> resourceNotDeleted =
+ // validateResourceNotDeleted(modifier, lifeCycleTransition, resource,
+ // resourceCurrVersion);
+ // if (resourceNotDeleted.isRight()) {
+ // return Either.right(resourceNotDeleted.right().value());
+ // }
+ //
+ // Either<Boolean, ResponseFormat> validateHighestVersion =
+ // validateHighestVersion(modifier, lifeCycleTransition, resource,
+ // resourceCurrVersion);
+ // if (validateHighestVersion.isRight()) {
+ // return Either.right(validateHighestVersion.right().value());
+ // }
+ //
+ // Either<User, ResponseFormat> ownerResult =
+ // lifeCycleTransition.getResourceOwner(resource);
+ // if (ownerResult.isRight()) {
+ // return Either.right(ownerResult.right().value());
+ // }
+ // User owner = ownerResult.left().value();
+ // log.debug("owner of resource {} is {}", resource.getUniqueId(),
+ // owner.getUserId());
+ //
+ // LifecycleStateEnum oldState = resource.getLifecycleState();
+ //
+ // Either<String, ResponseFormat> commentValidationResult =
+ // validateComment(changeInfo, transitionEnum);
+ // if (commentValidationResult.isRight()) {
+ // errorResponse = commentValidationResult.right().value();
+ // EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new
+ // EnumMap<AuditingFieldsKeysEnum,
+ // Object>(AuditingFieldsKeysEnum.class);
+ // auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT,
+ // changeInfo.getUserRemarks());
+ // componentUtils.auditResource(errorResponse, modifier, resource,
+ // resourceCurrState.name(), resourceCurrVersion,
+ // lifeCycleTransition.getAuditingAction(), auditingFields);
+ // return Either.right(errorResponse);
+ // }
+ // changeInfo.setUserRemarks(commentValidationResult.left().value());
+ //
+ // Either<Boolean, ResponseFormat> stateValidationResult =
+ // lifeCycleTransition.validateResourceBeforeTransition(resource.getResourceName(),
+ // ComponentTypeEnum.RESOURCE, modifier, owner, oldState);
+ // if (stateValidationResult.isRight()) {
+ // errorResponse = stateValidationResult.right().value();
+ // componentUtils.auditResource(errorResponse, modifier, resource,
+ // resourceCurrState.name(), resourceCurrVersion,
+ // lifeCycleTransition.getAuditingAction(), null);
+ // return Either.right(errorResponse);
+ // }
+ //
+ // operationResult = lifeCycleTransition.changeStateOperation(resource,
+ // modifier, owner, inTransaction);
+ //
+ // if (operationResult.isRight()) {
+ // errorResponse = operationResult.right().value();
+ // log.debug("audit before sending response");
+ // componentUtils.auditResource(errorResponse, modifier, resource,
+ // resourceCurrState.name(), resourceCurrVersion,
+ // lifeCycleTransition.getAuditingAction(), null);
+ //
+ // return Either.right(errorResponse);
+ // }
+ // Resource resourceAfterOperation = operationResult.left().value();
+ // EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new
+ // EnumMap<AuditingFieldsKeysEnum,
+ // Object>(AuditingFieldsKeysEnum.class);
+ // auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT,
+ // changeInfo.getUserRemarks());
+ // componentUtils.auditResource(componentUtils.getResponseFormat(ActionStatus.OK),
+ // modifier, resourceAfterOperation, resourceCurrState.name(),
+ // resourceCurrVersion, lifeCycleTransition.getAuditingAction(),
+ // auditingFields);
+ // return operationResult;
+ //
+ // } finally {
+ // log.debug("unlock resource {}", resourceId);
+ // if (needToUnlockResource && resource != null) {
+ // resource.setUniqueId(resourceId);
+ // graphLockOperation.unlockResource(resource);
+ // }
+ // }
+
+ }
+
+ public Either<? extends Component, ResponseFormat> changeComponentState(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
+ boolean needLock) {
+
+ LifeCycleTransition lifeCycleTransition = stateTransitions.get(transitionEnum.name());
+ if (lifeCycleTransition == null) {
+ log.debug("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString());
+ ResponseFormat error = componentUtils.getInvalidContentErrorAndAudit(modifier, AuditingActionEnum.CHECKOUT_RESOURCE);
+ return Either.right(error);
+ }
+ ComponentBusinessLogic bl = getComponentBL(componentType);
+
+ Either<? extends Component, ResponseFormat> operationResult = null;
+ Component component = null;
+ // boolean needToUnlockResource = false;
+ log.debug("get resource from graph");
+ ResponseFormat errorResponse;
+
+ Either<? extends Component, ResponseFormat> eitherResourceResponse = getComponentForChange(componentType, componentId, modifier, lifeCycleTransition, changeInfo);
+ if (eitherResourceResponse.isRight()) {
+ return eitherResourceResponse;
+ }
+ component = eitherResourceResponse.left().value();
+ String resourceCurrVersion = component.getVersion();
+ LifecycleStateEnum resourceCurrState = component.getLifecycleState();
+
+ // lock resource
+ if (inTransaction == false && needLock) {
+ Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(componentType, component);
+ if (eitherLockResource.isRight()) {
+ errorResponse = eitherLockResource.right().value();
+ componentUtils.auditComponent(errorResponse, modifier, component, resourceCurrState.name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType, null);
+ return Either.right(errorResponse);
+ }
+ // needToUnlockResource = true;
+ }
+ try {
+ Either<String, ResponseFormat> commentValidationResult = validateComment(changeInfo, transitionEnum);
+ if (commentValidationResult.isRight()) {
+ errorResponse = commentValidationResult.right().value();
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, changeInfo.getUserRemarks());
+ componentUtils.auditComponent(errorResponse, modifier, component, resourceCurrState.name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType, auditingFields);
+ return Either.right(errorResponse);
+ }
+ changeInfo.setUserRemarks(commentValidationResult.left().value());
+
+ Either<Boolean, ResponseFormat> validateHighestVersion = validateHighestVersion(modifier, lifeCycleTransition, component, resourceCurrVersion, componentType);
+ if (validateHighestVersion.isRight()) {
+ return Either.right(validateHighestVersion.right().value());
+ }
+
+ Either<User, ResponseFormat> ownerResult = lifeCycleTransition.getComponentOwner(component, componentType, inTransaction);
+ if (ownerResult.isRight()) {
+ return Either.right(ownerResult.right().value());
+ }
+ User owner = ownerResult.left().value();
+ log.debug("owner of resource {} is {}", component.getUniqueId(), owner.getUserId());
+
+ LifecycleStateEnum oldState = component.getLifecycleState();
+
+ Either<Boolean, ResponseFormat> stateValidationResult = lifeCycleTransition.validateBeforeTransition(component, componentType, modifier, owner, oldState, changeInfo);
+ if (stateValidationResult.isRight()) {
+ errorResponse = stateValidationResult.right().value();
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, changeInfo.getUserRemarks());
+ componentUtils.auditComponent(errorResponse, modifier, component, resourceCurrState.name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType, auditingFields);
+ return Either.right(errorResponse);
+
+ }
+
+ operationResult = lifeCycleTransition.changeState(componentType, component, bl, modifier, owner, false, inTransaction);
+
+ if (operationResult.isRight()) {
+ errorResponse = operationResult.right().value();
+ log.debug("audit before sending response");
+ componentUtils.auditComponentAdmin(errorResponse, modifier, component, resourceCurrState.name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType);
+
+ return Either.right(errorResponse);
+ }
+ Component resourceAfterOperation = operationResult.left().value();
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, changeInfo.getUserRemarks());
+ componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation, resourceCurrState.name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType, auditingFields);
+ return operationResult;
+
+ } finally {
+ log.debug("unlock component {}", componentId);
+ if (inTransaction == false && needLock && component != null) {
+ component.setUniqueId(componentId);
+ NodeTypeEnum nodeType = componentType.getNodeType();
+
+ // Handle component change in the cache of the side affect of
+ // the operation
+ if (operationResult != null && operationResult.isLeft()) {
+ Component componentAfterOpertion = operationResult.left().value();
+ String uniqueId = componentAfterOpertion.getUniqueId();
+ if (false == componentId.equals(uniqueId)) {
+ log.debug("During change state, another component {} has been created/updated", uniqueId);
+ if (uniqueId != null) {
+ cacheManagerOperation.updateComponentInCache(uniqueId, componentAfterOpertion.getLastUpdateDate(), nodeType);
+ }
+ }
+ }
+
+ graphLockOperation.unlockComponent(componentId, nodeType);
+
+ }
+ }
+
+ }
+
+ private Either<? extends Component, ResponseFormat> getComponentForChange(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransition lifeCycleTransition, LifecycleChangeInfoWithAction changeInfo) {
+
+ Either<? extends Component, StorageOperationStatus> eitherResourceResponse = Either.right(StorageOperationStatus.GENERAL_ERROR);
+ switch (componentType) {
+ case SERVICE:
+ eitherResourceResponse = serviceOperation.getComponent(componentId, true);
+ break;
+ case PRODUCT:
+ eitherResourceResponse = productOperation.getComponent(componentId, true);
+ break;
+ case RESOURCE:
+ eitherResourceResponse = resourceOperation.getComponent(componentId, true);
+ break;
+ default:
+ break;
+ }
+
+ ResponseFormat errorResponse = null;
+ if (eitherResourceResponse.isRight()) {
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(eitherResourceResponse.right().value(), componentType);
+ errorResponse = componentUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
+ log.debug("audit before sending response");
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, changeInfo.getUserRemarks());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, componentId);
+ componentUtils.auditComponent(errorResponse, modifier, null, Constants.EMPTY_STRING, Constants.EMPTY_STRING, lifeCycleTransition.getAuditingAction(), componentType, auditingFields);
+
+ return Either.right(errorResponse);
+ }
+ return Either.left(eitherResourceResponse.left().value());
+ }
+
+ private Either<Boolean, ResponseFormat> validateHighestVersion(User modifier, LifeCycleTransition lifeCycleTransition, Resource resource, String resourceCurrVersion) {
+ ResponseFormat errorResponse;
+ if (!resource.isHighestVersion()) {
+ log.debug("resource version {} is not the last version of resource {}", resource.getVersion(), resource.getName());
+ errorResponse = componentUtils.getResponseFormat(ActionStatus.COMPONENT_HAS_NEWER_VERSION, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase());
+ componentUtils.auditResource(errorResponse, modifier, resource, resource.getLifecycleState().name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), null);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateResourceNotDeleted(User modifier, LifeCycleTransition lifeCycleTransition, Resource resource, String resourceCurrVersion) {
+
+ ResponseFormat errorResponse;
+ if ((resource.getIsDeleted() != null) && (resource.getIsDeleted() == true)) {
+ ActionStatus actionStatus = ActionStatus.RESOURCE_NOT_FOUND;
+ errorResponse = componentUtils.getResponseFormatByResource(actionStatus, resource.getName());
+ log.debug("resource {} {} is marked for delete", resource.getName(), resource.getVersion());
+ componentUtils.auditResource(errorResponse, modifier, null, "", "", lifeCycleTransition.getAuditingAction(), null);
+
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateHighestVersion(User modifier, LifeCycleTransition lifeCycleTransition, Component component, String resourceCurrVersion, ComponentTypeEnum componentType) {
+ ResponseFormat errorResponse;
+ if (!component.isHighestVersion()) {
+ log.debug("Component version {} is not the last version of component {}", component.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion(),
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ errorResponse = componentUtils.getResponseFormat(ActionStatus.COMPONENT_HAS_NEWER_VERSION, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(), componentType.getValue().toLowerCase());
+ componentUtils.auditComponentAdmin(errorResponse, modifier, component, component.getLifecycleState().name(), resourceCurrVersion, lifeCycleTransition.getAuditingAction(), componentType);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> lockComponent(ComponentTypeEnum componentType, Component component) {
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(component.getUniqueId(), nodeType);
+
+ if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
+ return Either.left(true);
+ } else {
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(lockResourceStatus);
+ ResponseFormat responseFormat = componentUtils.getResponseFormat(actionStatus, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ return Either.right(responseFormat);
+ }
+
+ }
+
+ private Either<Resource, ResponseFormat> getResourceForChange(String resourceId, User modifier, LifeCycleTransition lifeCycleTransition) {
+ Either<Resource, StorageOperationStatus> eitherResourceResponse = resourceOperation.getResource(resourceId, true);
+
+ ResponseFormat errorResponse = null;
+ if (eitherResourceResponse.isRight()) {
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(eitherResourceResponse.right().value());
+ errorResponse = componentUtils.getResponseFormatByResource(actionStatus, "");
+ log.debug("audit before sending response");
+ // For audit of not found, resourceName should be uniqueID according
+ // to Ella
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceId);
+ componentUtils.auditResource(errorResponse, modifier, null, "", "", lifeCycleTransition.getAuditingAction(), null);
+
+ return Either.right(errorResponse);
+ }
+ Resource resource = eitherResourceResponse.left().value();
+
+ return Either.left(resource);
+
+ }
+
+ private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction changeInfo, LifeCycleTransitionEnum transitionEnum) {
+ String comment = changeInfo.getUserRemarks();
+ if (LifeCycleTransitionEnum.CANCEL_CERTIFICATION == transitionEnum || LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.FAIL_CERTIFICATION == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
+ || LifeCycleTransitionEnum.CERTIFICATION_REQUEST == transitionEnum
+ // import?
+ ) {
+
+ if (!ValidationUtils.validateStringNotEmpty(comment)) {
+ log.debug("user comment cannot be empty or null.");
+ ResponseFormat errorResponse = componentUtils.getResponseFormat(ActionStatus.MISSING_DATA, COMMENT);
+ return Either.right(errorResponse);
+ }
+
+ comment = ValidationUtils.removeNoneUtf8Chars(comment);
+ comment = ValidationUtils.removeHtmlTags(comment);
+ comment = ValidationUtils.normaliseWhitespace(comment);
+ comment = ValidationUtils.stripOctets(comment);
+
+ if (!ValidationUtils.validateLength(comment, ValidationUtils.COMMENT_MAX_LENGTH)) {
+ log.debug("user comment exceeds limit.");
+ return Either.right(componentUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, COMMENT, String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
+ }
+ if (!ValidationUtils.validateIsEnglish(comment)) {
+ return Either.right(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+ return Either.left(comment);
+ }
+
+ private ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum) {
+ ComponentBusinessLogic businessLogic;
+ switch (componentTypeEnum) {
+ case RESOURCE: {
+ businessLogic = this.resourceBusinessLogic;
+ break;
+ }
+ case SERVICE: {
+ businessLogic = this.serviceBusinessLogic;
+ break;
+ }
+ case PRODUCT: {
+ businessLogic = this.productBusinessLogic;
+ break;
+ }
+
+ default: {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "getComponentBL");
+ throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
+ }
+ }
+ return businessLogic;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java
new file mode 100644
index 0000000000..0c35caf41b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+public class LifecycleChangeInfoBase {
+
+ public LifecycleChangeInfoBase() {
+ }
+
+ public LifecycleChangeInfoBase(String userRemarks) {
+ super();
+ this.userRemarks = userRemarks;
+ }
+
+ private String userRemarks;
+
+ public String getUserRemarks() {
+ return userRemarks;
+ }
+
+ public void setUserRemarks(String userRemarks) {
+ this.userRemarks = userRemarks;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java
new file mode 100644
index 0000000000..170e187f15
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+public class LifecycleChangeInfoWithAction extends LifecycleChangeInfoBase {
+
+ public enum LifecycleChanceActionEnum {
+ CREATE_FROM_CSAR, UPDATE_FROM_EXTERNAL_API
+ };
+
+ private LifecycleChanceActionEnum action;
+
+ public LifecycleChangeInfoWithAction() {
+ }
+
+ public LifecycleChangeInfoWithAction(String userRemarks) {
+ super(userRemarks);
+ }
+
+ public LifecycleChangeInfoWithAction(String userRemarks, LifecycleChanceActionEnum action) {
+ super(userRemarks);
+ this.action = action;
+ }
+
+ public LifecycleChanceActionEnum getAction() {
+ return action;
+ }
+
+ public void setAction(LifecycleChanceActionEnum action) {
+ this.action = action;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java
new file mode 100644
index 0000000000..918140b0af
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.Arrays;
+
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class StartCertificationTransition extends LifeCycleTransition {
+
+ private static Logger log = LoggerFactory.getLogger(StartCertificationTransition.class.getName());
+
+ public StartCertificationTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+ super(componentUtils, lifecycleOperation);
+
+ // authorized roles
+ Role[] rsrcServiceStartCertificationRoles = { Role.ADMIN, Role.TESTER };
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(rsrcServiceStartCertificationRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(rsrcServiceStartCertificationRoles));
+ // TODO to be later defined for product
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return LifeCycleTransitionEnum.START_CERTIFICATION;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return AuditingActionEnum.START_CERTIFICATION_RESOURCE;
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+
+ log.debug("start performing certification test for resource {}", component.getUniqueId());
+
+ NodeTypeEnum nodeType = (componentType.equals(ComponentTypeEnum.SERVICE)) ? NodeTypeEnum.Service : NodeTypeEnum.Resource;
+ Either<? extends Component, StorageOperationStatus> stateChangeResult = lifeCycleOperation.startComponentCertification(nodeType, component, modifier, owner, inTransaction);
+ if (stateChangeResult.isRight()) {
+ log.debug("start certification failed on graph");
+ StorageOperationStatus response = stateChangeResult.right().value();
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
+
+ if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
+ actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
+ }
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(stateChangeResult.left().value());
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before start certification test. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN) || oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.CERTIFIED)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CERTIFIED, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ return Either.left(true);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java
new file mode 100644
index 0000000000..fcb211bc3e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java
@@ -0,0 +1,170 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.ILifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class UndoCheckoutTransition extends LifeCycleTransition {
+ private static Logger log = LoggerFactory.getLogger(CheckoutTransition.class.getName());
+ private ArtifactsBusinessLogic artifactsManager;
+
+ public UndoCheckoutTransition(ComponentsUtils componentUtils, ILifecycleOperation lifecycleOperation) {
+ super(componentUtils, lifecycleOperation);
+
+ // authorized roles
+ Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
+ Role[] productCheckoutRoles = { Role.ADMIN, Role.PRODUCT_MANAGER };
+ addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles));
+ addAuthorizedRoles(ComponentTypeEnum.PRODUCT, Arrays.asList(productCheckoutRoles));
+
+ }
+
+ @Override
+ public LifeCycleTransitionEnum getName() {
+ return LifeCycleTransitionEnum.UNDO_CHECKOUT;
+ }
+
+ @Override
+ public AuditingActionEnum getAuditingAction() {
+ return AuditingActionEnum.UNDO_CHECKOUT_RESOURCE;
+ }
+
+ public ArtifactsBusinessLogic getArtifactsBusinessLogic() {
+ return artifactsManager;
+ }
+
+ public void setArtifactsBusinessLogic(ArtifactsBusinessLogic artifactsBusinessLogic) {
+ this.artifactsManager = artifactsBusinessLogic;
+ }
+
+ @Override
+ public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
+ String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ log.debug("validate before undo checkout. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
+
+ // validate user
+ Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier, componentType, lifecycleChangeInfo);
+ if (userValidationResponse.isRight()) {
+ return userValidationResponse;
+ }
+
+ // check resource is not locked by another user
+ if (!oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CHECKED_IN, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ if (!modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
+ return Either.right(error);
+ }
+
+ return Either.left(true);
+ }
+
+ @Override
+ public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
+
+ Either<? extends Component, ResponseFormat> result = null;
+ log.debug("start performing undo-checkout for resource {}", component.getUniqueId());
+
+ Either<List<ArtifactDefinition>, StorageOperationStatus> artifactsRes = lifeCycleOperation.getComponentOperation(componentType.getNodeType()).getComponentArtifactsForDelete(component.getUniqueId(), componentType.getNodeType(), true);
+ if (artifactsRes.isRight()) {
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(artifactsRes.right().value());
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ // TODO - start transaction
+ try {
+ NodeTypeEnum nodeType = componentType.getNodeType();
+
+ // 1. perform undo checkout on graph (update status and delete
+ // current version)
+ Either<? extends Component, StorageOperationStatus> undoCheckoutResourceResult = lifeCycleOperation.undoCheckout(nodeType, component, modifier, owner, true);
+
+ if (undoCheckoutResourceResult.isRight()) {
+ log.debug("checkout failed on graph");
+ StorageOperationStatus response = undoCheckoutResourceResult.right().value();
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ result = Either.right(responseFormat);
+ return result;
+ }
+
+ // 2. delete unrelated artifacts
+ // use artifacts API to delete artifacts from swift / elasticsearch
+
+ if (artifactsRes.left().value() != null) {
+ List<ArtifactDefinition> artifacts = artifactsRes.left().value();
+ StorageOperationStatus deleteAllResourceArtifacts = artifactsManager.deleteAllComponentArtifactsIfNotOnGraph(artifacts);
+
+ if (!deleteAllResourceArtifacts.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentUtils.convertFromStorageResponse(deleteAllResourceArtifacts);
+ ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
+ result = Either.right(responseFormat);
+ return result;
+ }
+ }
+
+ result = Either.left(undoCheckoutResourceResult.left().value());
+ } finally {
+ if (result == null || result.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Change LifecycleState - Undo Checkout failed on graph");
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Change LifecycleState - Undo Checkout failed on graph");
+
+ log.debug("operation failed. do rollback");
+ lifeCycleOperation.getResourceOperation().getTitanGenericDao().rollback();
+ } else {
+ log.debug("operation success. do commit");
+ lifeCycleOperation.getResourceOperation().getTitanGenericDao().commit();
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/CategoryTypeEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/CategoryTypeEnum.java
new file mode 100644
index 0000000000..edfe56ebfa
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/CategoryTypeEnum.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datamodel.api;
+
+import java.io.Serializable;
+
+public enum CategoryTypeEnum implements Serializable {
+
+ CATEGORY("category"), SUBCATEGORY("sub-category"), GROUPING("grouping");
+
+ private String value;
+
+ CategoryTypeEnum(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/HighestFilterEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/HighestFilterEnum.java
new file mode 100644
index 0000000000..42ff4c900a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/api/HighestFilterEnum.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datamodel.api;
+
+public enum HighestFilterEnum {
+
+ ALL, HIGHEST_ONLY, NON_HIGHEST_ONLY;
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ArtifactUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ArtifactUtils.java
new file mode 100644
index 0000000000..9f66911461
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ArtifactUtils.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datamodel.utils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+public class ArtifactUtils {
+ public static ArtifactDefinition findMasterArtifact(Map<String, ArtifactDefinition> deplymentArtifact, List<ArtifactDefinition> artifacts, List<String> artifactsList) {
+ for (String artifactUid : artifactsList) {
+ for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
+ ArtifactDefinition artifact = entry.getValue();
+ if (artifactUid.equalsIgnoreCase(artifact.getUniqueId())) {
+ artifacts.add(artifact);
+ }
+
+ }
+ }
+ if (artifacts.size() == 1) {
+ return artifacts.get(0);
+ }
+ ArtifactDefinition masterArtifact = null;
+ for (ArtifactDefinition artifactInfo : artifacts) {
+ String atrifactType = artifactInfo.getArtifactType();
+ if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()) || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType())) {
+ masterArtifact = artifactInfo;
+ continue;
+ }
+ if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
+ masterArtifact = artifactInfo;
+ break;
+ }
+ }
+ return masterArtifact;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/NodeTypeConvertUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/NodeTypeConvertUtils.java
new file mode 100644
index 0000000000..ab71508e62
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/NodeTypeConvertUtils.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datamodel.utils;
+
+import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+
+public class NodeTypeConvertUtils {
+ public static NodeTypeEnum getCategoryNodeTypeByComponentParam(ComponentTypeEnum componentTypeEnum, CategoryTypeEnum categoryType) {
+ NodeTypeEnum res = null;
+ if (componentTypeEnum != null) {
+ switch (componentTypeEnum) {
+ case SERVICE:
+ switch (categoryType) {
+ case CATEGORY:
+ res = NodeTypeEnum.ServiceNewCategory;
+ break;
+
+ default:
+ // doesn't support subcategories or grouping
+ break;
+ }
+ break;
+ case RESOURCE:
+ switch (categoryType) {
+ case CATEGORY:
+ res = NodeTypeEnum.ResourceNewCategory;
+ break;
+ case SUBCATEGORY:
+ res = NodeTypeEnum.ResourceSubcategory;
+ break;
+ default:
+ // doesn't support grouping
+ break;
+ }
+ break;
+ case PRODUCT:
+ switch (categoryType) {
+ case CATEGORY:
+ res = NodeTypeEnum.ProductCategory;
+ break;
+ case SUBCATEGORY:
+ res = NodeTypeEnum.ProductSubcategory;
+ break;
+ case GROUPING:
+ res = NodeTypeEnum.ProductGrouping;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return res;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java
new file mode 100644
index 0000000000..0cc415c80d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution;
+
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+
+public class AuditHandler {
+ ComponentsUtils componentsUtils;
+ String instanceID;
+ private RegistrationRequest registrationRequest;
+
+ public AuditHandler(ComponentsUtils componentsUtils, String instanceID, RegistrationRequest registrationRequest) {
+ super();
+ this.componentsUtils = componentsUtils;
+ this.instanceID = instanceID;
+ this.registrationRequest = registrationRequest;
+ }
+
+ public void auditRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole) {
+
+ String topicName = (subscriberRole == SubscriberTypeEnum.CONSUMER) ? DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName())
+ : DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName());
+ componentsUtils.auditTopicACLKeys(AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL, registrationRequest.getDistrEnvName(), topicName, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
+ }
+
+ public void auditUnRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole) {
+ String topicName = (subscriberRole == SubscriberTypeEnum.CONSUMER) ? DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName())
+ : DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName());
+ componentsUtils.auditTopicACLKeys(AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL, registrationRequest.getDistrEnvName(), topicName, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
+
+ }
+
+ public void auditRegisterRequest(CambriaErrorResponse registerResponse) {
+ componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
+ registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
+
+ }
+
+ public void auditUnRegisterRequest(CambriaErrorResponse registerResponse) {
+ componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_UN_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
+ registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java
new file mode 100644
index 0000000000..ae1de21ea8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java
@@ -0,0 +1,243 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution;
+
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaHandler;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.distribution.api.client.ServerListResponse;
+import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse;
+import org.openecomp.sdc.be.distribution.api.client.TopicUnregistrationResponse;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+@Component("distributionBusinessLogic")
+public class DistributionBusinessLogic {
+ public static final String REGISTER_IN_DISTRIBUTION_ENGINE = "registerInDistributionEngine";
+ public static final String UN_REGISTER_IN_DISTRIBUTION_ENGINE = "unregisterInDistributionEngine";
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private static Logger log = LoggerFactory.getLogger(DistributionBusinessLogic.class.getName());
+ @Resource
+ private DistributionEngine distributionEngine;
+
+ private ResponseFormatManager responseFormatManager = ResponseFormatManager.getInstance();
+ private CambriaHandler cambriaHandler;
+
+ public Either<ServerListResponse, ResponseFormat> getUebServerList() {
+
+ DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+
+ List<String> serverList = distributionEngineConfiguration.getUebServers();
+
+ if (serverList != null && !serverList.isEmpty()) {
+
+ ServerListResponse serverListResponse = new ServerListResponse();
+
+ serverListResponse.setUebServerList(serverList);
+
+ return Either.left(serverListResponse);
+ } else {
+ ResponseFormat errorResponseWrapper = getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(errorResponseWrapper);
+ }
+
+ }
+
+ public void handleRegistration(Wrapper<Response> responseWrapper, RegistrationRequest registrationRequest, AuditHandler auditHandler) {
+ CambriaErrorResponse registerResponse = null;
+ try {
+ registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.PRODUCER);
+ auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.PRODUCER);
+
+ if (responseWrapper.isEmpty()) {
+ registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.CONSUMER);
+ auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.CONSUMER);
+ // Second Register failed - unregister the first
+ if (!responseWrapper.isEmpty()) {
+ CambriaErrorResponse unRegisterResponse = unRegisterDistributionClientFromTopic(registrationRequest, SubscriberTypeEnum.PRODUCER);
+ auditHandler.auditUnRegisterACL(unRegisterResponse, SubscriberTypeEnum.PRODUCER);
+ }
+ }
+
+ if (responseWrapper.isEmpty()) {
+ TopicRegistrationResponse okTopicResponse = buildTopicResponse(registrationRequest);
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(okTopicResponse).build());
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, REGISTER_IN_DISTRIBUTION_ENGINE, "registration of subscriber to topic");
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE, "registration of subscriber to topic");
+ Response errorResponse = buildErrorResponse(getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(errorResponse);
+ } finally {
+ auditHandler.auditRegisterRequest(registerResponse);
+ }
+ }
+
+ public void handleUnRegistration(Wrapper<Response> responseWrapper, RegistrationRequest unRegistrationRequest, AuditHandler auditHandler) {
+ Wrapper<CambriaErrorResponse> cambriaResponseWrapper = new Wrapper<>();
+ try {
+ CambriaErrorResponse unregisterClientProducerTopicResponse = unRegisterDistributionClientFromTopic(unRegistrationRequest, SubscriberTypeEnum.PRODUCER);
+ auditHandler.auditUnRegisterACL(unregisterClientProducerTopicResponse, SubscriberTypeEnum.PRODUCER);
+ updateResponseWrapper(cambriaResponseWrapper, unregisterClientProducerTopicResponse);
+
+ CambriaErrorResponse unregisterClientConsumerTopicResponse = unRegisterDistributionClientFromTopic(unRegistrationRequest, SubscriberTypeEnum.CONSUMER);
+ auditHandler.auditUnRegisterACL(unregisterClientConsumerTopicResponse, SubscriberTypeEnum.CONSUMER);
+ updateResponseWrapper(cambriaResponseWrapper, unregisterClientConsumerTopicResponse);
+
+ // Success unregister both topics
+ TopicUnregistrationResponse unregisterResponse = new TopicUnregistrationResponse(getNotificationTopicName(unRegistrationRequest.getDistrEnvName()), getStatusTopicName(unRegistrationRequest.getDistrEnvName()),
+ unregisterClientConsumerTopicResponse.getOperationStatus(), unregisterClientProducerTopicResponse.getOperationStatus());
+
+ if (cambriaResponseWrapper.getInnerElement().getOperationStatus() == CambriaOperationStatus.OK) {
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(unregisterResponse).build());
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration failed");
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration failed");
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(unregisterResponse).build());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration of subscriber to topic");
+ Response errorResponse = buildErrorResponse(getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(errorResponse);
+
+ } finally {
+ auditHandler.auditUnRegisterRequest(cambriaResponseWrapper.getInnerElement());
+ }
+ }
+
+ private void updateResponseWrapper(Wrapper<CambriaErrorResponse> cambriaResponseWrapper, CambriaErrorResponse currentResponse) {
+ if (cambriaResponseWrapper.isEmpty()) {
+ cambriaResponseWrapper.setInnerElement(currentResponse);
+ } else if (currentResponse.getOperationStatus() != CambriaOperationStatus.OK) {
+ cambriaResponseWrapper.setInnerElement(currentResponse);
+
+ }
+
+ }
+
+ public static String getNotificationTopicName(String envName) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+ return DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), envName);
+
+ }
+
+ public static String getStatusTopicName(String envName) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+ return DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), envName);
+
+ }
+
+ protected CambriaErrorResponse unRegisterDistributionClientFromTopic(RegistrationRequest unRegistrationRequest, SubscriberTypeEnum subscriberType) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+ String topicName;
+ if (subscriberType == SubscriberTypeEnum.PRODUCER) {
+ topicName = getStatusTopicName(unRegistrationRequest.getDistrEnvName());
+ } else {
+ topicName = getNotificationTopicName(unRegistrationRequest.getDistrEnvName());
+
+ }
+ log.debug("unregistering client as {} , from topic: {}", subscriberType.name(), topicName);
+ return getCambriaHandler().unRegisterFromTopic(config.getUebServers(), topicName, config.getUebPublicKey(), config.getUebSecretKey(), unRegistrationRequest.getApiPublicKey(), subscriberType);
+ }
+
+ private TopicRegistrationResponse buildTopicResponse(RegistrationRequest registrationRequest) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+ String statusTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ String notificationTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+
+ TopicRegistrationResponse topicResponse = new TopicRegistrationResponse();
+ topicResponse.setDistrNotificationTopicName(notificationTopicName);
+ topicResponse.setDistrStatusTopicName(statusTopicName);
+ return topicResponse;
+ }
+
+ protected CambriaErrorResponse registerDistributionClientToTopic(Wrapper<Response> responseWrapper, RegistrationRequest registrationRequest, SubscriberTypeEnum subscriberType) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
+ String topicName, errorMsg;
+
+ // Register for notifications as consumer
+ if (subscriberType == SubscriberTypeEnum.CONSUMER) {
+ topicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+ errorMsg = "registration of subscriber to topic:" + topicName + " as consumer failed";
+ }
+ // Register for status as producer
+ else {
+ topicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ errorMsg = "registration of subscriber to topic:" + topicName + " as producer failed";
+ }
+ log.debug("registering client as {} , from topic: {}", subscriberType.name(), topicName);
+ CambriaErrorResponse registerToTopic = getCambriaHandler().registerToTopic(config.getUebServers(), topicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), subscriberType);
+
+ if (registerToTopic.getOperationStatus() != CambriaOperationStatus.OK) {
+ Response failedRegistrationResponse = buildErrorResponse(getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, REGISTER_IN_DISTRIBUTION_ENGINE, errorMsg);
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE, errorMsg);
+ responseWrapper.setInnerElement(failedRegistrationResponse);
+ }
+ return registerToTopic;
+ }
+
+ protected Response buildErrorResponse(ResponseFormat requestErrorWrapper) {
+ Response response = Response.status(requestErrorWrapper.getStatus()).entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
+ return response;
+ }
+
+ public ResponseFormatManager getResponseFormatManager() {
+ return responseFormatManager;
+ }
+
+ public DistributionEngine getDistributionEngine() {
+ return distributionEngine;
+ }
+
+ public CambriaHandler getCambriaHandler() {
+ if (cambriaHandler == null) {
+ cambriaHandler = new CambriaHandler();
+ }
+ return cambriaHandler;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/CambriaOperationStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/CambriaOperationStatus.java
new file mode 100644
index 0000000000..a6a6602cb0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/CambriaOperationStatus.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.api.client;
+
+public enum CambriaOperationStatus {
+ OK, CONNNECTION_ERROR, NOT_FOUND, TOPIC_ALREADY_EXIST, OBJECT_NOT_FOUND, INTERNAL_SERVER_ERROR, AUTHENTICATION_ERROR, UNKNOWN_HOST_ERROR,
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java
new file mode 100644
index 0000000000..ef14efe4f8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.api.client;
+
+public class RegistrationRequest {
+ String apiPublicKey;
+ String distrEnvName;
+
+ public RegistrationRequest(String apiPublicKey, String distrEnvName) {
+ this.apiPublicKey = apiPublicKey;
+ this.distrEnvName = distrEnvName;
+ }
+
+ public String getApiPublicKey() {
+ return apiPublicKey;
+ }
+
+ public String getDistrEnvName() {
+ return distrEnvName;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java
new file mode 100644
index 0000000000..267a691e29
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.api.client;
+
+import java.util.List;
+
+public class ServerListResponse {
+
+ private List<String> uebServerList;
+
+ public List<String> getUebServerList() {
+ return uebServerList;
+ }
+
+ public void setUebServerList(List<String> uebServerList) {
+ this.uebServerList = uebServerList;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java
new file mode 100644
index 0000000000..e2a34a19d5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.api.client;
+
+public class TopicRegistrationResponse {
+ String distrNotificationTopicName;
+ String distrStatusTopicName;
+
+ public void setDistrNotificationTopicName(String distrNotificationTopicName) {
+ this.distrNotificationTopicName = distrNotificationTopicName;
+ }
+
+ public void setDistrStatusTopicName(String distrStatusTopicName) {
+ this.distrStatusTopicName = distrStatusTopicName;
+ }
+
+ public String getDistrNotificationTopicName() {
+ return distrNotificationTopicName;
+ }
+
+ public String getDistrStatusTopicName() {
+ return distrStatusTopicName;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java
new file mode 100644
index 0000000000..ffb9f9352f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.api.client;
+
+public class TopicUnregistrationResponse {
+ String distrNotificationTopicName;
+ String distrStatusTopicName;
+ CambriaOperationStatus notificationUnregisterResult;
+ CambriaOperationStatus statusUnregisterResult;
+
+ public TopicUnregistrationResponse(String distrNotificationTopicName, String distrStatusTopicName, CambriaOperationStatus notificationUnregisterResult, CambriaOperationStatus statusUnregisterResult) {
+ super();
+ this.distrNotificationTopicName = distrNotificationTopicName;
+ this.distrStatusTopicName = distrStatusTopicName;
+ this.notificationUnregisterResult = notificationUnregisterResult;
+ this.statusUnregisterResult = statusUnregisterResult;
+ }
+
+ public String getDistrNotificationTopicName() {
+ return distrNotificationTopicName;
+ }
+
+ public String getDistrStatusTopicName() {
+ return distrStatusTopicName;
+ }
+
+ public CambriaOperationStatus getNotificationUnregisterResult() {
+ return notificationUnregisterResult;
+ }
+
+ public CambriaOperationStatus getStatusUnregisterResult() {
+ return statusUnregisterResult;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java
new file mode 100644
index 0000000000..a5d1093648
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java
@@ -0,0 +1,230 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.servlet;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Singleton
+public class DistributionCatalogServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(DistributionCatalogServlet.class.getName());
+
+ // *******************************************************
+ // Download (GET) artifacts
+ // **********************************************************/
+
+ @GET
+ @Path("/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download service artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadServiceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("artifactName") final String artifactName,
+ @Context final HttpServletRequest request) {
+ Response response = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD;
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI);
+
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("Missing X-ECOMP-InstanceID header");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsLogic.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
+ if (downloadRsrcArtifactEither.isRight()) {
+ ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildErrorResponse(responseFormat);
+ } else {
+ byte[] value = downloadRsrcArtifactEither.left().value();
+ InputStream is = new ByteArrayInputStream(value);
+
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildOkResponse(responseFormat, is, headers);
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "download Murano package artifact for service - external API");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download Murano package artifact for service - external API");
+ log.debug("download artifact failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/services/{serviceName}/{serviceVersion}/resources/{resourceName}/{resourceVersion}/artifacts/{artifactName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download resource artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadResourceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("resourceName") final String resourceName,
+ @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName, @Context final HttpServletRequest request) {
+ Response response = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD;
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI);
+
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("Missing X-ECOMP-InstanceID header");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsLogic.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName, resourceVersion, artifactName);
+ if (downloadRsrcArtifactEither.isRight()) {
+ ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildErrorResponse(responseFormat);
+ } else {
+ byte[] value = downloadRsrcArtifactEither.left().value();
+ // Returning 64-encoded as it was received during upload
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildOkResponse(responseFormat, is, headers);
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "download interface artifact for resource - external API");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
+ log.debug("download artifact failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // --------------------------------
+
+ @GET
+ @Path("/services/{serviceName}/{serviceVersion}/resourceInstances/{resourceInstanceName}/artifacts/{artifactName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download resource artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadResourceInstanceArtifact(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @PathParam("artifactName") final String artifactName, @Context final HttpServletRequest request) {
+ Response response = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.DISTRIBUTION_ARTIFACT_DOWNLOAD;
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI);
+
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("Missing X-ECOMP-InstanceID header");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsLogic.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName, artifactName);
+ if (downloadRsrcArtifactEither.isRight()) {
+ ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildErrorResponse(responseFormat);
+ } else {
+ byte[] value = downloadRsrcArtifactEither.left().value();
+ // Returning 64-encoded as it was received during upload
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, auditingActionEnum, additionalParam);
+ response = buildOkResponse(responseFormat, is, headers);
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "download interface artifact for resource - external API");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
+ log.debug("download artifact failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // --------------------------------
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java
new file mode 100644
index 0000000000..b1556bafc3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java
@@ -0,0 +1,279 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.servlet;
+
+import javax.annotation.Resource;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.distribution.AuditHandler;
+import org.openecomp.sdc.be.distribution.DistributionBusinessLogic;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.distribution.api.client.ServerListResponse;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.HttpUtil;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1")
+@Singleton
+public class DistributionServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(DistributionServlet.class.getName());
+ @Resource
+ private DistributionBusinessLogic distributionLogic;
+
+ @GET
+ @Path("/distributionUebCluster")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getUebServerList(@Context final HttpServletRequest request, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) {
+ init(request);
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ if (instanceId == null) {
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ response = buildErrorResponse(responseFormat);
+ getComponentsUtils().auditMissingInstanceId(AuditingActionEnum.GET_UEB_CLUSTER, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ return response;
+ }
+ try {
+ Either<ServerListResponse, ResponseFormat> actionResponse = distributionLogic.getUebServerList();
+
+ if (actionResponse.isRight()) {
+ responseFormat = actionResponse.right().value();
+ response = buildErrorResponse(responseFormat);
+ } else {
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+ }
+
+ getComponentsUtils().auditGetUebCluster(AuditingActionEnum.GET_UEB_CLUSTER, instanceId, null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "failed to get ueb serbver list from cofiguration");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("failed to get ueb serbver list from cofiguration");
+ log.debug("failed to get ueb serbver list from cofiguration", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ getComponentsUtils().auditGetUebCluster(AuditingActionEnum.GET_UEB_CLUSTER, instanceId, null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ response = buildErrorResponse(responseFormat);
+ return response;
+ }
+
+ }
+
+ /**
+ * Returns list of valid artifact types for validation done in the distribution client.<br>
+ * The list is the representation of the values of the enum ArtifactTypeEnum.
+ *
+ * @param request
+ * @param instanceId
+ * @param requestId
+ * @param authorization
+ * @param accept
+ * @return
+ */
+ @GET
+ @Path("/artifactTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getValidArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId, @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, @HeaderParam(value = Constants.ACCEPT_HEADER) String accept) {
+ init(request);
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+
+ validateHeaders(responseWrapper, request, AuditingActionEnum.GET_VALID_ARTIFACT_TYPES);
+ if (responseWrapper.isEmpty()) {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values());
+ } else {
+ response = responseWrapper.getInnerElement();
+ }
+ return response;
+ }
+
+ @POST
+ @Path("/registerForDistribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response registerForDistribution(@Context final HttpServletRequest request, String requestJson) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ init(request);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<RegistrationRequest> registrationRequestWrapper = new Wrapper<>();
+
+ validateHeaders(responseWrapper, request, AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL);
+
+ if (responseWrapper.isEmpty()) {
+ validateJson(responseWrapper, registrationRequestWrapper, requestJson);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateEnv(responseWrapper, registrationRequestWrapper.getInnerElement().getDistrEnvName());
+ }
+
+ if (responseWrapper.isEmpty()) {
+ distributionLogic.handleRegistration(responseWrapper, registrationRequestWrapper.getInnerElement(), buildAuditHandler(request, registrationRequestWrapper.getInnerElement()));
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, DistributionBusinessLogic.REGISTER_IN_DISTRIBUTION_ENGINE, "registration validation failed");
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.REGISTER_IN_DISTRIBUTION_ENGINE, "registration validation failed");
+ }
+
+ return responseWrapper.getInnerElement();
+ }
+
+ @POST
+ @Path("/unRegisterForDistribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response unRegisterForDistribution(@Context final HttpServletRequest request, String requestJson) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ init(request);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<RegistrationRequest> unRegistrationRequestWrapper = new Wrapper<>();
+
+ validateHeaders(responseWrapper, request, AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL);
+
+ if (responseWrapper.isEmpty()) {
+ validateJson(responseWrapper, unRegistrationRequestWrapper, requestJson);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateEnv(responseWrapper, unRegistrationRequestWrapper.getInnerElement().getDistrEnvName());
+ }
+ if (responseWrapper.isEmpty()) {
+ distributionLogic.handleUnRegistration(responseWrapper, unRegistrationRequestWrapper.getInnerElement(), buildAuditHandler(request, unRegistrationRequestWrapper.getInnerElement()));
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDistributionEngineSystemError, DistributionBusinessLogic.UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration validation failed");
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration validation failed");
+ }
+
+ return responseWrapper.getInnerElement();
+ }
+
+ private void validateEnv(Wrapper<Response> responseWrapper, String distrEnvName) {
+
+ // DE194021
+ StorageOperationStatus environmentStatus = distributionLogic.getDistributionEngine().isEnvironmentAvailable();
+ // DE194021
+ // StorageOperationStatus environmentStatus =
+ // distributionLogic.getDistributionEngine().isEnvironmentAvailable(distrEnvName);
+ if (environmentStatus != StorageOperationStatus.OK) {
+ if (environmentStatus == StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND) {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.DISTRIBUTION_ENV_DOES_NOT_EXIST));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ } else {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ }
+ }
+
+ }
+
+ private void init(HttpServletRequest request) {
+ if (distributionLogic == null) {
+ distributionLogic = getDistributionBL(request.getSession().getServletContext());
+ }
+ }
+
+ private void validateHeaders(Wrapper<Response> responseWrapper, HttpServletRequest request, AuditingActionEnum auditingAction) {
+ if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null) {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ // Audit
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditMissingInstanceId(auditingAction, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+
+ }
+
+ }
+
+ private void validateJson(Wrapper<Response> responseWrapper, Wrapper<RegistrationRequest> registrationRequestWrapper, String requestJson) {
+ if (requestJson == null || requestJson.isEmpty()) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ } else {
+ Either<RegistrationRequest, Exception> eitherRegistration = HttpUtil.convertJsonStringToObject(requestJson, RegistrationRequest.class);
+ if (eitherRegistration.isLeft()) {
+ RegistrationRequest registrationRequest = eitherRegistration.left().value();
+ if (registrationRequest.getApiPublicKey() == null) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_PUBLIC_KEY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+
+ } else if (registrationRequest.getDistrEnvName() == null) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_ENV_NAME));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ } else {
+ registrationRequestWrapper.setInnerElement(registrationRequest);
+ }
+ } else {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ }
+ }
+
+ }
+
+ private DistributionBusinessLogic getDistributionBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(DistributionBusinessLogic.class);
+ }
+
+ private AuditHandler buildAuditHandler(HttpServletRequest request, RegistrationRequest registrationRequest) {
+ return new AuditHandler(getComponentsUtils(), request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), registrationRequest);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
new file mode 100644
index 0000000000..5670239ef7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
@@ -0,0 +1,376 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ecomp;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.ecomp.converters.EcompRoleConverter;
+import org.openecomp.sdc.be.ecomp.converters.EcompUserConverter;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.ContextLoader;
+
+import org.openecomp.portalsdk.core.onboarding.crossapi.IPortalRestAPIService;
+import org.openecomp.portalsdk.core.onboarding.crossapi.PortalAPIException;
+import org.openecomp.portalsdk.core.restful.domain.EcompRole;
+import org.openecomp.portalsdk.core.restful.domain.EcompUser;
+
+import fj.data.Either;
+
+/*
+ * PortalAPIException(String message, Throwable cause);
+ */
+public class EcompIntImpl implements IPortalRestAPIService {
+ private static Logger log = LoggerFactory.getLogger(EcompIntImpl.class.getName());
+
+ public EcompIntImpl() {
+ log.debug("EcompIntImpl Class Instantiated");
+ }
+
+ @Override
+ public void pushUser(EcompUser user) throws PortalAPIException {
+ log.debug("Start handle request of ECOMP pushUser");
+ try {
+ if (user == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUser", "Recieved null for argument user", ErrorSeverity.INFO);
+ log.debug("Recieved null for argument user");
+ throw new PortalAPIException("Recieved null for argument user");
+ }
+
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ final String modifierAttId = "jh0003";
+ User modifier = new User();
+ modifier.setUserId(modifierAttId);
+ log.debug("modifier id is {}", modifierAttId);
+
+ Either<User, String> newASDCUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (newASDCUser.isRight()) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUser", "Failed to convert user", ErrorSeverity.INFO);
+ log.debug("Failed to create user {}",user.toString());
+ throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
+ } else if (newASDCUser.left().value() == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUser", "NULL pointer returned from user converter", ErrorSeverity.INFO);
+ log.debug("Failed to create user {}", user.toString());
+ throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
+ }
+
+ User convertedAsdcUser = newASDCUser.left().value();
+ Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, convertedAsdcUser);
+
+ // ALREADY EXIST ResponseFormat
+ final String ALREADY_EXISTS_RESPONSE_ID = "SVC4006";
+
+ if (createUserResponse.isRight()) {
+ if (!createUserResponse.right().value().getMessageId().equals(ALREADY_EXISTS_RESPONSE_ID)) {
+ log.debug("Failed to create user {}", user.toString());
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUser", "Failed to create user", ErrorSeverity.ERROR);
+ throw new PortalAPIException("Failed to create user" + createUserResponse.right());
+ }
+ log.debug("User already exist {}", user.toString());
+ }
+ log.debug("User created {}", user.toString());
+ } catch (Exception e) {
+ log.debug("Failed to create user {}", user, e);
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUser", "Failed to create user", ErrorSeverity.ERROR);
+ throw new PortalAPIException("Failed to create user", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ *
+ * loginId - equals to userId
+ *
+ */
+ @Override
+ public void editUser(String loginId, EcompUser user) throws PortalAPIException {
+ log.debug("Start handle request of ECOMP editUser");
+
+ try {
+ if (user == null) {
+ log.debug("Recieved null for argument user");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "Recieved null for argument user", ErrorSeverity.INFO);
+ throw new PortalAPIException("Recieved null for argument user");
+ } else if (loginId == null) {
+ log.debug("Recieved null for argument loginId");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "Recieved null for argument loginId", ErrorSeverity.INFO);
+ throw new PortalAPIException("Recieved null for argument loginId");
+ }
+
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ if (user.getLoginId() != null && !user.getLoginId().equals(loginId)) {
+ log.debug("loginId and user loginId not equal");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "loginId and user loginId not equal", ErrorSeverity.INFO);
+ throw new PortalAPIException("loginId not equals to the user loginId field");
+ } else if (user.getLoginId() == null) {
+ user.setLoginId(loginId);
+ }
+
+ Either<User, String> asdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (asdcUser.isRight()) {
+ log.debug("Failed to convert user");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "Failed to convert user", ErrorSeverity.INFO);
+ throw new PortalAPIException(asdcUser.right().value());
+ } else if (asdcUser.left().value() == null) {
+ log.debug("NULL pointer returned from user converter");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "NULL pointer returned from user converter", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to edit user");
+ }
+
+ Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser.left().value());
+
+ if (updateUserCredentialsResponse.isRight()) {
+ log.debug("Failed to updateUserCredentials");
+ BeEcompErrorManager.getInstance().logInvalidInputError("EditUser", "Failed to updateUserCredentials", ErrorSeverity.ERROR);
+ throw new PortalAPIException("Failed to edit user" + updateUserCredentialsResponse.right().value());
+ }
+ } catch (Exception e) {
+ log.debug("Failed to updateUserCredentials");
+ throw new PortalAPIException("Failed to edit user", e);
+ }
+
+ }
+
+ @Override
+ public EcompUser getUser(String loginId) throws PortalAPIException {
+ log.debug("Start handle request of ECOMP getUser");
+
+ try {
+
+ if (loginId == null) {
+ log.debug("Recieved null for argument loginId");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUser", "Recieved null for argument loginId", ErrorSeverity.INFO);
+ throw new PortalAPIException("Recieved null for argument loginId");
+ }
+
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ Either<User, ActionStatus> getUserResponse = userBusinessLogic.getUser(loginId, false);
+
+ if (getUserResponse.isRight()) {
+ log.debug("Failed to get User");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUser", "Failed to get User", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get User" + getUserResponse.right());
+ } else {
+ if (getUserResponse.left().value() != null) {
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(getUserResponse.left().value());
+ if (ecompUser.isLeft() && ecompUser.left().value() != null) {
+ return ecompUser.left().value();
+ } else {
+ log.debug("Failed to get User");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUser", "Failed to get User", ErrorSeverity.INFO);
+ throw new PortalAPIException(ecompUser.right().value());
+ }
+ } else {
+ log.debug("Failed to get User");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUser", "Failed to get User", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get User" + getUserResponse.right());
+ }
+ }
+ } catch (Exception e) {
+ log.debug("Failed to get User");
+ throw new PortalAPIException("Failed to get User", e);
+ }
+ }
+
+ @Override
+ public List<EcompUser> getUsers() throws PortalAPIException {
+ log.debug("Start handle request of ECOMP getUsers");
+
+ try {
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ final String modifierAttId = "jh0003";
+
+ Either<List<User>, ResponseFormat> getUsersResponse = userBusinessLogic.getUsersList(modifierAttId, null, null);
+
+ if (getUsersResponse.isRight()) {
+ log.debug("Failed to get Users");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUsers", "Failed to get users", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get Users" + getUsersResponse.right());
+ } else {
+ if (getUsersResponse.left().value() != null) {
+ List<EcompUser> ecompUserList = new LinkedList<>();
+ for (User user : getUsersResponse.left().value()) {
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user);
+ if (ecompUser.isRight()) {
+ log.debug("Failed to convert User {}", user);
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUsers", "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
+ continue;
+ } else if (ecompUser.left().value() == null) {
+ log.debug("Failed to convert User {}", user);
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUsers", "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
+ continue;
+ }
+ ecompUserList.add(ecompUser.left().value());
+ }
+ return ecompUserList;
+ } else {
+ log.debug("Failed to get users");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUsers", "Failed to get users", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get Users" + getUsersResponse.right());
+ }
+ }
+ } catch (Exception e) {
+ log.debug("Failed to get users");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUsers", "Failed to get users", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get Users", e);
+ }
+ }
+
+ @Override
+ public List<EcompRole> getAvailableRoles() throws PortalAPIException {
+ log.debug("Start handle request of ECOMP getAvailableRoles");
+ try {
+ List<EcompRole> ecompRolesList = new LinkedList<>();
+ for (Role role : Role.values()) {
+ EcompRole ecompRole = new EcompRole();
+ ecompRole.setId(new Long(role.ordinal()));
+ ecompRole.setName(role.name());
+ ecompRolesList.add(ecompRole);
+ }
+
+ if (ecompRolesList.isEmpty()) {
+ throw new PortalAPIException();
+ }
+
+ return ecompRolesList;
+ } catch (Exception e) {
+ log.debug("Failed to fetch roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetAvailableRoles", "Failed to fetch roles", ErrorSeverity.INFO);
+ throw new PortalAPIException("Roles fetching failed", e);
+ }
+
+ }
+
+ /**
+ * The user role updated through this method only
+ */
+ @Override
+ public void pushUserRole(String loginId, List<EcompRole> roles) throws PortalAPIException {
+ log.debug("Start handle request of ECOMP pushUserRole");
+
+ final String modifierAttId = "jh0003";
+ User modifier = new User();
+ modifier.setUserId(modifierAttId);
+ log.debug("modifier id is {}", modifierAttId);
+
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ String updatedRole = null;
+
+ if (roles == null) {
+ throw new PortalAPIException("Error: Recieved null for roles");
+ } else if (roles.iterator().hasNext()) {
+ EcompRole ecompRole = roles.iterator().next();
+ updatedRole = EcompRoleConverter.convertEcompRoleToRole(ecompRole);
+ log.debug("pushing role: {} to user: {}", updatedRole, loginId);
+ } else {
+ log.debug("Error: No roles in List");
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUserRole", "Failed to fetch roles", ErrorSeverity.INFO);
+ throw new PortalAPIException("Error: No roles in List");
+ }
+
+ Either<User, ResponseFormat> updateUserRoleResponse = userBusinessLogic.updateUserRole(modifier, loginId, updatedRole);
+ if (updateUserRoleResponse.isRight()) {
+ log.debug("Error: Failed to update role");
+ BeEcompErrorManager.getInstance().logInvalidInputError("PushUserRole", "Failed to update role", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to update role" + updateUserRoleResponse.right().value().toString());
+ }
+ }
+
+ @Override
+ public List<EcompRole> getUserRoles(String loginId) throws PortalAPIException {
+ try {
+ log.debug("Start handle request of ECOMP getUserRoles");
+
+ UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
+
+ Either<User, ActionStatus> getUserResponse = userBusinessLogic.getUser(loginId, false);
+
+ if (getUserResponse.isRight()) {
+ log.debug("Error: Failed to get Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUserRoles", "Failed to get Roles", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get Roles" + getUserResponse.right());
+ } else {
+ if (getUserResponse.left().value() != null) {
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(getUserResponse.left().value());
+ if (ecompUser.isRight()) {
+ log.debug("Error: Failed to convert Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUserRoles", "Failed to convert Roles", ErrorSeverity.ERROR);
+ throw new PortalAPIException(ecompUser.right().value());
+ } else if (ecompUser.left().value() == null) {
+ log.debug("Error: Failed to convert Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUserRoles", "Failed to convert Roles", ErrorSeverity.ERROR);
+ throw new PortalAPIException();
+ }
+
+ return new LinkedList<>(ecompUser.left().value().getRoles());
+ } else {
+ log.debug("Error: Failed to get Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUserRoles", "Failed to get Roles", ErrorSeverity.ERROR);
+ throw new PortalAPIException("Failed to get Roles" + getUserResponse.right());
+ }
+ }
+ } catch (Exception e) {
+ log.debug("Error: Failed to get Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError("GetUserRoles", "Failed to get Roles", ErrorSeverity.INFO);
+ throw new PortalAPIException("Failed to get Roles", e);
+ }
+ }
+
+ @Override
+ public boolean isAppAuthenticated(HttpServletRequest request) throws PortalAPIException {
+ // TODO Validation should be changed completely
+ final String USERNAME = request.getHeader("username");
+ final String PASSWORD = request.getHeader("password");
+
+ if (USERNAME != null && PASSWORD != null) {
+ if (!USERNAME.equals("") && !PASSWORD.equals("")) {
+ log.debug("User authenticated - Username: {} Password: {}", USERNAME, PASSWORD);
+ return true;
+ }
+ }
+
+ log.debug("User authentication failed");
+ return false;
+ }
+
+ private UserBusinessLogic getUserBusinessLogic() {
+ ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
+ UserBusinessLogic userBusinessLogic = (UserBusinessLogic) ctx.getBean("userBusinessLogic");
+ return userBusinessLogic;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java
new file mode 100644
index 0000000000..ca970ce45f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ecomp.converters;
+
+import org.openecomp.sdc.be.user.Role;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.openecomp.portalsdk.core.restful.domain.EcompRole;
+
+public final class EcompRoleConverter {
+
+ private static Logger log = LoggerFactory.getLogger(EcompRoleConverter.class.getName());
+
+ private EcompRoleConverter() {
+ }
+
+ // TODO Add Either or Exception in case of convertation failure
+ public static String convertEcompRoleToRole(EcompRole ecompRole) {
+
+ log.debug("converting role");
+ if (ecompRole == null) {
+ log.debug("recieved null for roles");
+ return null;
+ }
+
+ for (Role role : Role.values()) {
+ if (role.ordinal() == ecompRole.getId()) {
+ return role.name();
+ }
+ }
+ log.debug("no roles converted");
+ return null;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
new file mode 100644
index 0000000000..e83b53c2a4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ecomp.converters;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+
+import org.openecomp.portalsdk.core.restful.domain.EcompRole;
+import org.openecomp.portalsdk.core.restful.domain.EcompUser;
+
+import fj.data.Either;
+
+public final class EcompUserConverter {
+
+ private EcompUserConverter() {
+ }
+
+ // private static final EcompUserConverter instance = new
+ // EcompUserConverter();
+
+ /*
+ * public static EcompUserConverter getInsatnce() { return instance; }
+ */
+
+ public static Either<EcompUser, String> convertUserToEcompUser(User asdcUser) {
+ EcompUser convertedUser = new EcompUser();
+
+ if (asdcUser == null) {
+ return Either.right("User is null");
+ }
+
+ convertedUser.setFirstName(asdcUser.getFirstName());
+ convertedUser.setLastName(asdcUser.getLastName());
+ convertedUser.setLoginId(asdcUser.getUserId());
+ convertedUser.setOrgUserId(asdcUser.getUserId());
+ convertedUser.setEmail(asdcUser.getEmail());
+
+ if (asdcUser.getStatus().equals(UserStatusEnum.ACTIVE)) {
+ convertedUser.setActive(true);
+ } else if (asdcUser.getStatus().equals(UserStatusEnum.INACTIVE)) {
+ convertedUser.setActive(false);
+ }
+
+ EcompRole convertedRole = new EcompRole();
+ for (Role role : Role.values()) {
+ if (role.name().equals(asdcUser.getRole()) || role.toString().equals(asdcUser.getRole())) {
+ convertedRole.setName(role.name());
+ convertedRole.setId(new Long(role.ordinal()));
+ break;
+ }
+ }
+
+ Set<EcompRole> convertedRoleSet = new HashSet<>();
+ convertedRoleSet.add(convertedRole);
+ convertedUser.setRoles(convertedRoleSet);
+
+ return Either.left(convertedUser);
+ }
+
+ public static Either<User, String> convertEcompUserToUser(EcompUser ecompUser) {
+ User convertedUser = new User();
+
+ if (ecompUser == null) {
+ return Either.right("EcompUser is null");
+ }
+
+ convertedUser.setFirstName(ecompUser.getFirstName());
+ convertedUser.setLastName(ecompUser.getLastName());
+
+ if (!ecompUser.getLoginId().isEmpty()) {
+ convertedUser.setUserId(ecompUser.getLoginId());
+ } else {
+ convertedUser.setUserId(ecompUser.getOrgUserId());
+ }
+
+ convertedUser.setEmail(ecompUser.getEmail());
+
+ if (ecompUser.getRoles() != null) {
+ Iterator<EcompRole> iter = ecompUser.getRoles().iterator();
+
+ if (iter.hasNext()) {
+ String updatedRole = EcompRoleConverter.convertEcompRoleToRole(iter.next());
+ convertedUser.setRole(updatedRole);
+ }
+ }
+
+ if (ecompUser.isActive()) {
+ convertedUser.setStatus(UserStatusEnum.ACTIVE);
+ } else {
+ convertedUser.setStatus(UserStatusEnum.INACTIVE);
+ }
+
+ return Either.left(convertedUser);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java
new file mode 100644
index 0000000000..ecdce79b29
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java
@@ -0,0 +1,646 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * This Servlet serves external users operations on artifacts.
+ *
+ * @author mshitrit
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Singleton
+public class ArtifactExternalServlet extends BeGenericServlet {
+
+ @Context
+ private HttpServletRequest request;
+
+ private static Logger log = LoggerFactory.getLogger(ArtifactExternalServlet.class.getName());
+
+ /**
+ * Uploads an artifact to resource or service
+ *
+ * @param assetType
+ * @param uuid
+ * @return
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/artifacts")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "uploads of artifact to a resource or service", httpMethod = "POST", notes = "uploads of artifact to a resource or service", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact uploaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response uploadArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @ApiParam(value = "json describe the artifact", required = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("uploadArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("uploadArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.uploadArtifactToComponentByUUID(data, request, componentType, uuid, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to upload artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to upload artifact to a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * Uploads an artifact to resource instance
+ *
+ * @param assetType
+ * @param uuid
+ * @param resourceInstanceName
+ * @return
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "uploads an artifact to a resource instance", httpMethod = "POST", notes = "uploads an artifact to a resource instance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact uploaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response uploadArtifactToInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @ApiParam(value = "json describe the artifact", required = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("uploadArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("uploadArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.uploadArtifactToRiByUUID(data, request, componentType, uuid, resourceInstanceName, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to upload artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalUploadArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to upload artifact to a resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * updates an artifact on a resource or service
+ *
+ * @param assetType
+ * @param uuid
+ * @param artifactUUID
+ * @return
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "updates an artifact on a resource or service", httpMethod = "POST", notes = "uploads of artifact to a resource or service", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Updated"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response updateArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID,
+ @ApiParam(value = "json describe the artifact", required = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("updateArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ // Mandatory
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("updateArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to update artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to update artifact on a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * updates an artifact on a resource instance
+ *
+ * @param assetType
+ * @param uuid
+ * @param resourceInstanceName
+ * @param artifactUUID
+ * @return
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "updates an artifact on a resource instance", httpMethod = "POST", notes = "uploads of artifact to a resource or service", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Updated"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response updateArtifactOnResourceInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @PathParam("artifactUUID") final String artifactUUID, @ApiParam(value = "json describe the artifact", required = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("updateArtifactOnResourceInstance: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("updateArtifactOnResourceInstance: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("updateArtifactOnResourceInstance: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to update artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalUpdateArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to update artifact on resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * deletes an artifact of a resource or service
+ *
+ * @param assetType
+ * @param uuid
+ * @param artifactUUID
+ * @return
+ */
+ @DELETE
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "deletes an artifact of a resource or service", httpMethod = "DELETE", notes = "deletes an artifact of a resource or service", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Deleted"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response deleteArtifact(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("deleteArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("deleteArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("deleteArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid, artifactUUID, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to delete artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to delete an artifact of a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * deletes an artifact of a resource instance
+ *
+ * @param assetType
+ * @param uuid
+ * @param resourceInstanceName
+ * @return
+ */
+ @DELETE
+ @Path("{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "deletes an artifact of a resource insatnce", httpMethod = "DELETE", notes = "deletes an artifact of a resource insatnce", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact Deleted"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response deleteArtifactOnResourceInstance(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("deleteArtifactOnResourceInsatnce: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParams = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("deleteArtifactOnResourceInsatnce: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("deleteArtifactOnResourceInsatnce: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.deleteArtifactOnRiByUUID(request, componentType, uuid, resourceInstanceName, artifactUUID, additionalParams);
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to delete artifact");
+ responseFormat = uploadArtifactEither.right().value();
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalDeleteArtifact(responseFormat, componentType.getValue(), request, additionalParams);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to delete an artifact of a resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * downloads an artifact of a component (either a service or a resource) by artifactUUID
+ *
+ * @param assetType
+ * @param uuid
+ * @param artifactUUID
+ * @return
+ */
+ @GET
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download component artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadComponentArtifact(
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType,
+ @PathParam("uuid") final String uuid, @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("downloadComponentArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("downloadComponentArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<byte[], ResponseFormat> downloadComponentArtifactEither = artifactsLogic.downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, additionalParam);
+ if (downloadComponentArtifactEither.isRight()) {
+ responseFormat = downloadComponentArtifactEither.right().value();
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ byte[] value = downloadComponentArtifactEither.left().value();
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByByteArray(value));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to download an artifact of a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * downloads an artifact of a resource instance of a component (either a service or a resource) by artifactUUID
+ *
+ * @param assetType
+ * @param uuid
+ * @param resourceInstanceName
+ * @param artifactUUID
+ * @return
+ */
+ @GET
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download resource instance artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadResourceInstanceArtifact(
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType,
+ @PathParam("uuid") final String uuid, @PathParam("resourceInstanceName") final String resourceInstanceName, @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ if (componentType == null) {
+ log.debug("downloadResourceInstanceArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<>(AuditingFieldsKeysEnum.class);
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("downloadResourceInstanceArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty()) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<byte[], ResponseFormat> downloadResourceArtifactEither = artifactsLogic.downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID, additionalParam);
+ if (downloadResourceArtifactEither.isRight()) {
+ responseFormat = downloadResourceArtifactEither.right().value();
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ byte[] value = downloadResourceArtifactEither.left().value();
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByByteArray(value));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, componentType.getValue(), request, additionalParam);
+ responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
+ }
+ } catch (Exception e) {
+ final String message = "failed to download an artifact of a resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ }
+ return responseWrapper.getInnerElement();
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetMetadataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetMetadataConverter.java
new file mode 100644
index 0000000000..20eac081c9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetMetadataConverter.java
@@ -0,0 +1,381 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.distribution.servlet.DistributionCatalogServlet;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ArtifactMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetDetailedMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceInstanceMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetDetailedMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetMetadata;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("asset-metadata-utils")
+public class AssetMetadataConverter {
+ private static Logger log = LoggerFactory.getLogger(DistributionCatalogServlet.class.getName());
+
+ @Autowired
+ private ComponentsUtils componentsUtils;
+ @Autowired
+ private ResourceOperation resourceOperation;
+
+ /*
+ * Relative asset’s URL. Should be used in REST GET API to download the asset’s CSAR. https://{serverBaseURL}/{csarPath} can be obtained from (HttpServletRequest)request.getServerName()
+ */
+ public Either<List<? extends AssetMetadata>, ResponseFormat> convertToAssetMetadata(List<? extends Component> componentList, String serverBaseURL, boolean detailed) {
+ if (componentList == null || componentList.isEmpty()) {
+ return Either.left(new LinkedList<>());
+ }
+
+ List<AssetMetadata> retResList = new LinkedList<>();
+ Component component = componentList.iterator().next();
+ ComponentTypeEnum componentType = component.getComponentType();
+
+ for (Component curr : componentList) {
+
+ Either<? extends AssetMetadata, ResponseFormat> resMetaData = convertToMetadata(componentType, serverBaseURL, detailed, curr);
+
+ if (resMetaData.isRight()) {
+ return Either.right(resMetaData.right().value());
+ }
+
+ retResList.add(resMetaData.left().value());
+ }
+
+ return Either.left(retResList);
+
+ }
+
+ private Either<? extends AssetMetadata, ResponseFormat> convertToMetadata(ComponentTypeEnum componentType, String serverBaseURL, boolean detailed, Component curr) {
+
+ switch (componentType) {
+
+ case RESOURCE:
+
+ return generateResourceMeatdata(serverBaseURL, detailed, curr);
+
+ case SERVICE:
+
+ return generateServiceMetadata(serverBaseURL, detailed, curr);
+
+ // For future US's that include product
+ /*
+ * case PRODUCT: if (component instanceof Product) { List<ProductAssetMetadata> retResList = new LinkedList<>(); for (Component curr : componentList) { retResList.add(convertToProductAssetMetadata((Product) curr, serverBaseURL)); } return
+ * Either.left(retResList);
+ */
+ default:
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_INVALID_CATEGORY);
+ return Either.right(responseFormat);
+ }
+ }
+
+ private Either<? extends AssetMetadata, ResponseFormat> generateResourceMeatdata(String serverBaseURL, boolean detailed, Component curr) {
+ AssetMetadata metaData;
+ metaData = createMetadaObject(detailed, curr.getComponentType());
+ metaData = convertToResourceMetadata((ResourceAssetMetadata) metaData, (Resource) curr, serverBaseURL, detailed);
+
+ if (detailed) {
+ Either<ResourceAssetDetailedMetadata, StorageOperationStatus> converted = convertToResourceDetailedMetadata((ResourceAssetDetailedMetadata) metaData, (Resource) curr, serverBaseURL);
+ if (converted.isRight()) {
+ ActionStatus storageResponse = componentsUtils.convertFromStorageResponse(converted.right().value(), ComponentTypeEnum.RESOURCE);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(storageResponse);
+ return Either.right(responseFormat);
+ }
+ }
+
+ return Either.left(metaData);
+ }
+
+ private AssetMetadata createMetadaObject(boolean detailed, ComponentTypeEnum type) {
+ AssetMetadata metaData = null;
+ switch (type) {
+ case SERVICE:
+ if (!detailed) {
+ metaData = new ServiceAssetMetadata();
+ } else {
+ metaData = new ServiceAssetDetailedMetadata();
+ }
+ break;
+ case RESOURCE:
+ if (!detailed) {
+ metaData = new ResourceAssetMetadata();
+ } else {
+ metaData = new ResourceAssetDetailedMetadata();
+ }
+ break;
+ default:
+ break;
+ }
+ return metaData;
+ }
+
+ private Either<? extends AssetMetadata, ResponseFormat> generateServiceMetadata(String serverBaseURL, boolean detailed, Component curr) {
+ AssetMetadata metaData = createMetadaObject(detailed, curr.getComponentType());
+
+ metaData = convertToServiceAssetMetadata((ServiceAssetMetadata) metaData, (Service) curr, serverBaseURL, detailed);
+
+ if (detailed) {
+ Either<ServiceAssetDetailedMetadata, StorageOperationStatus> converted = convertToServiceDetailedMetadata((ServiceAssetDetailedMetadata) metaData, (Service) curr, serverBaseURL);
+ if (converted.isRight()) {
+ ActionStatus storageResponse = componentsUtils.convertFromStorageResponse(converted.right().value(), ComponentTypeEnum.RESOURCE);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(storageResponse);
+ return Either.right(responseFormat);
+ }
+ }
+
+ return Either.left(metaData);
+ }
+
+ private <U extends AssetMetadata, T extends Component> U convertToAsset(U asset, T component, String serverBaseURL, boolean detailed) {
+ asset.setUuid(component.getUUID());
+ asset.setInvariantUUID(component.getInvariantUUID());
+ asset.setName(component.getName());
+ asset.setVersion(component.getVersion());
+ if (!detailed) {
+ asset.setToscaModelURL(serverBaseURL + "/" + component.getUUID() + "/toscaModel");
+ } else {
+ String toscaModelUrl = (new String(serverBaseURL)).replace("metadata", "toscaModel");
+ asset.setToscaModelURL(toscaModelUrl);
+ }
+
+ return asset;
+ }
+
+ private <T extends ResourceAssetMetadata> T convertToResourceMetadata(T assetToPopulate, Resource resource, String serverBaseURL, boolean detailed) {
+ assetToPopulate = convertToAsset(assetToPopulate, resource, serverBaseURL, detailed);
+ CategoryDefinition categoryDefinition = resource.getCategories().iterator().next();
+ assetToPopulate.setCategory(categoryDefinition.getName());
+
+ SubCategoryDefinition subCategoryDefinition = categoryDefinition.getSubcategories().iterator().next();
+
+ assetToPopulate.setSubCategory(subCategoryDefinition.getName());
+ assetToPopulate.setResourceType(resource.getResourceType().name());
+ assetToPopulate.setLifecycleState(resource.getLifecycleState().name());
+ assetToPopulate.setLastUpdaterUserId(resource.getLastUpdaterUserId());
+
+ return (T) assetToPopulate;
+ }
+
+ private <T extends ServiceAssetMetadata> T convertToServiceAssetMetadata(T assetToPopulate, Service service, String serverBaseURL, boolean detailed) {
+ assetToPopulate = convertToAsset(assetToPopulate, service, serverBaseURL, detailed);
+
+ CategoryDefinition categoryDefinition = service.getCategories().iterator().next();
+
+ assetToPopulate.setCategory(categoryDefinition.getName());
+ assetToPopulate.setLifecycleState(service.getLifecycleState().name());
+ assetToPopulate.setLastUpdaterUserId(service.getLastUpdaterUserId());
+ assetToPopulate.setDistributionStatus(service.getDistributionStatus().name());
+
+ return (T) assetToPopulate;
+ }
+
+ private <T extends ResourceAssetDetailedMetadata> Either<T, StorageOperationStatus> convertToResourceDetailedMetadata(T assetToPopulate, Resource resource, String serverBaseURL) {
+
+ List<ComponentInstance> componentInstances = resource.getComponentInstances();
+
+ if (componentInstances != null) {
+ Either<List<ResourceInstanceMetadata>, StorageOperationStatus> resourceInstanceMetadata = convertToResourceInstanceMetadata(componentInstances, ComponentTypeEnum.RESOURCE_PARAM_NAME, resource.getUUID());
+ if (resourceInstanceMetadata.isRight()) {
+ return Either.right(resourceInstanceMetadata.right().value());
+ }
+
+ assetToPopulate.setResources(resourceInstanceMetadata.left().value());
+ }
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
+ assetToPopulate = populateResourceWithArtifacts(assetToPopulate, resource, serverBaseURL, deploymentArtifacts);
+
+ assetToPopulate.setLastUpdaterFullName(resource.getLastUpdaterFullName());
+ assetToPopulate.setToscaResourceName(resource.getToscaResourceName());
+
+ return Either.left(assetToPopulate);
+ }
+
+ private <T extends ServiceAssetDetailedMetadata> Either<T, StorageOperationStatus> convertToServiceDetailedMetadata(T assetToPopulate, Service service, String serverBaseURL) {
+
+ List<ComponentInstance> componentInstances = service.getComponentInstances();
+
+ if (componentInstances != null) {
+ Either<List<ResourceInstanceMetadata>, StorageOperationStatus> resourceInstanceMetadata = convertToResourceInstanceMetadata(componentInstances, ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUUID());
+ if (resourceInstanceMetadata.isRight()) {
+ return Either.right(resourceInstanceMetadata.right().value());
+ }
+
+ assetToPopulate.setResources(resourceInstanceMetadata.left().value());
+ }
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = service.getDeploymentArtifacts();
+ assetToPopulate = populateServiceWithArtifacts(assetToPopulate, service, deploymentArtifacts);
+
+ assetToPopulate.setLastUpdaterFullName(service.getLastUpdaterFullName());
+
+ return Either.left(assetToPopulate);
+ }
+
+ private <T extends ResourceAssetDetailedMetadata> T populateResourceWithArtifacts(T asset, Resource resource, String serverBaseURL, Map<String, ArtifactDefinition> artifacts) {
+
+ List<ArtifactMetadata> artifactMetaList = populateAssetWithArtifacts(resource, artifacts);
+
+ asset.setArtifacts(artifactMetaList);
+
+ return asset;
+ }
+
+ private <T extends ServiceAssetDetailedMetadata> T populateServiceWithArtifacts(T asset, Service service, Map<String, ArtifactDefinition> artifacts) {
+
+ List<ArtifactMetadata> artifactMetaList = populateAssetWithArtifacts(service, artifacts);
+
+ asset.setArtifacts(artifactMetaList);
+
+ return asset;
+ }
+
+ private List<ArtifactMetadata> populateAssetWithArtifacts(Component component, Map<String, ArtifactDefinition> artifacts) {
+ List<ArtifactMetadata> artifactMetaList = null;
+ if (artifacts != null) {
+ artifactMetaList = new LinkedList<>();
+ Collection<ArtifactDefinition> artefactDefList = artifacts.values();
+
+ for (ArtifactDefinition artifactDefinition : artefactDefList) {
+ if (artifactDefinition.getEsId() != null && !artifactDefinition.getEsId().isEmpty()) {
+ ArtifactMetadata convertedArtifactMetadata = convertToArtifactMetadata(artifactDefinition, ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUUID(), null);
+ artifactMetaList.add(convertedArtifactMetadata);
+ }
+ }
+ }
+ return artifactMetaList.isEmpty() ? null : artifactMetaList;
+ }
+
+ private ArtifactMetadata convertToArtifactMetadata(ArtifactDefinition artifact, String componentType, String componentUUID, String resourceInstanceName) {
+ // /asdc/v1/catalog/{services/resources}/{componentUUID}/artifacts/{artifactUUID}
+ final String COMPONENT_ARTIFACT_URL = "/asdc/v1/catalog/%s/%s/artifacts/%s";
+
+ // /asdc/v1/catalog/{services/resources}/{componentUUID}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}
+ final String RESOURCE_INSTANCE_ARTIFACT_URL = "/asdc/v1/catalog/%s/%s/resourceInstances/%s/artifacts/%s";
+
+ ArtifactMetadata metadata = new ArtifactMetadata();
+
+ metadata.setArtifactName(artifact.getArtifactName());
+ metadata.setArtifactType(artifact.getArtifactType());
+
+ if (resourceInstanceName == null || resourceInstanceName.isEmpty()) {
+ metadata.setArtifactURL(String.format(COMPONENT_ARTIFACT_URL, componentType, componentUUID, artifact.getArtifactUUID()));
+ } else {
+ metadata.setArtifactURL(String.format(RESOURCE_INSTANCE_ARTIFACT_URL, componentType, componentUUID, resourceInstanceName, artifact.getArtifactUUID()));
+ }
+
+ metadata.setArtifactDescription(artifact.getDescription());
+ metadata.setArtifactTimeout(artifact.getTimeout() > 0 ? artifact.getTimeout() : null);
+ metadata.setArtifactChecksum(artifact.getArtifactChecksum());
+ metadata.setArtifactUUID(artifact.getArtifactUUID());
+ metadata.setArtifactVersion(artifact.getArtifactVersion());
+ metadata.setGeneratedFromUUID(artifact.getGeneratedFromId());
+
+ return metadata;
+ }
+
+ private Either<List<ResourceInstanceMetadata>, StorageOperationStatus> convertToResourceInstanceMetadata(List<ComponentInstance> componentInstances, String componentType, String componentUUID) {
+ List<ResourceInstanceMetadata> retList = new LinkedList<>();
+ Map<String, String> uuidDuplicatesMap = new HashMap<>();
+
+ for (ComponentInstance componentInstance : componentInstances) {
+ ResourceInstanceMetadata metadata = new ResourceInstanceMetadata();
+ String componentUid = componentInstance.getComponentUid();
+ String invariantUUID;
+
+ if (!uuidDuplicatesMap.containsKey(componentUid)) {
+ Either<String, StorageOperationStatus> getInvarUuidresponse = resourceOperation.getInvariantUUID(NodeTypeEnum.Resource, componentInstance.getComponentUid(), false);
+ if (getInvarUuidresponse.isRight()) {
+ log.debug("convertToResourceInstanceMetadata: Failed getting Invariant UUID");
+ return Either.right(getInvarUuidresponse.right().value());
+ } else {
+ invariantUUID = getInvarUuidresponse.left().value();
+ uuidDuplicatesMap.put(componentUid, invariantUUID);
+ }
+ } else {
+ invariantUUID = uuidDuplicatesMap.get(componentUid);
+ }
+
+ metadata.setResourceInvariantUUID(invariantUUID);
+ metadata.setResourceInstanceName(componentInstance.getName());
+ metadata.setResourceName(componentInstance.getComponentName());
+ metadata.setResourceVersion(componentInstance.getComponentVersion());
+ metadata.setResoucreType(componentInstance.getOriginType().getValue());
+ metadata.setResourceUUID(componentInstance.getComponentUid());
+
+ Collection<ArtifactDefinition> values = componentInstance.getDeploymentArtifacts().values();
+ LinkedList<ArtifactMetadata> artifactMetaList = new LinkedList<>();
+
+ for (ArtifactDefinition artifactDefinition : values) {
+ ArtifactMetadata converted = convertToArtifactMetadata(artifactDefinition, componentType, componentUUID, componentInstance.getNormalizedName());
+ artifactMetaList.add(converted);
+ }
+
+ metadata.setArtifacts(artifactMetaList);
+
+ retList.add(metadata);
+ }
+
+ return Either.left(retList);
+ }
+
+ // For future US to support Product
+ /*
+ * private ProductAssetMetadata convertToProductAssetMetadata(Product product, String serverBaseURL) { ProductAssetMetadata retProdAsset = new ProductAssetMetadata();
+ *
+ * retProdAsset = convertToAsset(retProdAsset, product, serverBaseURL); retProdAsset.setLifecycleState(product.getLifecycleState().name()); retProdAsset.setLastUpdaterUserId(product.getLastUpdaterUserId());
+ * retProdAsset.setActive(product.getIsActive()); retProdAsset.setContacts(product.getContacts());
+ *
+ * List<CategoryDefinition> categories = product.getCategories(); List<ProductCategoryGroupMetadata> categoryMetadataList = new LinkedList<>();
+ *
+ * if (categories == null || categories.isEmpty()) { return retProdAsset; } else { for (CategoryDefinition categoryDefinition : categories) { String categoryName = categoryDefinition.getName(); List<SubCategoryDefinition> subcategories =
+ * categoryDefinition.getSubcategories(); for (SubCategoryDefinition subCategoryDefinition : subcategories) { String subCategoryName = subCategoryDefinition.getName(); List<GroupDefinition> groups = product.getGroups(); for (GroupDefinition
+ * groupDefinition : groups) { String groupName = groupDefinition.getName(); categoryMetadataList.add(new ProductCategoryGroupMetadata(categoryName, subCategoryName, groupName)); } } } retProdAsset.setProductGroupings(categoryMetadataList);
+ * return retProdAsset; } }
+ */
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
new file mode 100644
index 0000000000..1b8d6fdb75
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
@@ -0,0 +1,300 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.http.NameValuePair;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Singleton
+public class AssetsDataServlet extends BeGenericServlet {
+
+ @Context
+ private HttpServletRequest request;
+
+ private AssetMetadataConverter assetMetadataUtils;
+ private static Logger log = LoggerFactory.getLogger(AssetsDataServlet.class.getName());
+
+ @GET
+ @Path("/{assetType}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Fetch list of assets", httpMethod = "GET", notes = "Returns list of assets", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Assets Fetched"), @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 401, message = "Authorization required"),
+ @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Asset not found") })
+ public Response getAssetList(@PathParam("assetType") final String assetType, @QueryParam("category") String category, @QueryParam("subCategory") String subCategory, @QueryParam("distributionStatus") String distributionStatus) {
+
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String query = request.getQueryString();
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ String serverBaseURL = request.getRequestURL().toString();
+
+ AuditingActionEnum auditingActionEnum = query == null ? AuditingActionEnum.GET_ASSET_LIST : AuditingActionEnum.GET_FILTERED_ASSET_LIST;
+
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, query == null ? requestURI : requestURI + "?" + query);
+
+ // Mandatory
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ElementBusinessLogic elementLogic = getElementBL(context);
+
+ getAssetUtils(context);
+ Map<FilterKeyEnum, String> filters = new HashMap<FilterKeyEnum, String>();
+
+ if (category != null) {
+ filters.put(FilterKeyEnum.CATEGORY, category);
+ }
+ if (subCategory != null) {
+ filters.put(FilterKeyEnum.SUB_CATEGORY, subCategory);
+ }
+ if (distributionStatus != null) {
+ filters.put(FilterKeyEnum.DISTRIBUTION_STATUS, distributionStatus);
+ }
+
+ Either<List<? extends Component>, ResponseFormat> assetTypeData = elementLogic.getFilteredCatalogComponents(assetType, filters, query);
+
+ if (assetTypeData.isRight()) {
+ log.debug("getAssetList: Asset Fetching Failed");
+ responseFormat = assetTypeData.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ } else {
+ log.debug("getAssetList: Asset Fetching Success");
+ Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataUtils.convertToAssetMetadata(assetTypeData.left().value(), serverBaseURL, false);
+ if (resMetadata.isRight()) {
+ log.debug("getAssetList: Asset conversion Failed");
+ responseFormat = resMetadata.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+ Object result = RepresentationUtils.toRepresentation(resMetadata.left().value());
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+
+ response = buildOkResponse(responseFormat, result);
+ return response;
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
+ log.debug("getAssetList: Fetch list of assets failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/{assetType}/{uuid}/metadata")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Fetch metadata of asset by uuid", httpMethod = "GET", notes = "Returns metadata of asset", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Assets Fetched"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response getAssetListByUuid(@PathParam("assetType") final String assetType, @PathParam("uuid") final String uuid, @Context final HttpServletRequest request) {
+
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+ String serverBaseURL = request.getRequestURL().toString();
+
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, componentType.getValue());
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, uuid);
+
+ // Mandatory
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ElementBusinessLogic elementLogic = getElementBL(context);
+ getAssetUtils(context);
+
+ Either<List<? extends Component>, ResponseFormat> assetTypeData = elementLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid);
+
+ if (assetTypeData.isRight()) {
+ log.debug("getAssetList: Asset Fetching Failed");
+ responseFormat = assetTypeData.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+
+ return buildErrorResponse(responseFormat);
+ } else {
+ log.debug("getAssetList: Asset Fetching Success");
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, assetTypeData.left().value().iterator().next().getName());
+ Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataUtils.convertToAssetMetadata(assetTypeData.left().value(), serverBaseURL, true);
+ if (resMetadata.isRight()) {
+ log.debug("getAssetList: Asset conversion Failed");
+ responseFormat = resMetadata.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+ Object result = RepresentationUtils.toRepresentation(resMetadata.left().value().iterator().next());
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+
+ response = buildOkResponse(responseFormat, result);
+ return response;
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
+ log.debug("getAssetList: Fetch list of assets failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private void getAssetUtils(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ assetMetadataUtils = webApplicationContext.getBean(AssetMetadataConverter.class);
+ }
+
+ @GET
+ @Path("/{assetType}/{uuid}/toscaModel")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Fetch asset csar", httpMethod = "GET", notes = "Returns asset csar", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Asset Model Fetched"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Asset not found") })
+ public Response getToscaModel(@PathParam("uuid") final String uuid,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("assetType") final String assetType,
+ @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) {
+
+ String url = request.getRequestURI();
+ log.debug("Start handle request of {} {}", request.getMethod(), url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ ServletContext context = request.getSession().getServletContext();
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL;
+ String userId = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, userId);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, url);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, componentType.getValue());
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, uuid);
+
+ if (userId == null || userId.isEmpty()) {
+ log.debug("getToscaModel: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ComponentBusinessLogic componentBL = getComponentBL(componentType, context);
+
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> csarArtifact = componentBL.getToscaModelByComponentUuid(componentType, uuid, additionalParam);
+ if (csarArtifact.isRight()) {
+ responseFormat = csarArtifact.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ response = buildErrorResponse(responseFormat);
+ } else {
+ byte[] value = csarArtifact.left().value().getRight();
+ InputStream is = new ByteArrayInputStream(value);
+ String contenetMD5 = GeneralUtility.calculateMD5ByByteArray(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(csarArtifact.left().value().getLeft()));
+ headers.put(Constants.MD5_HEADER, contenetMD5);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ response = buildOkResponse(responseFormat, is, headers);
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get asset tosca model");
+ log.debug("falied to get asset tosca model", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ response = buildErrorResponse(responseFormat);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
+ return response;
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ArtifactMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ArtifactMetadata.java
new file mode 100644
index 0000000000..f4194cf2f5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ArtifactMetadata.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public class ArtifactMetadata {
+ private String artifactName;
+ private String artifactType;
+ private String artifactURL;
+ private String artifactDescription;
+ private Integer artifactTimeout;
+ private String artifactChecksum;
+ private String artifactUUID;
+ private String artifactVersion;
+ private String generatedFromUUID;
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ public String getArtifactType() {
+ return artifactType;
+ }
+
+ public void setArtifactType(String artifactType) {
+ this.artifactType = artifactType;
+ }
+
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ public String getArtifactDescription() {
+ return artifactDescription;
+ }
+
+ public void setArtifactDescription(String artifactDescription) {
+ this.artifactDescription = artifactDescription;
+ }
+
+ public Integer getArtifactTimeout() {
+ return artifactTimeout;
+ }
+
+ public void setArtifactTimeout(Integer artifactTimeout) {
+ this.artifactTimeout = artifactTimeout;
+ }
+
+ public String getArtifactChecksum() {
+ return artifactChecksum;
+ }
+
+ public void setArtifactChecksum(String artifactChecksum) {
+ this.artifactChecksum = artifactChecksum;
+ }
+
+ public String getArtifactUUID() {
+ return artifactUUID;
+ }
+
+ public void setArtifactUUID(String artifactUUID) {
+ this.artifactUUID = artifactUUID;
+ }
+
+ public String getArtifactVersion() {
+ return artifactVersion;
+ }
+
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
+
+ public String getGeneratedFromUUID() {
+ return generatedFromUUID;
+ }
+
+ public void setGeneratedFromUUID(String generatedFromUUID) {
+ this.generatedFromUUID = generatedFromUUID;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/AssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/AssetMetadata.java
new file mode 100644
index 0000000000..cb14f76aff
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/AssetMetadata.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public abstract class AssetMetadata implements IAssetMetadata {
+ private String uuid;
+ private String invariantUUID;
+ private String name;
+ private String version;
+ private String toscaModelURL;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# getUuid()
+ */
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# setUuid(java.lang.String)
+ */
+ @Override
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# getInvariantUUID()
+ */
+ @Override
+ public String getInvariantUUID() {
+ return invariantUUID;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# setInvariantUUID(java.lang.String)
+ */
+ @Override
+ public void setInvariantUUID(String invariantUUID) {
+ this.invariantUUID = invariantUUID;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# getName()
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# setName(java.lang.String)
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# getVersion()
+ */
+ @Override
+ public String getVersion() {
+ return version;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# setVersion(java.lang.String)
+ */
+ @Override
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# toscaModelURL()
+ */
+ @Override
+ public String getToscaModelURL() {
+ return toscaModelURL;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.sdc.be.distribution.servlet.representation.IAssetMetadata# toscaModelURL(java.lang.String)
+ */
+ @Override
+ public void setToscaModelURL(String toscaModelURL) {
+ this.toscaModelURL = toscaModelURL;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/IAssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/IAssetMetadata.java
new file mode 100644
index 0000000000..f95a8e9684
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/IAssetMetadata.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public interface IAssetMetadata {
+
+ String getUuid();
+
+ void setUuid(String uuid);
+
+ String getInvariantUUID();
+
+ void setInvariantUUID(String invariantUUID);
+
+ String getName();
+
+ void setName(String name);
+
+ String getVersion();
+
+ void setVersion(String version);
+
+ String getToscaModelURL();
+
+ void setToscaModelURL(String toscaModelURL);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductAssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductAssetMetadata.java
new file mode 100644
index 0000000000..d2d9c2c902
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductAssetMetadata.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+import java.util.List;
+
+public class ProductAssetMetadata extends AssetMetadata {
+ private String lifecycleState;
+ private String lastUpdaterUserId;
+ private boolean isActive;
+ private List<String> contacts;
+ private List<ProductCategoryGroupMetadata> productGroupings;
+
+ public String getLifecycleState() {
+ return lifecycleState;
+ }
+
+ public void setLifecycleState(String lifecycleState) {
+ this.lifecycleState = lifecycleState;
+ }
+
+ public String getLastUpdaterUserId() {
+ return lastUpdaterUserId;
+ }
+
+ public void setLastUpdaterUserId(String lastUpdaterUserId) {
+ this.lastUpdaterUserId = lastUpdaterUserId;
+ }
+
+ public boolean isActive() {
+ return isActive;
+ }
+
+ public void setActive(boolean isActive) {
+ this.isActive = isActive;
+ }
+
+ public List<String> getContacts() {
+ return contacts;
+ }
+
+ public void setContacts(List<String> contacts) {
+ this.contacts = contacts;
+ }
+
+ public List<ProductCategoryGroupMetadata> getProductGroupings() {
+ return productGroupings;
+ }
+
+ public void setProductGroupings(List<ProductCategoryGroupMetadata> productGroupings) {
+ this.productGroupings = productGroupings;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductCategoryGroupMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductCategoryGroupMetadata.java
new file mode 100644
index 0000000000..047f9d6a2c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ProductCategoryGroupMetadata.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public class ProductCategoryGroupMetadata {
+ private String category;
+ private String subCategory;
+ private String group;
+
+ public ProductCategoryGroupMetadata(String category, String subCategory, String group) {
+ this.category = category;
+ this.subCategory = subCategory;
+ this.group = group;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubCategory() {
+ return subCategory;
+ }
+
+ public void setSubCategory(String subCategory) {
+ this.subCategory = subCategory;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetDetailedMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetDetailedMetadata.java
new file mode 100644
index 0000000000..ea282ec2e8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetDetailedMetadata.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+import java.util.List;
+
+public class ResourceAssetDetailedMetadata extends ResourceAssetMetadata {
+
+ private String lastUpdaterFullName;
+ private String toscaResourceName;
+ private List<ResourceInstanceMetadata> resources;
+ private List<ArtifactMetadata> artifacts;
+
+ public String getLastUpdaterFullName() {
+ return lastUpdaterFullName;
+ }
+
+ public void setLastUpdaterFullName(String lastUpdaterFullName) {
+ this.lastUpdaterFullName = lastUpdaterFullName;
+ }
+
+ public String getToscaResourceName() {
+ return toscaResourceName;
+ }
+
+ public void setToscaResourceName(String toscaResourceName) {
+ this.toscaResourceName = toscaResourceName;
+ }
+
+ public List<ResourceInstanceMetadata> getResources() {
+ return resources;
+ }
+
+ public void setResources(List<ResourceInstanceMetadata> resources) {
+ this.resources = resources;
+ }
+
+ public List<ArtifactMetadata> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactMetadata> artifactMetaList) {
+ this.artifacts = artifactMetaList;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetMetadata.java
new file mode 100644
index 0000000000..2b75facc6c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceAssetMetadata.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public class ResourceAssetMetadata extends AssetMetadata {
+ private String category;
+ private String subCategory;
+ private String resourceType;
+ private String lifecycleState;
+ private String lastUpdaterUserId;
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubCategory() {
+ return subCategory;
+ }
+
+ public void setSubCategory(String subCategory) {
+ this.subCategory = subCategory;
+ }
+
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ public String getLifecycleState() {
+ return lifecycleState;
+ }
+
+ public void setLifecycleState(String lifecycleState) {
+ this.lifecycleState = lifecycleState;
+ }
+
+ public String getLastUpdaterUserId() {
+ return lastUpdaterUserId;
+ }
+
+ public void setLastUpdaterUserId(String lastUpdaterUserId) {
+ this.lastUpdaterUserId = lastUpdaterUserId;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceInstanceMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceInstanceMetadata.java
new file mode 100644
index 0000000000..a53422f311
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ResourceInstanceMetadata.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+import java.util.List;
+
+public class ResourceInstanceMetadata {
+ private String resourceInstanceName;
+ private String resourceName;
+ private String resourceInvariantUUID;
+ private String resourceVersion;
+ private String resoucreType;
+ private String resourceUUID;
+ private List<ArtifactMetadata> artifacts;
+
+ public String getResourceInstanceName() {
+ return resourceInstanceName;
+ }
+
+ public void setResourceInstanceName(String resourceInstanceName) {
+ this.resourceInstanceName = resourceInstanceName;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public String getResourceInvariantUUID() {
+ return resourceInvariantUUID;
+ }
+
+ public void setResourceInvariantUUID(String resourceInvariantUUID) {
+ this.resourceInvariantUUID = resourceInvariantUUID;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getResoucreType() {
+ return resoucreType;
+ }
+
+ public void setResoucreType(String resoucreType) {
+ this.resoucreType = resoucreType;
+ }
+
+ public String getResourceUUID() {
+ return resourceUUID;
+ }
+
+ public void setResourceUUID(String resourceUUID) {
+ this.resourceUUID = resourceUUID;
+ }
+
+ public List<ArtifactMetadata> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactMetadata> artifacts) {
+ this.artifacts = artifacts;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java
new file mode 100644
index 0000000000..edd88b495d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+import java.util.List;
+
+public class ServiceAssetDetailedMetadata extends ServiceAssetMetadata {
+ private String lastUpdaterFullName;
+ private List<ResourceInstanceMetadata> resources;
+ private List<ArtifactMetadata> artifacts;
+
+ public String getLastUpdaterFullName() {
+ return lastUpdaterFullName;
+ }
+
+ public void setLastUpdaterFullName(String lastUpdaterFullName) {
+ this.lastUpdaterFullName = lastUpdaterFullName;
+ }
+
+ public List<ResourceInstanceMetadata> getResources() {
+ return resources;
+ }
+
+ public void setResources(List<ResourceInstanceMetadata> resources) {
+ this.resources = resources;
+ }
+
+ public List<ArtifactMetadata> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactMetadata> artifacts) {
+ this.artifacts = artifacts;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java
new file mode 100644
index 0000000000..094f973553
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet.representation;
+
+public class ServiceAssetMetadata extends AssetMetadata {
+ private String category;
+ private String lifecycleState;
+ private String lastUpdaterUserId;
+ private String distributionStatus;
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getLifecycleState() {
+ return lifecycleState;
+ }
+
+ public void setLifecycleState(String lifecycleState) {
+ this.lifecycleState = lifecycleState;
+ }
+
+ public String getLastUpdaterUserId() {
+ return lastUpdaterUserId;
+ }
+
+ public void setLastUpdaterUserId(String lastUpdaterUserId) {
+ this.lastUpdaterUserId = lastUpdaterUserId;
+ }
+
+ public String getDistributionStatus() {
+ return distributionStatus;
+ }
+
+ public void setDistributionStatus(String distributionStatus) {
+ this.distributionStatus = distributionStatus;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java
new file mode 100644
index 0000000000..f7e1d758ac
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java
@@ -0,0 +1,225 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.StringTokenizer;
+
+import javax.annotation.Priority;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.commons.codec.binary.Base64;
+import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.security.Passwords;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+@Priority(10)
+public class BasicAuthenticationFilter implements ContainerRequestFilter {
+
+ @Context
+ private HttpServletRequest sr;
+
+ protected Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ private String realm = "ASDC";
+
+ private static Logger log = LoggerFactory.getLogger(BasicAuthenticationFilter.class.getName());
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+
+ String authHeader = requestContext.getHeaderString(Constants.AUTHORIZATION_HEADER);
+ if (authHeader != null) {
+ StringTokenizer st = new StringTokenizer(authHeader);
+ if (st.hasMoreTokens()) {
+ String basic = st.nextToken();
+
+ if (basic.equalsIgnoreCase("Basic")) {
+ try {
+ String credentials = new String(Base64.decodeBase64(st.nextToken()), "UTF-8");
+ log.debug("Credentials: {}", credentials);
+ checkUserCredentiles(requestContext, credentials);
+ } catch (UnsupportedEncodingException e) {
+ log.error("Authentication Filter Failed Couldn't retrieve authentication", e);
+ authInvalidHeaderError(requestContext);
+ }
+ } else {
+ log.error("Authentication Filter Failed Couldn't retrieve authentication, no basic autantication.");
+ authInvalidHeaderError(requestContext);
+ }
+ } else {
+ log.error("Authentication Filter Failed Couldn't retrieve authentication, no basic autantication.");
+ authInvalidHeaderError(requestContext);
+ }
+
+ } else {
+ log.error("Authentication Filter Failed no autharization header");
+ authRequiredError(requestContext);
+ }
+ }
+
+ private void checkUserCredentiles(ContainerRequestContext requestContext, String credentials) {
+ int p = credentials.indexOf(":");
+ if (p != -1) {
+ String _username = credentials.substring(0, p).trim();
+ String _password = credentials.substring(p + 1).trim();
+
+ ConsumerBusinessLogic consumerBL = getConsumerBusinessLogic();
+ if (consumerBL == null) {
+ log.error("Authentication Filter Failed to get consumerBL.");
+ requestContext.abortWith(Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
+ } else {
+ Either<ConsumerDefinition, ResponseFormat> result = consumerBL.getConsumer(_username);
+ validatePassword(requestContext, _username, _password, result);
+ }
+ } else {
+ log.error("Authentication Filter Failed Couldn't retrieve authentication, no basic autantication.");
+ authInvalidHeaderError(requestContext);
+
+ }
+ }
+
+ private void validatePassword(ContainerRequestContext requestContext, String _username, String _password, Either<ConsumerDefinition, ResponseFormat> result) {
+ if (result.isRight()) {
+ Integer status = result.right().value().getStatus();
+ if (status == Status.NOT_FOUND.getStatusCode()) {
+ log.error("Authentication Filter Failed Couldn't find user");
+ authUserNotFoundError(requestContext, _username);
+ } else {
+ log.error("Authentication Filter Failed to get consumerBL.");
+ requestContext.abortWith(Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ } else {
+ ConsumerDefinition consumerCredentials = result.left().value();
+ if (!Passwords.isExpectedPassword(_password, consumerCredentials.getConsumerSalt(), consumerCredentials.getConsumerPassword())) {
+ log.error("Authentication Filter Failed invalide password");
+ authInvalidePasswordError(requestContext, _username);
+ } else {
+ authSuccesessful(requestContext, _username);
+ }
+ }
+ }
+
+ private void authSuccesessful(ContainerRequestContext requestContext, String _username) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Authentication Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ componentUtils.auditAuthEvent(AuditingActionEnum.AUTH_REQUEST, requestContext.getUriInfo().getPath(), _username, AuthStatus.AUTH_SUCCESS.toString(), realm);
+ }
+
+ private void authInvalidePasswordError(ContainerRequestContext requestContext, String _username) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Authentication Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ componentUtils.auditAuthEvent(AuditingActionEnum.AUTH_REQUEST, requestContext.getUriInfo().getPath(), _username, AuthStatus.AUTH_FAILED_INVALID_PASSWORD.toString(), realm);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_FAILED);
+ requestContext.abortWith(buildErrorResponse(responseFormat, false));
+ }
+
+ private void authUserNotFoundError(ContainerRequestContext requestContext, String _username) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Authentication Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ getComponentsUtils().auditAuthEvent(AuditingActionEnum.AUTH_REQUEST, requestContext.getUriInfo().getPath(), _username, AuthStatus.AUTH_FAILED_USER_NOT_FOUND.toString(), realm);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_FAILED);
+ requestContext.abortWith(buildErrorResponse(responseFormat, false));
+ }
+
+ private void authInvalidHeaderError(ContainerRequestContext requestContext) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Authentication Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ getComponentsUtils().auditAuthEvent(AuditingActionEnum.AUTH_REQUEST, requestContext.getUriInfo().getPath(), "", AuthStatus.AUTH_FAILED_INVALID_AUTHENTICATION_HEADER.toString(), realm);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_FAILED_INVALIDE_HEADER);
+ requestContext.abortWith(buildErrorResponse(responseFormat, false));
+ }
+
+ private void authRequiredError(ContainerRequestContext requestContext) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Authentication Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ getComponentsUtils().auditAuthEvent(AuditingActionEnum.AUTH_REQUEST, requestContext.getUriInfo().getPath(), "", AuthStatus.AUTH_REQUIRED.toString(), realm);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_REQUIRED);
+ requestContext.abortWith(buildErrorResponse(responseFormat, true));
+ }
+
+ private ComponentsUtils getComponentsUtils() {
+ ServletContext context = sr.getSession().getServletContext();
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ComponentsUtils componentsUtils = webApplicationContext.getBean(ComponentsUtils.class);
+ return componentsUtils;
+ }
+
+ private ConsumerBusinessLogic getConsumerBusinessLogic() {
+ ServletContext context = sr.getSession().getServletContext();
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ConsumerBusinessLogic consumerBusinessLogic = webApplicationContext.getBean(ConsumerBusinessLogic.class);
+ return consumerBusinessLogic;
+ }
+
+ public enum AuthStatus {
+ AUTH_REQUIRED, AUTH_FAILED_USER_NOT_FOUND, AUTH_FAILED_INVALID_PASSWORD, AUTH_FAILED_INVALID_AUTHENTICATION_HEADER, AUTH_SUCCESS
+ }
+
+ protected Response buildErrorResponse(ResponseFormat requestErrorWrapper, boolean addWwwAuthenticationHeader) {
+ ResponseBuilder responseBuilder = Response.status(requestErrorWrapper.getStatus());
+ if (addWwwAuthenticationHeader) {
+ responseBuilder = responseBuilder.header("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
+ }
+ Response response = responseBuilder.entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
+ return response;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java
new file mode 100644
index 0000000000..f6c11d062e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java
@@ -0,0 +1,202 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.annotation.Priority;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.GsonBuilder;
+
+@Provider
+@Priority(1)
+public class BeServletFilter implements ContainerRequestFilter, ContainerResponseFilter {
+
+ @Context
+ private HttpServletRequest sr;
+
+ private static Logger log = LoggerFactory.getLogger(BeServletFilter.class.getName());
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ try {
+
+ MDC.clear();
+
+ // In case of 405 response code, this function is not entered, then
+ // we'll process
+ // the MDC fields and UUID during the response
+ ThreadLocalsHolder.setMdcProcessed(true);
+
+ // Timing HTTP request
+ ThreadLocalsHolder.setRequestStartTime(System.currentTimeMillis());
+
+ String uuid = processMdcFields(requestContext);
+
+ ThreadLocalsHolder.setUuid(uuid);
+
+ inHttpRequest();
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Error during request filter");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
+ log.debug("Error during request filter: {} ", e);
+ }
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ try {
+ // Formatting the response in case of 405
+ if (responseContext.getStatus() == Response.Status.METHOD_NOT_ALLOWED.getStatusCode()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_ALLOWED);
+ responseContext.setEntity(new GsonBuilder().setPrettyPrinting().create().toJson(responseFormat.getRequestError()));
+ }
+
+ if (ThreadLocalsHolder.isMdcProcessed()) {
+ // filter() was executed during request - this is the regular
+ // flow
+ responseContext.getHeaders().add(Constants.X_ECOMP_REQUEST_ID_HEADER, ThreadLocalsHolder.getUuid());
+ Long startTime = ThreadLocalsHolder.getRequestStartTime();
+ if (startTime != null) {
+ long endTime = System.currentTimeMillis();
+ MDC.put("timer", Long.toString(endTime - startTime));
+ }
+ } else {
+ // this is the 405 response code case
+ // we have no MDC fields since filter() wasn't executed during
+ // request
+ String uuid = processMdcFields(requestContext);
+ responseContext.getHeaders().add(Constants.X_ECOMP_REQUEST_ID_HEADER, uuid);
+ }
+
+ outHttpResponse(responseContext);
+
+ // Cleaning up
+ MDC.clear();
+ ThreadLocalsHolder.cleanup();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Error during request filter");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
+ log.debug("Error during response filter: {} ", e);
+ }
+ }
+
+ private String processMdcFields(ContainerRequestContext requestContext) {
+ // userId for logging
+ String userId = requestContext.getHeaderString(Constants.USER_ID_HEADER);
+ MDC.put("userId", userId);
+
+ String serviceInstanceID = requestContext.getHeaderString(Constants.X_ECOMP_SERVICE_ID_HEADER);
+ MDC.put("serviceInstanceID", serviceInstanceID);
+
+ MDC.put("remoteAddr", sr.getRemoteAddr());
+ MDC.put("localAddr", sr.getLocalAddr());
+
+ // UUID
+ String uuid = requestContext.getHeaderString(Constants.X_ECOMP_REQUEST_ID_HEADER);
+ if (uuid == null) {
+ // Generate the UUID
+ uuid = UUID.randomUUID().toString();
+
+ // Add to MDC for logging
+ MDC.put("uuid", uuid);
+
+ // This log message should already be with the UUID
+ uuidGeneration(uuid);
+
+ } else {
+ // According to Ella, in case this header exists, we don't have to
+ // perform any validations
+ // since it's not our responsibilty, so we log the UUID just as it
+ // was received.
+ MDC.put("uuid", uuid);
+ }
+ return uuid;
+ }
+
+ private ComponentsUtils getComponentsUtils() {
+ ServletContext context = this.sr.getSession().getServletContext();
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(ComponentsUtils.class);
+ }
+
+ // Extracted for purpose of clear method name, for logback %M parameter
+ private void inHttpRequest() {
+ if (isInfoLog()) {
+ log.info("{} {} {}", sr.getMethod(), sr.getRequestURI(), sr.getProtocol());
+ } else {
+ log.debug("{} {} {}", sr.getMethod(), sr.getRequestURI(), sr.getProtocol());
+ }
+ }
+
+ // Extracted for purpose of clear method name, for logback %M parameter
+ private void outHttpResponse(ContainerResponseContext responseContext) {
+ if (isInfoLog()) {
+ log.info("{} {} {} SC=\"{}\"", sr.getMethod(), sr.getRequestURI(), sr.getProtocol(), responseContext.getStatus());
+ } else {
+ log.debug("{} {} {} SC=\"{}\"", sr.getMethod(), sr.getRequestURI(), sr.getProtocol(), responseContext.getStatus());
+ }
+ }
+
+ private boolean isInfoLog() {
+ boolean logRequest = true;
+ Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
+ String requestURI = sr.getRequestURI();
+ if (requestURI != null && configuration.getUnLoggedUrls() != null) {
+ logRequest = !configuration.getUnLoggedUrls().contains(requestURI);
+ }
+
+ return logRequest;
+ }
+
+ // Extracted for purpose of clear method name, for logback %M parameter
+ private void uuidGeneration(String uuid) {
+ log.info("No requestID provided -> Generated UUID {}", uuid);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java
new file mode 100644
index 0000000000..c572e2e552
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Priority;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.openecomp.sdc.be.components.impl.HealthCheckBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+@Priority(11)
+public class ComponentsAvailabilityFilter implements ContainerRequestFilter {
+
+ @Context
+ protected HttpServletRequest sr;
+ protected Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private static Logger log = LoggerFactory.getLogger(ComponentsAvailabilityFilter.class.getName());
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+
+ String requestUrl = requestContext.getUriInfo().getPath();
+ if (!requestUrl.equals("healthCheck")) {
+ List<HealthCheckInfo> beHealthCheckInfos = getBeHealthCheckInfos(this.sr.getSession().getServletContext());
+ ActionStatus status = getAggregateBeStatus(beHealthCheckInfos);
+
+ if (!status.equals(ActionStatus.OK)) {
+ log.error("Components Availability Filter Failed - ES/Cassandra is DOWN");
+ availabilityError(requestContext);
+ }
+ }
+
+ }
+
+ protected ActionStatus getAggregateBeStatus(List<HealthCheckInfo> beHealthCheckInfos) {
+ ActionStatus status = ActionStatus.OK;
+ for (HealthCheckInfo healthCheckInfo : beHealthCheckInfos) {
+ if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN)) {
+ status = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ }
+ return status;
+ }
+
+ protected List<HealthCheckInfo> getBeHealthCheckInfos(ServletContext servletContext) {
+
+ List<HealthCheckInfo> healthCheckInfos = new ArrayList<HealthCheckInfo>();
+ HealthCheckBusinessLogic healthCheckBusinessLogic = getHealthCheckBL(servletContext);
+ healthCheckBusinessLogic.getTitanHealthCheck(healthCheckInfos); // Titan
+ return healthCheckInfos;
+ }
+
+ protected ComponentsUtils getComponentsUtils() {
+ ServletContext context = sr.getSession().getServletContext();
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ComponentsUtils componentsUtils = webApplicationContext.getBean(ComponentsUtils.class);
+ return componentsUtils;
+ }
+
+ protected void availabilityError(ContainerRequestContext requestContext) {
+ ComponentsUtils componentUtils = getComponentsUtils();
+ if (componentUtils == null) {
+ log.error("Components Availability Filter Failed to get component utils.");
+ requestContext.abortWith(Response.status(Status.INTERNAL_SERVER_ERROR).build());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ ResponseBuilder responseBuilder = Response.status(responseFormat.getStatus());
+ Response response = responseBuilder.entity(gson.toJson(responseFormat.getRequestError())).build();
+ requestContext.abortWith(response);
+ }
+
+ private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ HealthCheckBusinessLogic healthCheckBl = webApplicationContext.getBean(HealthCheckBusinessLogic.class);
+ return healthCheckBl;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
new file mode 100644
index 0000000000..9e2abebdc5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -0,0 +1,1461 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.impl;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
+
+import org.codehaus.jackson.Version;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.module.SimpleModule;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.AdditionalInfoParameterInfo;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserialiser;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.tosca.ToscaError;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("componentUtils")
+public class ComponentsUtils {
+
+ @javax.annotation.Resource
+ private IAuditingManager auditingManager;
+
+ private ResponseFormatManager responseFormatManager;
+
+ private static Logger log = LoggerFactory.getLogger(ComponentsUtils.class.getName());
+
+ @PostConstruct
+ public void Init() {
+ this.responseFormatManager = ResponseFormatManager.getInstance();
+ }
+
+ public IAuditingManager getAuditingManager() {
+ return auditingManager;
+ }
+
+ public void setAuditingManager(IAuditingManager auditingManager) {
+ this.auditingManager = auditingManager;
+ }
+
+ public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
+ if (data == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
+ return Either.right(responseFormat);
+ }
+ try {
+ T obj = parseJsonToObject(data, clazz);
+ return Either.left(obj);
+ } catch (Exception e) {
+ // INVALID JSON
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", data, e);
+ ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
+ return Either.right(responseFormat);
+ }
+ }
+
+ public static <T> T parseJsonToObject(String data, Class<T> clazz) {
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
+ log.trace("convert json to object. json=\n{}", data);
+ T resource = gson.fromJson(data, clazz);
+ return resource;
+ }
+
+ public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
+ T component = null;
+ ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ try {
+ log.trace("convert json to object. json=\n{}", data);
+
+ final SimpleModule module = new SimpleModule("customerSerializationModule", new Version(1, 0, 0, "static version"));
+ JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
+ addDeserializer(module, PropertyConstraint.class, desrializer);
+ //
+ mapper.registerModule(module);
+
+ component = mapper.readValue(data, clazz);
+ if (component == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
+ return Either.right(responseFormat);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", data, e);
+ ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
+ return Either.right(responseFormat);
+ }
+ return Either.left(component);
+ }
+
+ public <T> void addDeserializer(SimpleModule module, Class<T> clazz, final JsonDeserializer<T> deserializer) {
+ module.addDeserializer(clazz, deserializer);
+ }
+
+ // Error response
+
+ public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
+ return responseFormatManager.getResponseFormat(actionStatus, params);
+ }
+
+ /**
+ * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus is anonymously converted from storage operation, and the caller doesn't know what actionStatus he
+ * received. It's caller's Responsibility to fill the resource object passed to this function with needed fields.
+ *
+ * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used for Service, this code needs to be refactored and we should tell Resource from Service.
+ *
+ * @param actionStatus
+ * @param resource
+ * @return
+ */
+ public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Resource resource) {
+ if (resource == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case COMPONENT_VERSION_ALREADY_EXIST:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getVersion());
+ break;
+ case RESOURCE_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
+ break;
+ case COMPONENT_NAME_ALREADY_EXIST:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ break;
+ case COMPONENT_IN_USE:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(), resource.getUniqueId());
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
+ if (resourceName == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case RESOURCE_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
+ if (capabilityType == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case CAPABILITY_TYPE_ALREADY_EXIST:
+ responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ /**
+ * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus is anynomously converted from storage operation, and the caller doesn't know what actionStatus he
+ * received. It's caller's responisibility to fill the passed resource object with needed fields.
+ *
+ * @param actionStatus
+ * @param user
+ * @return
+ */
+ public ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
+ if (user == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat requestErrorWrapper;
+ switch (actionStatus) {
+ case INVALID_USER_ID:
+ requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
+ break;
+ case INVALID_EMAIL_ADDRESS:
+ requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
+ break;
+ case INVALID_ROLE:
+ requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
+ break;
+ case USER_NOT_FOUND:
+ case USER_ALREADY_EXIST:
+ case USER_INACTIVE:
+ case USER_HAS_ACTIVE_ELEMENTS:
+ requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
+ break;
+ default:
+ requestErrorWrapper = getResponseFormat(actionStatus);
+ break;
+ }
+ return requestErrorWrapper;
+ }
+
+ public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
+ User user = new User();
+ user.setUserId(userId);
+ return getResponseFormatByUser(actionStatus, user);
+ }
+
+ public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String serviceId, String envName) {
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
+ responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
+ break;
+ case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
+ break;
+ case DISTRIBUTION_ARTIFACT_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ARTIFACT_NOT_FOUND, serviceId);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String artifactId) {
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case RESOURCE_NOT_FOUND:
+ case ARTIFACT_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactId);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
+ ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ log.debug("audit before sending response");
+ auditResource(responseFormat, user, null, "", "", actionEnum, null);
+ return responseFormat;
+ }
+
+ public ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
+ ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ log.debug("audit before sending response");
+ auditComponentAdmin(responseFormat, user, null, "", "", actionEnum, typeEnum);
+ return responseFormat;
+ }
+
+ public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String prevState, String prevVersion, AuditingActionEnum actionEnum, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ if (actionEnum != null) {
+ log.trace("Inside auditing for audit action {}", actionEnum.name());
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+
+ updateUserFields(modifier, auditingFields);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, ComponentTypeEnum.RESOURCE.getValue());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, prevVersion);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, prevState);
+ if (resource != null) {
+ // fields that are filled during creation and might still be
+ // empty
+ String resourceCurrVersion = (resource.getVersion() != null) ? resource.getVersion() : "";
+ String resourceCurrState = (resource.getLifecycleState() != null) ? resource.getLifecycleState().name() : "";
+ String uuid = (resource.getUUID() != null) ? resource.getUUID() : "";
+ String invariantUUID = (resource.getInvariantUUID() != null) ? resource.getInvariantUUID() : "";
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resource.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, resourceCurrVersion);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, resourceCurrState);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, uuid);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, invariantUUID);
+
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, "");
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ // In those specific cases we want some specific fields from
+ // resource object
+ switch (actionEnum) {
+ case IMPORT_RESOURCE:
+ if (resource != null) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TOSCA_NODE_TYPE, resource.getToscaResourceName());
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TOSCA_NODE_TYPE, "");
+ }
+ break;
+ default:
+ break;
+ }
+
+ // This is to add/overwrite anything set in this function if some
+ // params were passed from above,
+ // for example resourceName of resource import
+ if (additionalParams != null) {
+ auditingFields.putAll(additionalParams);
+ }
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+ }
+
+ private void updateUserFields(User modifier, EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ if (modifier != null) {
+ String firstName = modifier.getFirstName();
+ String lastName = modifier.getLastName();
+ if (firstName != null || lastName != null) {// to prevent "null
+ // null" names
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, firstName + " " + lastName);
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ }
+ }
+
+ public void auditDistributionDownload(ResponseFormat responseFormat, AuditingActionEnum actionEnum, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ log.trace("Inside auditing for audit action {}", actionEnum.name());
+ int status = responseFormat.getStatus();
+ String message = "";
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ // This is to add/overwrite anything set in this function if some params
+ // were passed from above,
+ // for example resourceName of resource import
+ if (additionalParams != null) {
+ auditingFields.putAll(additionalParams);
+ }
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ log.trace("Inside auditing for audit action {}", actionEnum.name());
+ int status = responseFormat.getStatus();
+ String message = "";
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ if (additionalParams != null) {
+ auditingFields.putAll(additionalParams);
+ }
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditExternalCrudApiArtifact(ResponseFormat responseFormat, String componentType, String actionEnum, HttpServletRequest request, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ log.trace("Inside auditing for audit action {}", actionEnum);
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+ int status = responseFormat.getStatus();
+ String message = "";
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, instanceIdHeader);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, requestURI);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, componentType);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ if (additionalParams != null) {
+ auditingFields.putAll(additionalParams);
+ }
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditExternalDownloadArtifact(ResponseFormat responseFormat, String componentType, HttpServletRequest request, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ auditExternalCrudApiArtifact(responseFormat, componentType, AuditingActionEnum.DOWNLOAD_ARTIFACT.getName(), request, additionalParams);
+ }
+
+ public void auditExternalUploadArtifact(ResponseFormat responseFormat, String componentType, HttpServletRequest request, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, request.getHeader(Constants.USER_ID_HEADER));
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID, "");
+ auditExternalCrudApiArtifact(responseFormat, componentType, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API.getName(), request, additionalParams);
+ }
+
+ public void auditExternalUpdateArtifact(ResponseFormat responseFormat, String componentType, HttpServletRequest request, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, request.getHeader(Constants.USER_ID_HEADER));
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID, "");
+ auditExternalCrudApiArtifact(responseFormat, componentType, AuditingActionEnum.ARTIFACT_UPDATE_BY_API.getName(), request, additionalParams);
+ }
+
+ public void auditExternalDeleteArtifact(ResponseFormat responseFormat, String componentType, HttpServletRequest request, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, request.getHeader(Constants.USER_ID_HEADER));
+ additionalParams.put(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID, "");
+ auditExternalCrudApiArtifact(responseFormat, componentType, AuditingActionEnum.ARTIFACT_DELETE_BY_API.getName(), request, additionalParams);
+ }
+
+ public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName, AuditingActionEnum actionEnum, String componentType) {
+ log.trace("Inside auditing for audit action {}", actionEnum.name());
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ updateUserFields(modifier, auditingFields);
+ // String componentTypeStr = (componentTypeEnum != null ?
+ // componentTypeEnum.getValue() : null);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, componentType);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_CATEGORY_NAME, categoryName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SUB_CATEGORY_NAME, subCategoryName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_GROUPING_NAME, groupingName);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
+
+ return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
+ }
+
+ public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
+
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ if (storageResponse == null) {
+ return responseEnum;
+ }
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
+ break;
+ case PARENT_RESOURCE_NOT_FOUND:
+ responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
+ break;
+ case MULTIPLE_PARENT_RESOURCE_FOUND:
+ responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
+ break;
+ case NOT_FOUND:
+ if (ComponentTypeEnum.RESOURCE == type) {
+ responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
+ } else if (ComponentTypeEnum.PRODUCT == type) {
+ responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
+ } else {
+ responseEnum = ActionStatus.SERVICE_NOT_FOUND;
+ }
+ break;
+ case FAILED_TO_LOCK_ELEMENT:
+ responseEnum = ActionStatus.COMPONENT_IN_USE;
+ break;
+ case ARTIFACT_NOT_FOUND:
+ responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
+ break;
+ case DISTR_ENVIRONMENT_NOT_AVAILABLE:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
+ break;
+ case DISTR_ENVIRONMENT_NOT_FOUND:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
+ break;
+ case DISTR_ENVIRONMENT_SENT_IS_INVALID:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
+ break;
+ case DISTR_ARTIFACT_NOT_FOUND:
+ responseEnum = ActionStatus.DISTRIBUTION_ARTIFACT_NOT_FOUND;
+ break;
+ case INVALID_TYPE:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case INVALID_VALUE:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case CSAR_NOT_FOUND:
+ responseEnum = ActionStatus.CSAR_NOT_FOUND;
+ break;
+ case PROPERTY_NAME_ALREADY_EXISTS:
+ responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
+ break;
+ case CATEGORY_NOT_FOUND:
+ responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromToscaError(ToscaError toscaError) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ if (toscaError == null) {
+ return responseEnum;
+ }
+ switch (toscaError) {// TODO match errors
+ case NODE_TYPE_CAPABILITY_ERROR:
+ case NOT_SUPPORTED_TOSCA_TYPE:
+ case NODE_TYPE_REQUIREMENT_ERROR:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
+ break;
+ case INVALID_PROPERTY:
+ responseEnum = ActionStatus.INVALID_PROPERTY;
+ break;
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
+ break;
+ case NOT_FOUND:
+ if (isRelation) {
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
+ } else {
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
+ }
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case RESOURCE_INSTANCE_NOT_FOUND:
+ responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus, serviceName);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case RESOURCE_INSTANCE_NOT_FOUND:
+ responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
+ break;
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
+ break;
+ case NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, String prevState, String prevVersion, AuditingActionEnum actionEnum, ComponentTypeEnum type) {
+ auditComponent(responseFormat, modifier, component, prevState, prevVersion, actionEnum, type, null);
+ }
+
+ public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, String prevState, String prevVersion, AuditingActionEnum actionEnum, ComponentTypeEnum type, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ if (actionEnum != null) {
+ log.trace("Inside auditing for audit action {}", actionEnum.name());
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+
+ updateUserFields(modifier, auditingFields);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, type.getValue().replace(" ", ""));
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, prevVersion);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, prevState);
+ if (component != null) {
+ // fields that are filled during creation and might still be
+ // empty
+ String resourceCurrVersion = component.getVersion();
+ String resourceCurrState = (component.getLifecycleState() != null) ? component.getLifecycleState().name() : "";
+ String resourceUuid = (component.getUUID() != null) ? component.getUUID() : "";
+ String invariantUUID = (component.getInvariantUUID() != null) ? component.getInvariantUUID() : "";
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, resourceCurrVersion);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, resourceCurrState);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, resourceUuid);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, invariantUUID);
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, "");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_INVARIANT_UUID, "");
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ // This is meant to overwrite anything set in this function if some
+ // params were passed from above,
+ // for example resourceName of resource import
+ if (additionalParams != null) {
+ auditingFields.putAll(additionalParams);
+ }
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+ }
+
+ public void auditDistributionEngine(AuditingActionEnum actionEnum, String environmentName, String topicName, String role, String apiKey, String status) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME, environmentName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ROLE, role);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_API_KEY, apiKey);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditDistributionNotification(AuditingActionEnum actionEnum, String serviceUUID, String resourceName, String resourceType, String currVersion, String modifierUid, String modifierName, String environmentName, String currState,
+ String topicName, String distributionId, String description, String status) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, serviceUUID);
+
+ // auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME,
+ // environmentName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, currVersion);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, currState);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, resourceType);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, description);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifierUid);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifierName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceName);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditAuthEvent(AuditingActionEnum actionEnum, String url, String user, String authStatus, String realm) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_AUTH_URL, url);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_AUTH_USER, user);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_AUTH_STATUS, authStatus);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_AUTH_REALM, realm);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditDistributionStatusNotification(AuditingActionEnum actionEnum, String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime, String status, String errorReason) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_REQUEST_ID, distributionId);
+ ThreadLocalsHolder.setUuid(distributionId);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, consumerId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, resourceUrl);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME, statusTime);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, errorReason);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditGetUebCluster(AuditingActionEnum actionEnum, String consumerId, String statusTime, String status, String description) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, consumerId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME, statusTime);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_DESC, description);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditMissingInstanceId(AuditingActionEnum actionEnum, String status, String description) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, null);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, null);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, description);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditTopicACLKeys(AuditingActionEnum actionEnum, String envName, String topicName, String role, String apiPublicKey, String status) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME, envName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ROLE, role);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_API_KEY, apiPublicKey);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditRegisterOrUnRegisterEvent(AuditingActionEnum actionEnum, String consumerId, String apiPublicKey, String envName, String status, String statusDesc, String notifTopicName, String statusTopicName) {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, consumerId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_API_KEY, apiPublicKey);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME, envName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_DESC, statusDesc);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_NOTIFICATION_TOPIC_NAME, notifTopicName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TOPIC_NAME, statusTopicName);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditServiceDistributionDeployed(AuditingActionEnum actionEnum, String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status, String desc, User modifier) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, serviceUUID);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifier.getFirstName() + " " + modifier.getLastName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, "Service");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, serviceName);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, serviceVersion);
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, desc);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat, User modifier) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ if (modifier != null) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifier.getFirstName() + " " + modifier.getLastName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ }
+ StringBuilder ecompUser = new StringBuilder();
+ if (consumer != null) {
+ if (consumer.getConsumerName() != null && !consumer.getConsumerName().trim().isEmpty()) {
+ ecompUser.append(consumer.getConsumerName());
+ }
+ if (consumer.getConsumerSalt() != null && !consumer.getConsumerSalt().trim().isEmpty()) {
+ if (ecompUser.length() > 0) {
+ ecompUser.append(",");
+ }
+ ecompUser.append(consumer.getConsumerSalt());
+ }
+ if (consumer.getConsumerPassword() != null && !consumer.getConsumerPassword().trim().isEmpty()) {
+ if (ecompUser.length() > 0) {
+ ecompUser.append(",");
+ }
+ ecompUser.append(consumer.getConsumerPassword());
+ }
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ECOMP_USER, ecompUser.toString());
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditGetUsersList(AuditingActionEnum actionEnum, User modifier, String details, ResponseFormat responseFormat) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ if (modifier != null) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifier.getFirstName() + " " + modifier.getLastName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ }
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_DETAILS, details);
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ if (modifier != null) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifier.getFirstName() + " " + modifier.getLastName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, "");
+ }
+ if (userBefore != null) {
+ String userBeforeUserId = (userBefore.getUserId() != null) ? userBefore.getUserId() : "";
+ String userBeforFirstName = (userBefore.getFirstName() != null) ? ", " + userBefore.getFirstName() + " " : "";
+ String userBeforLastName = (userBefore.getLastName() != null) ? userBefore.getLastName() : "";
+ String userBeforEmail = (userBefore.getEmail() != null) ? ", " + userBefore.getEmail() : "";
+ String userBeforRloe = (userBefore.getRole() != null) ? ", " + userBefore.getRole() : "";
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_BEFORE, userBeforeUserId + userBeforFirstName + userBeforLastName + userBeforEmail + userBeforRloe);
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_BEFORE, "");
+ }
+ if (userAfter != null) {
+ String userAfterUserId = (userAfter.getUserId() != null) ? userAfter.getUserId() : "";
+ String userAfterFirstName = (userAfter.getFirstName() != null) ? ", " + userAfter.getFirstName() + " " : "";
+ String userAfterLastName = (userAfter.getLastName() != null) ? userAfter.getLastName() : "";
+ String userAfterEmail = (userAfter.getEmail() != null) ? ", " + userAfter.getEmail() : "";
+ String userAfterRloe = (userAfter.getRole() != null) ? ", " + userAfter.getRole() : "";
+
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_AFTER, userAfterUserId + userAfterFirstName + userAfterLastName + userAfterEmail + userAfterRloe);
+ } else {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_AFTER, "");
+ }
+
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditUserAccess(AuditingActionEnum actionEnum, User user, ResponseFormat responseFormat) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_USER_UID, user.getFirstName() + " " + user.getLastName() + '(' + user.getUserId() + ')');
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public void auditGetCategoryHierarchy(AuditingActionEnum actionEnum, User modifier, String details, ResponseFormat responseFormat) {
+
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, actionEnum.getName());
+ if (modifier != null) {
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifier.getFirstName() + " " + modifier.getLastName());
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifier.getUserId());
+ }
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DETAILS, details);
+ int status = responseFormat.getStatus();
+ String message = "";
+
+ if (responseFormat.getMessageId() != null) {
+ message = responseFormat.getMessageId() + ": ";
+ }
+ message += responseFormat.getFormattedMessage();
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, message);
+ getAuditingManager().auditEvent(auditingFields);
+ }
+
+ public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
+ if (component == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case COMPONENT_VERSION_ALREADY_EXIST:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
+ break;
+ case RESOURCE_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ break;
+ case COMPONENT_NAME_ALREADY_EXIST:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ break;
+ case COMPONENT_IN_USE:
+ responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
+ break;
+ case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
+ responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+
+ public Either<Boolean, ResponseFormat> validateStringNotEmpty(User user, Component component, String value, ActionStatus badResult, AuditingActionEnum actionEnum) {
+ if ((value == null) || (value.trim().isEmpty())) {
+ log.info(badResult.name());
+ ResponseFormat errorResponse = getResponseFormat(badResult);
+ if (actionEnum != null) {
+ log.debug("audit before sending response");
+ auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, getComponentType(component));
+ }
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ public Boolean validateStringNotEmpty(String value) {
+ if ((value == null) || (value.trim().isEmpty())) {
+ return false;
+ }
+ return true;
+ }
+
+ private ComponentTypeEnum getComponentType(Component component) {
+ if (component instanceof Service) {
+ return ComponentTypeEnum.SERVICE;
+ } // else if(component instanceof Resource){
+ return null;
+ }
+
+ public Either<Boolean, ResponseFormat> validateStringMatchesPattern(User user, Component component, String value, Pattern pattern, ActionStatus badResult, AuditingActionEnum actionEnum) {
+ if (!pattern.matcher(value).matches()) {
+ log.error(badResult.name());
+ ResponseFormat errorResponse = getResponseFormat(badResult);
+ if (actionEnum != null) {
+ log.debug("audit before sending response");
+ auditComponentAdmin(errorResponse, user, component, "", "", actionEnum, getComponentType(component));
+ }
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+
+ /**
+ *
+ * " Error: Missing Mandatory Informational %s1 %s2 : %s3 " where %s1 - "resource"/"service" %s2 - "artifact"/ "artifacts" %s3 - Comma separated list of missing informational artifact types
+ *
+ * @param resource
+ * @param componentMissingMandatoryArtifacts
+ * @param value
+ * @return
+ */
+ public ResponseFormat getResponseFormatByMissingArtifacts(ComponentTypeEnum componentType, Map<String, ArtifactDefinition> artifacts) {
+
+ String artifactTitle = "artifact";
+ if (artifacts.size() > 1) {
+ artifactTitle = "artifacts";
+ }
+ Collection<ArtifactDefinition> artifactsLabels = artifacts.values();
+ StringBuilder artifactsLabelBuilder = new StringBuilder();
+
+ List<ArtifactDefinition> artifactsLabelsList = new ArrayList<ArtifactDefinition>();
+ artifactsLabelsList.addAll(artifactsLabels);
+ for (int i = 0; i < artifactsLabelsList.size(); i++) {
+ ArtifactDefinition artifactDef = artifactsLabelsList.get(i);
+ artifactsLabelBuilder.append(artifactDef.getArtifactDisplayName());
+ if (i < artifactsLabelsList.size() - 1) {
+ artifactsLabelBuilder.append(";");
+ }
+ }
+ ResponseFormat responseFormat = getResponseFormat(ActionStatus.COMPONENT_MISSING_MANDATORY_ARTIFACTS, componentType.name().toLowerCase(), artifactTitle, artifactsLabelBuilder.toString());
+
+ return responseFormat;
+ }
+
+ public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo, NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
+
+ if (additionalInfoParameterInfo == null) {
+ additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ }
+ if (labelOrValue == null) {
+ labelOrValue = AdditionalInformationEnum.None;
+ }
+
+ ResponseFormat responseFormat = null;
+ switch (actionStatus) {
+ case COMPONENT_NAME_ALREADY_EXIST:
+ responseFormat = getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
+ break;
+ case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
+ responseFormat = getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
+ break;
+ case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
+ responseFormat = getResponseFormat(actionStatus, nodeType.name().toLowerCase());
+ break;
+ case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ case ADDITIONAL_INFORMATION_NOT_FOUND:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+
+ return responseFormat;
+ }
+
+ public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
+ return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
+ }
+
+ public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
+ break;
+ case NOT_FOUND:
+ responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
+ ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+
+ switch (storageResponse) {
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
+ break;
+ case CANNOT_UPDATE_EXISTING_ENTITY:
+ responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ log.debug("convert storage response {} to action response {}", storageResponse.name(), responseEnum.name());
+ return responseEnum;
+ }
+
+ public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
+ if (groupType == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case GROUP_MEMBER_EMPTY:
+ case GROUP_TYPE_ALREADY_EXIST:
+ responseFormat = getResponseFormat(actionStatus, groupType.getType());
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+
+ }
+
+ public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
+ if (policyType == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case POLICY_TYPE_ALREADY_EXIST:
+ responseFormat = getResponseFormat(actionStatus, policyType.getType());
+ break;
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+
+ }
+
+ public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
+ if (dataType == null) {
+ return getResponseFormat(actionStatus);
+ }
+ ResponseFormat responseFormat;
+
+ switch (actionStatus) {
+ case DATA_TYPE_ALREADY_EXIST:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+ case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+ case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+ case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
+ break;
+ case DATA_TYPE_DERIVED_IS_MISSING:
+ responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
+ break;
+ case DATA_TYPE_DUPLICATE_PROPERTY:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+ case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
+ break;
+ case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+ case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
+ responseFormat = getResponseFormat(actionStatus, dataType.getName());
+ break;
+
+ default:
+ responseFormat = getResponseFormat(actionStatus);
+ break;
+ }
+ return responseFormat;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java
new file mode 100644
index 0000000000..fff6fd15a4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java
@@ -0,0 +1,166 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpStatus;
+import org.eclipse.jgit.util.Base64;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.info.ArtifactAccessInfo;
+import org.openecomp.sdc.be.info.ArtifactAccessList;
+import org.openecomp.sdc.be.info.ServletJsonResponse;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class DownloadArtifactLogic {
+
+ private static Logger log = LoggerFactory.getLogger(DownloadArtifactLogic.class.getName());
+
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ public Response downloadArtifact(final String resourceName, final String resourceVersion, final String artifactName, Either<? extends ESArtifactData, ResourceUploadStatus> getArtifactStatus, String artifactId) {
+ Response response = null;
+
+ if (getArtifactStatus.isRight()) {
+ log.debug("Could not find artifact for with id: {}", artifactId);
+ ResourceUploadStatus status = getArtifactStatus.right().value();
+ if (status == status.COMPONENT_NOT_EXIST)
+ response = Response.status(HttpStatus.SC_NO_CONTENT).build();
+ else
+ response = Response.status(HttpStatus.SC_NOT_FOUND).build();
+
+ return response;
+ }
+ // convert artifact to inputstream
+ else {
+ ESArtifactData artifactData = getArtifactStatus.left().value();
+ byte[] artifactPayload = artifactData.getDataAsArray();
+
+ String payloadStr = new String(artifactPayload);
+ byte[] decodedPayload = artifactPayload;
+ boolean isEncoded = GeneralUtility.isBase64Encoded(payloadStr);
+ if (isEncoded) {
+ log.debug("payload is encoded. perform decode");
+ decodedPayload = Base64.decode(new String(artifactPayload));
+ }
+ final InputStream artifactStream = new ByteArrayInputStream(decodedPayload);
+ log.debug("found artifact for with id: {}", artifactId);
+ try {
+
+ // outputstream for response
+ StreamingOutput stream = new StreamingOutput() {
+ public void write(OutputStream output) throws IOException, WebApplicationException {
+ try {
+ IOUtils.copy(artifactStream, output);
+ } catch (Exception e) {
+ throw new WebApplicationException(e);
+ }
+ }
+ };
+ artifactStream.close();
+ return Response.ok(stream).type(MediaType.APPLICATION_OCTET_STREAM_TYPE).header("content-disposition", "attachment; filename = " + artifactName)
+ // .header(Constants.MD5_HEADER, new
+ // String(artifactData.getArtifactChecksum()))
+ .build();
+
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Failed to stream artifact data on the response");
+ BeEcompErrorManager.getInstance().logBeSystemError("Failed to stream artifact data on the response");
+ log.debug("Failed to stream artifact data on the response: {}", e.getMessage());
+ response = buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Failed to stream artifact data on the response");
+ return response;
+ }
+ }
+ }
+
+ public List<ArtifactAccessInfo> convertArtifactList(List<? extends ESArtifactData> artifactsList, String servletPath) {
+
+ List<ArtifactAccessInfo> artifactAccessList = new ArrayList<ArtifactAccessInfo>();
+ for (ESArtifactData artifact : artifactsList) {
+ ArtifactAccessInfo accessInfo = new ArtifactAccessInfo(artifact, servletPath);
+ artifactAccessList.add(accessInfo);
+ }
+ return artifactAccessList;
+ }
+
+ public Response createArtifactListResponse(final String serviceName, Either<List<ESArtifactData>, ResourceUploadStatus> getArtifactsStatus/*
+ * List < ? extends IResourceData> artifactsList
+ */, String servletPath) {
+ Response response;
+ List<ArtifactAccessInfo> artifactAccessInfos;
+ if (getArtifactsStatus.isRight()) {
+ // if there are no artifacts - return No-Content
+ ResourceUploadStatus status = getArtifactsStatus.right().value();
+ if (status == ResourceUploadStatus.COMPONENT_NOT_EXIST || status == ResourceUploadStatus.SERVICE_NOT_EXIST) {
+ log.debug("resource {} does not exist", serviceName);
+ response = Response.status(HttpStatus.SC_NOT_FOUND).entity("[]").build();
+
+ } else {
+ log.debug("No content was found for {}", serviceName);
+ response = Response.status(HttpStatus.SC_NO_CONTENT).entity("[]").build();
+ }
+ return response;
+ } else {
+ List<? extends ESArtifactData> artifactsList = getArtifactsStatus.left().value();
+ log.debug("{} artifacts were found for {}", artifactsList.size(), serviceName);
+ artifactAccessInfos = convertArtifactList(artifactsList, servletPath);
+
+ String artifactDataJson = gson.toJson(new ArtifactAccessList(artifactAccessInfos));
+ response = Response.status(HttpStatus.SC_OK).entity(artifactDataJson).type(MediaType.APPLICATION_JSON_TYPE).build();
+
+ return response;
+ }
+ }
+
+ public Response buildResponse(int status, String errorMessage) {
+
+ ServletJsonResponse jsonResponse = new ServletJsonResponse();
+ jsonResponse.setDescription(errorMessage);
+ jsonResponse.setSource(Constants.CATALOG_BE);
+
+ Response response = Response.status(status).entity(jsonResponse).build();
+
+ return response;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java
new file mode 100644
index 0000000000..3a5d9bf85f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.impl;
+
+import javax.annotation.Resource;
+
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.Gson;
+
+@Component("servletUtils")
+public class ServletUtils {
+ @Resource
+ private ComponentsUtils componentsUtils;
+ private Gson gson = new Gson();
+ @Resource
+ private IUserBusinessLogic adminManager;
+
+ public ComponentsUtils getComponentsUtils() {
+ return componentsUtils;
+ }
+
+ public Gson getGson() {
+ return gson;
+ }
+
+ public IUserBusinessLogic getUserAdmin() {
+ return adminManager;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/WebAppContextWrapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/WebAppContextWrapper.java
new file mode 100644
index 0000000000..cb21984a7f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/WebAppContextWrapper.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.impl;
+
+import javax.servlet.ServletContext;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class WebAppContextWrapper {
+
+ public WebApplicationContext getWebAppContext(ServletContext context) {
+
+ return WebApplicationContextUtils.getWebApplicationContext(context);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java
new file mode 100644
index 0000000000..deb446e32f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java
@@ -0,0 +1,159 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+
+public class ArtifactAccessInfo {
+
+ public ArtifactAccessInfo() {
+ }
+
+ public ArtifactAccessInfo(ESArtifactData artifactData) {
+ // this.name = artifactData.getArtifactName();
+ this.id = artifactData.getId();
+ // this.type = artifactData.getArtifactType();
+ // this.description = artifactData.getArtifactDescription();
+ // this.creator = artifactData.getArtifactCreator();
+ // DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);
+ // Date creationTimestamp = artifactData.getArtifactCreationTimestamp();
+ // this.creationTime = (creationTimestamp !=
+ // null)?dateFormat.format(creationTimestamp): null;
+ // Date updateTimestamp = artifactData.getArtifactLastUpdateTimestamp();
+ // this.lastUpdateTime = (updateTimestamp !=
+ // null)?dateFormat.format(updateTimestamp):null;
+ // this.lastUpdater = artifactData.getArtifactLastUpdater();
+ // if (artifactData.getArtifactChecksum() != null){
+ // this.checksum = new String(artifactData.getArtifactChecksum());
+ // } else {
+ // this.checksum = null;
+ // }
+ }
+
+ public ArtifactAccessInfo(ESArtifactData artifactData, String servletContext) {
+ // this.name = artifactData.getArtifactName();
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder = urlBuilder.append(servletContext).append("/");
+ // if (ArtifactDataEnum.COMPONENT_ARTIFACT.equals(resource)){
+ urlBuilder.append("resources/")
+ // .append(artifactData.getResourceId()).append("/")
+
+ .append("/artifacts/");
+ /*
+ * }else { ServiceArtifactData serviceArtifact = (ServiceArtifactData)artifactData; urlBuilder.append("services/") .append(serviceArtifact.getServiceName()).append("/") .append(serviceArtifact.getServiceVersion()) .append("/artifacts/")
+ * .append(serviceArtifact.getNodeTemplateName()) .append("/"); }
+ */
+ // urlBuilder.append(artifactData.getArtifactName());
+ this.url = urlBuilder.toString();
+
+ }
+
+ private String name;
+ private String url;
+ private String id;
+ private String type;
+ private String description;
+ private String creator;
+ private String creationTime;
+ private String lastUpdater;
+ private String lastUpdateTime;
+ private String checksum;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getCreator() {
+ return creator;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ public String getCreationTime() {
+ return creationTime;
+ }
+
+ public void setCreationTime(String creationTime) {
+ this.creationTime = creationTime;
+ }
+
+ public String getLastUpdater() {
+ return lastUpdater;
+ }
+
+ public void setLastUpdater(String lastUpdater) {
+ this.lastUpdater = lastUpdater;
+ }
+
+ public String getLastUpdateTime() {
+ return lastUpdateTime;
+ }
+
+ public void setLastUpdateTime(String lastUpdateTime) {
+ this.lastUpdateTime = lastUpdateTime;
+ }
+
+ public String getChecksum() {
+ return checksum;
+ }
+
+ public void setChecksum(String checksum) {
+ this.checksum = checksum;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java
new file mode 100644
index 0000000000..ddeb0505d9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class ArtifactAccessList {
+
+ public ArtifactAccessList(List<ArtifactAccessInfo> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ private List<ArtifactAccessInfo> artifacts;
+
+ public List<ArtifactAccessInfo> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactAccessInfo> artifacts) {
+ this.artifacts = artifacts;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfo.java
new file mode 100644
index 0000000000..163d220871
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfo.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+
+public class ArtifactDefinitionInfo {
+
+ private String uniqueId;
+ /** Specifies the display name of the artifact. */
+ private String artifactName;
+ private String artifactDisplayName;
+ private String artifactVersion;
+ private String artifactUUID;
+
+ public ArtifactDefinitionInfo(ArtifactDefinition artifactDefinition) {
+ uniqueId = artifactDefinition.getUniqueId();
+ artifactName = artifactDefinition.getArtifactName();
+ artifactDisplayName = artifactDefinition.getArtifactDisplayName();
+ artifactVersion = artifactDefinition.getArtifactVersion();
+ artifactUUID = artifactDefinition.getArtifactUUID();
+
+ }
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ public String getArtifactDisplayName() {
+ return artifactDisplayName;
+ }
+
+ public void setArtifactDisplayName(String artifactDisplayName) {
+ this.artifactDisplayName = artifactDisplayName;
+ }
+
+ public String getArtifactVersion() {
+ return artifactVersion;
+ }
+
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
+
+ public String getArtifactUUID() {
+ return artifactUUID;
+ }
+
+ public void setArtifactUUID(String artifactUUID) {
+ this.artifactUUID = artifactUUID;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
new file mode 100644
index 0000000000..fca7bf38d8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
@@ -0,0 +1,352 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.Configuration.DeploymentArtifactTypeConfig;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+import fj.data.Either;
+
+public class ArtifactTemplateInfo {
+ public static final String TYPE = "type";
+ public static final String FILE_NAME = "fileName";
+ public static final String ENV = "env";
+ public static final String IS_BASE = "isBase";
+
+ private static final String CSAR_HEAT = "HEAT";
+ private static final String CSAR_ARTIFACT = "artifacts";
+ private static final String CSAR_NETWORK = "network";
+ private static final String CSAR_VOLUME = "volume";
+ private static final String CSAR_NESTED = "nested";
+ private static final Object DESC = "description";
+ private static Logger log = LoggerFactory.getLogger(ArtifactTemplateInfo.class.getName());
+ String type;
+ String fileName;
+ String env;
+ boolean isBase;
+ String groupName;
+ String description;
+
+ List<ArtifactTemplateInfo> relatedArtifactsInfo;
+ private static Gson gson = new Gson();
+
+ public ArtifactTemplateInfo() {
+ super();
+ }
+
+ public ArtifactTemplateInfo(String type, String fileName, String env, List<ArtifactTemplateInfo> relatedArtifactsInfo) {
+ super();
+ this.type = type;
+ this.fileName = fileName;
+ this.env = env;
+ this.relatedArtifactsInfo = relatedArtifactsInfo;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getEnv() {
+ return env;
+ }
+
+ public void setEnv(String env) {
+ this.env = env;
+ }
+
+ public List<ArtifactTemplateInfo> getRelatedArtifactsInfo() {
+ return relatedArtifactsInfo;
+ }
+
+ public void setRelatedArtifactsInfo(List<ArtifactTemplateInfo> relatedArtifactsInfo) {
+ this.relatedArtifactsInfo = relatedArtifactsInfo;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public boolean isBase() {
+ return isBase;
+ }
+
+ public void setBase(boolean isBase) {
+ this.isBase = isBase;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String toString() {
+ return "ArtifactTemplateInfo [type=" + type + ", fileName=" + fileName + ", env=" + env + ", isBase=" + isBase + ", groupName=" + groupName + ", description=" + description + ", relatedArtifactsInfo=" + relatedArtifactsInfo + "]";
+ }
+
+ public static Either<ArtifactTemplateInfo, ResponseFormat> createArtifactTemplateInfoFromJson(ComponentsUtils componentsUtils, String type, Map<String, Object> o, List<ArtifactTemplateInfo> createdArtifactTemplateInfoList,
+ ArtifactTemplateInfo parentArtifact) {
+ String content = gson.toJson(o);
+ JsonObject jsonElement = new JsonObject();
+ ArtifactTemplateInfo resourceInfo = new ArtifactTemplateInfo();
+
+ jsonElement = gson.fromJson(content, jsonElement.getClass());
+
+ Map<String, Object> artifactTemplateMap = componentsUtils.parseJsonToObject(jsonElement.toString(), HashMap.class);
+ if (artifactTemplateMap.containsKey(TYPE))
+ resourceInfo.setType((String) artifactTemplateMap.get(TYPE));
+ if (artifactTemplateMap.containsKey(FILE_NAME))
+ resourceInfo.setFileName((String) artifactTemplateMap.get(FILE_NAME));
+ if (artifactTemplateMap.containsKey(IS_BASE))
+ resourceInfo.setBase((Boolean) artifactTemplateMap.get(IS_BASE));
+ if (artifactTemplateMap.containsKey(ENV)) {
+ Object envObj = artifactTemplateMap.get(ENV);
+ String envStr = "";
+ if (envObj instanceof String) {
+ envStr = (String) envObj;
+ } else if (envObj instanceof Map) {
+ Map envMap = (Map) envObj;
+ if (envMap.containsKey(FILE_NAME)) {
+ envStr = (String) envMap.get(FILE_NAME);
+ }
+ }
+ resourceInfo.setEnv(envStr);
+ }
+ if (artifactTemplateMap.containsKey(DESC)) {
+ resourceInfo.setDescription((String) artifactTemplateMap.get(DESC));
+ } else {
+ resourceInfo.setDescription((String) artifactTemplateMap.get(FILE_NAME));
+ }
+
+ boolean artifactTypeExist = false;
+ String correctType = type;
+ if (type.equalsIgnoreCase(CSAR_NESTED))
+ correctType = ArtifactTypeEnum.HEAT_NESTED.getType();
+ else if ((type.equalsIgnoreCase(CSAR_VOLUME)))
+ correctType = ArtifactTypeEnum.HEAT_VOL.getType();
+ else if ((type.equalsIgnoreCase(CSAR_NETWORK)))
+ correctType = ArtifactTypeEnum.HEAT_NET.getType();
+ else if ((type.equalsIgnoreCase(CSAR_ARTIFACT)))
+ correctType = ArtifactTypeEnum.HEAT_ARTIFACT.getType();
+ else if ((type.equalsIgnoreCase(CSAR_HEAT)))
+ correctType = ArtifactTypeEnum.HEAT.getType();
+ else
+ correctType = ArtifactTypeEnum.OTHER.getType();
+ Either<List<ArtifactType>, ActionStatus> allArtifactTypes = getDeploymentArtifactTypes(NodeTypeEnum.Resource);
+
+ if (allArtifactTypes.isRight()) {
+ BeEcompErrorManager.getInstance().logBeInvalidConfigurationError("Artifact Upload / Update", "artifactTypes", allArtifactTypes.right().value().name());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.FAILED_RETRIVE_ARTIFACTS_TYPES));
+ }
+
+ for (ArtifactType artType : allArtifactTypes.left().value()) {
+
+ if (artType.getName().contains(correctType)) {
+ resourceInfo.type = artType.getName();
+ artifactTypeExist = true;
+ break;
+ }
+ }
+
+ if (!artifactTypeExist) {
+ BeEcompErrorManager.getInstance().logBeInvalidTypeError("Artifact", "-Not supported artifact type ", correctType);
+ log.debug("Not supported artifact type = {}", correctType);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, correctType));
+ }
+
+ Either<Boolean, ResponseFormat> eitherNeedToCreate = validateEnv(componentsUtils, createdArtifactTemplateInfoList, resourceInfo);
+ if (eitherNeedToCreate.isRight())
+ return Either.right(eitherNeedToCreate.right().value());
+ eitherNeedToCreate = validateParentType(componentsUtils, resourceInfo, parentArtifact);
+ if (eitherNeedToCreate.isRight())
+ return Either.right(eitherNeedToCreate.right().value());
+ eitherNeedToCreate = validateIsAlreadyExist(componentsUtils, resourceInfo, createdArtifactTemplateInfoList, parentArtifact);
+ if (eitherNeedToCreate.isRight())
+ return Either.right(eitherNeedToCreate.right().value());
+ Set<String> keys = o.keySet();
+ for (String key : keys) {
+ if (o.get(key) instanceof List) {
+ List<Map<String, Object>> artifList = (List<Map<String, Object>>) o.get(key);
+ for (Map<String, Object> relatedArtifactsMap : artifList) {
+ Either<ArtifactTemplateInfo, ResponseFormat> relatedArtifact = ArtifactTemplateInfo.createArtifactTemplateInfoFromJson(componentsUtils, key, relatedArtifactsMap, createdArtifactTemplateInfoList, resourceInfo);
+ if (relatedArtifact.isRight())
+ return relatedArtifact;
+ if (resourceInfo.relatedArtifactsInfo == null)
+ resourceInfo.relatedArtifactsInfo = new ArrayList<ArtifactTemplateInfo>();
+ resourceInfo.relatedArtifactsInfo.add(relatedArtifact.left().value());
+ }
+ }
+ }
+ return Either.left(resourceInfo);
+ }
+
+ private static Either<Boolean, ResponseFormat> validateIsAlreadyExist(ComponentsUtils componentsUtils, ArtifactTemplateInfo resourceInfo, List<ArtifactTemplateInfo> createdArtifactTemplateInfoList, ArtifactTemplateInfo parentArtifact) {
+
+ if (parentArtifact == null) {
+ if (createdArtifactTemplateInfoList == null || createdArtifactTemplateInfoList.isEmpty())
+ return Either.left(true);
+ for (ArtifactTemplateInfo createdArtifact : createdArtifactTemplateInfoList) {
+ if (createdArtifact.getType().equalsIgnoreCase(resourceInfo.getType()) && createdArtifact.getFileName().equalsIgnoreCase(resourceInfo.getFileName())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR, resourceInfo.getFileName(), createdArtifact.type));
+ }
+ }
+ return Either.left(true);
+ } else {
+ List<ArtifactTemplateInfo> relatedArtifacts = parentArtifact.getRelatedArtifactsInfo();
+ if (relatedArtifacts == null || relatedArtifacts.isEmpty())
+ return Either.left(true);
+ for (ArtifactTemplateInfo relatedArtifact : relatedArtifacts) {
+ if (relatedArtifact.getType().equalsIgnoreCase(resourceInfo.getType())) {
+ if (relatedArtifact.getFileName().equalsIgnoreCase(resourceInfo.getFileName())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR, resourceInfo.getFileName(), parentArtifact.getFileName()));
+ }
+ }
+ }
+ return Either.left(true);
+ }
+ }
+
+ private static Either<Boolean, ResponseFormat> validateParentType(ComponentsUtils componentsUtils, ArtifactTemplateInfo resourceInfo, ArtifactTemplateInfo parentArtifact) {
+
+ if (parentArtifact == null)
+ return Either.left(true);
+ if (resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ARTIFACT.getType()))
+ return Either.left(true);
+ if (resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) && parentArtifact != null) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_IN_MASTER, resourceInfo.getFileName(), resourceInfo.getType(), parentArtifact.getFileName(), parentArtifact.getType()));
+ }
+ if ((resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()))
+ && !parentArtifact.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_IN_MASTER, resourceInfo.getFileName(), resourceInfo.getType(), parentArtifact.getFileName(), parentArtifact.getType()));
+ }
+ if (parentArtifact.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_NESTED.getType())) {
+ if (resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ARTIFACT.getType())) {
+ Either.left(true);
+ }
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_IN_MASTER, resourceInfo.getFileName(), resourceInfo.getType(), parentArtifact.getFileName(), parentArtifact.getType()));
+ }
+ if (parentArtifact.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) && resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_IN_MASTER, resourceInfo.getFileName(), resourceInfo.getType(), parentArtifact.getFileName(), parentArtifact.getType()));
+ }
+
+ if (parentArtifact.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
+ Either.left(true);
+ }
+ return Either.left(true);
+ }
+
+ private static Either<Boolean, ResponseFormat> validateEnv(ComponentsUtils componentsUtils, List<ArtifactTemplateInfo> createdArtifactTemplateInfoList, ArtifactTemplateInfo resourceInfo) {
+
+ if (createdArtifactTemplateInfoList == null || createdArtifactTemplateInfoList.isEmpty())
+ return Either.left(true);
+ if (resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_NESTED.getType()) || resourceInfo.getType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ARTIFACT.getType()))
+ return Either.left(true);
+ for (ArtifactTemplateInfo createdArtifactTemplateInfo : createdArtifactTemplateInfoList) {
+ // check if artifact with this name already parsed. If parsed check
+ // env name. it must be the same.
+ if (resourceInfo.getFileName().equalsIgnoreCase(createdArtifactTemplateInfo.getFileName())) {
+ if ((resourceInfo.getEnv() == null || resourceInfo.getEnv().isEmpty()) && (createdArtifactTemplateInfo.getEnv() != null && !createdArtifactTemplateInfo.getEnv().isEmpty())) {
+ log.debug("Artifact file with name {} type{} already parsed but with env {}", resourceInfo.getFileName(), resourceInfo.getType(), createdArtifactTemplateInfo.getEnv());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_ENV, resourceInfo.getFileName(), resourceInfo.getType(), resourceInfo.getEnv(), createdArtifactTemplateInfo.getEnv()));
+ }
+ if (resourceInfo.getEnv() != null && !resourceInfo.getEnv().isEmpty() && createdArtifactTemplateInfo.getEnv() != null && !createdArtifactTemplateInfo.getEnv().isEmpty()
+ && !createdArtifactTemplateInfo.getEnv().equalsIgnoreCase(resourceInfo.getEnv())) {
+ log.debug("Artifact file with name {} type{} env {} already parsed but with env {}", resourceInfo.getFileName(), resourceInfo.getType(), resourceInfo.getEnv(), createdArtifactTemplateInfo.getEnv());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_ENV, resourceInfo.getFileName(), resourceInfo.getType(), resourceInfo.getEnv(), createdArtifactTemplateInfo.getEnv()));
+ }
+ if ((resourceInfo.getEnv() != null && !resourceInfo.getEnv().isEmpty()) && (createdArtifactTemplateInfo.getEnv() == null || createdArtifactTemplateInfo.getEnv().isEmpty())) {
+ log.debug("Artifact file with name {} type{} env {} already parsed but with env {}", resourceInfo.getFileName(), resourceInfo.getType(), resourceInfo.getEnv(), createdArtifactTemplateInfo.getEnv());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_VALID_ENV, resourceInfo.getFileName(), resourceInfo.getType(), resourceInfo.getEnv(), createdArtifactTemplateInfo.getEnv()));
+ }
+ }
+ List<ArtifactTemplateInfo> relatedArtifacts = createdArtifactTemplateInfo.getRelatedArtifactsInfo();
+ Either<Boolean, ResponseFormat> status = validateEnv(componentsUtils, relatedArtifacts, resourceInfo);
+ if (status.isRight())
+ return status;
+ }
+ return Either.left(true);
+ }
+
+ private static Either<List<ArtifactType>, ActionStatus> getDeploymentArtifactTypes(NodeTypeEnum parentType) {
+
+ Map<String, DeploymentArtifactTypeConfig> deploymentArtifacts = null;
+ List<ArtifactType> artifactTypes = new ArrayList<ArtifactType>();
+
+ if (parentType.equals(NodeTypeEnum.Service)) {
+ deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts();
+ } else {
+ deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+ }
+ if (deploymentArtifacts != null) {
+ for (String artifactType : deploymentArtifacts.keySet()) {
+ ArtifactType artifactT = new ArtifactType();
+ artifactT.setName(artifactType);
+ artifactTypes.add(artifactT);
+ }
+ return Either.left(artifactTypes);
+ } else {
+ return Either.right(ActionStatus.GENERAL_ERROR);
+ }
+
+ }
+
+ public static int compareByGroupName(ArtifactTemplateInfo art1, ArtifactTemplateInfo art2) {
+ return art1.isBase ? (art2.isBase ? 0 : -1) : (art2.isBase ? 1 : 0);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTypesInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTypesInfo.java
new file mode 100644
index 0000000000..249b420908
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTypesInfo.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+import org.openecomp.sdc.be.model.ArtifactType;
+
+public class ArtifactTypesInfo {
+
+ Integer heatDefaultTimeout = 60;
+ List<ArtifactType> artifactTypes;
+
+ public List<ArtifactType> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+ public void setArtifactTypes(List<ArtifactType> artifactTypes) {
+ this.artifactTypes = artifactTypes;
+ }
+
+ public Integer getHeatDefaultTimeout() {
+ return heatDefaultTimeout;
+ }
+
+ public void setHeatDefaultTimeout(Integer heatDefaultTimeout) {
+ this.heatDefaultTimeout = heatDefaultTimeout;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/CreateAndAssotiateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/CreateAndAssotiateInfo.java
new file mode 100644
index 0000000000..b2fa493443
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/CreateAndAssotiateInfo.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+
+public class CreateAndAssotiateInfo {
+ private ComponentInstance node;
+ private RequirementCapabilityRelDef associate;
+
+ public CreateAndAssotiateInfo(ComponentInstance node, RequirementCapabilityRelDef associate) {
+ super();
+ this.node = node;
+ this.associate = associate;
+ }
+
+ public ComponentInstance getNode() {
+ return node;
+ }
+
+ public void setNode(ComponentInstance node) {
+ this.node = node;
+ }
+
+ public RequirementCapabilityRelDef getAssociate() {
+ return associate;
+ }
+
+ public void setAssociate(RequirementCapabilityRelDef associate) {
+ this.associate = associate;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java
new file mode 100644
index 0000000000..d0f3ff868e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public enum DistributionStatus {
+ DEPLOYED("Deployed", "DEPLOYED");
+
+ private String name;
+ private String auditingStatus;
+
+ private static Logger log = LoggerFactory.getLogger(DistributionStatus.class.getName());
+
+ DistributionStatus(String name, String auditingStatus) {
+ this.name = name;
+ this.auditingStatus = auditingStatus;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getAuditingStatus() {
+ return auditingStatus;
+ }
+
+ public static DistributionStatus getStatusByAuditingStatusName(String auditingStatus) {
+ DistributionStatus res = null;
+ DistributionStatus[] values = values();
+ for (DistributionStatus value : values) {
+ if (value.getAuditingStatus().equals(auditingStatus)) {
+ res = value;
+ break;
+ }
+ }
+ if (res == null) {
+ log.debug("No DistributionStatus is mapped to name {}", auditingStatus);
+ }
+ return res;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java
new file mode 100644
index 0000000000..6f7596cd5f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
+
+public class DistributionStatusInfo {
+ String omfComponentID;
+ String timestamp;
+ String url;
+ String status;
+ String errorReason;
+
+ public DistributionStatusInfo(ESTimeBasedEvent distributionStatusEvent) {
+ super();
+ omfComponentID = (String) distributionStatusEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName());
+ timestamp = (String) distributionStatusEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName());// distributionStatusEvent.getStatusTime();
+ url = (String) distributionStatusEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName());// distributionStatusEvent.getResoureURL();
+ status = (String) distributionStatusEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_STATUS.getDisplayName());// distributionStatusEvent.getStatus();
+ errorReason = (String) distributionStatusEvent.getFields().get(AuditingFieldsKeysEnum.AUDIT_DESC.getDisplayName());
+
+ }
+
+ public DistributionStatusInfo(String omfComponentID, String timestamp, String url, String status) {
+ super();
+ this.omfComponentID = omfComponentID;
+ this.timestamp = timestamp;
+ this.url = url;
+ this.status = status;
+ }
+
+ public String getOmfComponentID() {
+ return omfComponentID;
+ }
+
+ public void setOmfComponentID(String omfComponentID) {
+ this.omfComponentID = omfComponentID;
+ }
+
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(String timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getErrorReason() {
+ return errorReason;
+ }
+
+ public void setErrorReason(String errorReason) {
+ this.errorReason = errorReason;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusListResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusListResponse.java
new file mode 100644
index 0000000000..ab122efc74
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusListResponse.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class DistributionStatusListResponse {
+
+ private List<DistributionStatusInfo> distribStatusInfoList;
+
+ public List<DistributionStatusInfo> getDistributionStatusList() {
+ return distribStatusInfoList;
+ }
+
+ public void setDistributionStatusList(List<DistributionStatusInfo> distribStatusInfoList) {
+ this.distribStatusInfoList = distribStatusInfoList;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceInfo.java
new file mode 100644
index 0000000000..dfa481d34d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceInfo.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+public class DistributionStatusOfServiceInfo {
+ String distributionID;
+ String timestamp;
+ String userId;
+ String deployementStatus;
+
+ public DistributionStatusOfServiceInfo() {
+ super();
+
+ }
+
+ public DistributionStatusOfServiceInfo(String distributionID, String timestamp, String userId, String deployementStatus) {
+ super();
+ this.distributionID = distributionID;
+ this.timestamp = timestamp;
+ this.userId = userId;
+ this.deployementStatus = deployementStatus;
+ }
+
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ public void setDistributionID(String distributionID) {
+ this.distributionID = distributionID;
+ }
+
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(String timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getDeployementStatus() {
+ return deployementStatus;
+ }
+
+ public void setDeployementStatus(String deployementStatus) {
+ this.deployementStatus = deployementStatus;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponce.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponce.java
new file mode 100644
index 0000000000..8415736be1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponce.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class DistributionStatusOfServiceListResponce {
+
+ private List<DistributionStatusOfServiceInfo> distribStatusOfServiceInfoList;
+
+ public List<DistributionStatusOfServiceInfo> getDistributionStatusOfServiceList() {
+ return distribStatusOfServiceInfoList;
+ }
+
+ public void setDistributionStatusOfServiceList(List<DistributionStatusOfServiceInfo> distribStatusOfServiceInfoList) {
+ this.distribStatusOfServiceInfoList = distribStatusOfServiceInfoList;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java
new file mode 100644
index 0000000000..24d9c5644d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+
+public class GroupDefinitionInfo {
+ private String name;
+
+ // the id is unique per group instance on graph.
+ private String uniqueId;
+
+ // the group UUID should be changed when one of the artifacts/component
+ // instances has been changed.
+ private String groupUUID;
+
+ // version should be changed when there is a change to the group's metadata
+ // or to the groups members
+ // (not necessarily when the VF version is changed). This field cannot be
+ // updated by user
+ private String version;
+
+ private String invariantUUID;
+
+ Boolean isBase = null;
+
+ // artifacts - list of artifact uid. All artifacts in the group must already
+ // be uploaded to the VF
+ private List<ArtifactDefinitionInfo> artifacts;
+
+ public GroupDefinitionInfo() {
+ super();
+ }
+
+ public GroupDefinitionInfo(GroupDefinition other) {
+ this.setName(other.getName());
+ this.setUniqueId(other.getUniqueId());
+ this.setVersion(other.getVersion());
+ this.setGroupUUID(other.getGroupUUID());
+ this.setInvariantUUID(other.getInvariantUUID());
+
+ }
+
+ public String getInvariantUUID() {
+ return invariantUUID;
+ }
+
+ public void setInvariantUUID(String invariantUUID) {
+ this.invariantUUID = invariantUUID;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ public String getGroupUUID() {
+ return groupUUID;
+ }
+
+ public void setGroupUUID(String groupUUID) {
+ this.groupUUID = groupUUID;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public Boolean getIsBase() {
+ return isBase;
+ }
+
+ public void setIsBase(Boolean isBase) {
+ this.isBase = isBase;
+ }
+
+ public List<ArtifactDefinitionInfo> getArtifacts() {
+ return artifacts;
+ }
+
+ public void setArtifacts(List<ArtifactDefinitionInfo> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ @Override
+ public String toString() {
+ return "GroupDefinitionInfo [" + super.toString() + ", isBase=" + isBase + ", artifacts=" + artifacts + "]";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupTemplateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupTemplateInfo.java
new file mode 100644
index 0000000000..8471a801ac
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupTemplateInfo.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+import java.util.Map;
+
+public class GroupTemplateInfo {
+ String groupName;
+ boolean isBase;
+ ArtifactTemplateInfo artifactTemplateInfo;
+
+ public GroupTemplateInfo() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public boolean isBase() {
+ return isBase;
+ }
+
+ public void setBase(boolean isBase) {
+ this.isBase = isBase;
+ }
+
+ public ArtifactTemplateInfo getArtifactTemplateInfo() {
+ return artifactTemplateInfo;
+ }
+
+ public void setArtifactTemplateInfo(ArtifactTemplateInfo artifactTemplateInfo) {
+ this.artifactTemplateInfo = artifactTemplateInfo;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java
new file mode 100644
index 0000000000..95038b1830
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+
+public class MergedArtifactInfo {
+
+ private List<ArtifactDefinition> createdArtifact;
+ private ArtifactTemplateInfo jsonArtifactTemplate;
+ private Set<String> parsetArtifactsNames;
+
+ public List<ArtifactDefinition> getCreatedArtifact() {
+ return createdArtifact;
+ }
+
+ public void setCreatedArtifact(List<ArtifactDefinition> createdArtifact) {
+ this.createdArtifact = createdArtifact;
+ parsetArtifactsNames = new HashSet<String>();
+ parsetArtifactsNames.add(jsonArtifactTemplate.getFileName());
+ List<ArtifactTemplateInfo> relatedGroupTemplateList = jsonArtifactTemplate.getRelatedArtifactsInfo();
+ if (relatedGroupTemplateList != null && !relatedGroupTemplateList.isEmpty()) {
+ this.createArtifactsGroupSet(relatedGroupTemplateList, parsetArtifactsNames);
+ }
+
+ }
+
+ public ArtifactTemplateInfo getJsonArtifactTemplate() {
+ return jsonArtifactTemplate;
+ }
+
+ public void setJsonArtifactTemplate(ArtifactTemplateInfo jsonArtifactTemplate) {
+ this.jsonArtifactTemplate = jsonArtifactTemplate;
+ }
+
+ public List<ArtifactTemplateInfo> getListToAssociateArtifactToGroup() {
+ List<ArtifactTemplateInfo> resList = new ArrayList<ArtifactTemplateInfo>();
+ List<ArtifactTemplateInfo> relatedArtifacts = jsonArtifactTemplate.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ getNewArtifactsInGroup(resList, relatedArtifacts);
+ }
+ return resList;
+ }
+
+ public List<ArtifactDefinition> getListToDissotiateArtifactFromGroup(List<ArtifactDefinition> deletedArtifacts) {
+ List<ArtifactDefinition> resList = new ArrayList<ArtifactDefinition>();
+ for (ArtifactDefinition artifactDefinition : createdArtifact) {
+ if (!parsetArtifactsNames.contains(artifactDefinition.getArtifactName())) {
+ boolean isDeleted = false;
+ for (ArtifactDefinition deletedArtifact : deletedArtifacts) {
+ if (artifactDefinition.getUniqueId().equalsIgnoreCase(deletedArtifact.getUniqueId())) {
+ isDeleted = true;
+ break;
+ }
+
+ }
+ if (!isDeleted)
+ resList.add(artifactDefinition);
+ }
+
+ }
+
+ return resList;
+ }
+
+ public List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> getListToUpdateArtifactInGroup() {
+ List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> resList = new ArrayList<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>();
+ for (ArtifactDefinition artifactDefinition : createdArtifact) {
+ if (artifactDefinition.getArtifactName().equalsIgnoreCase(jsonArtifactTemplate.getFileName())) {
+ resList.add(new ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>(artifactDefinition, jsonArtifactTemplate));
+ }
+ }
+ List<ArtifactTemplateInfo> relatedArtifacts = jsonArtifactTemplate.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ getUpdateArtifactsInGroup(resList, relatedArtifacts);
+ }
+ return resList;
+ }
+
+ private void getUpdateArtifactsInGroup(List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> resList, List<ArtifactTemplateInfo> jsonArtifacts) {
+
+ for (ArtifactTemplateInfo artifactTemplateInfo : jsonArtifacts) {
+
+ for (ArtifactDefinition artifactDefinition : createdArtifact) {
+ if (artifactDefinition.getArtifactName().equalsIgnoreCase(artifactTemplateInfo.getFileName())) {
+ resList.add(new ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>(artifactDefinition, artifactTemplateInfo));
+ }
+ }
+
+ List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ getUpdateArtifactsInGroup(resList, relatedArtifacts);
+ }
+ }
+ }
+
+ private void getNewArtifactsInGroup(List<ArtifactTemplateInfo> resList, List<ArtifactTemplateInfo> jsonArtifacts) {
+
+ for (ArtifactTemplateInfo artifactTemplateInfo : jsonArtifacts) {
+ boolean isNewArtifact = true;
+ for (ArtifactDefinition artifactDefinition : createdArtifact) {
+ if (artifactDefinition.getArtifactName().equalsIgnoreCase(artifactTemplateInfo.getFileName())) {
+ isNewArtifact = false;
+ }
+ }
+ if (isNewArtifact)
+ resList.add(artifactTemplateInfo);
+ List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ getNewArtifactsInGroup(resList, relatedArtifacts);
+ }
+ }
+ }
+
+ private void createArtifactsGroupSet(List<ArtifactTemplateInfo> parsedGroupTemplateList, Set<String> parsedArtifactsName) {
+
+ for (ArtifactTemplateInfo parsedGroupTemplate : parsedGroupTemplateList) {
+ parsedArtifactsName.add(parsedGroupTemplate.getFileName());
+ List<ArtifactTemplateInfo> relatedArtifacts = parsedGroupTemplate.getRelatedArtifactsInfo();
+ if (relatedArtifacts != null && !relatedArtifacts.isEmpty()) {
+ createArtifactsGroupSet(relatedArtifacts, parsedArtifactsName);
+ }
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java
new file mode 100644
index 0000000000..457c49ee8e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class ServiceInfo {
+
+ private String name;
+ private List<ServiceVersionInfo> versions;
+
+ public ServiceInfo(String serviceName, List<ServiceVersionInfo> list) {
+ this.name = serviceName;
+ this.versions = list;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<ServiceVersionInfo> getVersions() {
+ return versions;
+ }
+
+ public void setVersions(List<ServiceVersionInfo> versions) {
+ this.versions = versions;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceVersionInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceVersionInfo.java
new file mode 100644
index 0000000000..13f8a1307f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceVersionInfo.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+public class ServiceVersionInfo {
+
+ // private String serviceName;
+ private String version;
+ private String url;
+
+ public ServiceVersionInfo(String serviceName, String serviceVersion, String context) {
+ super();
+ // this.serviceName = serviceName;
+ this.version = serviceVersion;
+ StringBuilder sb = new StringBuilder(context);
+ sb.append("services/").append(serviceName).append("/").append(serviceVersion);
+ url = sb.toString();
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String serviceVersion) {
+ this.version = serviceVersion;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServicesWrapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServicesWrapper.java
new file mode 100644
index 0000000000..9c26cf5959
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServicesWrapper.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class ServicesWrapper {
+ private List<ServiceInfo> services;
+
+ public List<ServiceInfo> getServices() {
+ return services;
+ }
+
+ public void setServices(List<ServiceInfo> services) {
+ this.services = services;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServletJsonResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServletJsonResponse.java
new file mode 100644
index 0000000000..5559311e9e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServletJsonResponse.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+public class ServletJsonResponse {
+
+ String source;
+ String description;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInfo.java
new file mode 100644
index 0000000000..11b27af7a1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInfo.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class ToscaNodeTypeInfo {
+
+ private String nodeName;
+ private String templateVersion;
+ private List<ToscaNodeTypeInterface> interfaces;
+ private String iconPath;
+
+ public String getNodeName() {
+ return nodeName;
+ }
+
+ public void setNodeName(String nodeName) {
+ this.nodeName = nodeName;
+ }
+
+ public String getTemplateVersion() {
+ return templateVersion;
+ }
+
+ public void setTemplateVersion(String templateVersion) {
+ this.templateVersion = templateVersion;
+ }
+
+ public List<ToscaNodeTypeInterface> getInterfaces() {
+ return interfaces;
+ }
+
+ public void setInterfaces(List<ToscaNodeTypeInterface> interfaces) {
+ this.interfaces = interfaces;
+ }
+
+ public String getIconPath() {
+ return iconPath;
+ }
+
+ public void setIconPath(String iconPath) {
+ this.iconPath = iconPath;
+ }
+
+ @Override
+ public String toString() {
+ return "ToscaNodeTypeInfo [nodeName=" + nodeName + ", templateVersion=" + templateVersion + ", interfaces=" + interfaces + ", iconPath=" + iconPath + "]";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInterface.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInterface.java
new file mode 100644
index 0000000000..25bab766bf
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ToscaNodeTypeInterface.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.info;
+
+import java.util.List;
+
+public class ToscaNodeTypeInterface {
+
+ List<String> scripts;
+
+ public List<String> getScripts() {
+ return scripts;
+ }
+
+ public void setScripts(List<String> scripts) {
+ this.scripts = scripts;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java b/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java
new file mode 100644
index 0000000000..d40a3d4433
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.listen;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.monitoring.BeMonitoringService;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.listener.AppContextListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
+import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
+
+public class BEAppContextListener extends AppContextListener implements ServletContextListener {
+
+ private static final String MANIFEST_FILE_NAME = "/META-INF/MANIFEST.MF";
+ private static Logger log = LoggerFactory.getLogger(BEAppContextListener.class.getName());
+
+ private static UebManager uebManager = null;
+
+ public void contextInitialized(ServletContextEvent context) {
+
+ super.contextInitialized(context);
+
+ ConfigurationManager configurationManager = new ConfigurationManager(ExternalConfiguration.getConfigurationSource());
+ log.debug("loading configuration from configDir: {} appName: {}", ExternalConfiguration.getConfigDir(), ExternalConfiguration.getAppName());
+
+ context.getServletContext().setAttribute(Constants.CONFIGURATION_MANAGER_ATTR, configurationManager);
+
+ WebAppContextWrapper webAppContextWrapper = new WebAppContextWrapper();
+ context.getServletContext().setAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR, webAppContextWrapper);
+
+ DownloadArtifactLogic downloadArtifactLogic = new DownloadArtifactLogic();
+ context.getServletContext().setAttribute(Constants.DOWNLOAD_ARTIFACT_LOGIC_ATTR, downloadArtifactLogic);
+
+ context.getServletContext().setAttribute(Constants.SDC_RELEASE_VERSION_ATTR, getVersionFromManifest(context));
+
+ // Monitoring service
+ BeMonitoringService bms = new BeMonitoringService(context.getServletContext());
+ bms.start(configurationManager.getConfiguration().getSystemMonitoring().getProbeIntervalInSeconds(15));
+
+ initUebManager();
+
+ log.debug("After executing {}", this.getClass());
+
+ }
+
+ private void initUebManager() {
+ try {
+ if (uebManager == null) {
+ uebManager = UebManager.getInstance();
+ uebManager.initListener(null);
+ }
+ } catch (UebException ex) {
+ log.debug("Failed to initialize UebManager", ex);
+ BeEcompErrorManager.getInstance().logInternalConnectionError("InitUebManager", "Failed to initialize listener of UebManager", ErrorSeverity.ERROR);
+ }
+ log.debug("After init listener of UebManager");
+ }
+
+ public void contextDestroyed(ServletContextEvent context) {
+ if (uebManager != null) {
+ uebManager.shutdown();
+ uebManager = null;
+ }
+ super.contextDestroyed(context);
+
+ }
+
+ private IResourceOperation getResourceOperationManager(Class<? extends IResourceOperation> clazz, WebApplicationContext webContext) {
+
+ return webContext.getBean(clazz);
+ }
+
+ private String getVersionFromManifest(ServletContextEvent context) {
+ ServletContext servletContext = context.getServletContext();
+ InputStream inputStream = servletContext.getResourceAsStream(MANIFEST_FILE_NAME);
+
+ String version = null;
+ try {
+ Manifest mf = new Manifest(inputStream);
+ Attributes atts = mf.getMainAttributes();
+ version = atts.getValue(Constants.SDC_RELEASE_VERSION_ATTR);
+ if (version == null || version.isEmpty()) {
+ log.warn("failed to read ASDC version from MANIFEST.");
+ } else {
+ log.info("ASDC version from MANIFEST is {}", version);
+ }
+
+ } catch (IOException e) {
+ log.warn("failed to read ASDC version from MANIFEST", e.getMessage());
+ }
+
+ return version;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java b/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java
new file mode 100644
index 0000000000..34a56cdd13
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.monitoring;
+
+import java.net.URI;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.client.api.Request;
+import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.proxy.ProxyServlet;
+import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+public class EsGateway extends ProxyServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static Logger log = LoggerFactory.getLogger(EsGateway.class.getName());
+
+ @Override
+ public URI rewriteURI(HttpServletRequest request) {
+
+ String originalUrl = request.getRequestURI();
+
+ String redirectedUrl = getModifiedUrl(request);
+
+ log.debug("EsGateway Redirecting request from: {} , to: {}", originalUrl, redirectedUrl);
+ return URI.create(redirectedUrl);
+ }
+
+ @Override
+ public void customizeProxyRequest(Request proxyRequest, HttpServletRequest request) {
+ super.customizeProxyRequest(proxyRequest, request);
+
+ }
+
+ @Override
+ protected void onResponseSuccess(HttpServletRequest request, HttpServletResponse response, Response proxyResponse) {
+ super.onResponseSuccess(request, response, proxyResponse);
+ }
+
+ public String getModifiedUrl(HttpServletRequest request) {
+ String esHost = null;
+ String esPort = null;
+ MonitoringBusinessLogic monitoringBL = getMonitoringBL(request.getSession().getServletContext());
+ if (monitoringBL == null) {
+ log.error("failed to retrive monitoringBL.");
+ } else {
+ esHost = monitoringBL.getEsHost();
+ esPort = monitoringBL.getEsPort();
+ }
+
+ String scheme = request.getScheme();
+ String contextPath = request.getContextPath(); // /mywebapp
+ String servletPath = request.getServletPath(); // /servlet/MyServlet
+ String pathInfo = request.getPathInfo(); // /a/b;c=123
+ String queryString = request.getQueryString(); // d=789
+
+ StringBuilder url = new StringBuilder();
+ url.append(scheme).append("://").append(esHost);
+ url.append(":").append(esPort);
+ url.append(contextPath).append(servletPath);
+
+ if (pathInfo != null) {
+ url.append(pathInfo);
+ }
+ if (queryString != null) {
+ url.append("?").append(queryString);
+ }
+
+ String redirectedUrl = url.toString().replace("/sdc2/esGateway/", "/");
+ return redirectedUrl;
+
+ }
+
+ protected MonitoringBusinessLogic getMonitoringBL(ServletContext context) {
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ MonitoringBusinessLogic monitoringBusinessLogic = webApplicationContext.getBean(MonitoringBusinessLogic.class);
+
+ return monitoringBusinessLogic;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
new file mode 100644
index 0000000000..0e8addf692
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -0,0 +1,843 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+import java.util.zip.ZipInputStream;
+
+import javax.annotation.Resource;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityTypeEnum;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.UploadArtifactInfo;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
+import org.openecomp.sdc.common.util.ZipUtil;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.context.WebApplicationContext;
+import org.yaml.snakeyaml.Yaml;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
+
+import fj.data.Either;
+
+public abstract class AbstractValidationsServlet extends BeGenericServlet {
+
+ @Resource
+ private ServletUtils servletUtils;
+
+ @Resource
+ private ResourceImportManager resourceImportManager;
+
+ @Autowired
+ protected ComponentsUtils componentsUtils;
+
+ private static final Object LOCK = new Object();
+ private Logger log = null;
+
+ protected void init(Logger log) {
+ initLog(log);
+ initSpringFromContext();
+
+ }
+
+ private void initLog(Logger log) {
+ if (this.log == null) {
+ synchronized (LOCK) {
+ if (this.log == null) {
+ this.log = log;
+ }
+
+ }
+ }
+ }
+
+ private void initSpringFromContext() {
+ if (servletUtils == null) {
+ synchronized (LOCK) {
+ if (servletUtils == null) {
+ ServletContext context = servletRequest.getSession().getServletContext();
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ servletUtils = webApplicationContext.getBean(ServletUtils.class);
+ resourceImportManager = webApplicationContext.getBean(ResourceImportManager.class);
+ }
+ }
+ }
+ }
+
+ protected void validateResourceDoesNotExist(Wrapper<Response> responseWrapper, User user, String resourceName) {
+ if (resourceImportManager.isResourceExist(resourceName)) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceName);
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ protected void validateUserExist(Wrapper<Response> responseWrapper, Wrapper<User> userWrapper, String userId) {
+ log.debug("get user {} from DB", userId);
+ // get user details
+ if (userId == null) {
+ log.info("user userId is null");
+ Response response = returnMissingInformation(new User());
+ responseWrapper.setInnerElement(response);
+ }
+
+ else {
+ IUserBusinessLogic userAdmin = getServletUtils().getUserAdmin();
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, false);
+ if (eitherCreator.isRight()) {
+ log.info("user is not listed. userId={}", userId);
+ User user = new User();
+ user.setUserId(userId);
+ Response response = returnMissingInformation(user);
+ responseWrapper.setInnerElement(response);
+ } else {
+ userWrapper.setInnerElement(eitherCreator.left().value());
+ }
+ }
+ }
+
+ protected Response returnMissingInformation(User user) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ return buildErrorResponse(responseFormat);
+ }
+
+ protected void validateDataNotNull(Wrapper<Response> responseWrapper, Object... dataParams) {
+ for (Object dataElement : dataParams) {
+ if (dataElement == null) {
+ log.info("Invalid body was received.");
+ Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ responseWrapper.setInnerElement(response);
+ break;
+ }
+ }
+
+ }
+
+ protected void validateUserRole(Wrapper<Response> errorResponseWrapper, User user) {
+ log.debug("validate user role");
+ if (!user.getRole().equals(Role.ADMIN.name()) && !user.getRole().equals(Role.DESIGNER.name())) {
+ log.info("user is not in appropriate role to perform action");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("audit before sending response");
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+
+ Response response = buildErrorResponse(responseFormat);
+ errorResponseWrapper.setInnerElement(response);
+ }
+
+ }
+
+ protected void validateZip(Wrapper<Response> responseWrapper, File file, String payloadName) throws FileNotFoundException {
+ InputStream fileInputStream = new FileInputStream(file);
+ Map<String, byte[]> unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream));
+ if (payloadName == null || payloadName.isEmpty() || !unzippedFolder.containsKey(payloadName)) {
+ log.info("Invalid json was received. payloadName should be yml file name");
+ Response errorResponse = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void fillZipContents(Wrapper<String> yamlStringWrapper, File file) throws FileNotFoundException {
+ InputStream fileInputStream = new FileInputStream(file);
+ Map<String, byte[]> unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream));
+ String ymlName = unzippedFolder.keySet().iterator().next();
+ fillToscaTemplateFromZip(yamlStringWrapper, ymlName, file);
+ }
+
+ protected void fillToscaTemplateFromZip(Wrapper<String> yamlStringWrapper, String payloadName, File file) throws FileNotFoundException {
+ InputStream fileInputStream = new FileInputStream(file);
+ Map<String, byte[]> unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream));
+ byte[] yamlFileInBytes = unzippedFolder.get(payloadName);
+ String yamlAsString = new String(yamlFileInBytes, StandardCharsets.UTF_8);
+ log.debug("received yaml: {}", yamlAsString);
+ yamlStringWrapper.setInnerElement(yamlAsString);
+ }
+
+ protected void validateUserRole(Wrapper<Response> errorResponseWrapper, User user, ResourceAuthorityTypeEnum resourceAuthority) {
+ log.debug("validate user role");
+ if (resourceAuthority == ResourceAuthorityTypeEnum.NORMATIVE_TYPE_BE) {
+ if (!user.getRole().equals(Role.ADMIN.name())) {
+ log.info("user is not in appropriate role to perform action");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ log.debug("audit before sending response");
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+
+ Response response = buildErrorResponse(responseFormat);
+ errorResponseWrapper.setInnerElement(response);
+ }
+ } else {
+ validateUserRole(errorResponseWrapper, user);
+ }
+
+ }
+
+ protected void validateAndFillResourceJson(Wrapper<Response> responseWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, User user, ResourceAuthorityTypeEnum resourceAuthorityEnum, String resourceInfo) {
+ boolean isValid;
+ try {
+ log.debug("The received json is {}", resourceInfo);
+ UploadResourceInfo resourceInfoObject = gson.fromJson(resourceInfo, UploadResourceInfo.class);
+ if (resourceInfoObject == null) {
+ isValid = false;
+ } else {
+ if (!resourceAuthorityEnum.isBackEndImport()) {
+ isValid = resourceInfoObject.getPayloadName() != null && !resourceInfoObject.getPayloadName().isEmpty();
+ // TODO Tal only resource name is checked
+ } else {
+ isValid = true;
+ }
+ uploadResourceInfoWrapper.setInnerElement(resourceInfoObject);
+ }
+
+ } catch (JsonSyntaxException e) {
+ isValid = false;
+
+ }
+ if (!isValid) {
+ log.info("Invalid json was received.");
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ Response errorResp = buildErrorResponse(responseFormat);
+ responseWrapper.setInnerElement(errorResp);
+ }
+ }
+
+ protected void validateAuthorityType(Wrapper<Response> responseWrapper, String authorityType) {
+ log.debug("The received authority type is {}", authorityType);
+ ResourceAuthorityTypeEnum authorityTypeEnum = ResourceAuthorityTypeEnum.findByUrlPath(authorityType);
+ if (authorityTypeEnum == null) {
+ log.info("Invalid authority type was received.");
+ Response errorResp = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ responseWrapper.setInnerElement(errorResp);
+ }
+ }
+
+ public ServletUtils getServletUtils() {
+ initSpringFromContext();
+ return servletUtils;
+ }
+
+ public Gson getGson() {
+ return getServletUtils().getGson();
+ }
+
+ public ComponentsUtils getComponentsUtils() {
+ return getServletUtils().getComponentsUtils();
+ }
+
+ protected void validatePayloadIsTosca(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user, String toscaPayload) {
+ log.debug("checking payload is valid tosca");
+ boolean isValid;
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<String, ResultStatusEnum> findFirstToscaStringElement = ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION);
+
+ if (findFirstToscaStringElement.isRight()) {
+ isValid = false;
+ } else {
+ String defenitionVersionFound = findFirstToscaStringElement.left().value();
+ if (defenitionVersionFound == null || defenitionVersionFound.isEmpty()) {
+ isValid = false;
+ } else {
+ isValid = ImportUtils.Constants.TOSCA_DEFINITION_VERSIONS.contains(defenitionVersionFound);
+ }
+ }
+
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void validatePayloadIsYml(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaTamplatePayload) {
+ log.debug("checking tosca template is valid yml");
+ YamlToObjectConverter yamlConvertor = new YamlToObjectConverter();
+ boolean isYamlValid = yamlConvertor.isValidYaml(toscaTamplatePayload.getBytes());
+ if (!isYamlValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_YAML_FILE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ protected void validatePayloadNameSpace(Wrapper<Response> responseWrapper, UploadResourceInfo resourceInfo, User user, String toscaPayload) {
+ boolean isValid;
+ String nameSpace = "";
+
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<Map<String, Object>, ResultStatusEnum> toscaElement = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES);
+ if (toscaElement.isRight() || toscaElement.left().value().size() != 1) {
+ isValid = false;
+ } else {
+ nameSpace = toscaElement.left().value().keySet().iterator().next();
+ isValid = nameSpace.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ }
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_RESOURCE_NAMESPACE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ } else {
+ String str1 = nameSpace.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = str1.split("\\.");
+ if (ResourceTypeEnum.contains(findTypes[0].toUpperCase())) {
+ String type = findTypes[0].toUpperCase();
+ resourceInfo.setResourceType(type);
+ } else {
+ resourceInfo.setResourceType(ResourceTypeEnum.VFC.name());
+ }
+ }
+
+ }
+
+ protected void validatePayloadIsSingleResource(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user, String toscaPayload) {
+ log.debug("checking payload contains single resource");
+ boolean isValid;
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<Map<String, Object>, ResultStatusEnum> toscaElement = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES);
+ if (toscaElement.isRight()) {
+ isValid = false;
+ } else {
+ isValid = toscaElement.left().value().size() == 1;
+ }
+
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_SINGLE_RESOURCE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void validatePayloadIsNotService(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaPayload) {
+ log.debug("checking payload is not a tosca service");
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<Object, ResultStatusEnum> toscaElement = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL);
+
+ if (toscaElement.isLeft()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void validatePayloadIsTopologyTemplate(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaPayload) {
+ log.debug("checking payload is a tosca topology template");
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<Object, ResultStatusEnum> toscaElement = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL);
+
+ if (toscaElement.isRight()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void validateToscaTemplatePayloadName(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user) {
+ String toscaTemplatePayloadName = uploadResourceInfo.getPayloadName();
+ boolean isValidSuffix = false;
+ if (toscaTemplatePayloadName != null && !toscaTemplatePayloadName.isEmpty()) {
+ for (String validSuffix : ImportUtils.Constants.TOSCA_YML_CSAR_VALID_SUFFIX) {
+ isValidSuffix = isValidSuffix || toscaTemplatePayloadName.toLowerCase().endsWith(validSuffix);
+ }
+ }
+ if (!isValidSuffix) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_FILE_EXTENSION);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+
+ }
+
+ protected void validateMD5(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfo, HttpServletRequest request, String resourceInfoJsonString) {
+ boolean isValid;
+ String recievedMD5 = request.getHeader(Constants.MD5_HEADER);
+ if (recievedMD5 == null) {
+ isValid = false;
+ } else {
+ String calculateMD5 = GeneralUtility.calculateMD5ByString(resourceInfoJsonString);
+ isValid = calculateMD5.equals(recievedMD5);
+ }
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_RESOURCE_CHECKSUM);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ protected void validateComponentType(Wrapper<Response> responseWrapper, Wrapper<ComponentTypeEnum> componentWrapper, String componentType) {
+ boolean isValid;
+ if (componentType == null) {
+ isValid = false;
+ } else {
+ if (ComponentTypeEnum.RESOURCE_PARAM_NAME.equalsIgnoreCase(componentType)) {
+ isValid = true;
+ componentWrapper.setInnerElement(ComponentTypeEnum.RESOURCE);
+ } else if (ComponentTypeEnum.SERVICE_PARAM_NAME.equalsIgnoreCase(componentType)) {
+ isValid = true;
+ componentWrapper.setInnerElement(ComponentTypeEnum.SERVICE);
+ } else {
+ isValid = false;
+ }
+ }
+ if (!isValid) {
+ log.debug("Invalid componentType:{}", componentType);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ Response errorResp = buildErrorResponse(responseFormat);
+ responseWrapper.setInnerElement(errorResp);
+ }
+ }
+
+ protected void fillToscaTemplateFromJson(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo resourceInfo) {
+ if (resourceInfo.getPayloadData() == null || resourceInfo.getPayloadData().isEmpty()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_RESOURCE_PAYLOAD);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ } else {
+ String toscaPayload = resourceInfo.getPayloadData();
+ String decodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload;
+ yamlStringWrapper.setInnerElement(decodedPayload);
+ }
+
+ }
+
+ protected void fillPayload(Wrapper<Response> responseWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, Wrapper<String> yamlStringWrapper, User user, String resourceInfoJsonString, ResourceAuthorityTypeEnum resourceAuthorityEnum,
+ File file) throws FileNotFoundException {
+
+ if (responseWrapper.isEmpty()) {
+ if (resourceAuthorityEnum.isBackEndImport()) {
+ // PrePayload Validations
+ if (responseWrapper.isEmpty()) {
+ validateDataNotNull(responseWrapper, file, resourceInfoJsonString);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateZip(responseWrapper, file, uploadResourceInfoWrapper.getInnerElement().getPayloadName());
+ }
+
+ // Fill PayLoad From File
+ if (responseWrapper.isEmpty()) {
+ fillToscaTemplateFromZip(yamlStringWrapper, uploadResourceInfoWrapper.getInnerElement().getPayloadName(), file);
+ }
+
+ } else {
+ // Fill PayLoad From JSON
+ if (responseWrapper.isEmpty()) {
+ fillToscaTemplateFromJson(responseWrapper, yamlStringWrapper, user, uploadResourceInfoWrapper.getInnerElement());
+ }
+ }
+
+ }
+
+ }
+
+ protected void specificResourceAuthorityValidations(Wrapper<Response> responseWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, Wrapper<String> yamlStringWrapper, User user, HttpServletRequest request, String resourceInfoJsonString,
+ ResourceAuthorityTypeEnum resourceAuthorityEnum) throws FileNotFoundException {
+
+ if (responseWrapper.isEmpty()) {
+ // UI Only Validation
+ if (!resourceAuthorityEnum.isBackEndImport()) {
+ importUIValidations(responseWrapper, uploadResourceInfoWrapper.getInnerElement(), user, request, resourceInfoJsonString);
+ }
+
+ // User Defined Type Resources
+ if (resourceAuthorityEnum.isUserTypeResource() && !CsarValidationUtils.isCsarPayloadName(uploadResourceInfoWrapper.getInnerElement().getPayloadName())) {
+ if (responseWrapper.isEmpty()) {
+ validatePayloadNameSpace(responseWrapper, uploadResourceInfoWrapper.getInnerElement(), user, yamlStringWrapper.getInnerElement());
+ }
+
+ }
+ }
+ }
+
+ protected void commonGeneralValidations(Wrapper<Response> responseWrapper, Wrapper<User> userWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, ResourceAuthorityTypeEnum resourceAuthorityEnum, String userId,
+ String resourceInfoJsonString) {
+
+ if (responseWrapper.isEmpty()) {
+ validateUserExist(responseWrapper, userWrapper, userId);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ validateUserRole(responseWrapper, userWrapper.getInnerElement(), resourceAuthorityEnum);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ validateAndFillResourceJson(responseWrapper, uploadResourceInfoWrapper, userWrapper.getInnerElement(), resourceAuthorityEnum, resourceInfoJsonString);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ validateToscaTemplatePayloadName(responseWrapper, uploadResourceInfoWrapper.getInnerElement(), userWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validateResourceType(responseWrapper, uploadResourceInfoWrapper.getInnerElement(), userWrapper.getInnerElement());
+ }
+
+ }
+
+ private void validateResourceType(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user) {
+ String resourceType = uploadResourceInfo.getResourceType();
+ if (resourceType == null || !ResourceTypeEnum.contains(resourceType)) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ Response errorResponse = buildErrorResponse(responseFormat);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ }
+
+ protected void importUIValidations(Wrapper<Response> responseWrapper, UploadResourceInfo resourceInfo, User user, HttpServletRequest request, String resourceInfoJsonString) {
+ if (responseWrapper.isEmpty()) {
+ validateMD5(responseWrapper, user, resourceInfo, request, resourceInfoJsonString);
+ }
+ if (responseWrapper.isEmpty() && request != null && request.getMethod() != null && request.getMethod().equals("POST")) {
+ validateResourceDoesNotExist(responseWrapper, user, resourceInfo.getName());
+ }
+ }
+
+ protected void commonPayloadValidations(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo uploadResourceInfo) {
+
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsYml(responseWrapper, user, uploadResourceInfo, yamlStringWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsTosca(responseWrapper, uploadResourceInfo, user, yamlStringWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsNotService(responseWrapper, user, uploadResourceInfo, yamlStringWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsSingleResource(responseWrapper, uploadResourceInfo, user, yamlStringWrapper.getInnerElement());
+ }
+ }
+
+ protected void topologyTemplatePayloadValidations(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo uploadResourceInfo) {
+
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsYml(responseWrapper, user, uploadResourceInfo, yamlStringWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsTosca(responseWrapper, uploadResourceInfo, user, yamlStringWrapper.getInnerElement());
+ }
+ if (responseWrapper.isEmpty()) {
+ validatePayloadIsTopologyTemplate(responseWrapper, user, uploadResourceInfo, yamlStringWrapper.getInnerElement());
+ }
+
+ }
+
+ protected void handleImport(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfoObject, String yamlAsString, ResourceAuthorityTypeEnum authority, boolean createNewVersion, String resourceUniqueId) {
+ Either<ImmutablePair<org.openecomp.sdc.be.model.Resource, ActionStatus>, ResponseFormat> createOrUpdateResponse = null;
+ Response response = null;
+ Object representation = null;
+
+ if (CsarValidationUtils.isCsarPayloadName(resourceInfoObject.getPayloadName())) {
+ log.debug("import resource from csar");
+ createOrUpdateResponse = importResourceFromUICsar(resourceInfoObject, user, resourceUniqueId);
+ } else if (!authority.isUserTypeResource()) {
+ log.debug("import normative type resource");
+ createOrUpdateResponse = resourceImportManager.importNormativeResource(yamlAsString, resourceInfoObject, user, createNewVersion, true);
+ } else {
+ log.debug("import user resource (not normative type)");
+ createOrUpdateResponse = resourceImportManager.importUserDefinedResource(yamlAsString, resourceInfoObject, user, false, false);
+ }
+ if (createOrUpdateResponse.isRight()) {
+ response = buildErrorResponse(createOrUpdateResponse.right().value());
+ } else {
+ try {
+ representation = RepresentationUtils.toRepresentation(createOrUpdateResponse.left().value().getLeft());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ ActionStatus successStatus = createOrUpdateResponse.left().value().right;
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(successStatus), representation);
+ }
+ responseWrapper.setInnerElement(response);
+ }
+
+ private Either<ImmutablePair<org.openecomp.sdc.be.model.Resource, ActionStatus>, ResponseFormat> importResourceFromUICsar(UploadResourceInfo resourceInfoObject, User user, String resourceUniqueId) {
+
+ Either<org.openecomp.sdc.be.model.Resource, ResponseFormat> createOrUpdateResourceRes = null;
+ ImmutablePair<org.openecomp.sdc.be.model.Resource, ActionStatus> result = null;
+ ActionStatus actionStatus = null;
+ org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource();
+ String payloadName = resourceInfoObject.getPayloadName();
+ fillResourceFromResourceInfoObject(resource, resourceInfoObject);
+
+ Either<Map<String, byte[]>, ResponseFormat> csarUIPayloadRes = getScarFromPayload(resourceInfoObject);
+ if (csarUIPayloadRes.isRight()) {
+ return Either.right(csarUIPayloadRes.right().value());
+ }
+ Map<String, byte[]> csarUIPayload = csarUIPayloadRes.left().value();
+
+ createOrUpdateResourceRes = getAndValidateCsarYaml(csarUIPayload, resource, user, payloadName);
+ if (createOrUpdateResourceRes.isRight()) {
+ return Either.right(createOrUpdateResourceRes.right().value());
+ }
+ if (resourceUniqueId == null || resourceUniqueId.isEmpty()) {
+ createOrUpdateResourceRes = resourceImportManager.getResourceBusinessLogic().createResource(resource, user, csarUIPayload, payloadName);
+ if (createOrUpdateResourceRes.isRight()) {
+ return Either.right(createOrUpdateResourceRes.right().value());
+ }
+ actionStatus = ActionStatus.CREATED;
+ } else {
+ createOrUpdateResourceRes = resourceImportManager.getResourceBusinessLogic().validateAndUpdateResourceFromCsar(resource, user, csarUIPayload, payloadName, resourceUniqueId);
+ if (createOrUpdateResourceRes.isRight()) {
+ return Either.right(createOrUpdateResourceRes.right().value());
+ }
+ actionStatus = ActionStatus.OK;
+ }
+ result = new ImmutablePair<org.openecomp.sdc.be.model.Resource, ActionStatus>(createOrUpdateResourceRes.left().value(), actionStatus);
+ return Either.left(result);
+ }
+
+ private Either<org.openecomp.sdc.be.model.Resource, ResponseFormat> getAndValidateCsarYaml(Map<String, byte[]> csarUIPayload, org.openecomp.sdc.be.model.Resource resource, User user, String csarUUID) {
+
+ Either<ImmutablePair<String, String>, ResponseFormat> getToscaYamlRes = CsarValidationUtils.getToscaYaml(csarUIPayload, csarUUID, getComponentsUtils());
+
+ if (getToscaYamlRes.isRight()) {
+ ResponseFormat responseFormat = getToscaYamlRes.right().value();
+ log.debug("Error when try to get csar toscayamlFile with csar ID {}, error: {}", csarUUID, responseFormat);
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Creating resource from CSAR: fetching CSAR with id " + csarUUID + " failed");
+ getComponentsUtils().auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.CREATE_RESOURCE, null);
+ return Either.right(responseFormat);
+ }
+ String toscaYaml = getToscaYamlRes.left().value().getValue();
+
+ log.debug("checking tosca template is valid yml");
+ YamlToObjectConverter yamlConvertor = new YamlToObjectConverter();
+ boolean isValid = yamlConvertor.isValidYaml(toscaYaml.getBytes());
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_YAML_FILE);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resource.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ return Either.right(responseFormat);
+ }
+
+ log.debug("checking payload is valid tosca");
+ String heatDecodedPayload = (GeneralUtility.isBase64Encoded(toscaYaml)) ? new String(Base64.decodeBase64(toscaYaml)) : toscaYaml;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
+ Either<String, ResultStatusEnum> findFirstToscaStringElement = ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION);
+
+ if (findFirstToscaStringElement.isRight()) {
+ isValid = false;
+ } else {
+ String defenitionVersionFound = findFirstToscaStringElement.left().value();
+ if (defenitionVersionFound == null || defenitionVersionFound.isEmpty()) {
+ isValid = false;
+ } else {
+ isValid = ImportUtils.Constants.TOSCA_DEFINITION_VERSIONS.contains(defenitionVersionFound);
+ }
+ }
+
+ if (!isValid) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
+ additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resource.getName());
+ getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam);
+ return Either.right(responseFormat);
+ }
+ return Either.left(resource);
+ }
+
+ private void fillResourceFromResourceInfoObject(org.openecomp.sdc.be.model.Resource resource, UploadResourceInfo resourceInfoObject) {
+ if (resource != null && resourceInfoObject != null) {
+ resource.setDescription(resourceInfoObject.getDescription());
+ resource.setTags(resourceInfoObject.getTags());
+ resource.setCategories(resourceInfoObject.getCategories());
+ resource.setContactId(resourceInfoObject.getContactId());
+ resource.setName(resourceInfoObject.getName());
+ resource.setIcon(resourceInfoObject.getResourceIconPath());
+ resource.setVendorName(resourceInfoObject.getVendorName());
+ resource.setVendorRelease(resourceInfoObject.getVendorRelease());
+ resource.setResourceType(ResourceTypeEnum.valueOf(resourceInfoObject.getResourceType()));
+ List<UploadArtifactInfo> artifactList = resourceInfoObject.getArtifactList();
+ if (artifactList != null) {
+ Map<String, ArtifactDefinition> artifactsHM = new HashMap<String, ArtifactDefinition>();
+ for (UploadArtifactInfo artifact : artifactList) {
+ ArtifactDefinition artifactDef = new ArtifactDefinition();
+ artifactDef.setArtifactName(artifact.getArtifactName());
+ artifactDef.setArtifactType(artifact.getArtifactType().getType());
+ artifactDef.setDescription(artifact.getArtifactDescription());
+ artifactDef.setPayloadData(artifact.getArtifactData());
+ artifactDef.setArtifactRef(artifact.getArtifactPath());
+ artifactsHM.put(artifactDef.getArtifactName(), artifactDef);
+ }
+ resource.setArtifacts(artifactsHM);
+ }
+ }
+
+ }
+
+ private Either<Map<String, byte[]>, ResponseFormat> getScarFromPayload(UploadResourceInfo innerElement) {
+ String csarUUID = innerElement.getPayloadName();
+ String payloadData = innerElement.getPayloadData();
+ if (payloadData == null) {
+ log.info("Failed to decode received csar", csarUUID);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_NOT_FOUND, csarUUID));
+ }
+
+ byte[] decodedPayload = (GeneralUtility.isBase64Encoded(payloadData)) ? Base64.decodeBase64(payloadData.getBytes(StandardCharsets.UTF_8)) : payloadData.getBytes(StandardCharsets.UTF_8);
+ if (decodedPayload == null) {
+ log.info("Failed to decode received csar", csarUUID);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_NOT_FOUND, csarUUID));
+ }
+
+ Map<String, byte[]> csar = ZipUtil.readZip(decodedPayload);
+ if (csar == null) {
+ log.info("Failed to unzip received csar", csarUUID);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID, csarUUID));
+ }
+ return Either.left(csar);
+ }
+
+ protected void validateInputStream(final HttpServletRequest request, Wrapper<String> dataWrapper, Wrapper<ResponseFormat> errorWrapper) throws IOException {
+ InputStream inputStream = request.getInputStream();
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+ if (bytes == null || bytes.length == 0) {
+ log.info("Empty body was sent.");
+ errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ } else {
+ dataWrapper.setInnerElement(new String(bytes, StandardCharsets.UTF_8));
+ }
+
+ }
+
+ protected <T> void validateClassParse(String data, Wrapper<T> parsedClassWrapper, Supplier<Class<T>> classGen, Wrapper<ResponseFormat> errorWrapper) {
+ try {
+ T parsedClass = gson.fromJson(data, classGen.get());
+ if (parsedClass == null) {
+ errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ } else {
+ parsedClassWrapper.setInnerElement(parsedClass);
+ }
+ } catch (JsonSyntaxException e) {
+ log.debug("Failed to decode received {} {} to object.", classGen.get().getName(), data, e);
+ errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ }
+
+ protected void validateComponentInstanceBusinessLogic(HttpServletRequest request, String containerComponentType, Wrapper<ComponentInstanceBusinessLogic> blWrapper, Wrapper<ResponseFormat> errorWrapper) {
+ ServletContext context = request.getSession().getServletContext();
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ } else {
+ blWrapper.setInnerElement(componentInstanceLogic);
+ }
+ }
+
+ protected <T> Response buildResponseFromElement(Wrapper<ResponseFormat> errorWrapper, Wrapper<T> attributeWrapper) throws IOException {
+ Response response;
+ if (errorWrapper.isEmpty()) {
+ ObjectMapper mapper = new ObjectMapper();
+ String result = mapper.writeValueAsString(attributeWrapper.getInnerElement());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } else {
+ response = buildErrorResponse(errorWrapper.getInnerElement());
+ }
+ return response;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java
new file mode 100644
index 0000000000..aaf8f96dca
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java
@@ -0,0 +1,472 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.AdditionalInfoParameterInfo;
+import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Additional Information Servlet", description = "Additional Information Servlet")
+@Singleton
+public class AdditionalInformationServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(AdditionalInformationServlet.class.getName());
+
+ @POST
+ @Path("/resources/{resourceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Additional Information Label and Value", httpMethod = "POST", notes = "Returns created Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Additional information created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response createResourceAdditionalInformationLabel(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "Additional information key value to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return createAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userId, data);
+
+ }
+
+ @POST
+ @Path("/services/{serviceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Additional Information Label and Value", httpMethod = "POST", notes = "Returns created Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Additional information created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response createServiceAdditionalInformationLabel(@ApiParam(value = "service id to update with new property", required = true) @PathParam("serviceId") final String serviceId,
+ @ApiParam(value = "Additional information key value to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return createAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, request, userId, data);
+
+ }
+
+ @PUT
+ @Path("/resources/{resourceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Additional Information Label and Value", httpMethod = "PUT", notes = "Returns updated Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Additional information updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response updateResourceAdditionalInformationLabel(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @ApiParam(value = "Additional information key value to be created", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return updateAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId, data);
+
+ }
+
+ @PUT
+ @Path("/services/{serviceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Additional Information Label and Value", httpMethod = "PUT", notes = "Returns updated Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Additional information updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response updateServiceAdditionalInformationLabel(@ApiParam(value = "service id to update with new property", required = true) @PathParam("serviceId") final String serviceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @ApiParam(value = "Additional information key value to be created", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return updateAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId, data);
+
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Additional Information Label and Value", httpMethod = "DELETE", notes = "Returns deleted Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Additional information deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response updateResourceAdditionalInformationLabel(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return deleteAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId);
+
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Additional Information Label and Value", httpMethod = "DELETE", notes = "Returns deleted Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Additional information deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response deleteServiceAdditionalInformationLabel(@ApiParam(value = "service id to update with new property", required = true) @PathParam("serviceId") final String serviceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return deleteAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId);
+
+ }
+
+ @GET
+ @Path("/resources/{resourceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Additional Information by id", httpMethod = "GET", notes = "Returns Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "fetched additional information"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response getResourceAdditionalInformationLabel(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, labelId, request, userId);
+
+ }
+
+ @GET
+ @Path("/services/{serviceId}/additionalinfo/{labelId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Additional Information by id", httpMethod = "GET", notes = "Returns Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "fetched additional information"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response getServiceAdditionalInformationLabel(@ApiParam(value = "service id to update with new property", required = true) @PathParam("serviceId") final String serviceId,
+ @ApiParam(value = "label id", required = true) @PathParam("labelId") final String labelId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId);
+
+ }
+
+ @GET
+ @Path("/resources/{resourceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get all Additional Information under resource", httpMethod = "GET", notes = "Returns Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "list of additional information"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response getAllResourceAdditionalInformationLabel(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userId);
+
+ }
+
+ @GET
+ @Path("/services/{serviceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get all Additional Information under service", httpMethod = "GET", notes = "Returns Additional Inforamtion property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "list of additional information"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Additional information key already exist") })
+ public Response getAllServiceAdditionalInformationLabel(@ApiParam(value = "service id to update with new property", required = true) @PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, request, userId);
+
+ }
+
+ /**
+ *
+ * Create additional information property under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param request
+ * @param userId
+ * @param data
+ * @return
+ */
+ protected Response createAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId, String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+ log.debug("data is {}", data);
+
+ try {
+ // convert json to AdditionalInfoParameterInfo
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
+
+ // create the new property
+ AdditionalInformationBusinessLogic businessLogic = getBL(context);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.createAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, null, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to create additional information {}. REason - {}", additionalInfoParameterInfo, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} created successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Additional Information");
+ log.debug("Create additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Update additional information property by id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @param data
+ * @return
+ */
+ protected Response updateAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId, String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+ log.debug("data is {}", data);
+
+ try {
+ // convert json to AdditionalInfoParameterInfo
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
+
+ // create the new property
+ AdditionalInformationBusinessLogic businessLogic = getBL(context);
+
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.updateAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, null, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to update additional information property. Reason - {}", responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} updated successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Additional Information");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Additional Information");
+ log.debug("Update additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ *
+ * Delete an additional information property by id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response deleteAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ AdditionalInformationBusinessLogic businessLogic = getBL(context);
+
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.deleteAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, null, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to update additional information property. Reason - {}", responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} deleted successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Additional Information");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Additional Information");
+ log.debug("Delete additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Get a specific additional information property by a given id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response getAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ // create the new property
+ AdditionalInformationBusinessLogic businessLogic = getBL(context);
+
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.getAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, null, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to update additional information property. Reason - {}", responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} fetched successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Additional Information");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Additional Information");
+
+ log.debug("get additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Get all additional information properties under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response getAllAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ AdditionalInformationBusinessLogic businessLogic = getBL(context);
+
+ Either<AdditionalInformationDefinition, ResponseFormat> either = businessLogic.getAllAdditionalInformation(nodeType, uniqueId, null, userId);
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to update additional information property. Reason - {}", responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInformationDefinition additionalInformationDefinition = either.left().value();
+
+ log.debug("All Additional information retrieved for component {} is {}", uniqueId, additionalInformationDefinition);
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, additionalInformationDefinition);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get All Additional Information");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Additional Information");
+ log.debug("Get all addiotanl information properties failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ private AdditionalInformationBusinessLogic getBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ AdditionalInformationBusinessLogic bl = webApplicationContext.getBean(AdditionalInformationBusinessLogic.class);
+ return bl;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
new file mode 100644
index 0000000000..b7af00a7d2
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
@@ -0,0 +1,564 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperation;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resource Artifact Servlet", description = "Resource Artifact Servlet")
+@Singleton
+public class ArtifactServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ArtifactServlet.class.getName());
+
+ private Gson gson = new Gson();
+
+ // *************** Resources
+ @POST
+ @Path("/resources/{resourceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Artifact", httpMethod = "POST", notes = "Returns created ArtifactDefinition", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Artifact already exist") })
+ public Response loadArtifact(@PathParam("resourceId") final String resourceId, @ApiParam(value = "json describe the artifact", required = true) String data, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "loadArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifact");
+ log.debug("loadArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Artifact", httpMethod = "POST", notes = "Returns updated artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateArtifact(@PathParam("resourceId") final String resourceId, @PathParam("artifactId") final String artifactId, @ApiParam(value = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleUpdateRequest(data, request, resourceId, artifactId, ComponentTypeEnum.RESOURCE);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "updateArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifact");
+ log.debug("updateArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete Artifact", httpMethod = "DELETE", notes = "Returns delete artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response deleteArtifact(@PathParam("resourceId") final String resourceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, null, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "deleteArtifact");
+ log.debug("deleteArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // *************** Services
+ @POST
+ @Path("/services/{serviceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Artifact", httpMethod = "POST", notes = "Returns created ArtifactDefinition", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Artifact already exist") })
+ public Response loadInformationArtifact(@PathParam("serviceId") final String serviceId, @ApiParam(value = "json describe the artifact", required = true) String data, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleUploadRequest(data, request, serviceId, ComponentTypeEnum.SERVICE);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "loadInformationArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadInformationArtifact");
+ log.debug("loadInformationArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Artifact", httpMethod = "POST", notes = "Returns updated artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Service artifact created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateInformationArtifact(@PathParam("serviceId") final String serviceId, @PathParam("artifactId") final String artifactId, @ApiParam(value = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "updateInformationArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateInformationArtifact");
+ log.debug("updateInformationArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // *************** Services api artifacts
+ @POST
+ @Path("/services/{serviceId}/artifacts/api/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Api Artifact", httpMethod = "POST", notes = "Returns created ArtifactDefinition", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Api Artifact Updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateApiArtifact(@PathParam("serviceId") final String serviceId, @PathParam("artifactId") final String artifactId, @ApiParam(value = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "updateApiArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateApiArtifact");
+ log.debug("updateApiArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}/artifacts/api/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete Api Artifact", httpMethod = "DELETE", notes = "Returns Deleted ArtifactDefinition", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "Api Artifact deleted"), @ApiResponse(code = 403, message = "Restricted operation") })
+ public Response deleteApiArtifact(@PathParam("serviceId") final String serviceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "deleteApiArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteApiArtifact");
+ log.debug("deleteApiArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete Artifact", httpMethod = "DELETE", notes = "Returns delete artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Service artifact deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response deleteInformationalArtifact(@PathParam("serviceId") final String serviceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "deleteInformationalArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteInformationalArtifact");
+ log.debug("deleteInformationalArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /*
+ * DOWNLOAD Artifacts by json body in base 64 (because of userId problem with href)
+ */
+
+ @GET
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Download service Artifact in Base64", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service artifact downloaded"), @ApiResponse(code = 404, message = "Service/Artifact not found") })
+ public Response downloadServiceArtifactBase64(@PathParam("serviceId") final String serviceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDownloadRequest(request, serviceId, artifactId, null, ComponentTypeEnum.SERVICE, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "downloadServiceArtifactBase64");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadServiceArtifactBase64");
+ log.debug("downloadServiceArtifactBase64 unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Download resource Artifact in Base64", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource artifact downloaded"), @ApiResponse(code = 404, message = "Resource/Artifact not found") })
+ public Response downloadResourceArtifactBase64(@PathParam("resourceId") final String resourceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDownloadRequest(request, resourceId, artifactId, null, ComponentTypeEnum.RESOURCE, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "downloadResourceArtifactBase64");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
+ log.debug("downloadResourceArtifactBase64 unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Download component Artifact in Base64", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "ResourceInstance artifact downloaded"), @ApiResponse(code = 404, message = "ResourceInstance/Artifact not found") })
+ public Response downloadResourceInstanceArtifactBase64(
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDownloadRequest(request, componentInstanceId, artifactId, componentId, ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentType);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "downloadResourceInstanceArtifactBase64");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceInstanceArtifactBase64");
+ log.debug("downloadResourceInstanceArtifactBase64 unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // *************** Resource lifecycle ( interfces )
+
+ @POST
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Artifact and Attach to interface", httpMethod = "POST", notes = "Returns created resource", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Artifact already exist") })
+ public Response loadArtifactToInterface(@PathParam("resourceId") final String resourceId, @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @ApiParam(value = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleArtifactRequest(data, request, resourceId, interfaceType, operation, null, ComponentTypeEnum.RESOURCE, ArtifactOperation.Create, null, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "loadArtifactToInterface");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifactToInterface");
+ log.debug("loadArtifactToInterface unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "delete Artifact from interface", httpMethod = "delete", notes = "delete matching artifact from interface", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "delete artifact under interface deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Artifact already exist") })
+ public Response deleteArtifactToInterface(@PathParam("resourceId") final String resourceId, @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation, @PathParam("artifactId") final String artifactId,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, interfaceType, operation);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "deleteArtifactToInterface");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteArtifactToInterface");
+ log.debug("deleteArtifactToInterface unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "update Artifact Attach to interface", httpMethod = "post", notes = "updates artifact by interface", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "delete artifact under interface deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Artifact already exist") })
+ public Response updateArtifactToInterface(@PathParam("resourceId") final String resourceId, @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation, @PathParam("artifactId") final String artifactId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @Context final HttpServletRequest request,
+ @ApiParam(value = "json describe the artifact", required = true) String data) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleArtifactRequest(data, request, resourceId, interfaceType, operation, artifactId, ComponentTypeEnum.RESOURCE, ArtifactOperation.Update, null, null);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "updateArtifactToInterface");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifactToInterface");
+ log.debug("updateArtifactToInterface unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}/heatParams")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Instance HEAT_ENV parameters", httpMethod = "POST", notes = "Returns updated artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateRIArtifact(
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("artifactId") final String artifactId,
+ @ApiParam(value = "json describe the artifact", required = true) String data, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperation.Update, componentId, containerComponentType);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "updateRIArtifact");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateRIArtifact");
+ log.debug("updateRIArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Instance artifact payload", httpMethod = "POST", notes = "Returns updated artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("artifactId") final String artifactId,
+ @ApiParam(value = "json describe the artifact", required = true) String data, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperation.Update, componentId, containerComponentType);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "loadResourceInstanceHeatEnvArtifact");
+ log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Load Resource Instance artifact payload", httpMethod = "POST", notes = "Returns updated artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response loadComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ return handleArtifactRequest(data, request, componentInstanceId, null, null, null, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperation.Create, componentId, containerComponentType);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "loadResourceInstanceHeatEnvArtifact");
+ log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete Resource Instance artifact", httpMethod = "POST", notes = "Returns deleted artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response deleteComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("artifactId") final String artifactId,
+ @ApiParam(value = "json describe the artifact", required = true) String data, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
+ return handleDeleteRequest(request, componentInstanceId, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, null, null, componentId);
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "deleteArtifact");
+ log.debug("deleteArtifact unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // ////////// API END ///////////////////////////
+
+ // ************ private *********************
+
+ private Response handleUploadRequest(String data, HttpServletRequest request, String componentId, ComponentTypeEnum componentType) {
+ return handleArtifactRequest(data, request, componentId, null, componentType, ArtifactOperation.Create);
+ }
+
+ private Response handleUpdateRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType) {
+ return handleArtifactRequest(data, request, componentId, artifactId, componentType, ArtifactOperation.Update);
+ }
+
+ private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) {
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> actionResult = artifactsLogic.handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType);
+
+ Response response;
+ if (actionResult.isRight()) {
+ response = buildErrorResponse(actionResult.right().value());
+ } else {
+ byte[] file = actionResult.left().value().getRight();
+ String base64Contents = new String(Base64.encodeBase64(file));
+ String artifactName = actionResult.left().value().getLeft();
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
+ artifactUiDownloadData.setArtifactName(artifactName);
+ artifactUiDownloadData.setBase64Contents(base64Contents);
+ response = buildOkResponse(responseFormat, artifactUiDownloadData);
+ }
+ return response;
+ }
+
+ private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName) {
+ return handleDeleteRequest(request, componentId, artifactId, componentType, interfaceType, operationName, null);
+ }
+
+ private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) {
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = artifactsLogic.handleArtifactRequest(componentId, userId, componentType, ArtifactOperation.Delete, artifactId, null, null, null, interfaceType, operationName,
+ parentId, null);
+ Response response;
+ if (actionResult.isRight()) {
+ response = buildErrorResponse(actionResult.right().value());
+ } else {
+ Either<ArtifactDefinition, Operation> result = actionResult.left().value();
+ if (result.isLeft()) {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
+ }
+ }
+ return response;
+
+ }
+
+ private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String interfaceName, String operationName, String artifactId, ComponentTypeEnum componentType, ArtifactOperation operation, String parentId,
+ String containerComponentType) {
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = artifactsLogic.handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId,
+ containerComponentType);
+ Response response;
+ if (actionResult.isRight()) {
+ response = buildErrorResponse(actionResult.right().value());
+ } else {
+ Either<ArtifactDefinition, Operation> result = actionResult.left().value();
+ if (result.isLeft()) {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
+ }
+ }
+ return response;
+
+ }
+
+ private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperation operation) {
+ return handleArtifactRequest(data, servletRequest, componentId, null, null, artifactId, componentType, operation, null, null);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
new file mode 100644
index 0000000000..b5e64ae00e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
@@ -0,0 +1,278 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * Web Servlet for actions on Attributes
+ *
+ * @author mshitrit
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resource Attribute Servlet", description = "Resource Attribute Servlet")
+@Singleton
+public class AttributeServlet extends AbstractValidationsServlet {
+ private static Logger log = LoggerFactory.getLogger(AttributeServlet.class.getName());
+
+ /**
+ * Creates new Attribute on a resource with given resource ID
+ *
+ * @param resourceId
+ * @param data
+ * @param request
+ * @param userId
+ * @return
+ */
+ @POST
+ @Path("resources/{resourceId}/attributes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource Attribute", httpMethod = "POST", notes = "Returns created resource attribute", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource property created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Resource attribute already exist") })
+ public Response createAttribute(@ApiParam(value = "resource id to update with new attribute", required = true) @PathParam("resourceId") final String resourceId, @ApiParam(value = "Resource attribute to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+ log.debug("data is {}", data);
+
+ try {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<AttributeDefinition> attributesWrapper = new Wrapper<>();
+ // convert json to AttributeDefinition
+
+ buildAttributeFromString(data, attributesWrapper, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ AttributeBusinessLogic businessLogic = getBusinessLogic(context, () -> AttributeBusinessLogic.class);
+ Either<AttributeDefinition, ResponseFormat> createAttribute = businessLogic.createAttribute(resourceId, attributesWrapper.getInnerElement(), userId);
+ if (createAttribute.isRight()) {
+ errorWrapper.setInnerElement(createAttribute.right().value());
+ } else {
+ attributesWrapper.setInnerElement(createAttribute.left().value());
+ }
+ }
+
+ Response response;
+ if (!errorWrapper.isEmpty()) {
+ log.info("Failed to create Attribute. Reason - ", errorWrapper.getInnerElement());
+ response = buildErrorResponse(errorWrapper.getInnerElement());
+ } else {
+ AttributeDefinition createdAttDef = attributesWrapper.getInnerElement();
+ log.debug("Attribute {} created successfully with id {}", createdAttDef.getName(), createdAttDef.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(createdAttDef));
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Attribute");
+ log.debug("create property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ /**
+ * Updates existing Attribute with given attributeID on a resource with given resourceID
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param data
+ * @param request
+ * @param userId
+ * @return
+ */
+ @PUT
+ @Path("resources/{resourceId}/attributes/{attributeId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Attribute", httpMethod = "PUT", notes = "Returns updated attribute", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource attribute updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateAttribute(@ApiParam(value = "resource id to update with new attribute", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "attribute id to update", required = true) @PathParam("attributeId") final String attributeId, @ApiParam(value = "Resource attribute to update", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ try {
+ // convert json to PropertyDefinition
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<AttributeDefinition> attributesWrapper = new Wrapper<>();
+ // convert json to AttributeDefinition
+
+ buildAttributeFromString(data, attributesWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ AttributeBusinessLogic businessLogic = getBusinessLogic(context, () -> AttributeBusinessLogic.class);
+ Either<AttributeDefinition, ResponseFormat> eitherUpdateAttribute = businessLogic.updateAttribute(resourceId, attributeId, attributesWrapper.getInnerElement(), userId);
+ // update property
+ if (eitherUpdateAttribute.isRight()) {
+ errorWrapper.setInnerElement(eitherUpdateAttribute.right().value());
+ } else {
+ attributesWrapper.setInnerElement(eitherUpdateAttribute.left().value());
+ }
+ }
+
+ Response response;
+ if (!errorWrapper.isEmpty()) {
+ log.info("Failed to update Attribute. Reason - ", errorWrapper.getInnerElement());
+ response = buildErrorResponse(errorWrapper.getInnerElement());
+ } else {
+ AttributeDefinition updatedAttribute = attributesWrapper.getInnerElement();
+ log.debug("Attribute id {} updated successfully ", updatedAttribute.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(updatedAttribute));
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Attribute");
+ log.debug("update attribute failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ /**
+ * Deletes existing Attribute with given attributeID on a resource with given resourceID
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param request
+ * @param userId
+ * @return
+ */
+ @DELETE
+ @Path("resources/{resourceId}/attributes/{attributeId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource Attribute", httpMethod = "DELETE", notes = "Returns deleted attribute", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "deleted attribute"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "Resource property not found") })
+ public Response deleteAttribute(@ApiParam(value = "resource id of attribute", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "Attribute id to delete", required = true) @PathParam("attributeId") final String attributeId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ // delete the property
+ AttributeBusinessLogic businessLogic = getBusinessLogic(context, () -> AttributeBusinessLogic.class);
+ Either<AttributeDefinition, ResponseFormat> eitherAttribute = businessLogic.deleteAttribute(resourceId, attributeId, userId);
+ if (eitherAttribute.isRight()) {
+ log.debug("Failed to delete Attribute. Reason - ", eitherAttribute.right().value());
+ return buildErrorResponse(eitherAttribute.right().value());
+ }
+ AttributeDefinition attributeDefinition = eitherAttribute.left().value();
+ String name = attributeDefinition.getName();
+
+ log.debug("Attribute {} deleted successfully with id {}", name, attributeDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(attributeDefinition));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Attribute");
+ log.debug("delete attribute failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ private void buildAttributeFromString(String data, Wrapper<AttributeDefinition> attributesWrapper, Wrapper<ResponseFormat> errorWrapper) {
+
+ try {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ final AttributeDefinition attribute = gson.fromJson(data, AttributeDefinition.class);
+ if (attribute == null) {
+ log.info("Attribute content is invalid - {}", data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ errorWrapper.setInnerElement(responseFormat);
+ } else {
+ attributesWrapper.setInnerElement(attribute);
+ }
+
+ } catch (Exception e) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug("Attribute content is invalid - {}", data, e);
+ log.info("Attribute content is invalid - {}", data);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
new file mode 100644
index 0000000000..f21b57f6fb
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
@@ -0,0 +1,226 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Supplier;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.openecomp.sdc.be.components.clean.ComponentsCleanBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.VFComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.IElementDAO;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.servlets.BasicServlet;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+public class BeGenericServlet extends BasicServlet {
+
+ @Context
+ protected HttpServletRequest servletRequest;
+
+ private static Logger log = LoggerFactory.getLogger(BeGenericServlet.class.getName());
+
+ /******************** New error response mechanism **************/
+
+ protected Response buildErrorResponse(ResponseFormat requestErrorWrapper) {
+ Response response = Response.status(requestErrorWrapper.getStatus()).entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
+ return response;
+ }
+
+ protected Response buildOkResponse(ResponseFormat errorResponseWrapper, Object entity) {
+ return buildOkResponse(errorResponseWrapper, entity, null);
+ }
+
+ protected Response buildOkResponse(ResponseFormat errorResponseWrapper, Object entity, Map<String, String> additionalHeaders) {
+ int status = errorResponseWrapper.getStatus();
+ ResponseBuilder responseBuilder = Response.status(status);
+ if (entity != null) {
+ if (log.isTraceEnabled())
+ log.trace("returned entity is {}", entity.toString());
+ responseBuilder = responseBuilder.entity(entity);
+ }
+ if (additionalHeaders != null) {
+ for (Entry<String, String> additionalHeader : additionalHeaders.entrySet()) {
+ String headerName = additionalHeader.getKey();
+ String headerValue = additionalHeader.getValue();
+ if (log.isTraceEnabled())
+ log.trace("Adding header {} with value {} to the response", headerName, headerValue);
+ responseBuilder.header(headerName, headerValue);
+ }
+ }
+ return responseBuilder.build();
+ }
+
+ /*******************************************************************************************************/
+
+ protected UserBusinessLogic getUserAdminManager(ServletContext context) {
+ return getBusinessLogic(context, () -> UserBusinessLogic.class);
+ }
+
+ protected ResourceBusinessLogic getResourceBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ResourceBusinessLogic.class);
+ }
+
+ protected ComponentsCleanBusinessLogic getComponentCleanerBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ComponentsCleanBusinessLogic.class);
+ }
+
+ protected ServiceBusinessLogic getServiceBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ServiceBusinessLogic.class);
+ }
+
+ protected ProductBusinessLogic getProductBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ProductBusinessLogic.class);
+ }
+
+ protected ArtifactsBusinessLogic getArtifactBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ArtifactsBusinessLogic.class);
+ }
+
+ protected ElementBusinessLogic getElementBL(ServletContext context) {
+ return getBusinessLogic(context, () -> ElementBusinessLogic.class);
+ }
+
+ protected MonitoringBusinessLogic getMonitoringBL(ServletContext context) {
+ return getBusinessLogic(context, () -> MonitoringBusinessLogic.class);
+ }
+
+ protected <SomeBusinessLogic> SomeBusinessLogic getBusinessLogic(ServletContext context, Supplier<Class<SomeBusinessLogic>> businessLogicClassGen) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ SomeBusinessLogic monitoringBusinessLogic = webApplicationContext.getBean(businessLogicClassGen.get());
+ return monitoringBusinessLogic;
+ }
+
+ protected GroupBusinessLogic getGroupBL(ServletContext context) {
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ GroupBusinessLogic groupBusinessLogic = webApplicationContext.getBean(GroupBusinessLogic.class);
+ return groupBusinessLogic;
+ }
+
+ protected ComponentInstanceBusinessLogic getComponentInstanceBL(ServletContext context, ComponentTypeEnum containerComponentType) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ if (containerComponentType == ComponentTypeEnum.RESOURCE) {
+ return webApplicationContext.getBean(VFComponentInstanceBusinessLogic.class);
+ }
+ if (containerComponentType == ComponentTypeEnum.SERVICE) {
+ return webApplicationContext.getBean(ServiceComponentInstanceBusinessLogic.class);
+ }
+ if (containerComponentType == ComponentTypeEnum.PRODUCT) {
+ return webApplicationContext.getBean(ProductComponentInstanceBusinessLogic.class);
+ }
+ return null;
+ }
+
+ protected IElementDAO getElementDao(Class<? extends IElementDAO> clazz, ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+
+ return webApplicationContext.getBean(clazz);
+ }
+
+ protected ComponentsUtils getComponentsUtils() {
+ ServletContext context = this.servletRequest.getSession().getServletContext();
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ComponentsUtils componentsUtils = webApplicationContext.getBean(ComponentsUtils.class);
+ return componentsUtils;
+ }
+
+ /**
+ * Used to support Unit Test.<br>
+ * Header Params are not supported in Unit Tests
+ *
+ * @return
+ */
+ protected String initHeaderParam(String headerValue, HttpServletRequest request, String headerName) {
+ String retValue;
+ if (headerValue != null) {
+ retValue = headerValue;
+ } else {
+ retValue = request.getHeader(headerName);
+ }
+ return retValue;
+ }
+
+ protected String getContentDispositionValue(String artifactFileName) {
+ return new StringBuilder().append("attachment; filename=\"").append(artifactFileName).append("\"").toString();
+ }
+
+ protected ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum, ServletContext context) {
+ ComponentBusinessLogic businessLogic;
+ switch (componentTypeEnum) {
+ case RESOURCE: {
+ businessLogic = getResourceBL(context);
+ break;
+ }
+ case SERVICE: {
+ businessLogic = getServiceBL(context);
+ break;
+ }
+ case PRODUCT: {
+ businessLogic = getProductBL(context);
+ break;
+ }
+ case RESOURCE_INSTANCE: {
+ businessLogic = getResourceBL(context);
+ break;
+ }
+ default: {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "getComponentBL");
+ BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL");
+ throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
+ }
+ }
+ return businessLogic;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java
new file mode 100644
index 0000000000..ffcd9c68fc
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java
@@ -0,0 +1,203 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.List;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
+import org.openecomp.sdc.be.components.impl.HealthCheckBusinessLogic;
+import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckWrapper;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.monitoring.MonitoringEvent;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.TRACE, trim = false)
+@Path("/")
+@Api(value = "BE Monitoring", description = "BE Monitoring")
+@Singleton
+public class BeMonitoringServlet extends BeGenericServlet {
+
+ Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
+
+ private static Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
+
+ @GET
+ @Path("/healthCheck")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "return aggregate BE health check of Titan, ES and BE", notes = "return BE health check", response = String.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Titan, ES and BE are all up"), @ApiResponse(code = 500, message = "One or more BE components (Titan, ES, BE) are down") })
+ public Response getHealthCheck(@Context final HttpServletRequest request) {
+ try {
+ HealthCheckBusinessLogic healthCheckBusinessLogic = getHealthCheckBL(request.getSession().getServletContext());
+ List<HealthCheckInfo> beHealthCheckInfos = healthCheckBusinessLogic.getBeHealthCheckInfosStatus();
+
+ // List<HealthCheckInfo> beHealthCheckInfos =
+ // HealthCheckBusinessLogic.getInstance().getBeHealthCheckInfos(request.getSession().getServletContext());
+ ActionStatus status = getAggregateBeStatus(beHealthCheckInfos);
+ String sdcVersion = getVersionFromContext(request);
+ if (sdcVersion == null || sdcVersion.isEmpty()) {
+ sdcVersion = "UNKNOWN";
+ }
+ String siteMode = healthCheckBusinessLogic.getSiteMode();
+ HealthCheckWrapper healthCheck = new HealthCheckWrapper(beHealthCheckInfos, sdcVersion, siteMode);
+ // The response can be either with 200 or 500 aggregate status - the
+ // body of individual statuses is returned either way
+
+ String healthCheckStr = prettyGson.toJson(healthCheck);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(status), healthCheckStr);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeHealthCheckError, "BeHealthCheck");
+ BeEcompErrorManager.getInstance().logBeHealthCheckError("BeHealthCheck");
+ log.debug("BE health check unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/monitoring")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response processMonitoringMetrics(@Context final HttpServletRequest request, String json) {
+ try {
+ MonitoringEvent monitoringEvent = convertContentToJson(json, MonitoringEvent.class);
+ if (monitoringEvent == null) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormatAdditionalProperty(ActionStatus.GENERAL_ERROR));
+ }
+ log.trace("Received monitoring metrics: {}", monitoringEvent.toString());
+ ServletContext context = request.getSession().getServletContext();
+ MonitoringBusinessLogic bl = getMonitoringBL(context);
+ Either<Boolean, ResponseFormat> result = bl.logMonitoringEvent(monitoringEvent);
+ if (result.isRight()) {
+ return buildErrorResponse(result.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
+
+ } catch (Exception e) {
+ log.debug("BE system metrics unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormatAdditionalProperty(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/version")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "return the ASDC application version", notes = "return the SDC application version", response = String.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "return SDC version"), @ApiResponse(code = 500, message = "Internal Error") })
+ public Response getSdcVersion(@Context final HttpServletRequest request) {
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ String version = getVersionFromContext(request);
+ log.debug("sdc version from manifest is: {}", version);
+ if (version == null || version.isEmpty()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.SDC_VERSION_NOT_FOUND));
+ }
+
+ HealthCheckInfo versionInfo = new HealthCheckInfo();
+ versionInfo.setVersion(version);
+
+ // The response can be either with 200 or 500 aggregate status - the
+ // body of individual statuses is returned either way
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), versionInfo);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "getSDCVersion");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");
+ log.debug("BE get SDC version unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private String getVersionFromContext(HttpServletRequest request) {
+ ServletContext servletContext = request.getSession().getServletContext();
+ String version = (String) servletContext.getAttribute(Constants.SDC_RELEASE_VERSION_ATTR);
+ return version;
+ }
+
+ private ActionStatus getAggregateBeStatus(List<HealthCheckInfo> beHealthCheckInfos) {
+ ActionStatus status = ActionStatus.OK;
+ for (HealthCheckInfo healthCheckInfo : beHealthCheckInfos) {
+ if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN) && healthCheckInfo.getHealthCheckComponent() != HealthCheckComponent.DE) {
+ status = ActionStatus.GENERAL_ERROR;
+ break;
+ }
+ }
+ return status;
+ }
+
+ protected MonitoringEvent convertContentToJson(String content, Class<MonitoringEvent> clazz) {
+
+ MonitoringEvent object = null;
+ try {
+ object = gson.fromJson(content, clazz);
+ object.setFields(null);
+ } catch (Exception e) {
+ log.debug("Failed to convert the content {} to object. {}", content.substring(0, Math.min(50, content.length())), e);
+ }
+
+ return object;
+ }
+
+ private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ HealthCheckBusinessLogic healthCheckBl = webApplicationContext.getBean(HealthCheckBusinessLogic.class);
+ return healthCheckBl;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
new file mode 100644
index 0000000000..4e6d0bcd7f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
@@ -0,0 +1,744 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.io.IOUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resource Instance Servlet", description = "Resource Instance Servlet")
+@Singleton
+public class ComponentInstanceServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ComponentInstanceServlet.class.getName());
+
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create ComponentInstance", httpMethod = "POST", notes = "Returns created ComponentInstance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Component created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Component instance already exist") })
+ public Response createComponentInstance(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("componentId") final String containerComponentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ try {
+
+ ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Component Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
+ log.debug("create component instance failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateComponentInstance(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
+ @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+
+ log.debug("Start handle request of {}", url);
+
+ InputStream inputStream = request.getInputStream();
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info("Empty body was sent.");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Resource Instance - updateResourceInstance");
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
+ log.debug("Failed to convert received data to BE format.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ ComponentInstance resourceInstance = convertResponse.left().value();
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
+ log.debug("update resource instance with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ // TODO Tal New Multiple Instance API
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance multiple component", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId,
+ @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request, @ApiParam(value = "Component Instance JSON Array", required = true) final String componentInstanceJsonArray) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ try {
+ log.debug("Start handle request of {}", url);
+
+ if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
+ log.info("Empty JSON list was sent.");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
+
+ if (convertResponse.isRight()) {
+ // Using both ECOMP error methods, show to Sofer
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
+ /*
+ * BeEcompErrorManager.getInstance().processEcompError( EcompErrorName.BeSystemError, "Resource Instance - updateResourceInstance");
+ */
+ log.debug("Failed to convert received data to BE format.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ List<ComponentInstance> componentInstanceList = convertResponse.left().value();
+
+ Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true, true);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ /*
+ * BeEcompErrorManager.getInstance().processEcompError( EcompErrorName.BeRestApiGeneralError, "Update Resource Instance" );
+ */
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
+ log.debug("update resource instance with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete ResourceInstance", httpMethod = "DELETE", notes = "Returns delete resourceInstance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "ResourceInstance deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response deleteResourceInstance(@PathParam("componentId") final String componentId, @PathParam("resourceInstanceId") final String resourceInstanceId,
+ @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ Response response = null;
+ try {
+ log.debug("Start handle request of {}", url);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
+
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ }
+ return response;
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
+ log.debug("delete resource instance with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Associate RI to RI", httpMethod = "POST", notes = "Returns created RelationshipInfo", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship created"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Relationship already exist") })
+ public Response associateRIToRI(@ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId,
+ @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> resultOp;
+ if (regInfoW.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Resource Instance - associateRIToRI");
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - associateRIToRI");
+ log.debug("Failed to convert received data to BE format.");
+ resultOp = Either.right(regInfoW.right().value());
+ } else {
+ RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
+ resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
+
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Associate Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
+ log.debug("associate resource instance to another RI with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Dissociate RI from RI", httpMethod = "PUT", notes = "Returns deleted RelationshipInfo", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship deleted"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response dissociateRIFromRI(
+ @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
+ @ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ try {
+
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
+ if (regInfoW.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Resource Instance - dissociateRIFromRI");
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - dissociateRIFromRI");
+ log.debug("Failed to convert received data to BE format.");
+ return buildErrorResponse(regInfoW.right().value());
+ }
+
+ RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
+ Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Dissociate Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
+ log.debug("dissociate resource instance from service failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create RI and associate RI to RI", httpMethod = "POST", notes = "Returns created RI and RelationshipInfo", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "RI created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Relationship already exist") })
+ public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+
+ log.debug("Start handle request of {}", url);
+
+ InputStream inputStream = request.getInputStream();
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info("Empty body was sent.");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
+ if (convertStatus.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Resource Instance - createAndAssociateRIToRI");
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
+ log.debug("Failed to convert received data to BE format.");
+ Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
+ return buildErrorResponse(formattedResponse.right().value());
+ }
+
+ CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
+ Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create and Associate Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
+ log.debug("create and associate RI failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ try {
+ Wrapper<String> dataWrapper = new Wrapper<>();
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
+
+ validateInputStream(request, dataWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
+ }
+
+ if (!errorWrapper.isEmpty()) {
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ }
+
+ ComponentInstanceProperty property = propertyWrapper.getInnerElement();
+
+ log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", property);
+
+ ServletContext context = request.getSession().getServletContext();
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertyValue(componentTypeEnum, componentId, componentInstanceId, property, userId);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ String result = mapper.writeValueAsString(resourceInstanceProperty);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ log.error("create and associate RI failed with exception: ", e.getMessage());
+ log.debug("create and associate RI failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ /**
+ * Updates ResourceInstance Attribute
+ *
+ * @param componentId
+ * @param containerComponentType
+ * @param componentInstanceId
+ * @param userId
+ * @param request
+ * @return
+ */
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance attribute", httpMethod = "POST", notes = "Returns updated resource instance attribute", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateResourceInstanceAttribute(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ try {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<String> dataWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceAttribute> attributeWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
+
+ validateInputStream(request, dataWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceAttribute.class, errorWrapper);
+ }
+
+ if (errorWrapper.isEmpty()) {
+ validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
+ }
+
+ if (errorWrapper.isEmpty()) {
+ ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
+ Either<ComponentInstanceAttribute, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
+ if (eitherAttribute.isRight()) {
+ errorWrapper.setInnerElement(eitherAttribute.right().value());
+ } else {
+ attributeWrapper.setInnerElement(eitherAttribute.left().value());
+ }
+ }
+
+ return buildResponseFromElement(errorWrapper, attributeWrapper);
+
+ } catch (Exception e) {
+ log.error("create and associate RI failed with exception: ", e.getMessage());
+ log.debug("create and associate RI failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance", httpMethod = "DELETE", notes = "Returns deleted resource instance property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response deleteResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "property id") @PathParam("propertyId") final String propertyId,
+ @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ } catch (Exception e) {
+ log.error("create and associate RI failed with exception: ", e.getMessage());
+ log.debug("create and associate RI failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ try {
+
+ log.debug("Start handle request of {}", url);
+
+ InputStream inputStream = request.getInputStream();
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info("Empty body was sent.");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
+ if (componentInstanceLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Resource Instance - updateResourceInstance");
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
+ log.debug("Failed to convert received data to BE format.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ ComponentInstance newResourceInstance = convertResponse.left().value();
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Resource Instance");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
+ log.debug("update resource instance with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
+
+ // Either<ComponentInstance, ActionStatus> convertStatus =
+ // convertJsonToObject(data, ComponentInstance.class);
+ Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+ ComponentInstance resourceInstanceInfo = convertStatus.left().value();
+
+ return Either.left(resourceInstanceInfo);
+ }
+
+ // TODO Tal New API for Multiple Items move on canvas
+ private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
+
+ Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+ private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
+
+ Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
+ if (convertStatus.isRight()) {
+ return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
+ }
+ RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
+ return Either.left(requirementCapabilityRelDef);
+ }
+
+ private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
+ try {
+ log.trace("convert json to object. json=\n{}", data);
+ T t = null;
+ t = gson.fromJson(data, clazz);
+ if (t == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ return Either.left(t);
+ } catch (Exception e) {
+ // INVALID JSON
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json", e);
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
new file mode 100644
index 0000000000..c5bebb41bf
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
@@ -0,0 +1,270 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.CapReqDef;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Component Servlet", description = "Component Servlet")
+@Singleton
+public class ComponentServlet extends BeGenericServlet {
+ private static Logger log = LoggerFactory.getLogger(ComponentServlet.class.getName());
+
+ @GET
+ @Path("/{componentType}/{componentId}/requirmentsCapabilities")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Component Requirments And Capabilities", httpMethod = "GET", notes = "Returns Requirments And Capabilities according to componentId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ Response response;
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum != null) {
+ ComponentBusinessLogic compBL = getComponentBL(componentTypeEnum, context);
+ Either<CapReqDef, ResponseFormat> eitherRequirementsAndCapabilities = compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId);
+ if (eitherRequirementsAndCapabilities.isRight()) {
+ response = buildErrorResponse(eitherRequirementsAndCapabilities.right().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), gson.toJson(eitherRequirementsAndCapabilities.left().value()));
+ }
+ } else {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return response;
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Component Requirments And Capabilities", httpMethod = "GET", notes = "Returns Requirments And Capabilities according to componentId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getLatestVersionNotAbstractCheckoutComponents(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType,
+ @QueryParam("componentUids") List<String> componentUids, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context);
+
+ log.debug("Received componentUids size is {}", (componentUids == null ? 0 : componentUids.size()));
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, componentUids, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract {}", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Certified Non Abstract" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Non Abstract" + componentType);
+ log.debug("getCertifiedNotAbstractComponents failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+
+ }
+
+ @POST
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Component Requirments And Capabilities", httpMethod = "GET", notes = "Returns Requirments And Capabilities according to componentId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getLatestVersionNotAbstractCheckoutComponentsByBody(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "Consumer Object to be created", required = true) List<String> data) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ if (log.isDebugEnabled())
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context);
+ List<String> componentUids = data;
+ if (log.isDebugEnabled())
+ log.debug("Received componentUids size is {}", (componentUids == null ? 0 : componentUids.size()));
+
+ // long start = System.currentTimeMillis();
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, componentUids, userId);
+
+ // long endBl = System.currentTimeMillis();
+
+ if (actionResponse.isRight()) {
+ if (log.isDebugEnabled())
+ log.debug("failed to get all non abstract {}", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ Response responseToReturn = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ long endResp = System.currentTimeMillis();
+
+ // log.info("********** Time calculation in ms: BL {} , Response {},
+ // Total {}", (endBl - start ), (endResp - endBl), (endResp -
+ // start));
+ return responseToReturn;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Certified Non Abstract" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Non Abstract" + componentType);
+ log.debug("getCertifiedNotAbstractComponents failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract/uidonly")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Component uid only", httpMethod = "GET", notes = "Returns componentId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "uid list", required = true) String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context);
+
+ Either<List<Map<String, String>>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsUidOnly(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId);
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract {}", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Certified Non Abstract" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Non Abstract" + componentType);
+ log.debug("getCertifiedNotAbstractComponents failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Component instances", httpMethod = "GET", notes = "Returns component instances", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getComponentInstancesFilteredByPropertiesAndInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @QueryParam("searchText") String searchText, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "uid" + "" + "list", required = true) String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = getComponentBL(componentTypeEnum, context);
+
+ Either<List<ComponentInstance>, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, componentTypeEnum, userId, searchText);
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all component instances filtered by properties and inputs {}", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Component Instances filtered by properties & inputs" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Instances filtered by properties & inputs" + componentType);
+ log.debug("getComponentInstancesFilteredByPropertiesAndInputs failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java
new file mode 100644
index 0000000000..164b1d7665
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.servlets.BasicServlet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/configmgr")
+public class ConfigMgrServlet extends BasicServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ConfigMgrServlet.class.getName());
+
+ @GET
+ @Path("/get")
+ @Produces(MediaType.APPLICATION_JSON)
+ public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
+
+ String result = null;
+
+ ServletContext context = request.getSession().getServletContext();
+
+ ConfigurationManager configurationManager = (ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
+
+ if (type == null || type.equals("configuration")) {
+
+ Configuration configuration = configurationManager.getConfiguration();
+ if (configuration == null) {
+ log.warn("Configuration of type {} was not found", Configuration.class);
+ } else {
+ log.info("The value returned from getConfig is {}", configuration);
+
+ result = gson.toJson(configuration);
+
+ }
+ }
+
+ return result;
+
+ }
+
+ @POST
+ @Path("/set1")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public String setConfig1(@Context final HttpServletRequest request, Configuration configuration) {
+
+ log.debug("{}", configuration);
+
+ return "ok";
+
+ }
+
+ @POST
+ @Path("/set2")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public void setConfig2(@Context final HttpServletRequest request, Configuration configuration) {
+
+ log.debug("{}", configuration);
+
+ }
+
+ @PUT
+ @Path("/setput1")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public String setConfig3(@Context final HttpServletRequest request, Configuration configuration) {
+
+ log.debug("{}", configuration);
+
+ return "ok";
+
+ }
+
+ @PUT
+ @Path("/setput2")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public void setConfig4(@Context final HttpServletRequest request, Configuration configuration) {
+
+ log.debug("{}", configuration);
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java
new file mode 100644
index 0000000000..2a3a87d942
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.servlets.BasicServlet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/config")
+public class ConfigServlet extends BasicServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
+
+ @GET
+ @Path("/get")
+ @Produces(MediaType.APPLICATION_JSON)
+ public String getConfig(@Context final HttpServletRequest request) {
+
+ String result = null;
+
+ ServletContext context = request.getSession().getServletContext();
+
+ ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
+ if (configurationSource != null) {
+ Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
+
+ if (configuration == null) {
+ log.warn("Configuration of type {} was not found", Configuration.class);
+ }
+ log.debug("{}", configuration);
+ if (log.isInfoEnabled()) {
+ log.debug("Info level ENABLED...");
+ }
+ log.info("The value returned from getConfig is {}", configuration);
+
+ result = gson.toJson(configuration);
+
+ } else {
+ log.warn("Source Configuration object was not initialized in the context.");
+ }
+
+ return result;
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java
new file mode 100644
index 0000000000..0603f267ab
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java
@@ -0,0 +1,227 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/consumers")
+@Api(value = "Consumer Servlet", description = "Consumer Servlet")
+@Singleton
+public class ConsumerServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ConsumerServlet.class.getName());
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Consumer credentials", httpMethod = "POST", notes = "Returns created ECOMP consumer credentials", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Consumer credentials created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response createConsumer(@ApiParam(value = "Consumer Object to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ try {
+ ConsumerBusinessLogic businessLogic = getConsumerBL(context);
+
+ Either<ConsumerDefinition, ResponseFormat> convertionResponse = convertJsonToObject(data, modifier, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS);
+
+ if (convertionResponse.isRight()) {
+ log.debug("failed to create Consumer");
+ return buildErrorResponse(convertionResponse.right().value());
+ }
+
+ ConsumerDefinition consumer = convertionResponse.left().value();
+
+ Either<ConsumerDefinition, ResponseFormat> actionResult = businessLogic.createConsumer(modifier, consumer);
+
+ if (actionResult.isRight()) {
+ log.debug("failed to create Consumer");
+ return buildErrorResponse(actionResult.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResult.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create consumer");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create consumer");
+ log.debug("create consumer failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ @GET
+ @Path("/{consumerId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Consumer", httpMethod = "GET", notes = "Returns consumer according to ConsumerID", response = ConsumerDefinition.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Consumer found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Consumer not found") })
+ public Response getConsumer(@PathParam("consumerId") final String consumerId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ConsumerBusinessLogic businessLogic = getConsumerBL(context);
+
+ Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.getConsumer(consumerId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get consumer");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Consumer");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
+ log.debug("get consumer failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/{consumerId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Deletes Consumer", httpMethod = "DELETE", notes = "Returns deleted consumer according to ConsumerID", response = ConsumerDefinition.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "Consumer deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Consumer not found") })
+ public Response deleteConsumer(@PathParam("consumerId") final String consumerId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ConsumerBusinessLogic businessLogic = getConsumerBL(context);
+
+ Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.deleteConsumer(consumerId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to delete consumer");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Consumer");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
+ log.debug("delete consumer failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ private ConsumerBusinessLogic getConsumerBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ ConsumerBusinessLogic consumerBL = webApplicationContext.getBean(ConsumerBusinessLogic.class);
+
+ return consumerBL;
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> convertJsonToObject(String data, User user, AuditingActionEnum actionEnum) {
+ ConsumerDefinition consumer = null;
+ Gson gson = new Gson();
+ try {
+ log.trace("convert json to object. json=\n{}", data);
+ consumer = gson.fromJson(data, ConsumerDefinition.class);
+ if (consumer == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(user, actionEnum);
+ return Either.right(responseFormat);
+ }
+ } catch (Exception e) {
+ // INVALID JSON
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", data, e);
+ ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(user, actionEnum);
+ return Either.right(responseFormat);
+ }
+ return Either.left(consumer);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java
new file mode 100644
index 0000000000..4ba6b7516d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java
@@ -0,0 +1,296 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+//import org.openecomp.sdc.be.builders.tosca.api.TopologyService;
+//import org.openecomp.sdc.be.tosca.parsers.ParserMode;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/services")
+public class CsarBuildServlet extends ToscaDaoServlet {
+
+ private static Logger log = LoggerFactory.getLogger(CsarBuildServlet.class.getName());
+
+ @GET
+ @Path("/{serviceName}/{serviceVersion}")
+ public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
+
+ return null;// buildToscaCsar(request, serviceName, serviceVersion);
+
+ }
+
+ @GET
+ @Path("/{serviceName}/{serviceVersion}/csar")
+ public Response getToscaCsarTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
+
+ return null; // buildToscaCsar(request, serviceName, serviceVersion);
+
+ }
+
+ /*
+ * private Response buildToscaCsar(final HttpServletRequest request, String serviceName, String serviceVersion) { log.debug("Building CSAR for service:{} , version:{}", serviceName, serviceVersion); ServletContext context =
+ * request.getSession().getServletContext(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream); String fileName =
+ * serviceName+"_"+serviceVersion+".zip";
+ *
+ * IResourceUploader resourceUploader = getResourceUploader(context); TopologyService topologyService = getToscaYamlBuilder(context).getServiceYaml(serviceName, serviceVersion, ParserMode.CSAR, "Scripts"); try {
+ *
+ *
+ * //Add Service yml to Zip addZipEntry(zipOutputStream, "Definitions/"+serviceName+".yaml", topologyService.getTopologyServiceYaml());
+ *
+ * //Add Resources to Zip addResourcesToZip(zipOutputStream, topologyService);
+ *
+ * //Add Artifacts to Zip addArtifactsToZip(serviceName, serviceVersion, zipOutputStream, resourceUploader);
+ *
+ * //Prepare Tosca metadata addToscaMetaToZip(zipOutputStream, topologyService, resourceUploader);
+ *
+ * }
+ *
+ * catch (IOException e) { log.error("Failed to create CSAR file", e); return null; } finally{ try { byteArrayOutputStream.close(); zipOutputStream.close(); } catch (IOException e) { log.error("Failed to close output srream", e); }
+ *
+ * } return buildResponse(fileName, byteArrayOutputStream);
+ *
+ *
+ * }
+ */
+
+ public static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
+ // protected void addToscaMetaToZip(ZipOutputStream zipOutputStream,
+ // TopologyService topService, IResourceUploader resUploader) throws
+ // IOException {
+ // String serviceVersion = topService.getTopologyVersion();
+ // String serviceName = topService.getTopologyName();
+ // StringBuffer buff = new StringBuffer();
+ //
+ // String[] serviceToscaMeta = prepareToscaMetaHeader(serviceName);
+ //
+ // for( String toAppend : serviceToscaMeta){
+ // buff.append(toAppend);
+ // }
+ //
+ // List<String> toscaMetaComponents =
+ // prepareToscaMetaComponents(topService.getDependenciesYamls().keySet());
+ // for( String toAppend : toscaMetaComponents ){
+ // buff.append(toAppend);
+ // }
+ //
+ // Either<ServiceArtifactsDataCollection, ResourceUploadStatus>
+ // getServiceArtifactsCollectionStatus =
+ // Either.right(ResourceUploadStatus.ERROR);//resUploader.getServiceArtifactsCollection(serviceName,
+ // serviceVersion);
+ // if(getServiceArtifactsCollectionStatus.isLeft()){
+ // List<String> toscaMetaArtifacts =
+ // prepareToscaMetaArtifacts(getServiceArtifactsCollectionStatus.left().value());
+ // for( String toAppend : toscaMetaArtifacts ){
+ // buff.append(toAppend);
+ // }
+ // }
+ //
+ // addZipEntry(zipOutputStream, TOSCA_META_PATH, buff.toString());
+ // }
+
+ // protected List<String> prepareToscaMetaArtifacts(
+ // ServiceArtifactsDataCollection serviceArtifactsDataCollection) {
+ // List<String> artifactsForToscaMeta = new ArrayList<String>();
+ // Iterator<Entry<String, List<ArtifactData>>> nodeTemplateArtifactsItr =
+ // serviceArtifactsDataCollection.getServiceArtifactDataMap().entrySet().iterator();
+ // while( nodeTemplateArtifactsItr.hasNext() ){
+ // Entry<String, List<ArtifactData>> nodeNameArtifacts =
+ // nodeTemplateArtifactsItr.next();
+ // String nodeName = nodeNameArtifacts.getKey();
+ // Iterator<ArtifactData> artifactDataItr =
+ // nodeNameArtifacts.getValue().iterator();
+ // while( artifactDataItr.hasNext() ){
+ // ArtifactData artifactData = artifactDataItr.next();
+ // artifactsForToscaMeta.add("\n");
+ // artifactsForToscaMeta.add("Name: "+getArtifactPath(nodeName,
+ // artifactData)+"\n");
+ // artifactsForToscaMeta.add("Content-Type:
+ // application/"+getAppliactionMime(artifactData.getArtifactName())+"\n");
+ // }
+ // }
+ // return artifactsForToscaMeta;
+ // }
+
+ // protected List<String> prepareToscaMetaComponents(Set<String> components)
+ // {
+ // Iterator<String> resourceNameItr = components.iterator();
+ // List<String> componentsForToscaMeta = new ArrayList<String>();
+ // while( resourceNameItr.hasNext() ){
+ // String resourceName = resourceNameItr.next();
+ // componentsForToscaMeta.add("\n");
+ // componentsForToscaMeta.add("Name: "+getResourcePath(resourceName)+"\n");
+ // componentsForToscaMeta.add("Content-Type:
+ // application/vnd.oasis.tosca.definitions.yaml\n");
+ //
+ // }
+ // return componentsForToscaMeta;
+ // }
+
+ protected String[] prepareToscaMetaHeader(String serviceName) {
+ return new String[] { "TOSCA-Meta-File-Version: 1.0\n", "CSAR-Version: 1.1\n", "Created-By: INTERWISE\n", "\n", "Entry-Definitions: Definitions/" + serviceName + ".yaml\n", "\n", "Name: Definitions/" + serviceName + ".yaml\n",
+ "Content-Type: application/vnd.oasis.tosca.definitions.yaml\n" };
+ }
+
+ protected String getAppliactionMime(String fileName) {
+ String mimeType;
+ if (fileName.contains(".sh")) {
+ mimeType = "x-sh";
+ } else if (fileName.contains(".yang")) {
+ mimeType = "yang";
+ }
+
+ else if (fileName.contains(".rar")) {
+ mimeType = "x-rar-compressed";
+ }
+
+ else if (fileName.contains(".zip")) {
+ mimeType = "zip";
+ }
+
+ else if (fileName.contains(".tar")) {
+ mimeType = "x-tar";
+ }
+
+ else if (fileName.contains(".7z")) {
+ mimeType = "x-7z-compressed";
+ }
+
+ else {
+ // Undefined
+ mimeType = "undefined";
+ }
+ return mimeType;
+ }
+
+ // protected void addResourcesToZip(ZipOutputStream zipOutputStream,
+ // TopologyService topService) throws IOException {
+ // Iterator<Entry<String, String>> resourceNameDataItr =
+ // topService.getDependenciesYamls().entrySet().iterator();
+ // while( resourceNameDataItr.hasNext() ){
+ // Entry<String, String> resourceNameData = resourceNameDataItr.next();
+ // addZipEntry(zipOutputStream, getResourcePath(resourceNameData.getKey()),
+ // resourceNameData.getValue());
+ // }
+ // }
+
+ protected String getArtifactPath(String nodeTamplateName, ESArtifactData artifactData) {
+ // return "Scripts/"+nodeTamplateName+"/"+
+ // artifactData.getArtifactName();
+ return "Scripts/" + nodeTamplateName + "/" + artifactData.getId();
+ }
+
+ protected String getResourcePath(String resourceName) {
+ return "Definitions/" + resourceName + ".yaml";
+ }
+
+ // protected void addArtifactsToZip(String serviceName, String
+ // serviceVersion, ZipOutputStream zipOutputStream, IResourceUploader
+ // resourceUploader)
+ // throws IOException {
+ // //Add Artifacts to Zip
+ // Either<ServiceArtifactsDataCollection, ResourceUploadStatus>
+ // getServiceArtifactsCollectionStatus =
+ // Either.right(ResourceUploadStatus.ERROR);//resourceUploader.getServiceArtifactsCollection(serviceName,
+ // serviceVersion);
+ // if(getServiceArtifactsCollectionStatus.isLeft()){
+ // Iterator<Entry<String, List<ArtifactData>>> nodeTemplateArtifactsItr
+ // =getServiceArtifactsCollectionStatus.left().value().getServiceArtifactDataMap().entrySet().iterator();
+ // while( nodeTemplateArtifactsItr.hasNext() ){
+ // Entry<String, List<ArtifactData>> nodeTemplateArtifacts =
+ // nodeTemplateArtifactsItr.next();
+ // String nodeTamplateName = nodeTemplateArtifacts.getKey();
+ // List<ArtifactData> artifacts = nodeTemplateArtifacts.getValue();
+ // for(ArtifactData artifactData : artifacts ){
+ // addZipEntry(zipOutputStream,
+ // getArtifactPath(nodeTamplateName,artifactData), artifactData.getData());
+ // }
+ //
+ // }
+ // }
+ // }
+
+ // private Response buildResponse(String fileName, ByteArrayOutputStream
+ // fileOutputStream) {
+ // final InputStream inputStream = new
+ // ByteArrayInputStream(fileOutputStream.toByteArray());
+ //
+ // StreamingOutput stream = new StreamingOutput() {
+ // public void write(OutputStream output) throws WebApplicationException {
+ // try {
+ // IOUtils.copy(inputStream, output);
+ // } catch (Exception e) {
+ // throw new WebApplicationException(e);
+ // }
+ // }
+ // };
+ //
+ // return
+ // Response.ok(stream).type(MediaType.APPLICATION_OCTET_STREAM_TYPE).header("content-disposition","attachment;
+ // filename = "+fileName).build();
+ // }
+
+ // protected void addZipEntry(ZipOutputStream zipOutputStream, String
+ // filePath, String data) throws IOException {
+ // addZipEntry(zipOutputStream, filePath, encodeString(data));
+ // }
+
+ private byte[] encodeString(String data) throws CharacterCodingException {
+ Charset charset = Charset.forName("UTF-8");
+ CharsetEncoder encoder = charset.newEncoder();
+ ByteBuffer bb = encoder.encode(CharBuffer.wrap(data.toCharArray()));
+ byte[] ba = new byte[bb.limit()];
+ bb.get(ba);
+ return ba;
+ }
+
+ // private void addZipEntry(ZipOutputStream zipOutputStream, String
+ // filePath, byte[] data) throws IOException {
+ // log.debug("Adding to CSAR zip :{}", filePath);
+ // ZipEntry entry = new ZipEntry(filePath);
+ // zipOutputStream.putNextEntry(entry);
+ // zipOutputStream.write(data);
+ // zipOutputStream.closeEntry();
+ // }
+
+ @Override
+ public Logger getLogger() {
+ return log;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java
new file mode 100644
index 0000000000..62a321fa5b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java
@@ -0,0 +1,169 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.annotation.Resource;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.info.DistributionStatusListResponse;
+import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Distribution Service Servlet", description = "Distribution Service Servlet")
+@Singleton
+public class DistributionServiceServlet extends BeGenericServlet {
+ private static Logger log = LoggerFactory.getLogger(DistributionServiceServlet.class.getName());
+
+ @Resource
+ private DistributionMonitoringBusinessLogic distributionMonitoringLogic;
+
+ @GET
+ @Path("/services/{serviceUUID}/distribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Distributions", httpMethod = "GET", notes = "Returns list bases on the information extracted from Auditing Records according to service uuid", response = DistributionStatusListResponse.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") })
+ public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ init(request);
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+
+ try {
+ Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionServiceStatus(serviceUUID, userId);
+
+ if (actionResponse.isRight()) {
+
+ responseFormat = actionResponse.right().value();
+ response = buildErrorResponse(responseFormat);
+ } else {
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Distribution list for Service");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service");
+ log.debug("failed to get service distribution statuses", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ response = buildErrorResponse(responseFormat);
+ return response;
+ }
+
+ }
+
+ @GET
+ @Path("/services/distribution/{did}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Distributions", httpMethod = "GET", notes = "Return the list of distribution status objects", response = DistributionStatusListResponse.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Status not found") })
+ public Response getListOfDistributionStatuses(@PathParam("did") final String did, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ init(request);
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+
+ try {
+ Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionStatus(did, userId);
+
+ if (actionResponse.isRight()) {
+
+ responseFormat = actionResponse.right().value();
+ log.debug("failed to fount statuses for did {} {}", did, responseFormat);
+ response = buildErrorResponse(responseFormat);
+ } else {
+
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value());
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Distribution Status");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status");
+ log.debug("failed to get distribution status ", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+
+ response = buildErrorResponse(responseFormat);
+ return response;
+ }
+
+ }
+
+ private void init(HttpServletRequest request) {
+ if (distributionMonitoringLogic == null) {
+ distributionMonitoringLogic = getDistributionBL(request.getSession().getServletContext());
+ }
+ }
+
+ private DistributionMonitoringBusinessLogic getDistributionBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ DistributionMonitoringBusinessLogic distributionBl = webApplicationContext.getBean(DistributionMonitoringBusinessLogic.class);
+ return distributionBl;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
new file mode 100644
index 0000000000..433a1bfc58
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
@@ -0,0 +1,611 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.clean.ComponentsCleanBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.info.ArtifactTypesInfo;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.Category;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PropertyScope;
+import org.openecomp.sdc.be.model.Tag;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Path("/v1/")
+
+/****
+ *
+ * UI oriented servlet - to return elements in specific format UI needs
+ *
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Api(value = "Element Servlet", description = "Element Servlet")
+@Singleton
+public class ElementServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ElementServlet.class.getName());
+
+ /*
+ ******************************************************************************
+ * NEW CATEGORIES category / \ subcategory subcategory / grouping
+ ******************************************************************************/
+
+ /*
+ *
+ *
+ * CATEGORIES
+ */
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all component categories
+ @GET
+ @Path("/categories/{componentType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve the list of all resource/service/product categories/sub-categories/groupings", httpMethod = "GET", notes = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid component type"),
+ @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getComponentCategories(@ApiParam(value = "allowed values are resources / services/ products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<CategoryDefinition>, ResponseFormat> either = elementBL.getAllCategories(componentType, userId);
+ if (either.isRight()) {
+ log.debug("No categories were found for type {}", componentType);
+ return buildErrorResponse(either.right().value());
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Component Categories");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
+ log.debug("getComponentCategories failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/category/{componentType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create new component category", httpMethod = "POST", notes = "Create new component category")
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Category created"), @ApiResponse(code = 400, message = "Invalid category data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
+ @ApiResponse(code = 409, message = "Category already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
+ public Response createComponentCategory(
+ @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
+ @ApiParam(value = "Category to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
+
+ Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.createCategory(category, componentType, userId);
+ if (createResourceCategory.isRight()) {
+ return buildErrorResponse(createResourceCategory.right().value());
+ }
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createResourceCategory.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create resource category");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
+ log.debug("createResourceCategory failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
+ @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
+ public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId);
+
+ if (createResourceCategory.isRight()) {
+ return buildErrorResponse(createResourceCategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create resource category");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
+ log.debug("createResourceCategory failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ /*
+ *
+ *
+ * SUBCATEGORIES
+ *
+ */
+
+ @POST
+ @Path("/category/{componentType}/{categoryId}/subCategory")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create new component sub-category", httpMethod = "POST", notes = "Create new component sub-category for existing category")
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Subcategory created"), @ApiResponse(code = 400, message = "Invalid subcategory data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
+ @ApiResponse(code = 404, message = "Parent category wasn't found"), @ApiResponse(code = 409, message = "Subcategory already exists / User not permitted to perform the action"), @ApiResponse(code = 500, message = "General Error") })
+ public Response createComponentSubCategory(
+ @ApiParam(value = "allowed values are resources / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
+ @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String categoryId, @ApiParam(value = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
+
+ Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId);
+ if (createSubcategory.isRight()) {
+ return buildErrorResponse(createSubcategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createSubcategory.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create sub-category");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
+ log.debug("createComponentSubCategory failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
+ @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
+ public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
+ @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory = elementBL.deleteSubCategory(categoryUniqueId, subCategoryUniqueId, componentType, userId);
+ if (deleteSubResourceCategory.isRight()) {
+ return buildErrorResponse(deleteSubResourceCategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete component category");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
+ log.debug("deleteComponentSubCategory failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ /*
+ * GROUPINGS
+ */
+ @POST
+ @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create new component grouping", httpMethod = "POST", notes = "Create new component grouping for existing sub-category")
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Grouping created"), @ApiResponse(code = 400, message = "Invalid grouping data"), @ApiResponse(code = 403, message = "USER_ID header is missing"),
+ @ApiResponse(code = 404, message = "Parent category or subcategory were not found"), @ApiResponse(code = 409, message = "Grouping already exists / User not permitted to perform the action"),
+ @ApiResponse(code = 500, message = "General Error") })
+ public Response createComponentGrouping(@ApiParam(value = "allowed values are products", allowableValues = ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam(value = "componentType") final String componentType,
+ @ApiParam(value = "Parent category unique ID", required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
+ @ApiParam(value = "Parent sub-category unique ID", required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId, @ApiParam(value = "Subcategory to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
+
+ Either<GroupingDefinition, ResponseFormat> createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
+ if (createGrouping.isRight()) {
+ return buildErrorResponse(createGrouping.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createGrouping.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create grouping");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
+ log.debug("createComponentGrouping failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete component category", httpMethod = "DELETE", notes = "Delete component category", response = Category.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "Category deleted"), @ApiResponse(code = 403, message = "USER_ID header is missing"), @ApiResponse(code = 409, message = "User not permitted to perform the action"),
+ @ApiResponse(code = 404, message = "Category not found"), @ApiResponse(code = 500, message = "General Error") })
+ public Response deleteComponentGrouping(@PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId, @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
+ @PathParam(value = "groupingUniqueId") final String groupingUniqueId, @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBL.deleteGrouping(grandParentCategoryUniqueId, parentSubCategoryUniqueId, groupingUniqueId, componentType, userId);
+ if (deleteGrouping.isRight()) {
+ return buildErrorResponse(deleteGrouping.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete component grouping");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
+ log.debug("deleteGrouping failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all tags
+ @GET
+ @Path("/tags")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve all tags", httpMethod = "GET", notes = "Retrieve all tags", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns tags Ok"), @ApiResponse(code = 404, message = "No tags were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getTags(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getTags) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<Tag>, ActionStatus> either = elementBL.getAllTags(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No tags were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get All Tags");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
+ log.debug("getAllTags failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all property scopes
+ @GET
+ @Path("/propertyScopes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve all propertyScopes", httpMethod = "GET", notes = "Retrieve all propertyScopes", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns propertyScopes Ok"), @ApiResponse(code = 404, message = "No propertyScopes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getPropertyScopes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getPropertyScopes) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<PropertyScope>, ActionStatus> either = elementBL.getAllPropertyScopes(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No property scopes were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Property Scopes Categories");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
+ log.debug("getPropertyScopes failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all artifact types
+ @GET
+ @Path("/artifactTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getArtifactTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getArtifactTypes) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<ArtifactType>, ActionStatus> either = elementBL.getAllArtifactTypes(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No artifact types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+
+ Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes();
+ ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
+ typesResponse.setArtifactTypes(either.left().value());
+ typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Artifact Types");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
+ log.debug("getArtifactTypes failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all artifact types
+ @GET
+ @Path("/configuration/ui")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve all artifactTypes", httpMethod = "GET", notes = "Retrieve all artifactTypes", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns artifactTypes Ok"), @ApiResponse(code = 404, message = "No artifactTypes were found"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getConfiguration(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getConfiguration) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<ArtifactType>, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId);
+ Either<Integer, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
+ Either<Map<String, Object>, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes();
+ Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
+
+ if (otherEither.isRight() || otherEither.left().value() == null) {
+ log.debug("No other artifact types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
+ log.debug("No deployment artifact types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
+ log.debug("heat default timeout was not found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
+ log.debug("No resource types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ Map<String, Object> artifacts = new HashMap<String, Object>();
+ Map<String, Object> configuration = new HashMap<String, Object>();
+
+ artifacts.put("other", otherEither.left().value());
+ artifacts.put("deployment", deploymentEither.left().value());
+ configuration.put("artifacts", artifacts);
+ configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
+ configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
+ configuration.put("roles", elementBL.getAllSupportedRoles());
+ configuration.put("resourceTypes", resourceTypesMap.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Artifact Types");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
+ log.debug("getArtifactTypes failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all followed resources and services
+ @GET
+ @Path("/followed")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve all followed", httpMethod = "GET", notes = "Retrieve all followed", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns followed Ok"), @ApiResponse(code = 404, message = "No followed were found"), @ApiResponse(code = 404, message = "User not found"),
+ @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getFollowedResourcesServices(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Response res = null;
+ User userData = null;
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+
+ // Getting the user
+ Either<User, ActionStatus> either = userAdminManager.getUser(userId, false);
+ if (either.isRight()) {
+ // Couldn't find or otherwise fetch the user
+ return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
+ }
+
+ if (either.left().value() != null) {
+ userData = either.left().value();
+ Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData);
+ // res =
+ // buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ // followedResourcesServices.left().value());
+ if (followedResourcesServices.isRight()) {
+ log.debug("failed to get followed resources services ");
+ return buildErrorResponse(followedResourcesServices.right().value());
+ }
+ Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
+ res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+ } else {
+ res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Followed Resources / Services Categories");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
+ log.debug("Getting followed resources/services failed with exception", e);
+ res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return res;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all certified resources and services and their last version
+ @GET
+ @Path("/screen")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve catalog resources and services", httpMethod = "GET", notes = "Retrieve catalog resources and services", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns resources and services Ok"), @ApiResponse(code = 404, message = "No resources and services were found"), @ApiResponse(code = 404, message = "User not found"),
+ @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Response res = null;
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ Either<Map<String, List<? extends Component>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId);
+
+ if (catalogData.isRight()) {
+ log.debug("failed to get catalog data");
+ return buildErrorResponse(catalogData.right().value());
+ }
+ Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
+ res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Catalog Components");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
+ log.debug("Getting catalog components failed with exception", e);
+ res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return res;
+ }
+
+ @DELETE
+ @Path("/inactiveComponents/{componentType}")
+ public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
+ if (nodeType == null) {
+ log.info("componentType is not valid: {}", componentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ List<NodeTypeEnum> componentsList = new ArrayList<NodeTypeEnum>();
+ componentsList.add(nodeType);
+ try {
+ ComponentsCleanBusinessLogic businessLogic = getComponentCleanerBL(context);
+ Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = businessLogic.cleanComponents(componentsList);
+ Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
+
+ if (cleanResult.isRight()) {
+ log.debug("failed to delete marked components of type {}", nodeType);
+ response = buildErrorResponse(cleanResult.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Marked Components");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
+ log.debug("delete marked components failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/ecompPortalMenu")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve ecomp portal menu - MOC", httpMethod = "GET", notes = "Retrieve ecomp portal menu", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Retrieve ecomp portal menu") })
+ public Response getListOfCsars(@Context final HttpServletRequest request) {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ "[{\"menuId\":1,\"column\":2,\"text\":\"Design\",\"parentMenuId\":null,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":11,\"column\":1,\"text\":\"ProductDesign\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":12,\"column\":2,\"text\":\"Service\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":21,\"column\":1,\"text\":\"ViewPolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":90,\"column\":1,\"text\":\"4thLevelApp1aR16\",\"parentMenuId\":21,\"url\":\"http://google.com\",\"appid\":null,\"roles\":null}]},{\"menuId\":22,\"column\":2,\"text\":\"UpdatePolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":91,\"column\":1,\"text\":\"4thLevelApp1bR16\",\"parentMenuId\":22,\"url\":\"http://jsonlint.com/\",\"appid\":null,\"roles\":null}]},{\"menuId\":23,\"column\":3,\"text\":\"UpdateRules\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":24,\"column\":4,\"text\":\"CreateSignatures?\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":25,\"column\":5,\"text\":\"Definedata\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null}]}]}]");
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
new file mode 100644
index 0000000000..bde8f93929
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
@@ -0,0 +1,182 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.info.GroupDefinitionInfo;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resource Group Servlet", description = "Resource Group Servlet")
+@Singleton
+public class GroupServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(GroupServlet.class.getName());
+
+ private Gson gson = new Gson();
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/groups/{groupId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get group artifacts ", httpMethod = "GET", notes = "Returns artifacts metadata according to groupId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "group found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Group not found") })
+ public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ GroupBusinessLogic businessLogic = this.getGroupBL(context);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ Either<GroupDefinitionInfo, ResponseFormat> actionResponse = businessLogic.getGroupWithArtifactsById(componentTypeEnum, componentId, groupId, userId, false);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract {}", containerComponentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "getGroupArtifactById");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
+ log.debug("getGroupArtifactById unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Group Metadata", httpMethod = "PUT", notes = "Returns updated group definition", response = GroupDefinition.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Group Updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateGroupMetadata(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
+ @ApiParam(value = "Service object to be Updated", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User user = new User();
+ user.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ GroupBusinessLogic businessLogic = getGroupBL(context);
+
+ Either<GroupDefinition, ResponseFormat> convertResponse = parseToGroup(data);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse group");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ GroupDefinition updatedGroup = convertResponse.left().value();
+
+ // Update GroupDefinition
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ Either<GroupDefinition, ResponseFormat> actionResponse = businessLogic.updateGroupMetadata(componentId, user, groupUniqueId, componentTypeEnum, updatedGroup, true);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update GroupDefinition");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ GroupDefinition group = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(group);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Group Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Group Metadata");
+ log.debug("update group metadata failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ /**
+ * Convert data to GroupDefinition object
+ *
+ * @param groupJson
+ * @return
+ */
+ public Either<GroupDefinition, ResponseFormat> parseToGroup(String groupJson) {
+ try {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ GroupDefinition groupDefinition = gson.fromJson(groupJson, GroupDefinition.class);
+ return Either.left(groupDefinition);
+ } catch (Exception e) {
+ log.debug("Failed to parse json (group data) to GroupDefinition object");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return Either.right(responseFormat);
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
new file mode 100644
index 0000000000..e835c43e14
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
@@ -0,0 +1,320 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.List;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Input Catalog", description = "Input Servlet")
+@Singleton
+public class InputsServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ProductServlet.class.getName());
+
+ @GET
+ @Path("/services/{componentId}/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Inputs only", httpMethod = "GET", notes = "Returns Inputs list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getComponentInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request, @QueryParam("fromId") String fromName,
+ @QueryParam("amount") int amount, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ InputsBusinessLogic businessLogic = getInputBL(context);
+
+ Either<List<InputDefinition>, ResponseFormat> inputsResponse = businessLogic.getInputs(userId, componentId, fromName, amount);
+ if (inputsResponse.isRight()) {
+ log.debug("failed to get inputs {}", componentType);
+ return buildErrorResponse(inputsResponse.right().value());
+ }
+ Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Component Instance Inputs" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs" + componentType);
+ log.debug("getInputs failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComonentUid}/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get Inputs only", httpMethod = "GET", notes = "Returns Inputs list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
+ @PathParam("originComonentUid") final String originComonentUid, @Context final HttpServletRequest request, @QueryParam("fromName") String fromName, @QueryParam("amount") int amount,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ InputsBusinessLogic businessLogic = getInputBL(context);
+
+ Either<List<InputDefinition>, ResponseFormat> inputsResponse = businessLogic.getInputs(userId, originComonentUid, fromName, amount);
+ if (inputsResponse.isRight()) {
+ log.debug("failed to get component instance inputs {}", componentType);
+ return buildErrorResponse(inputsResponse.right().value());
+ }
+ Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Component Instance Inputs" + componentType);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs" + componentType);
+ log.debug("getInputs failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get properties", httpMethod = "GET", notes = "Returns properties list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
+ @PathParam("inputId") final String inputId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ InputsBusinessLogic businessLogic = getInputBL(context);
+
+ Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = businessLogic.getComponentInstancePropertiesByInputId(userId, instanceId, inputId);
+ if (inputPropertiesRes.isRight()) {
+ log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
+ return buildErrorResponse(inputPropertiesRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get properties by input id {}, for component instance {} ", inputId, instanceId);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
+ log.debug("getInputPropertiesForComponentInstance failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get inputs", httpMethod = "GET", notes = "Returns inputs list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response getInputsForComponentInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ InputsBusinessLogic businessLogic = getInputBL(context);
+
+ Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes = businessLogic.getInputsForComponentInput(userId, componentId, inputId);
+ if (inputsRes.isRight()) {
+ log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
+ return buildErrorResponse(inputsRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get inputs by input id {}, for component {} ", inputId, componentId);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
+ log.debug("getInputsForComponentInput failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ public Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ @POST
+ @Path("/{componentType}/{componentId}/create/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create inputs on service", httpMethod = "POST", notes = "Return inputs list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response createMultipleInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ InputsBusinessLogic businessLogic = getInputBL(context);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Either<ComponentInstInputsMap, ResponseFormat> componentInstInputsMapRes = parseToComponentInstanceMap(componentInstInputsMapObj, modifier);
+ if (componentInstInputsMapRes.isRight()) {
+ log.debug("failed to parse componentInstInputsMap");
+ response = buildErrorResponse(componentInstInputsMapRes.right().value());
+ return response;
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentInstInputsMap componentInstInputsMap = componentInstInputsMapRes.left().value();
+
+ Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = businessLogic.createMultipleInputs(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
+ if (inputPropertiesRes.isRight()) {
+ log.debug("failed to create inputs for service: {}", componentId);
+ return buildErrorResponse(inputPropertiesRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create inputs for service with id: {}", componentId);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create inputs for service with id: " + componentId);
+ log.debug("createMultipleInputs failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @DELETE
+ @Path("/{componentType}/{componentId}/delete/{inputId}/input")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Delete input from service", httpMethod = "DELETE", notes = "Delete service input", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Input deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Input not found") })
+ public Response deleteInput (
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("inputId") final String inputId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @ApiParam(value = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ InputsBusinessLogic businessLogic = getInputBL(context);
+ Either<InputDefinition, ResponseFormat> deleteInput = businessLogic.deleteInput(componentType, componentId, userId, inputId, true);
+ if (deleteInput.isRight()){
+ ResponseFormat deleteResponseFormat = deleteInput.right().value();
+ response = buildErrorResponse(deleteResponseFormat);
+ return response;
+ }
+ InputDefinition inputDefinition = deleteInput.left().value();
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputDefinition);
+ } catch (Exception e){
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete input for service {} with id: {}", componentId, inputId);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
+ log.debug("Delete input failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ protected InputsBusinessLogic getInputBL(ServletContext context) {
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ InputsBusinessLogic inputsBusinessLogic = webApplicationContext.getBean(InputsBusinessLogic.class);
+ return inputsBusinessLogic;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java
new file mode 100644
index 0000000000..3f8bfd9149
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java
@@ -0,0 +1,216 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Lifecycle Actions Servlet", description = "Lifecycle Actions Servlet")
+@Singleton
+public class LifecycleServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(LifecycleServlet.class.getName());
+
+ @POST
+ @Path("/{componentCollection}/{componentId}/lifecycleState/{lifecycleOperation}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Change Resource lifecycle State", httpMethod = "POST", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource state changed"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 409, message = "Resource already exist") })
+ public Response changeResourceState(@ApiParam(value = "LifecycleChangeInfo - relevant for checkin, failCertification, cancelCertification", required = false) String jsonChangeInfo,
+ @ApiParam(value = "validValues: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
+ + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam(value = "componentCollection") final String componentCollection,
+ @ApiParam(allowableValues = "checkout, undoCheckout, checkin, certificationRequest, startCertification, failCertification, cancelCertification, certify", required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition,
+ @ApiParam(value = "id of component to be changed") @PathParam(value = "componentId") final String componentId, @Context final HttpServletRequest request,
+ @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ LifecycleBusinessLogic businessLogic = getLifecycleBL(context);
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ Response response = null;
+
+ // get modifier from graph
+ log.debug("get modifier properties");
+ Either<User, Response> eitherGetUser = getUser(request, userId);
+ if (eitherGetUser.isRight()) {
+ return eitherGetUser.right().value();
+ }
+ User user = eitherGetUser.left().value();
+
+ String resourceIdLower = componentId.toLowerCase();
+ log.debug("perform {} operation to resource with id {} ", lifecycleTransition, resourceIdLower);
+ Either<LifeCycleTransitionEnum, Response> validateEnum = validateTransitionEnum(lifecycleTransition, user);
+ if (validateEnum.isRight()) {
+ return validateEnum.right().value();
+ }
+
+ LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction();
+
+ try {
+ if (jsonChangeInfo != null && !jsonChangeInfo.isEmpty()) {
+ // Either<LifecycleChangeInfo, ResponseFormat > changeInfoResult
+ // =
+ // getComponentsUtils().convertJsonToObjectUsingObjectMapper(jsonChangeInfo,
+ // user, LifecycleChangeInfo.class,
+ // AuditingActionEnum.CHECKOUT_RESOURCE, null);
+ ObjectMapper mapper = new ObjectMapper();
+ changeInfo = new LifecycleChangeInfoWithAction(mapper.readValue(jsonChangeInfo, LifecycleChangeInfoBase.class).getUserRemarks());
+ }
+ }
+
+ catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInvalidJsonInput, "convertJsonToObject");
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", jsonChangeInfo, e);
+ ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(user, AuditingActionEnum.CHECKOUT_RESOURCE);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ LifeCycleTransitionEnum transitionEnum = validateEnum.left().value();
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(componentCollection);
+ // if (componentType == ComponentTypeEnum.RESOURCE){
+ // Either<Resource, ResponseFormat> actionResponse =
+ // businessLogic.changeState(resourceIdLower, user, transitionEnum,
+ // changeInfo, false);
+ //
+ // if (actionResponse.isRight()){
+ // log.info("failed to change resource state");
+ // response = buildErrorResponse(actionResponse.right().value());
+ // return response;
+ // }
+ //
+ // log.debug("change state successful !!!");
+ // Object resource =
+ // RepresentationUtils.toRepresentation(actionResponse.left().value());
+ // response =
+ // buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ // resource);
+ // return response;
+ //
+ // } else if (componentType == ComponentTypeEnum.SERVICE ||
+ // componentType == ComponentTypeEnum.PRODUCT){
+ if (componentType != null) {
+ Either<? extends Component, ResponseFormat> actionResponse = businessLogic.changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true);
+
+ if (actionResponse.isRight()) {
+ log.info("failed to change resource state");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ log.debug("change state successful !!!");
+ Object value = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), value);
+ return response;
+ } else {
+ log.info("componentCollection \"{}\" is not valid. Supported componentCollection values are \"{}\", \"{}\" or \"{}\"", componentCollection, ComponentTypeEnum.RESOURCE_PARAM_NAME, ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME);
+ ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, AuditingActionEnum.CHECKOUT_RESOURCE);
+ return buildErrorResponse(error);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Change Lifecycle State");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Change Lifecycle State");
+ log.debug("change lifecycle state failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ private Either<LifeCycleTransitionEnum, Response> validateTransitionEnum(final String lifecycleTransition, User user) {
+ LifeCycleTransitionEnum transitionEnum = LifeCycleTransitionEnum.CHECKOUT;
+ try {
+ transitionEnum = LifeCycleTransitionEnum.getFromDisplayName(lifecycleTransition);
+ } catch (IllegalArgumentException e) {
+ log.info("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString());
+ ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, AuditingActionEnum.CHECKOUT_RESOURCE);
+ return Either.right(buildErrorResponse(error));
+ }
+ return Either.left(transitionEnum);
+ }
+
+ private LifecycleBusinessLogic getLifecycleBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ LifecycleBusinessLogic resourceBl = webApplicationContext.getBean(LifecycleBusinessLogic.class);
+ return resourceBl;
+ }
+
+ protected Either<User, Response> getUser(final HttpServletRequest request, String userId) {
+
+ Either<User, ActionStatus> eitherCreator = getUserAdminManager(request.getSession().getServletContext()).getUser(userId, false);
+ if (eitherCreator.isRight()) {
+ log.info("createResource method - user is not listed. userId={}", userId);
+ ResponseFormat errorResponse = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ User user = new User("", "", userId, "", null, null);
+
+ getComponentsUtils().auditResource(errorResponse, user, null, "", "", AuditingActionEnum.CHECKOUT_RESOURCE, null);
+ return Either.right(buildErrorResponse(errorResponse));
+ }
+ return Either.left(eitherCreator.left().value());
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java
new file mode 100644
index 0000000000..f4ac921cb7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java
@@ -0,0 +1,311 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.Product;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Product Catalog", description = "Product Servlet")
+@Singleton
+public class ProductServlet extends BeGenericServlet {
+ private static Logger log = LoggerFactory.getLogger(ProductServlet.class.getName());
+
+ @POST
+ @Path("/products")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create product", httpMethod = "POST", notes = "Returns created product", response = Product.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Product created"), @ApiResponse(code = 403, message = "Restricted operation / Empty USER_ID header"), @ApiResponse(code = 400, message = "Invalid/missing content"),
+ @ApiResponse(code = 409, message = "Product already exists / User not found / Wrong user role") })
+ public Response createProduct(@ApiParam(value = "Product object to be created", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of product strategist user", required = true) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ProductBusinessLogic businessLogic = getProductBL(context);
+ Product product = RepresentationUtils.fromRepresentation(data, Product.class);
+ Either<Product, ResponseFormat> actionResponse = businessLogic.createProduct(product, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("Failed to create product");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), result);
+ return response;
+
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Product");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Product");
+ log.debug("create product failed with error ", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @GET
+ @Path("/products/{productId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve product", httpMethod = "GET", notes = "Returns product according to productId", response = Product.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Product found"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 409, message = "Restricted operation"),
+ @ApiResponse(code = 500, message = "Internal Server Error"), @ApiResponse(code = 404, message = "Product not found"), })
+ public Response getProductById(@PathParam("productId") final String productId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ ProductBusinessLogic businessLogic = getProductBL(context);
+ log.trace("get product with id {}", productId);
+ Either<Product, ResponseFormat> actionResponse = businessLogic.getProduct(productId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("Failed to get product");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Object product = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), product);
+
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Product");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Product");
+ log.debug("get product failed with error ", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @GET
+ @Path("/products/productName/{productName}/productVersion/{productVersion}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Service", httpMethod = "GET", notes = "Returns product according to name and version", response = Product.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Product found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Product not found") })
+ public Response getServiceByNameAndVersion(@PathParam("productName") final String productName, @PathParam("productVersion") final String productVersion, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ProductBusinessLogic businessLogic = getProductBL(context);
+ Either<Product, ResponseFormat> actionResponse = businessLogic.getProductByNameAndVersion(productName, productVersion, userId);
+
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Product product = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(product);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get product by name and version");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get product by name and version");
+ log.debug("get product failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/products/{productId}")
+ public Response deleteProduct(@PathParam("productId") final String productId, @Context final HttpServletRequest request) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ ProductBusinessLogic businessLogic = getProductBL(context);
+ log.trace("delete product with id {}", productId);
+ Either<Product, ResponseFormat> actionResponse = businessLogic.deleteProduct(productId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("Failed to delete product");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Object product = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), product);
+ return response;
+
+ } catch (Throwable e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource");
+ log.debug("delete resource failed with error ", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @PUT
+ @Path("/products/{productId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Product Metadata", httpMethod = "PUT", notes = "Returns updated product", response = Product.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Product Updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateProductMetadata(@PathParam("productId") final String productId, @ApiParam(value = "Product object to be Updated", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Response response = null;
+
+ try {
+ String productIdLower = productId.toLowerCase();
+ ProductBusinessLogic businessLogic = getProductBL(context);
+ Product updatedProduct = RepresentationUtils.fromRepresentation(data, Product.class);
+ Either<Product, ResponseFormat> actionResponse = businessLogic.updateProductMetadata(productIdLower, updatedProduct, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update product");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Product product = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(product);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Product Metadata");
+ log.debug("update product metadata failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @GET
+ @Path("/products/validate-name/{productName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "validate product name", httpMethod = "GET", notes = "checks if the chosen product name is available ", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation") })
+ public Response validateServiceName(@PathParam("productName") final String productName, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Response response = null;
+ try {
+ ProductBusinessLogic businessLogic = getProductBL(context);
+
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse = businessLogic.validateProductNameExists(productName, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get validate service name");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Validate Service Name");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Product Name");
+ log.debug("validate product name failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PropertyServlet.java
new file mode 100644
index 0000000000..2c693c71a8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PropertyServlet.java
@@ -0,0 +1,562 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintSerialiser;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resource Property Servlet", description = "Resource Property Servlet")
+@Singleton
+public class PropertyServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(PropertyServlet.class.getName());
+
+ @POST
+ @Path("resources/{resourceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource Property", httpMethod = "POST", notes = "Returns created resource property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource property created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Resource property already exist") })
+ public Response createProperty(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId, @ApiParam(value = "Resource property to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+ log.debug("data is {}", data);
+
+ try {
+ // convert json to PropertyDefinition
+ Either<Map<String, PropertyDefinition>, ActionStatus> either = getPropertyModel(data);
+ if (either.isRight()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(either.right().value());
+ return buildErrorResponse(responseFormat);
+ }
+ Map<String, PropertyDefinition> properties = either.left().value();
+ if (properties == null || properties.size() != 1) {
+ log.info("Property conetnt is invalid - {}", data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return buildErrorResponse(responseFormat);
+ }
+ Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
+ String propertyName = entry.getKey();
+ PropertyDefinition newPropertyDefinition = entry.getValue();
+
+ // create the new property
+ PropertyBusinessLogic businessLogic = getPropertyBL(context);
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> status = businessLogic.createProperty(resourceId, propertyName, newPropertyDefinition, userId);
+ if (status.isRight()) {
+ log.info("Failed to create Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ EntryData<String, PropertyDefinition> property = status.left().value();
+ String name = property.getKey();
+ PropertyDefinition propertyDefinition = property.getValue();
+
+ log.debug("Property {} created successfully with id {}", name, propertyDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, propertyToJson(property));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Property");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Property");
+ log.debug("create property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ @GET
+ @Path("resources/{resourceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource Property", httpMethod = "GET", notes = "Returns property of resource", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "property"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "Resource property not found") })
+ public Response getProperty(@ApiParam(value = "resource id of property", required = true) @PathParam("resourceId") final String resourceId, @ApiParam(value = "proerty id to get", required = true) @PathParam("propertyId") final String propertyId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ //
+ PropertyBusinessLogic businessLogic = getPropertyBL(context);
+ Either<Entry<String, PropertyDefinition>, ResponseFormat> status = businessLogic.getProperty(resourceId, propertyId, userId);
+
+ if (status.isRight()) {
+ log.info("Failed to get Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ Entry<String, PropertyDefinition> property = status.left().value();
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, propertyToJson(property));
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Property");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property");
+ log.debug("get property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ @DELETE
+ @Path("resources/{resourceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource Property", httpMethod = "DELETE", notes = "Returns deleted property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 204, message = "deleted property"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "Resource property not found") })
+ public Response deleteProperty(@ApiParam(value = "resource id of property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "Property id to delete", required = true) @PathParam("propertyId") final String propertyId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ // delete the property
+ PropertyBusinessLogic businessLogic = getPropertyBL(context);
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> status = businessLogic.deleteProperty(resourceId, propertyId, userId);
+ if (status.isRight()) {
+ log.debug("Failed to delete Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ EntryData<String, PropertyDefinition> property = status.left().value();
+ String name = property.getKey();
+ PropertyDefinition propertyDefinition = property.getValue();
+
+ log.debug("Property {} deleted successfully with id {}", name, propertyDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, propertyToJson(property));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Property");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Property");
+ log.debug("delete property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ @PUT
+ @Path("resources/{resourceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Property", httpMethod = "PUT", notes = "Returns updated property", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource property updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateProperty(@ApiParam(value = "resource id to update with new property", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "proerty id to update", required = true) @PathParam("propertyId") final String propertyId, @ApiParam(value = "Resource property to update", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ try {
+ // convert json to PropertyDefinition
+ Either<Map<String, PropertyDefinition>, ActionStatus> either = getPropertyModel(data);
+ if (either.isRight()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(either.right().value());
+ return buildErrorResponse(responseFormat);
+ }
+ Map<String, PropertyDefinition> properties = either.left().value();
+ if (properties == null || properties.size() != 1) {
+ log.info("Property conetnt is invalid - {}", data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return buildErrorResponse(responseFormat);
+ }
+ Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
+ PropertyDefinition newPropertyDefinition = entry.getValue();
+
+ // update property
+ PropertyBusinessLogic businessLogic = getPropertyBL(context);
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> status = businessLogic.updateProperty(resourceId, propertyId, newPropertyDefinition, userId);
+ if (status.isRight()) {
+ log.info("Failed to update Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ EntryData<String, PropertyDefinition> property = status.left().value();
+ PropertyDefinition propertyDefinition = property.getValue();
+
+ log.debug("Property id {} updated successfully ", propertyDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, propertyToJson(property));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Property");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Property");
+ log.debug("update property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ // private String propertyToJsonUi(Map.Entry<String, PropertyDefinition>
+ // property) {
+ // String name = property.getKey();
+ // PropertyDefinition propertyDefinition = property.getValue();
+ // JSONObject root = new JSONObject();
+ // root.put("type", propertyDefinition.getType());
+ // root.put("source", propertyDefinition.getDefaultValue());
+ // root.put("name", name);
+ // root.put("description", propertyDefinition.getDescription());
+ // root.put("uniqueId", propertyDefinition.getUniqueId());
+ // return root.toString();
+ //
+ // }
+ //
+
+ // private Either<String ,ActionStatus> getJsonModel(String data){
+ // Either<UiProperty,ActionStatus> uiPropertyEither = getUiProperty(data);
+ // if (uiPropertyEither.isRight()){
+ // log.error("Property conetnt is invalid - {}",data);
+ // return Either.right(ActionStatus.INVALID_CONTENT);
+ // }
+ // UiProperty uiProperty = uiPropertyEither.left().value();
+ // String json = convertUiPropertyToJsonModel(uiProperty);
+ // return Either.left(json);
+ // }
+ //
+
+ // private String convertUiPropertyToJsonModel(UiProperty uiProperty) {
+ // JSONObject root = new JSONObject();
+ // JSONObject propertyD = new JSONObject();
+ // propertyD.put("type",uiProperty.getType());
+ // propertyD.put("required",false);
+ // propertyD.put("description",uiProperty.getDescription());
+ // propertyD.put("isPassword",false);
+ // propertyD.put("defaultValue",uiProperty.getSource());
+ // JSONArray jsonArr = new JSONArray();
+ // JSONArray jsonR = new JSONArray();
+ // jsonR.add(100);
+ // jsonR.add(500);
+ // JSONObject o = new JSONObject();
+ // o.put("inRange", jsonR);
+ // jsonArr.add(o);
+ // propertyD.put("constraints",jsonArr);
+ // root.put(uiProperty.getName(), propertyD);
+ // return root.toString();
+ // }
+
+ private Either<Map<String, PropertyDefinition>, ActionStatus> getPropertyModel(String data) {
+ JSONParser parser = new JSONParser();
+ JSONObject root;
+ try {
+ Map<String, PropertyDefinition> properties = new HashMap<String, PropertyDefinition>();
+ root = (JSONObject) parser.parse(data);
+
+ Set entrySet = root.entrySet();
+ Iterator iterator = entrySet.iterator();
+ while (iterator.hasNext()) {
+ Entry next = (Entry) iterator.next();
+ String propertyName = (String) next.getKey();
+ JSONObject value = (JSONObject) next.getValue();
+ String jsonString = value.toJSONString();
+ Either<PropertyDefinition, ActionStatus> convertJsonToObject = convertJsonToObject(jsonString, PropertyDefinition.class);
+ if (convertJsonToObject.isRight()) {
+ return Either.right(convertJsonToObject.right().value());
+ }
+ PropertyDefinition propertyDefinition = convertJsonToObject.left().value();
+ // PropertyDefinition propertyDefinition =
+ // gson.fromJson(jsonString , PropertyDefinition.class);
+ String uniqueId = UniqueIdBuilder.buildPropertyUniqueId("resourceId", (String) propertyName);
+ propertyDefinition.setUniqueId(uniqueId);
+ properties.put(propertyName, propertyDefinition);
+ }
+
+ // Set keySet = root.keySet();
+ // for (Object propertyName : keySet){
+ // JSONObject val = (JSONObject) root.get(propertyName);
+ // String jsonString = val.toJSONString();
+ // Either<PropertyDefinition,ActionStatus> convertJsonToObject =
+ // convertJsonToObject(jsonString, PropertyDefinition.class);
+ // if (convertJsonToObject.isRight()){
+ // return Either.right(convertJsonToObject.right().value());
+ // }
+ // PropertyDefinition propertyDefinition =
+ // convertJsonToObject.left().value();
+ // //PropertyDefinition propertyDefinition =
+ // gson.fromJson(jsonString , PropertyDefinition.class);
+ // String uniqueId =
+ // UniqueIdBuilder.buildPropertyUniqueId("resourceId",
+ // (String)propertyName);
+ // propertyDefinition.setUniqueId(uniqueId);
+ // properties.put((String)propertyName,propertyDefinition);
+ // }
+ return Either.left(properties);
+ } catch (ParseException e) {
+ log.info("Property conetnt is invalid - {}", data);
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ }
+
+ // private Either<Map<String,PropertyDefinition>,ActionStatus>
+ // getProperty(String data){
+ // Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
+ // PropertyConstraintDeserialiser propertyConstraintDeserialiser = new
+ // PropertyConstraintDeserialiser();
+ // Gson gson = new
+ // GsonBuilder().registerTypeAdapter(constraintType,propertyConstraintDeserialiser).create();
+ // JSONParser parser = new JSONParser();
+ // JSONObject root;
+ // try {
+ // Map<String,PropertyDefinition> properties = new
+ // HashMap<String,PropertyDefinition>();
+ // root = (JSONObject) parser.parse(data);
+ // Set keySet = root.keySet();
+ // for (Object propertyName : keySet){
+ // JSONObject val = (JSONObject) root.get(propertyName);
+ // String jsonString = val.toJSONString();
+ // PropertyDefinition propertyDefinition = gson.fromJson(jsonString ,
+ // PropertyDefinition.class);
+ // String uniqueId = UniqueIdBuilder.buildPropertyUniqueId("resourceId",
+ // (String)propertyName);
+ // propertyDefinition.setUniqueId(uniqueId);
+ // properties.put((String)propertyName,propertyDefinition);
+ // }
+ // return Either.left(properties);
+ // } catch (ParseException e) {
+ // log.error("Property conetnt is invalid - {}",data);
+ // return Either.right(ActionStatus.INVALID_CONTENT);
+ // }
+ // }
+ //
+ // private Either<UiProperty, ActionStatus> getUiProperty(String data) {
+ // try{
+ // Gson gson = new Gson();
+ // UiProperty uiProperty = gson.fromJson(data, UiProperty.class);
+ // return Either.left(uiProperty);
+ // }catch(JsonSyntaxException e){
+ // log.warn("Problem create UiProperty from {}",data);
+ // log.debug("Problem create UiProperty from {}",data,e);
+ // return Either.right(ActionStatus.INVALID_CONTENT);
+ // }
+ // }
+
+ private String propertyToJson(Map.Entry<String, PropertyDefinition> property) {
+ // Type constraintType = new TypeToken<PropertyConstraint>()
+ // {}.getType();
+ // Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new
+ // PropertyConstraintDeserialiser()).create();
+ JSONObject root = new JSONObject();
+ String propertyName = property.getKey();
+ PropertyDefinition propertyDefinition = property.getValue();
+ // String jsonPropertyDefinition = gson.toJson(propertyDefinition);
+ // root.put(propertyName, jsonPropertyDefinition);
+ JSONObject propertyDefinitionO = getPropertyDefinitionJSONObject(propertyDefinition);
+ root.put(propertyName, propertyDefinitionO);
+ propertyDefinition.getType();
+ return root.toString();
+ }
+
+ private JSONObject getPropertyDefinitionJSONObject(PropertyDefinition propertyDefinition) {
+
+ Either<String, ActionStatus> either = convertObjectToJson(propertyDefinition);
+ if (either.isRight()) {
+ return new JSONObject();
+ }
+ String value = either.left().value();
+ try {
+ JSONObject root = (JSONObject) new JSONParser().parse(value);
+ return root;
+ } catch (ParseException e) {
+ log.info("failed to convert input to json");
+ log.debug("failed to convert to json", e);
+ return new JSONObject();
+ }
+
+ }
+
+ // private JSONObject getPropertyDefinitionJSONObject(PropertyDefinition
+ // propertyDefinition) {
+ // JSONObject root = new JSONObject();
+ // root.put("type", propertyDefinition.getType());
+ // root.put("required", propertyDefinition.isRequired());
+ // root.put("defaultValue", propertyDefinition.getDefaultValue());
+ // root.put("description", propertyDefinition.getDescription());
+ // root.put("isPassword", propertyDefinition.isPassword());
+ // List<PropertyConstraint> constraints =
+ // propertyDefinition.getConstraints();
+ // for (PropertyConstraint p : constraints){
+ // p.toString();
+ // }
+ // root.put("constraints", propertyDefinition.getConstraints());
+ // return root;
+ // }
+
+ private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
+ T t = null;
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
+ try {
+ log.trace("convert json to object. json=\n{}", data);
+ t = gson.fromJson(data, clazz);
+ if (t == null) {
+ log.info("object is null after converting from json");
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ } catch (Exception e) {
+ // INVALID JSON
+ log.info("failed to convert from json");
+ log.debug("failed to convert from json", e);
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ return Either.left(t);
+ }
+
+ private <T> Either<String, ActionStatus> convertObjectToJson(PropertyDefinition propertyDefinition) {
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintSerialiser()).create();
+ try {
+ log.trace("convert object to json. propertyDefinition={}", propertyDefinition.toString());
+ String json = gson.toJson(propertyDefinition);
+ if (json == null) {
+ log.info("object is null after converting to json");
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ return Either.left(json);
+ } catch (Exception e) {
+ // INVALID JSON
+ log.info("failed to convert to json");
+ log.debug("failed to convert fto json", e);
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+
+ }
+
+ private PropertyBusinessLogic getPropertyBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class);
+ return propertytBl;
+ }
+
+ // private class UiProperty{
+ // String type;
+ // String source;
+ // String name;
+ // String description;
+ // public String getType() {
+ // return type;
+ // }
+ // public void setType(String type) {
+ // this.type = type;
+ // }
+ // public String getSource() {
+ // return source;
+ // }
+ // public void setSource(String source) {
+ // this.source = source;
+ // }
+ // 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/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
new file mode 100644
index 0000000000..565911eaa9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig.Feature;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+public class RepresentationUtils {
+
+ private static Logger log = LoggerFactory.getLogger(RepresentationUtils.class.getName());
+
+ public static class ResourceRep {
+
+ }
+
+ /**
+ * Build Representation of given Object
+ *
+ * @param elementToRepresent
+ * @return
+ * @throws IOException
+ * @throws JsonGenerationException
+ * @throws JsonMappingException
+ */
+ public static <T> Object toRepresentation(T elementToRepresent) throws IOException, JsonGenerationException, JsonMappingException {
+
+ // return theResource;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false);
+ mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+ return mapper.writeValueAsString(elementToRepresent);
+ }
+
+ public static <T> T fromRepresentation(String json, Class<T> clazz) {
+ ObjectMapper mapper = new ObjectMapper();
+ T object = null;
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false);
+ mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+ try {
+ object = mapper.readValue(json, clazz);
+ } catch (Exception e) {
+ log.error("Error when parsing JSON of object of type {}", clazz.getSimpleName(), e);
+ } // return null in case of exception
+
+ return object;
+ }
+
+ public static ArtifactDefinition convertJsonToArtifactDefinition(String content, Class<ArtifactDefinition> clazz) {
+
+ JsonObject jsonElement = new JsonObject();
+ ArtifactDefinition resourceInfo = null;
+ try {
+ Gson gson = new Gson();
+ jsonElement = gson.fromJson(content, jsonElement.getClass());
+ JsonElement artifactGroupValue = jsonElement.get(Constants.ARTIFACT_GROUP_TYPE_FIELD);
+ if (artifactGroupValue != null && !artifactGroupValue.isJsonNull()) {
+ String groupValueUpper = artifactGroupValue.getAsString().toUpperCase();
+ if (!ArtifactGroupTypeEnum.getAllTypes().contains(groupValueUpper)) {
+ StringBuilder sb = new StringBuilder();
+ for (String value : ArtifactGroupTypeEnum.getAllTypes()) {
+ sb.append(value).append(", ");
+ }
+ log.debug("artifactGroupType is {}. valid values are: {}", groupValueUpper, sb.toString());
+ return null;
+ } else {
+ jsonElement.remove(Constants.ARTIFACT_GROUP_TYPE_FIELD);
+ jsonElement.addProperty(Constants.ARTIFACT_GROUP_TYPE_FIELD, groupValueUpper);
+ }
+ }
+ String payload = null;
+ JsonElement artifactPayload = jsonElement.get(Constants.ARTIFACT_PAYLOAD_DATA);
+ if (artifactPayload != null && !artifactPayload.isJsonNull()) {
+ payload = artifactPayload.getAsString();
+ }
+ jsonElement.remove(Constants.ARTIFACT_PAYLOAD_DATA);
+ resourceInfo = gson.fromJson(jsonElement, clazz);
+ resourceInfo.setPayloadData(payload);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeArtifactInformationInvalidError, "Artifact Upload / Update");
+ BeEcompErrorManager.getInstance().logBeArtifactInformationInvalidError("Artifact Upload / Update");
+ log.debug("Failed to convert the content {} to object. {}", content.substring(0, Math.min(50, content.length())), e);
+ }
+
+ return resourceInfo;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java
new file mode 100644
index 0000000000..e853ee4f7f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonSyntaxException;
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+public class RequirementsServlet extends BeGenericServlet {
+
+ private static Logger log = LoggerFactory.getLogger(RequirementsServlet.class.getName());
+
+ @PUT
+ @Path("resources/{resourceId}/requirements/{requirementId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Requirement", httpMethod = "PUT", notes = "Returns updated requirement", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource requirement updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateRequirement(@ApiParam(value = "resource id to update with new requirement", required = true) @PathParam("resourceId") final String resourceId,
+ @ApiParam(value = "requirement id to update", required = true) @PathParam("requirementId") final String requirementId, @ApiParam(value = "Resource property to update", required = true) String requirementData,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ // Convert RequirementDefinition from JSON
+ // TODO: it's going to be another object, probably. This is placeholder
+ // for sake of JSON validation
+ // RequirementDefinition requirementDefinition;
+ ResponseFormat responseFormat;
+ try {
+ // requirementDefinition = gson.fromJson(requirementData,
+ // RequirementDefinition.class);
+ // .....
+
+ // TODO pass real entity
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
+ } catch (JsonSyntaxException e) {
+ // INVALID JSON
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return buildErrorResponse(responseFormat);
+ } catch (Exception e) {
+ log.debug("Unexpected error: {}", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java
new file mode 100644
index 0000000000..673187b0a1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
+import org.openecomp.sdc.be.info.ArtifactAccessInfo;
+import org.openecomp.sdc.be.resources.api.IResourceUploader;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/resources/available")
+public class ResourceArtifactDownloadServlet extends ToscaDaoServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ResourceArtifactDownloadServlet.class.getName());
+
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ // @GET
+ // @Path("/{resourceName}/{resourceVersion}/artifacts")
+ // @Produces(MediaType.APPLICATION_JSON)
+ // public Response getResourceArtifactList(@PathParam("resourceName") final
+ // String resourceName,
+ // @PathParam("resourceVersion") final String resourceVersion,
+ // @Context final HttpServletRequest request){
+ //
+ //
+ // String url = request.getMethod() + " " + request.getRequestURI();
+ // log.info("Start handle request of {}", url);
+ //
+ // Response response = null;
+ //
+ // // get artifact list from dao
+ // IResourceUploader resourceDao =
+ // getResourceUploader(request.getSession().getServletContext());
+ // if (resourceDao == null){
+ // log.error("resource dao cannot be found");
+ // response = buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ // "Resource dao cannot be found");
+ // return response;
+ // }
+ // Either<List<ESArtifactData>, ResourceUploadStatus> getArtifactsStatus =
+ // resourceDao.getArtifacts(resourceName, resourceVersion);
+ //
+ // response =
+ // getLogic(request.getSession().getServletContext()).createArtifactListResponse(resourceName,
+ // getArtifactsStatus, getServletPath(request));
+ //
+ // log.info("Finish handle request of {} | result = {}", url, response.getStatus() );
+ // return response;
+ //
+ // }
+
+ @GET
+ @Path("/{resourceName}/{resourceVersion}/artifacts/{artifactName}")
+ // @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response getResourceArtifactByName(@PathParam("resourceName") final String resourceName, @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ try {
+ // get the artifact data
+ String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName);
+
+ IResourceUploader resouceUploader = getResourceUploader(request.getSession().getServletContext());
+ if (resouceUploader == null) {
+ return buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "");
+
+ }
+ Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = resouceUploader.getArtifact(artifactId);
+
+ DownloadArtifactLogic logic = getLogic(request.getSession().getServletContext());
+ if (logic == null) {
+ return buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "");
+
+ }
+ response = logic.downloadArtifact(resourceName, resourceVersion, artifactName, getArtifactStatus, artifactId);
+
+ log.info("Finish handle request of {} | result = {}", url, response.getStatus());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Resource Artifact By Name");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource Artifact By Name");
+ log.debug("getResourceArtifactByName failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @GET
+ @Path("/{resourceName}/{resourceVersion}/artifacts/{artifactName}/metadata")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getResourceArtifactMetadata(@PathParam("resourceName") final String resourceName, @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ Response response = null;
+ try {
+ IResourceUploader resourceDao = getResourceUploader(request.getSession().getServletContext());
+ if (resourceDao == null) {
+ log.error("resource dao cannot be found");
+ response = buildResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Resource dao cannot be found");
+ return response;
+ }
+
+ String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName);
+ Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = resourceDao.getArtifact(artifactId);
+
+ if (getArtifactStatus.isRight()) {
+ ResourceUploadStatus status = getArtifactStatus.right().value();
+ if (status == ResourceUploadStatus.COMPONENT_NOT_EXIST) {
+ response = Response.status(HttpStatus.SC_NOT_FOUND).build();
+ log.debug("Could not find artifact for with id: {}", artifactId);
+ } else {
+ response = Response.status(HttpStatus.SC_NO_CONTENT).build();
+ log.debug("Could not find artifact for with id: {}", artifactId);
+ }
+ return response;
+ } else {
+ ESArtifactData artifactData = getArtifactStatus.left().value();
+ log.debug("found artifact with id: {}", artifactId);
+ ArtifactAccessInfo artifactInfo = new ArtifactAccessInfo(artifactData);
+ String artifactDataJson = gson.toJson(artifactInfo);
+ response = Response.status(HttpStatus.SC_OK).entity(artifactDataJson).type(MediaType.APPLICATION_JSON_TYPE).build();
+
+ log.info("Finish handle request of {} | result = {}", url, response.getStatus());
+ return response;
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Resource Artifact Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource Artifact Metadata");
+ log.debug("getResourceArtifactMetadata failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+
+ }
+
+ @Override
+ public Logger getLogger() {
+ return log;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
new file mode 100644
index 0000000000..5cd765abe0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
@@ -0,0 +1,180 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.File;
+
+import javax.annotation.Resource;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/upload")
+@Api(value = "Resources Catalog Upload", description = "Upload resource yaml")
+@Singleton
+public class ResourceUploadServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ResourceUploadServlet.class.getName());
+ public static final String NORMATIVE_TYPE_RESOURCE = "multipart";
+ public static final String USER_TYPE_RESOURCE = "user-resource";
+ public static final String USER_TYPE_RESOURCE_UI_IMPORT = "user-resource-ui-import";
+
+ public enum ResourceAuthorityTypeEnum {
+ NORMATIVE_TYPE_BE(NORMATIVE_TYPE_RESOURCE, true, false), USER_TYPE_BE(USER_TYPE_RESOURCE, true, true), USER_TYPE_UI(USER_TYPE_RESOURCE_UI_IMPORT, false, true);
+
+ private String urlPath;
+ private boolean isBackEndImport, isUserTypeResource;
+
+ public static ResourceAuthorityTypeEnum findByUrlPath(String urlPath) {
+ ResourceAuthorityTypeEnum found = null;
+ for (ResourceAuthorityTypeEnum curr : ResourceAuthorityTypeEnum.values()) {
+ if (curr.getUrlPath().equals(urlPath)) {
+ found = curr;
+ break;
+ }
+ }
+ return found;
+ }
+
+ private ResourceAuthorityTypeEnum(String urlPath, boolean isBackEndImport, boolean isUserTypeResource) {
+ this.urlPath = urlPath;
+ this.isBackEndImport = isBackEndImport;
+ this.isUserTypeResource = isUserTypeResource;
+ }
+
+ public String getUrlPath() {
+ return urlPath;
+ }
+
+ public boolean isBackEndImport() {
+ return isBackEndImport;
+ }
+
+ public boolean isUserTypeResource() {
+ return isUserTypeResource;
+ }
+ }
+
+ @Resource
+ private ResourceImportManager resourceImportManager;
+
+ @POST
+ @Path("/{resourceAuthority}")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource from yaml", httpMethod = "POST", notes = "Returns created resource", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Resource already exist") })
+ public Response uploadMultipart(
+ @ApiParam(value = "validValues: normative-resource / user-resource", allowableValues = NORMATIVE_TYPE_RESOURCE + "," + USER_TYPE_RESOURCE + ","
+ + USER_TYPE_RESOURCE_UI_IMPORT) @PathParam(value = "resourceAuthority") final String resourceAuthority,
+ @ApiParam("FileInputStream") @FormDataParam("resourceZip") File file, @ApiParam("ContentDisposition") @FormDataParam("resourceZip") FormDataContentDisposition contentDispositionHeader,
+ @ApiParam("resourceMetadata") @FormDataParam("resourceMetadata") String resourceInfoJsonString, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ // updateResourse Query Parameter if false checks if already exist
+ @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) {
+
+ init(request.getSession().getServletContext());
+ try {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+ Wrapper<UploadResourceInfo> uploadResourceInfoWrapper = new Wrapper<>();
+ Wrapper<String> yamlStringWrapper = new Wrapper<>();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // When we get an errorResponse it will be filled into the
+ // responseWrapper
+ validateAuthorityType(responseWrapper, resourceAuthority);
+
+ ResourceAuthorityTypeEnum resourceAuthorityEnum = ResourceAuthorityTypeEnum.findByUrlPath(resourceAuthority);
+
+ commonGeneralValidations(responseWrapper, userWrapper, uploadResourceInfoWrapper, resourceAuthorityEnum, userId, resourceInfoJsonString);
+
+ fillPayload(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), resourceInfoJsonString, resourceAuthorityEnum, file);
+
+ // PayLoad Validations
+ commonPayloadValidations(responseWrapper, yamlStringWrapper, userWrapper.getInnerElement(), uploadResourceInfoWrapper.getInnerElement());
+
+ specificResourceAuthorityValidations(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, resourceInfoJsonString, resourceAuthorityEnum);
+
+ if (responseWrapper.isEmpty()) {
+ handleImport(responseWrapper, userWrapper.getInnerElement(), uploadResourceInfoWrapper.getInnerElement(), yamlStringWrapper.getInnerElement(), resourceAuthorityEnum, createNewVersion, null);
+ }
+
+ return responseWrapper.getInnerElement();
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Upload Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Upload Resource");
+ log.debug("upload resource failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /********************************************************************************************************************/
+
+ private void init(ServletContext context) {
+ init(log);
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ resourceImportManager = webApplicationContext.getBean(ResourceImportManager.class);
+ resourceImportManager.init(context);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java
new file mode 100644
index 0000000000..e3d39610a8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java
@@ -0,0 +1,692 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.ResourceMetadataDefinition;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Resources Catalog", description = "Resources Servlet")
+@Singleton
+public class ResourcesServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ResourcesServlet.class.getName());
+
+ @POST
+ @Path("/resources")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource", httpMethod = "POST", notes = "Returns created resource", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Resource already exist") })
+ public Response createResource(@ApiParam(value = "Resource object to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
+ init(log);
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ // UI Import
+ if (isUIImport(data)) {
+ performUIImport(responseWrapper, data, request, userId, null);
+ }
+ // UI Create
+ else {
+
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ Either<Resource, ResponseFormat> convertResponse = parseToResource(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse resource");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+
+ Resource resource = convertResponse.left().value();
+ Either<Resource, ResponseFormat> actionResponse = businessLogic.createResource(resource, modifier, null, null);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to create resource");
+ response = buildErrorResponse(actionResponse.right().value());
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), representation);
+ }
+ responseWrapper.setInnerElement(response);
+ }
+
+ return responseWrapper.getInnerElement();
+
+ // return response;
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Resource");
+ log.debug("create resource failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ private boolean isUIImport(String data) {
+ boolean isUIImport;
+ try {
+ JSONObject json = new JSONObject(data);
+ String payloadName = json.getString(ImportUtils.Constants.UI_JSON_PAYLOAD_NAME);
+ isUIImport = payloadName != null && !payloadName.isEmpty();
+ } catch (Exception e) {
+ log.debug("failed to parse json sent from client, json:{}", data);
+ isUIImport = false;
+ }
+ return isUIImport;
+ }
+
+ private void performUIImport(Wrapper<Response> responseWrapper, String data, final HttpServletRequest request, String userId, String resourceUniqueId) throws FileNotFoundException {
+
+ Wrapper<User> userWrapper = new Wrapper<>();
+ Wrapper<UploadResourceInfo> uploadResourceInfoWrapper = new Wrapper<>();
+ Wrapper<String> yamlStringWrapper = new Wrapper<>();
+ String resourceInfoJsonString = data;
+
+ ResourceAuthorityTypeEnum resourceAuthorityEnum = ResourceAuthorityTypeEnum.USER_TYPE_UI;
+
+ commonGeneralValidations(responseWrapper, userWrapper, uploadResourceInfoWrapper, resourceAuthorityEnum, userId, resourceInfoJsonString);
+
+ // TODO suspect next line is unnecessary
+ userWrapper.getInnerElement();
+ if (!CsarValidationUtils.isCsarPayloadName(uploadResourceInfoWrapper.getInnerElement().getPayloadName())) {
+ fillPayload(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), resourceInfoJsonString, resourceAuthorityEnum, null);
+
+ // PayLoad Validations
+ commonPayloadValidations(responseWrapper, yamlStringWrapper, userWrapper.getInnerElement(), uploadResourceInfoWrapper.getInnerElement());
+ }
+ specificResourceAuthorityValidations(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, resourceInfoJsonString, resourceAuthorityEnum);
+
+ if (responseWrapper.isEmpty()) {
+ handleImport(responseWrapper, userWrapper.getInnerElement(), uploadResourceInfoWrapper.getInnerElement(), yamlStringWrapper.getInnerElement(), resourceAuthorityEnum, true, resourceUniqueId);
+ }
+ }
+
+ public Either<Resource, ResponseFormat> parseToResource(String resourceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(resourceJson, user, Resource.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE);
+ }
+
+ public Either<Resource, ResponseFormat> parseToLightResource(String resourceJson, User user) {
+ Either<Resource, ResponseFormat> ret = getComponentsUtils().convertJsonToObjectUsingObjectMapper(resourceJson, user, Resource.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.RESOURCE);
+ if (ret.isLeft()) {// drop unwanted data (sent from UI in update flow)
+ ret.left().value().setRequirements(null);
+ ret.left().value().setCapabilities(null);
+ }
+ return ret;
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}")
+ public Response deleteResource(@PathParam("resourceId") final String resourceId, @Context final HttpServletRequest request) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ String resourceIdLower = resourceId.toLowerCase();
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteResource(resourceIdLower, modifier);
+
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete resource");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource");
+ log.debug("delete resource failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @DELETE
+ @Path("/resources/{resourceName}/{version}")
+ public Response deleteResourceByNameAndVersion(@PathParam("resourceName") final String resourceName, @PathParam("version") final String version, @Context final HttpServletRequest request) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteResourceByNameAndVersion(resourceName, version, modifier);
+
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete resource");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource");
+ log.debug("delete resource failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/resources/{resourceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Resource", httpMethod = "GET", notes = "Returns resource according to resourceId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Resource not found") })
+ public Response getResourceById(@PathParam("resourceId") final String resourceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ String resourceIdLower = resourceId.toLowerCase();
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ log.trace("get resource with id {}", resourceId);
+ Either<Resource, ResponseFormat> actionResponse = businessLogic.getResource(resourceIdLower, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get resource");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource");
+ log.debug("get resource failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @GET
+ @Path("/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Resource by name and version", httpMethod = "GET", notes = "Returns resource according to resourceId", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Resource not found") })
+ public Response getResourceByNameAndVersion(@PathParam("resourceName") final String resourceName, @PathParam("resourceVersion") final String resourceVersion, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Response response = null;
+ try {
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ Either<List<Resource>, ResponseFormat> actionResponse = businessLogic.getResourceByNameAndVersion(resourceName, resourceVersion, userId);
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Resource by name and version");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource by name and version");
+ log.debug("get resource failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @GET
+ @Path("/resources/validate-name/{resourceName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "validate resource name", httpMethod = "GET", notes = "checks if the chosen resource name is available ", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource found"), @ApiResponse(code = 403, message = "Restricted operation") })
+ public Response validateResourceName(@PathParam("resourceName") final String resourceName, @QueryParam("subtype") String resourceType, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Response response = null;
+ try {
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ if (resourceType != null && !ResourceTypeEnum.contains(resourceType)) {
+ log.debug("invalid resource type received");
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ return response;
+
+ }
+ ResourceTypeEnum typeEnum = null;
+ if (resourceType != null) {
+ typeEnum = ResourceTypeEnum.valueOf(resourceType);
+ }
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse = businessLogic.validateResourceNameExists(resourceName, typeEnum, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to validate resource name");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Validate Resource Name");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Resource Name");
+ log.debug("validate resource name failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/resources/certified/abstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCertifiedAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ // TODO: any validations???
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+ try {
+
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ Either<List<Resource>, ResponseFormat> actionResponse = businessLogic.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all abstract resources");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resources = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resources);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Certified Abstract Resources");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Abstract Resources");
+ log.debug("getCertifiedAbstractResources failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/resources/certified/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCertifiedNotAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ // TODO: any vlidations???
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ Either<List<Resource>, ResponseFormat> actionResponse = businessLogic.getAllCertifiedResources(false, HighestFilterEnum.ALL, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract resources");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object resources = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resources);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Certified Non Abstract Resources");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Non Abstract Resources");
+ log.debug("getCertifiedNotAbstractResources failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+
+ }
+
+ @PUT
+ @Path("/resources/{resourceId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource Metadata", httpMethod = "PUT", notes = "Returns updated resource metadata", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource metadata updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content") })
+ public Response updateResourceMetadata(@PathParam("resourceId") final String resourceId, @ApiParam(value = "Resource metadata to be updated", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ String resourceIdLower = resourceId.toLowerCase();
+ Either<Resource, ResponseFormat> updateInfoResource = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, modifier, Resource.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.RESOURCE);
+ if (updateInfoResource.isRight()) {
+ log.debug("failed to parse resource metadata");
+ response = buildErrorResponse(updateInfoResource.right().value());
+ return response;
+ }
+ Either<Resource, ResponseFormat> actionResponse = businessLogic.updateResourceMetadata(resourceIdLower,
+ updateInfoResource.left().value(), null, modifier, false);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update resource metadata");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Resource Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Metadata");
+ log.debug("Update Resource Metadata failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @PUT
+ @Path("/resources/{resourceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Resource", httpMethod = "PUT", notes = "Returns updated resource", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Resource already exist") })
+ public Response updateResource(@ApiParam(value = "Resource object to be updated", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @PathParam(value = "resourceId") String resourceId) {
+
+ userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
+ init(log);
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ // UI Import
+ if (isUIImport(data)) {
+ performUIImport(responseWrapper, data, request, userId, resourceId);
+ } else {
+
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ Either<Resource, ResponseFormat> convertResponse = parseToLightResource(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse resource");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+
+ Resource resource = convertResponse.left().value();
+ Either<Resource, ResponseFormat> actionResponse = businessLogic.validateAndUpdateResourceFromCsar(resource, modifier, null, null, resourceId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update resource");
+ response = buildErrorResponse(actionResponse.right().value());
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation);
+ }
+ responseWrapper.setInnerElement(response);
+ }
+
+ return responseWrapper.getInnerElement();
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Resource");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource");
+ log.debug("update resource failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ /*
+ * @GET
+ *
+ * @Path("/resources/latestversion/notabstract")
+ *
+ * @Consumes(MediaType.APPLICATION_JSON)
+ *
+ * @Produces(MediaType.APPLICATION_JSON) public Response getLatestVersionNotAbstractResources(@Context final HttpServletRequest request) { //TODO: any vlidations??? ServletContext context = request.getSession().getServletContext();
+ *
+ * String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); Response response=null;
+ *
+ * try {
+ *
+ * ResourceBusinessLogic businessLogic = getResourceBL(context);
+ *
+ * Either<List<Resource>, ResponseFormat> actionResponse = businessLogic.getLatestVersionResources(false, HighestFilterEnum.HIGHEST_ONLY);
+ *
+ *
+ * if (actionResponse.isRight()){ log.debug( "failed to get all non abstract resources"); return buildErrorResponse(actionResponse.right().value()); } return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ * actionResponse.left().value());
+ *
+ * } catch (Exception e){ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName. BeRestApiGeneralError, "Get Certified Non Abstract Resources"); log.debug("getCertifiedNotAbstractResources failed with exception", e); response =
+ * buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus. GENERAL_ERROR)); return response;
+ *
+ * } }
+ */
+ public static List<PropertyDefinition> convertMapToList(Map<String, PropertyDefinition> properties) {
+ if (properties == null) {
+ return null;
+ }
+
+ List<PropertyDefinition> definitions = new ArrayList<>();
+ for (Entry<String, PropertyDefinition> entry : properties.entrySet()) {
+ String name = entry.getKey();
+ PropertyDefinition propertyDefinition = entry.getValue();
+ propertyDefinition.setName(name);
+ definitions.add(propertyDefinition);
+ }
+
+ return definitions;
+ }
+
+ @GET
+ @Path("/resources/csar/{csaruuid}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Resource", httpMethod = "POST", notes = "Returns resource created from csar uuid", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource retrieced"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response getResourceFromCsar(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @PathParam(value = "csaruuid") String csarUUID) {
+
+ init(log);
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // retrieve user details
+ userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
+ User user = new User();
+ user.setUserId(userId);
+
+ log.debug("user id is {}", userId);
+
+ Response response = null;
+
+ try {
+
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+
+ Either<Resource, ResponseFormat> eitherResource = businessLogic.getLatestResourceFromCsarUuid(csarUUID, user);
+
+ // validate response
+ if (eitherResource.isRight()) {
+ log.debug("failed to get resource from csarUuid : {}", csarUUID);
+ // response =
+ // buildErrorResponse(eitherResource.right().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), eitherResource.right().value());
+ } else {
+ Object representation = RepresentationUtils.toRepresentation(eitherResource.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation);
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ log.debug("get resource by csar failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
new file mode 100644
index 0000000000..7e7068f5d7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
@@ -0,0 +1,728 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Service Catalog", description = "Service Servlet")
+@Singleton
+public class ServiceServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(ServiceServlet.class.getName());
+
+ @POST
+ @Path("/services")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Service", httpMethod = "POST", notes = "Returns created service", response = Service.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Service created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Service already exist") })
+ public Response createService(@ApiParam(value = "Service object to be created", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse service");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+
+ Service service = convertResponse.left().value();
+ Either<Service, ResponseFormat> actionResponse = businessLogic.createService(service, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("Failed to create service");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), result);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Create Service");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Service");
+ log.debug("create service failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ public Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ @GET
+ @Path("/services/validate-name/{serviceName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "validate service name", httpMethod = "GET", notes = "checks if the chosen service name is available ", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation") })
+ public Response validateServiceName(@PathParam("serviceName") final String serviceName, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse = businessLogic.validateServiceNameExists(serviceName, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get validate service name");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Validate Service Name");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
+ log.debug("validate service name failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/audit-records/{componentType}/{componentUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "get component audit records", httpMethod = "GET", notes = "get audit records for a service or a resource", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation") })
+ public Response getComponentAuditRecords(@PathParam("componentType") final String componentType, @PathParam("componentUniqueId") final String componentUniqueId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ init(log);
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ Wrapper<Response> responseWrapper = new Wrapper<Response>();
+ Wrapper<String> uuidWrapper = new Wrapper<String>();
+ Wrapper<String> versionWrapper = new Wrapper<String>();
+ Wrapper<User> userWrapper = new Wrapper<User>();
+ Wrapper<ComponentTypeEnum> componentWrapper = new Wrapper<ComponentTypeEnum>();
+ try {
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ validateComponentType(responseWrapper, componentWrapper, componentType);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(), componentWrapper.getInnerElement(), componentUniqueId, context);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit = getServiceBL(context).getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId);
+
+ if (eitherServiceAudit.isRight()) {
+ Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+ } else {
+ List<Map<String, Object>> auditRecords = eitherServiceAudit.left().value();
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), auditRecords);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Validate Service Name");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
+ log.debug("get Service Audit Records failed with exception", e);
+ Response errorResponse = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(errorResponse);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) {
+
+ if (componentTypeEnum == ComponentTypeEnum.RESOURCE) {
+ Either<Resource, ResponseFormat> eitherResource = getResourceBL(context).getResource(componentUniqueId, user);
+ if (eitherResource.isLeft()) {
+ uuidWrapper.setInnerElement(eitherResource.left().value().getUUID());
+ versionWrapper.setInnerElement(eitherResource.left().value().getVersion());
+ } else {
+ responseWrapper.setInnerElement(buildErrorResponse(eitherResource.right().value()));
+ }
+
+ } else {
+ Either<Service, ResponseFormat> eitherService = getServiceBL(context).getService(componentUniqueId, user);
+ if (eitherService.isLeft()) {
+ uuidWrapper.setInnerElement(eitherService.left().value().getUUID());
+ versionWrapper.setInnerElement(eitherService.left().value().getVersion());
+ } else {
+ responseWrapper.setInnerElement(buildErrorResponse(eitherService.right().value()));
+
+ }
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}")
+ public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier);
+
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete service");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Service");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
+ log.debug("delete service failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceName}/{version}")
+ public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("version") final String version, @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier);
+
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete service");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Delete Service");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
+ log.debug("delete service failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @PUT
+ @Path("/services/{serviceId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Service Metadata", httpMethod = "PUT", notes = "Returns updated service", response = Service.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service Updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
+ public Response updateServiceMetadata(@PathParam("serviceId") final String serviceId, @ApiParam(value = "Service object to be Updated", required = true) String data, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+
+ Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse service");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ Service updatedService = convertResponse.left().value();
+ Either<Service, ResponseFormat> actionResponse = businessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update service");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Service Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
+ log.debug("update service metadata failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @GET
+ @Path("/services/{serviceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Service", httpMethod = "GET", notes = "Returns service according to serviceId", response = Service.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") })
+ public Response getServiceById(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ log.debug("get service with id {}", serviceId);
+ Either<Service, ResponseFormat> actionResponse = businessLogic.getService(serviceIdLower, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get service");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Service");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
+ log.debug("get service failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @GET
+ @Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve Service", httpMethod = "GET", notes = "Returns service according to name and version", response = Service.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") })
+ public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Either<Service, ResponseFormat> actionResponse = businessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId);
+
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get Service by name and version");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service by name and version");
+ log.debug("get service failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/distribution-state/{state}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Update Service Distribution State", httpMethod = "POST", notes = "service with the changed distribution status")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service distribution state changed"), @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 403, message = "Service is not available for distribution"),
+ @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 404, message = "Requested service was not found"), @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") })
+ public Response updateServiceDistributionState(@ApiParam(value = "DistributionChangeInfo - get comment out of body", required = true) LifecycleChangeInfoWithAction jsonChangeInfo, @PathParam("serviceId") final String serviceId,
+ @ApiParam(allowableValues = "approve, reject", required = true) @PathParam("state") final String state, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Either<Service, ResponseFormat> actionResponse = businessLogic.changeServiceDistributionState(serviceId, state, jsonChangeInfo, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to Update Service Distribution State");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update Service Distribution State");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Distribution State");
+ log.debug("updateServiceDistributionState failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/distribution/{env}/activate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Activate distribution", httpMethod = "POST", notes = "activate distribution")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 409, message = "Service cannot be distributed due to missing deployment artifacts"), @ApiResponse(code = 404, message = "Requested service was not found"),
+ @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") })
+ public Response activateDistribution(@PathParam("serviceId") final String serviceId, @PathParam("env") final String env, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Either<Service, ResponseFormat> distResponse = businessLogic.activateDistribution(serviceId, env, modifier, request);
+
+ if (distResponse.isRight()) {
+ log.debug("failed to activate service distribution");
+ response = buildErrorResponse(distResponse.right().value());
+ return response;
+ }
+ Service service = distResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Activate Distribution");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
+ log.debug("activate distribution failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/distribution/{did}/markDeployed")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Mark distribution as deployed", httpMethod = "POST", notes = "relevant audit record will be created")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Service was marked as deployed"), @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 403, message = "Service is not available"),
+ @ApiResponse(code = 400, message = "Invalid content / Missing content"), @ApiResponse(code = 404, message = "Requested service was not found"), @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") })
+ public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId, @PathParam("did") final String did, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Either<Service, ResponseFormat> distResponse = businessLogic.markDistributionAsDeployed(serviceId, did, modifier);
+
+ if (distResponse.isRight()) {
+ log.debug("failed to mark distribution as deployed");
+ response = buildErrorResponse(distResponse.right().value());
+ return response;
+ }
+ Service service = distResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Mark Distribution As Deployed");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Mark Distribution As Deployed");
+ log.debug("mark distribution as deployed failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/tempUrlToBeDeleted")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Internal Server Error. Please try again later.") })
+ public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+ try {
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ Service service = (businessLogic.getService(serviceId, modifier)).left().value();
+ Either<Service, ResponseFormat> res = (businessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED));
+
+ if (res.isRight()) {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "tempUrlToBeDeleted");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("tempUrlToBeDeleted");
+ log.debug("failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ @GET
+ @Path("/services/toscatoheat/{artifactName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @ApiOperation(value = "Download service artifact", httpMethod = "GET", notes = "Returns downloaded artifact", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Artifact downloaded"), @ApiResponse(code = 401, message = "Authorization required"), @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 404, message = "Artifact not found") })
+ public Response downloadServiceArtifact(@PathParam("artifactName") final String artifactName, @Context final HttpServletRequest request) {
+ Response response = null;
+ String instanceIdHeader = request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER);
+ String requestURI = request.getRequestURI();
+
+ try {
+ log.debug("artifact name = {}", artifactName);
+ ServletContext context = request.getSession().getServletContext();
+
+ Either<byte[], ResponseFormat> executeCommand = executeCommand(artifactName);
+
+ if (executeCommand.isRight()) {
+ log.debug("Failed to convert tosca {} to heat", artifactName);
+ ResponseFormat responseFormat = executeCommand.right().value();
+ response = buildErrorResponse(responseFormat);
+ } else {
+ log.debug("Succeed to convert tosca {} to heat", artifactName);
+ byte[] value = executeCommand.left().value();
+ InputStream is = new ByteArrayInputStream(value);
+
+ Map<String, String> headers = new HashMap<>();
+ String heatFileName = null;
+ if (artifactName.indexOf(".") > -1) {
+ heatFileName = artifactName.substring(0, artifactName.indexOf(".")) + ".heat";
+ } else {
+ heatFileName = artifactName + ".heat";
+ }
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(heatFileName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, is, headers);
+ }
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "download heat artifact");
+ log.error("download artifact failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Either<byte[], ResponseFormat> executeCommand(String artifactName) {
+
+ Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
+ String toscaFilesDir = configuration.getToscaFilesDir();
+ if (toscaFilesDir == null) {
+ toscaFilesDir = "/apps/jetty/base/be/config/tosca";
+ }
+ String heatTranslator = configuration.getHeatTranslatorPath();
+ if (heatTranslator == null) {
+ heatTranslator = "/home/m98835/heat-translator-0.3.0/heat_translator.py";
+ }
+
+ log.debug("toscaFilesDir={}", toscaFilesDir);
+ log.debug("heatTranslator={}", heatTranslator);
+
+ StringBuffer output = new StringBuffer();
+
+ String heatHeader = configuration.getHeatEnvArtifactHeader();
+ String heatFooter = configuration.getHeatEnvArtifactFooter();
+
+ output.append(heatHeader + "\n");
+
+ MessageFormat mf = new MessageFormat("python {0} --template-file={1}/{2} --template-type=tosca");
+
+ log.debug("After creating message format");
+
+ Object[] objArray = { heatTranslator, toscaFilesDir, artifactName };
+ String command = null;
+ try {
+ command = mf.format(objArray);
+ } catch (Exception e) {
+ log.debug("Failed to convert message format", e);
+ }
+
+ log.debug("Going to run command {}", command);
+
+ Process p;
+ try {
+ p = Runtime.getRuntime().exec(command);
+ int waitFor = p.waitFor();
+ log.debug("waitFor = {}", waitFor);
+
+ if (waitFor != 0) {
+ log.error("Failed running the command {}", command);
+ return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+
+ String line = "";
+ while ((line = reader.readLine()) != null) {
+ output.append(line + "\n");
+ }
+
+ } catch (Exception e) {
+ log.error("Failed running the command {} {}", command, e);
+ e.printStackTrace();
+ return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ output.append(heatFooter);
+
+ return Either.left(output.toString().getBytes());
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java
new file mode 100644
index 0000000000..eea2bfdc42
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.info.ServletJsonResponse;
+import org.openecomp.sdc.be.resources.api.IResourceUploader;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.slf4j.Logger;
+import org.springframework.web.context.WebApplicationContext;
+
+public abstract class ToscaDaoServlet extends BeGenericServlet {
+ public abstract Logger getLogger();
+
+ protected IResourceUploader getResourceUploader(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+
+ if (webApplicationContextWrapper == null) {
+ getLogger().error("Failed to get web application context from context.");
+ return null;
+ }
+
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+
+ return webApplicationContext.getBean(IResourceUploader.class);
+
+ }
+
+ // protected IToscaYamlBuilder getToscaYamlBuilder(ServletContext context){
+ // WebAppContextWrapper webApplicationContextWrapper =
+ // (WebAppContextWrapper) context
+ // .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ //
+ // if (webApplicationContextWrapper == null) {
+ // getLogger().error("Failed to get web application context from context.");
+ // return null;
+ // }
+ //
+ // WebApplicationContext webApplicationContext =
+ // webApplicationContextWrapper
+ // .getWebAppContext(context);
+ //
+ // return webApplicationContext.getBean(IToscaYamlBuilder.class);
+ //
+ // }
+
+ protected DownloadArtifactLogic getLogic(ServletContext context) {
+ DownloadArtifactLogic downloadLogic = (DownloadArtifactLogic) context.getAttribute(Constants.DOWNLOAD_ARTIFACT_LOGIC_ATTR);
+
+ if (downloadLogic == null) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInitializationError, "DownloadArtifactLogic from context");
+ BeEcompErrorManager.getInstance().logBeInitializationError("DownloadArtifactLogic from context");
+ return null;
+ }
+ return downloadLogic;
+ }
+
+ protected Response buildResponse(int status, String errorMessage) {
+
+ ServletJsonResponse jsonResponse = new ServletJsonResponse();
+ jsonResponse.setDescription(errorMessage);
+ jsonResponse.setSource(Constants.CATALOG_BE);
+
+ Response response = Response.status(status).entity(jsonResponse).build();
+
+ return response;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
new file mode 100644
index 0000000000..0825a25cbe
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.Map;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Types Fetch Servlet", description = "Types Fetch Servlet")
+@Singleton
+public class TypesFetchServlet extends AbstractValidationsServlet {
+
+ private static Logger log = LoggerFactory.getLogger(TypesFetchServlet.class.getName());
+
+ @GET
+ @Path("dataTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get data types", httpMethod = "GET", notes = "Returns data types", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "datatypes"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "Data types not found") })
+ public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<Response>();
+ Wrapper<User> userWrapper = new Wrapper<User>();
+ ServletContext context = request.getSession().getServletContext();
+
+ try {
+ init(log);
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ PropertyBusinessLogic businessLogic = getPropertyBL(context);
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = businessLogic.getAllDataTypes();
+
+ if (allDataTypes.isRight()) {
+ log.info("Failed to get all dara types. Reason - ", allDataTypes.right().value());
+ Response errorResponse = buildErrorResponse(allDataTypes.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+
+ // return buildErrorResponse(allDataTypes.right().value());
+ } else {
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypes);
+ responseWrapper.setInnerElement(okResponse);
+ }
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get all data types");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property");
+ log.debug("get all data types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+ private PropertyBusinessLogic getPropertyBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class);
+ return propertytBl;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
new file mode 100644
index 0000000000..6ba8c521f1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -0,0 +1,317 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+import javax.annotation.Resource;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
+import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
+import org.openecomp.sdc.be.components.impl.DataTypeImportManager;
+import org.openecomp.sdc.be.components.impl.GroupTypeImportManager;
+import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
+import org.openecomp.sdc.be.components.impl.PolicyTypeImportManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/uploadType")
+@Api(value = "Catalog Types Upload", description = "Upload Type from yaml")
+@Singleton
+public class TypesUploadServlet extends AbstractValidationsServlet {
+ @Resource
+ private CapabilityTypeImportManager capabilityTypeImportManager;
+
+ @Resource
+ private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
+
+ @Resource
+ private CategoriesImportManager categoriesImportManager;
+
+ @Resource
+ private DataTypeImportManager dataTypeImportManager;
+
+ @Resource
+ private GroupTypeImportManager groupTypeImportManager;
+
+ @Resource
+ private PolicyTypeImportManager policyTypeImportManager;
+
+ private static Logger log = LoggerFactory.getLogger(TypesUploadServlet.class.getName());
+
+ @POST
+ @Path("/capability")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Capability Type from yaml", httpMethod = "POST", notes = "Returns created Capability Type", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Capability Type created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Capability Type already exist") })
+ public Response uploadCapabilityType(@ApiParam("FileInputStream") @FormDataParam("capabilityTypeZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ capabilityTypeImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> CapabilityTypeImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper, () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name());
+
+ }
+
+ @POST
+ @Path("/interfaceLifecycle")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Interface Lyfecycle Type from yaml", httpMethod = "POST", notes = "Returns created Interface Lifecycle Type", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Interface Lifecycle Type created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Interface Lifecycle Type already exist") })
+ public Response uploadInterfaceLifecycleType(@ApiParam("FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ interfaceLifecycleTypeImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> InterfaceLifecycleTypeImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper, () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types");
+ }
+
+ @POST
+ @Path("/categories")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Categories from yaml", httpMethod = "POST", notes = "Returns created categories", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Categories created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Category already exist") })
+ public Response uploadCategories(@ApiParam("FileInputStream") @FormDataParam("categoriesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ categoriesImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> CategoriesImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper, () -> categoriesImportManager.createCategories(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "categories");
+
+ }
+
+ @POST
+ @Path("/datatypes")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create Categories from yaml", httpMethod = "POST", notes = "Returns created data types", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "Data types created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "Data types already exist") })
+ public Response uploadDataTypes(@ApiParam("FileInputStream") @FormDataParam("dataTypesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ dataTypeImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> DataTypeImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createDataTypes(responseWrapper, ymlPayload);
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.DataType.getName());
+
+ }
+
+ @POST
+ @Path("/grouptypes")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create GroupTypes from yaml", httpMethod = "POST", notes = "Returns created group types", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "group types created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "group types already exist") })
+ public Response uploadGroupTypes(@ApiParam("FileInputStream") @FormDataParam("groupTypesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ groupTypeImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> GroupTypeImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createGroupTypes(responseWrapper, ymlPayload);
+
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.GroupType.getName());
+ }
+
+ @POST
+ @Path("/policytypes")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Create PolicyTypes from yaml", httpMethod = "POST", notes = "Returns created policy types", response = Response.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "policy types created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 409, message = "policy types already exist") })
+ public Response uploadPolicyTypes(@ApiParam("FileInputStream") @FormDataParam("policyTypesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+
+ policyTypeImportManager = initElementTypeImportManager(request.getSession().getServletContext(), () -> PolicyTypeImportManager.class);
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createPolicyTypes(responseWrapper, ymlPayload);
+
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.PolicyType.getName());
+
+ }
+
+ private Response uploadElementTypeServletLogic(ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod, File file, final HttpServletRequest request, String creator, String elementTypeName) {
+ init(log);
+ String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
+ try {
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+ Wrapper<String> yamlStringWrapper = new Wrapper<>();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ validateUserRole(responseWrapper, userWrapper.getInnerElement());
+ }
+
+ if (responseWrapper.isEmpty()) {
+ validateDataNotNull(responseWrapper, file);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ fillZipContents(yamlStringWrapper, file);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement());
+ }
+
+ return responseWrapper.getInnerElement();
+
+ } catch (Exception e) {
+ log.debug("create {} failed with exception: {}", elementTypeName, e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create " + elementTypeName);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private <T> void createElementsType(Wrapper<Response> responseWrapper, Supplier<Either<T, ResponseFormat>> elementsCreater) {
+ Either<T, ResponseFormat> eitherResult = elementsCreater.get();
+ if (eitherResult.isRight()) {
+ Response response = buildErrorResponse(eitherResult.right().value());
+ responseWrapper.setInnerElement(response);
+ } else {
+ Response response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), eitherResult.left().value());
+ responseWrapper.setInnerElement(response);
+ }
+ }
+
+ // data types
+ private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml) {
+ final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> dataTypeImportManager.createDataTypes(dataTypesYml);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.DATA_TYPE_ALREADY_EXIST, NodeTypeEnum.DataType.name());
+ }
+
+ // group types
+ private void createGroupTypes(Wrapper<Response> responseWrapper, String groupTypesYml) {
+ final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> groupTypeImportManager.createGroupTypes(groupTypesYml);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.GROUP_TYPE_ALREADY_EXIST, NodeTypeEnum.GroupType.name());
+
+ }
+
+ // policy types
+ private void createPolicyTypes(Wrapper<Response> responseWrapper, String policyTypesYml) {
+ final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> policyTypeImportManager.createPolicyTypes(policyTypesYml);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.POLICY_TYPE_ALREADY_EXIST, NodeTypeEnum.PolicyType.name());
+
+ }
+
+ // data types
+ private <ElementTypeDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper, Supplier<Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml,
+ ActionStatus alreadyExistStatus, String elementTypeName) {
+
+ Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
+
+ if (eitherResult.isRight()) {
+ Response response = buildErrorResponse(eitherResult.right().value());
+ responseWrapper.setInnerElement(response);
+ } else {
+ Object representation;
+ try {
+ List<ImmutablePair<ElementTypeDefinition, Boolean>> list = eitherResult.left().value();
+ ActionStatus status = ActionStatus.OK;
+ if (list != null) {
+
+ // Group result by the right value - true or false.
+ // I.e., get the number of data types which are new and
+ // which are old.
+ Map<Boolean, List<ImmutablePair<ElementTypeDefinition, Boolean>>> collect = list.stream().collect(Collectors.groupingBy(ImmutablePair<ElementTypeDefinition, Boolean>::getRight));
+ if (collect != null) {
+ Set<Boolean> keySet = collect.keySet();
+ if (keySet.size() == 1) {
+ Boolean isNew = keySet.iterator().next();
+ if (isNew.booleanValue() == true) {
+ // all data types created at the first time
+ status = ActionStatus.CREATED;
+ } else {
+ // All data types already exists
+
+ status = alreadyExistStatus;
+ }
+ }
+ }
+ }
+ representation = RepresentationUtils.toRepresentation(eitherResult.left().value());
+
+ Response response = buildOkResponse(getComponentsUtils().getResponseFormat(status), representation);
+ responseWrapper.setInnerElement(response);
+
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create " + elementTypeName);
+ log.debug("failed to convert {} to json", elementTypeName, e);
+ Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(response);
+ }
+ }
+ }
+
+ private <T> T initElementTypeImportManager(ServletContext context, Supplier<Class<T>> classGetter) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ T elementTypeImortManager = webApplicationContext.getBean(classGetter.get());
+ return elementTypeImortManager;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java
new file mode 100644
index 0000000000..c700c31a64
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java
@@ -0,0 +1,516 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.FunctionalMenuInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jcabi.aspects.Loggable;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import com.wordnik.swagger.annotations.ApiResponse;
+import com.wordnik.swagger.annotations.ApiResponses;
+
+import fj.data.Either;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/user")
+@Api(value = "User Administration", description = "User admininstarator operations")
+@Singleton
+public class UserAdminServlet extends BeGenericServlet {
+
+ private static final String ROLE_DELIMITER = ",";
+ private static Logger log = LoggerFactory.getLogger(UserAdminServlet.class.getName());
+
+ /***************************************
+ * API start
+ *************************************************************/
+
+ /* User by userId CRUD start */
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all user details
+ @GET
+ @Path("/{userId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "retrieve user details", httpMethod = "GET", notes = "Returns user details according to userId", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns user Ok"), @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"),
+ @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response get(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+
+ try {
+ Either<User, ActionStatus> either = userAdminManager.getUser(userId, false);
+
+ if (either.isRight()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
+ } else {
+ if (either.left().value() != null) {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ } else {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get User");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get User");
+ log.debug("get user failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // update user - internal API
+ /*
+ * @POST
+ *
+ * @Path("/{userId}")
+ *
+ * @Consumes(MediaType.APPLICATION_JSON)
+ *
+ * @Produces(MediaType.APPLICATION_JSON)
+ *
+ * @ApiOperation(value = "update user - internal API", notes = "Update user", response = User.class)
+ *
+ * @ApiResponses(value = {
+ *
+ * @ApiResponse(code = 200, message = "Update user OK"),
+ *
+ * @ApiResponse(code = 400, message = "Invalid Content."),
+ *
+ * @ApiResponse(code = 403, message = "Missing information/Restricted operation"),
+ *
+ * @ApiResponse(code = 404, message = "User not found"),
+ *
+ * @ApiResponse(code = 405, message = "Method Not Allowed"),
+ *
+ * @ApiResponse(code = 409, message = "User already exists"),
+ *
+ * @ApiResponse(code = 500, message = "Internal Server Error") }) public Response updateUser(@ApiParam(value="userId of user to get", required=true) @PathParam("userId") final String UserIdUpdateUser,
+ *
+ * @Context final HttpServletRequest request,
+ *
+ * @ApiParam(value="json describe the update user", required=true) String data,
+ *
+ * @HeaderParam(value = Constants.USER_ID_HEADER) String modifierAttId) {
+ *
+ * ServletContext context = request.getSession().getServletContext();
+ *
+ * String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url);
+ *
+ * // get modifier id User modifier = new User(); modifier.setUserId(modifierAttId); log.debug("modifier id is {}", modifierAttId);
+ *
+ * Response response = null;
+ *
+ * try { UserAdminBuisinessLogic businessLogic = getUserAdminManager(context); User updateInfoUser = getComponentsUtils().convertJsonToObject(data, modifier, User.class, AuditingActionEnum.UPDATE_USER).left().value(); Either<User, ResponseFormat>
+ * updateUserResponse = null;// businessLogic.updateUser(modifier, UserIdUpdateUser, updateInfoUser);
+ *
+ * if (updateUserResponse.isRight()) { log.debug("failed to update user metadata"); response = buildErrorResponse(updateUserResponse.right().value()); return response; } response =
+ * buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateUserResponse.left().value()); return response;
+ *
+ * } catch (Exception e) { BeEcompErrorManager.getInstance().processEcompError(EcompErrorName. BeRestApiGeneralError, "Update User Metadata"); log.debug("Update User Metadata failed with exception", e); response =
+ * buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus. GENERAL_ERROR)); return response;
+ *
+ * } }
+ *
+ */
+ /* User userId CRUD end */
+
+ /* User role CRUD start */
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve user role
+ @GET
+ @Path("/{userId}/role")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "retrieve user role", notes = "Returns user role according to userId", response = String.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns user role Ok"), @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"),
+ @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getRole(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getRole) Start handle request of {}", url);
+
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+
+ try {
+ Either<User, ActionStatus> either = userAdminManager.getUser(userId, false);
+ if (either.isRight()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
+ } else {
+ if (either.left().value() != null) {
+ String roleJson = ("{ \"role\" : \"" + either.left().value().getRole().toString() + "\" }");
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), roleJson);
+ } else {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get User Role");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get User Role");
+ log.debug("Get user role failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // update user role
+ @POST
+ @Path("/{userId}/role")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "update user role", notes = "Update user role", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Update user OK"), @ApiResponse(code = 400, message = "Invalid Content."), @ApiResponse(code = 403, message = "Missing information/Restricted operation"),
+ @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 409, message = "User already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response updateUserRole(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String UserIdUpdateUser, @Context final HttpServletRequest request,
+ @ApiParam(value = "json describe the update role", required = true) String data, @HeaderParam(value = Constants.USER_ID_HEADER) String modifierUserId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(modifierUserId);
+ log.debug("modifier id is {}", modifierUserId);
+
+ Response response = null;
+
+ try {
+ UserBusinessLogic businessLogic = getUserAdminManager(context);
+ User updateInfoUser = getComponentsUtils().convertJsonToObject(data, modifier, User.class, AuditingActionEnum.UPDATE_USER).left().value();
+ Either<User, ResponseFormat> updateUserResponse = businessLogic.updateUserRole(modifier, UserIdUpdateUser, updateInfoUser.getRole());
+
+ if (updateUserResponse.isRight()) {
+ log.debug("failed to update user role");
+ response = buildErrorResponse(updateUserResponse.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateUserResponse.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update User Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update User Metadata");
+ log.debug("Update User Role failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ /* User role CRUD end */
+
+ /* New user CRUD start */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "add user", httpMethod = "POST", notes = "Provision new user", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 201, message = "New user created"), @ApiResponse(code = 400, message = "Invalid Content."), @ApiResponse(code = 403, message = "Missing information"),
+ @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 409, message = "User already exists"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response createUser(@Context final HttpServletRequest request, @ApiParam(value = "json describe the user", required = true) String newUserData, @HeaderParam(value = Constants.USER_ID_HEADER) String modifierAttId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(modifierAttId);
+ log.debug("modifier id is {}", modifierAttId);
+
+ Response response = null;
+
+ try {
+ UserBusinessLogic businessLogic = getUserAdminManager(context);
+ User newUserInfo = getComponentsUtils().convertJsonToObject(newUserData, modifier, User.class, AuditingActionEnum.ADD_USER).left().value();
+ Either<User, ResponseFormat> createUserResponse = businessLogic.createUser(modifier, newUserInfo);
+
+ if (createUserResponse.isRight()) {
+ log.debug("failed to create user");
+ response = buildErrorResponse(createUserResponse.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), createUserResponse.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Update User Metadata");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update User Metadata");
+ log.debug("Create User failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ /* New user CRUD end */
+
+ /* User authorization start */
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // User Authorization
+ @GET
+ @Path("/authorize")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+
+ @ApiOperation(value = "authorize", notes = "authorize user", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns user Ok"), @ApiResponse(code = 403, message = "Restricted Access"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response authorize(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam("HTTP_CSP_FIRSTNAME") String firstName, @HeaderParam("HTTP_CSP_LASTNAME") String lastName,
+ @HeaderParam("HTTP_CSP_EMAIL") String email) {
+
+ try {
+ userId = (userId != null ? URLDecoder.decode(userId, "UTF-8") : null);
+ firstName = (firstName != null ? URLDecoder.decode(firstName, "UTF-8") : null);
+ lastName = (lastName != null ? URLDecoder.decode(lastName, "UTF-8") : null);
+ email = (email != null ? URLDecoder.decode(email, "UTF-8") : null);
+ } catch (UnsupportedEncodingException e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Authorize User - decode headers");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Authorize User - decode headers");
+ ResponseFormat errorResponseWrapper = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(errorResponseWrapper);
+ }
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User authUser = new User();
+ authUser.setUserId(userId);
+ authUser.setFirstName(firstName);
+ authUser.setLastName(lastName);
+ authUser.setEmail(email);
+ log.debug("auth user id is {}", userId);
+
+ Response response = null;
+ try {
+ UserBusinessLogic userAdminManager = getUserAdminManager(context);
+ Either<User, ResponseFormat> authorize = userAdminManager.authorize(authUser);
+
+ if (authorize.isRight()) {
+ log.debug("authorize user failed");
+ response = buildErrorResponse(authorize.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), authorize.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get ASDC users");
+ log.debug("authorize user failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /* User authorization end */
+
+ @GET
+ @Path("/admins")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "retrieve all administrators", httpMethod = "GET", notes = "Returns all administrators", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns user Ok"), @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getAdminsUser(@PathParam("userId") final String userId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+
+ try {
+ Either<List<User>, ResponseFormat> either = userAdminManager.getAllAdminUsers(request.getSession().getServletContext());
+
+ if (either.isRight()) {
+ log.debug("Failed to get all admin users");
+ return buildErrorResponse(either.right().value());
+ } else {
+ if (either.left().value() != null) {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ } else {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get All Administrators");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Administrators");
+ log.debug("get all admins failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/users")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve the list of all active ASDC users or only group of users having specific roles.", httpMethod = "GET", notes = "Returns list of users with the specified roles, or all of users in the case of empty 'roles' header", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns users Ok"), @ApiResponse(code = 204, message = "No provisioned ASDC users of requested role"), @ApiResponse(code = 403, message = "Restricted Access"),
+ @ApiResponse(code = 400, message = "Missing content"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getUsersList(@Context final HttpServletRequest request, @ApiParam(value = "Any active user's USER_ID") @HeaderParam(Constants.USER_ID_HEADER) final String userId,
+ @ApiParam(value = "TESTER,DESIGNER,PRODUCT_STRATEGIST,OPS,PRODUCT_MANAGER,GOVERNOR, ADMIN OR all users by not typing anything") @QueryParam("roles") final String roles) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ List<String> rolesList = new ArrayList<>();
+ if (roles != null && !roles.trim().isEmpty()) {
+ String[] rolesArr = roles.split(ROLE_DELIMITER);
+ for (String role : rolesArr) {
+ rolesList.add(role.trim());
+ }
+ }
+
+ try {
+ UserBusinessLogic userAdminManager = getUserAdminManager(context);
+ Either<List<User>, ResponseFormat> either = userAdminManager.getUsersList(userId, rolesList, roles);
+
+ if (either.isRight()) {
+ log.debug("Failed to get ASDC users");
+ return buildErrorResponse(either.right().value());
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get ASDC users");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get ASDC users");
+ log.debug("get users failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // delete user
+ @DELETE
+ @Path("/{userId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "delete user", notes = "Delete user", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Update deleted OK"), @ApiResponse(code = 400, message = "Invalid Content."), @ApiResponse(code = 403, message = "Missing information"),
+ @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"), @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response deActivateUser(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userIdHeader) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+ modifier.setUserId(userIdHeader);
+ log.debug("modifier id is {}", userIdHeader);
+
+ Response response = null;
+ try {
+ UserBusinessLogic userAdminManager = getUserAdminManager(context);
+ Either<User, ResponseFormat> deactiveUserResponse = userAdminManager.deActivateUser(modifier, userId);
+
+ if (deactiveUserResponse.isRight()) {
+ log.debug("Failed to deactivate user");
+ response = buildErrorResponse(deactiveUserResponse.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deactiveUserResponse.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeRestApiGeneralError, "Get ASDC users");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get ASDC users");
+ log.debug("deactivate user failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Path("/{userId}/functionalmenu")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "retrieve user details", httpMethod = "GET", notes = "Returns user details according to userId", response = User.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns user Ok"), @ApiResponse(code = 404, message = "User not found"), @ApiResponse(code = 405, message = "Method Not Allowed"),
+ @ApiResponse(code = 500, message = "Internal Server Error") })
+ public Response getFunctionalMenu(@ApiParam(value = "userId of user to get", required = true) @PathParam("userId") final String userId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+
+ try {
+ Either<FunctionalMenuInfo, ActionStatus> functionalMenuResp = userAdminManager.getFunctionalMenu(userId);
+
+ if (functionalMenuResp.isRight()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormatByUserId(functionalMenuResp.right().value(), userId));
+ } else {
+ FunctionalMenuInfo functionalMenuInfo = functionalMenuResp.left().value();
+ if (functionalMenuInfo != null && functionalMenuInfo.getFunctionalMenu() != null) {
+ log.debug("Functional menu fetched is {}", functionalMenuInfo.getFunctionalMenu());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), functionalMenuInfo.getFunctionalMenu());
+ } else {
+ log.debug("Functional menu is null");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get User");
+ log.debug("get user failed with unexpected error: {}", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
new file mode 100644
index 0000000000..4027144911
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
@@ -0,0 +1,315 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.switchover.detector;
+
+import java.net.InetAddress;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.apache.commons.codec.binary.Base64;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.Configuration.SwitchoverDetectorConfig;
+import org.openecomp.sdc.be.dao.rest.HttpRestClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component("switchover-detector")
+public class SwitchoverDetector {
+
+ protected static String SWITCHOVER_DETECTOR_LOG_CONTEXT = "switchover.detector";
+
+ private static Logger switchoverLogger = LoggerFactory.getLogger(SWITCHOVER_DETECTOR_LOG_CONTEXT);
+
+ private SwitchoverDetectorConfig switchoverDetectorConfig;
+
+ private Properties authHeader = null;
+
+ private long detectorInterval = 60;
+
+ private int maxBeQueryAttempts = 3;
+
+ private int maxFeQueryAttempts = 3;
+
+ private Boolean beMatch = null;
+
+ private Boolean feMatch = null;
+
+ private static Logger logger = LoggerFactory.getLogger(SwitchoverDetector.class.getName());
+
+ private volatile String siteMode = SwitchoverDetectorState.UNKNOWN.getState();
+
+ private ScheduledFuture<?> scheduledFuture = null;
+
+ ScheduledExecutorService switchoverDetectorScheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "Switchover-Detector-Task");
+ }
+ });
+
+ SwitchoverDetectorScheduledTask switchoverDetectorScheduledTask = null;
+
+ public enum SwitchoverDetectorState {
+
+ UNKNOWN("unknown"), ACTIVE("active"), STANDBY("standby");
+
+ private String state;
+
+ SwitchoverDetectorState(String state) {
+ this.state = state;
+ }
+
+ public String getState() {
+ return state;
+ }
+ }
+
+ public enum SwitchoverDetectorGroup {
+
+ BE_SET("beSet"), FE_SET("feSet");
+
+ private String group;
+
+ SwitchoverDetectorGroup(String group) {
+ this.group = group;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+ }
+
+ public String getSiteMode() {
+ return siteMode;
+ }
+
+ public void setSiteMode(String mode) {
+ this.siteMode = mode;
+ }
+
+ private Boolean queryBe() {
+ return queryGss(switchoverDetectorConfig.getgBeFqdn(), switchoverDetectorConfig.getBeVip(), maxBeQueryAttempts);
+ }
+
+ private Boolean queryFe() {
+ return queryGss(switchoverDetectorConfig.getgFeFqdn(), switchoverDetectorConfig.getFeVip(), maxFeQueryAttempts);
+ }
+
+ private void setAuthorizationProperties() {
+ String userInfo = switchoverDetectorConfig.getChangePriorityUser() + ":" + switchoverDetectorConfig.getChangePriorityPassword();
+ String auth = "Basic " + new String(new Base64().encode(userInfo.getBytes()));
+ authHeader = new Properties();
+ authHeader.put("Authorization", auth);
+ }
+
+ private void initializeSiteMode() {
+ while (siteMode == SwitchoverDetectorState.UNKNOWN.getState()) {
+
+ beMatch = queryBe();
+ feMatch = queryFe();
+
+ if (beMatch == feMatch && beMatch != null) {
+ if (beMatch) {
+ setSiteMode(SwitchoverDetectorState.ACTIVE.getState());
+ } else {
+ setSiteMode(SwitchoverDetectorState.STANDBY.getState());
+ }
+ }
+ }
+ }
+
+ private Boolean queryGss(String fqdn, String vip, int maxAttempts) {
+
+ Boolean result = null;
+ int attempts = 0;
+
+ while (result == null && (++attempts < maxAttempts)) {
+ try {
+ InetAddress inetAddress = InetAddress.getByName(fqdn);
+ result = inetAddress.getHostAddress().equals(vip);
+
+ } catch (Exception e) {
+ String message = e.getMessage();
+ if (message == null) {
+ message = e.getClass().getName();
+ }
+ switchoverLogger.debug("Error occured during switchover detector query, Result is {}", message);
+ }
+ }
+ if (null == result) {
+ BeEcompErrorManager.getInstance().logFqdnResolveError(SWITCHOVER_DETECTOR_LOG_CONTEXT, "host " + fqdn + " not resolved after " + attempts + " attempts");
+ }
+ return result;
+ }
+
+ public class SwitchoverDetectorScheduledTask implements Runnable {
+
+ public SwitchoverDetectorScheduledTask() {
+
+ }
+
+ @Override
+ public void run() {
+ switchoverLogger.trace("Executing Switchover Detector Task - Start");
+
+ initializeSiteMode();
+
+ Boolean beRes = queryBe();
+ Boolean feRes = queryFe();
+
+ Boolean updateRequired = siteMode == SwitchoverDetectorState.STANDBY.getState() && (beRes || feRes);
+
+ updateSiteModeAndPriority(beRes && feRes, siteMode == SwitchoverDetectorState.STANDBY.getState(), updateRequired);
+
+ beMatch = beRes;
+ feMatch = feRes;
+ }
+
+ ExecutorService switchoverDetectorExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "Switchover-Detector-Thread");
+ }
+ });
+
+ private void updateSiteModeAndPriority(Boolean bothMatch, Boolean previousModeStandby, Boolean updateRequired) {
+ if (bothMatch && previousModeStandby) {
+ logger.trace("Site switch over was done. Site is now in active mode");
+ setSiteMode(SwitchoverDetectorState.ACTIVE.getState());
+ BeEcompErrorManager.getInstance().logSiteSwitchoverInfo(SWITCHOVER_DETECTOR_LOG_CONTEXT, siteMode);
+ } else if (!bothMatch && !previousModeStandby) {
+ logger.trace("Site switch over was done. Site is now in stand-by mode");
+ setSiteMode(SwitchoverDetectorState.STANDBY.getState());
+ BeEcompErrorManager.getInstance().logSiteSwitchoverInfo(SWITCHOVER_DETECTOR_LOG_CONTEXT, siteMode);
+ }
+ if (updateRequired) {
+ changeSitePriority(SwitchoverDetectorGroup.BE_SET.getGroup());
+ changeSitePriority(SwitchoverDetectorGroup.FE_SET.getGroup());
+ publishNetwork();
+ }
+ }
+
+ private void changeSitePriority(String groupToSet) {
+
+ String url = switchoverDetectorConfig.getGroups().get(groupToSet).getChangePriorityUrl();
+ String body = switchoverDetectorConfig.getGroups().get(groupToSet).getChangePriorityBody();
+
+ HttpRestClient httpRestClient = new HttpRestClient();
+
+ try {
+ httpRestClient.doPUT(url, authHeader, body);
+
+ } catch (Exception e) {
+ String message = e.getMessage();
+ if (message == null) {
+ message = e.getClass().getName();
+ }
+ switchoverLogger.error("Error occured during change site priority request, Result is {}", message);
+ }
+
+ }
+
+ private void publishNetwork() {
+
+ String url = switchoverDetectorConfig.getPublishNetworkUrl();
+ String body = switchoverDetectorConfig.getPublishNetworkBody();
+
+ HttpRestClient httpRestClient = new HttpRestClient();
+
+ try {
+ httpRestClient.doPOST(url, authHeader, body);
+
+ } catch (Exception e) {
+ String message = e.getMessage();
+ if (message == null) {
+ message = e.getClass().getName();
+ }
+ switchoverLogger.error("Error occured during publish network request, Result is {}", message);
+ }
+ }
+
+ }
+
+ @PostConstruct
+ private void init() {
+ logger.info("Enter init method of SwitchoverDetector");
+
+ switchoverDetectorConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getSwitchoverDetector();
+
+ if (!switchoverDetectorConfig.getEnabled()) {
+ logger.info("switchover detector service is disabled");
+ return;
+ }
+
+ Long detectorIntervalConfig = switchoverDetectorConfig.getInterval();
+ if (detectorIntervalConfig != null) {
+ detectorInterval = detectorIntervalConfig.longValue();
+ }
+
+ Integer maxAttempts = switchoverDetectorConfig.getBeResolveAttempts();
+ if (maxAttempts != null) {
+ maxBeQueryAttempts = maxAttempts.intValue();
+ }
+ maxAttempts = switchoverDetectorConfig.getFeResolveAttempts();
+ if (maxAttempts != null) {
+ maxFeQueryAttempts = maxAttempts.intValue();
+ }
+
+ setAuthorizationProperties();
+ logger.info("switchover detector service is enabled, interval is {} seconds", detectorInterval);
+
+ this.switchoverDetectorScheduledTask = new SwitchoverDetectorScheduledTask();
+ startSwitchoverDetectorTask();
+ logger.trace("Exit init method of SwitchoverDetector");
+
+ }
+
+ @PreDestroy
+ private void destroy() {
+
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
+ }
+
+ if (switchoverDetectorScheduler != null) {
+ switchoverDetectorScheduler.shutdown();
+ }
+
+ }
+
+ public void startSwitchoverDetectorTask() {
+ if (this.scheduledFuture == null) {
+ this.scheduledFuture = this.switchoverDetectorScheduler.scheduleAtFixedRate(switchoverDetectorScheduledTask, 0, detectorInterval, TimeUnit.SECONDS);
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java
new file mode 100644
index 0000000000..85b4493c8e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.List;
+
+import org.openecomp.sdc.generator.data.ArtifactType;
+
+public class ArtifactTypes {
+ private List<ArtifactType> artifactTypes;
+
+ public List<ArtifactType> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+ public void setArtifactTypes(List<ArtifactType> artifactTypes) {
+ this.artifactTypes = artifactTypes;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java
new file mode 100644
index 0000000000..7fecced358
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import org.openecomp.sdc.be.model.Component;
+
+public class CSARTool {
+ public static byte[] createCsar(Component component) {
+
+ final String TOSCA_META_VERSION = "1.0";
+ final String CSAR_VERSION = component.getCsarVersion();
+ final String CREATED_BY = component.getCreatorFullName();
+ final String ENTRY_DEFINITIONS = component.getNormalizedName();
+
+ /*
+ * StringBuilder builder = new StringBuilder(); try( FileOutputStream f = new FileOutputStream("test.zip"); ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(f)); ){ }
+ */
+
+ return null;
+ }
+
+ public static String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
+ final String BLOCK_0_TEMPLATE = "TOSCA-Meta-File-Version: %s";
+
+ return null;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
new file mode 100644
index 0000000000..d1f2557413
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
@@ -0,0 +1,261 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.resources.data.CapabilityData;
+import org.openecomp.sdc.be.resources.data.RequirementData;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CapabiltyRequirementConvertor {
+ private static CapabiltyRequirementConvertor instance;
+
+ protected CapabiltyRequirementConvertor() {
+
+ }
+
+ public static synchronized CapabiltyRequirementConvertor getInstance() {
+ if (instance == null) {
+ instance = new CapabiltyRequirementConvertor();
+ }
+ return instance;
+ }
+
+ private static Logger log = LoggerFactory.getLogger(CapabiltyRequirementConvertor.class.getName());
+
+ public Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceCapabilties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate) {
+
+ Map<String, List<CapabilityDefinition>> capabilitiesInst = componentInstance.getCapabilities();
+ if (capabilitiesInst != null && !capabilitiesInst.isEmpty()) {
+ Map<String, ToscaTemplateCapability> capabilties = new HashMap<>();
+ capabilitiesInst.entrySet().forEach(e -> {
+ List<CapabilityDefinition> capList = e.getValue();
+ if (capList != null && !capList.isEmpty()) {
+ capList.forEach(c -> {
+ convertOverridenProperties(componentInstance, dataTypes, capabilties, c);
+ });
+ }
+ });
+ if (capabilties != null && !capabilties.isEmpty()) {
+ nodeTemplate.setCapabilities(capabilties);
+ }
+ }
+ return Either.left(nodeTemplate);
+ }
+
+ private void convertOverridenProperties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c) {
+ List<ComponentInstanceProperty> properties = c.getProperties();
+ if (properties != null && !properties.isEmpty()) {
+ properties.stream().filter(p -> (p.getValueUniqueUid() != null)).forEach(p -> {
+ convertOverridenProperty(componentInstance, dataTypes, capabilties, c, p);
+ });
+ }
+ }
+
+ private void convertOverridenProperty(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c, ComponentInstanceProperty p) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exist overriden property {} for capabity {} with value {}", p.getName(), c.getName(), p.getValue());
+ }
+ ToscaTemplateCapability toscaTemplateCapability = capabilties.get(c.getName());
+ if (toscaTemplateCapability == null) {
+ toscaTemplateCapability = new ToscaTemplateCapability();
+ capabilties.put(c.getName(), toscaTemplateCapability);
+ }
+ Map<String, Object> toscaCapProp = toscaTemplateCapability.getProperties();
+ if (toscaCapProp == null) {
+ toscaCapProp = new HashMap<>();
+ }
+ Object convertedValue = convertInstanceProperty(dataTypes, componentInstance, p);
+ toscaCapProp.put(p.getName(), convertedValue);
+ toscaTemplateCapability.setProperties(toscaCapProp);
+ }
+
+ private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) {
+ log.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
+ String propertyType = prop.getType();
+ String innerType = null;
+ if (prop.getSchema() != null && prop.getSchema().getProperty() != null) {
+ innerType = prop.getSchema().getProperty().getType();
+ }
+ Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes);
+ return convertedValue;
+ }
+
+ public Either<ToscaNodeType, ToscaError> convertRequirements(Component component, ToscaNodeType nodeType) {
+ List<Map<String, ToscaRequirement>> toscaRequirements = convertRequirementsAsList(component);
+ if (!toscaRequirements.isEmpty()) {
+ nodeType.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+
+ return Either.left(nodeType);
+ }
+
+ public Either<SubstitutionMapping, ToscaError> convertRequirements(Component component, SubstitutionMapping substitutionMapping) {
+ Map<String, ToscaRequirement> toscaRequirements = convertRequirementsAsMap(component);
+ if (!toscaRequirements.isEmpty()) {
+ substitutionMapping.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+
+ return Either.left(substitutionMapping);
+ }
+
+ private List<Map<String, ToscaRequirement>> convertRequirementsAsList(Component component) {
+ Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
+ List<Map<String, ToscaRequirement>> toscaRequirements = new ArrayList<>();
+ if (requirements != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
+ entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())))).forEach(r -> {
+ ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, isNodeType, r);
+ Map<String, ToscaRequirement> requirement = new HashMap<>();
+
+ requirement.put(pair.left, pair.right);
+ toscaRequirements.add(requirement);
+ });
+
+ log.debug("Finish convert Requirements for node type");
+ }
+ } else {
+ log.debug("No Requirements for node type");
+ }
+ return toscaRequirements;
+ }
+
+ private Map<String, ToscaRequirement> convertRequirementsAsMap(Component component) {
+ Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
+ Map<String, ToscaRequirement> toscaRequirements = new HashMap<>();
+ if (requirements != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
+ entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())))).forEach(r -> {
+ ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, isNodeType, r);
+ toscaRequirements.put(pair.left, pair.right);
+ });
+
+ log.debug("Finish convert Requirements for node type");
+ }
+ } else {
+ log.debug("No Requirements for node type");
+ }
+ return toscaRequirements;
+ }
+
+ private ImmutablePair<String, ToscaRequirement> convertRequirement(Component component, boolean isNodeType, RequirementDefinition r) {
+ String name = r.getName();
+ if (!isNodeType) {
+ name = r.getOwnerName() + "." + name;
+ }
+ log.debug("the requirement {} belongs to resource {} ", name, component.getUniqueId());
+ ToscaRequirement toscaRequirement = new ToscaRequirement();
+
+ List<Object> occurences = new ArrayList<>();
+ occurences.add(Integer.valueOf(r.getMinOccurrences()));
+ if (r.getMaxOccurrences().equals(RequirementData.MAX_OCCURRENCES)) {
+ occurences.add(r.getMaxOccurrences());
+ } else {
+ occurences.add(Integer.valueOf(r.getMaxOccurrences()));
+ }
+ toscaRequirement.setOccurrences(occurences);
+ // toscaRequirement.setOccurrences(createOcurrencesRange(requirementDefinition.getMinOccurrences(),
+ // requirementDefinition.getMaxOccurrences()));
+ toscaRequirement.setNode(r.getNode());
+ toscaRequirement.setCapability(r.getCapability());
+ toscaRequirement.setRelationship(r.getRelationship());
+
+ ImmutablePair<String, ToscaRequirement> pair = new ImmutablePair<String, ToscaRequirement>(name, toscaRequirement);
+ return pair;
+ }
+
+ public Map<String, ToscaCapability> convertCapabilities(Component component, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities();
+ Map<String, ToscaCapability> toscaCapabilities = new HashMap<>();
+ if (capabilities != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
+ entry.getValue().stream().filter(c -> (!isNodeType || (isNodeType && component.getUniqueId().equals(c.getOwnerId())))).forEach(c -> {
+ convertCapabilty(component, toscaCapabilities, isNodeType, c, dataTypes);
+
+ });
+ }
+ } else {
+ log.debug("No Capabilities for node type");
+ }
+
+ return toscaCapabilities;
+ }
+
+ private void convertCapabilty(Component component, Map<String, ToscaCapability> toscaCapabilities, boolean isNodeType, CapabilityDefinition c, Map<String, DataTypeDefinition> dataTypes) {
+ String name = c.getName();
+ if (!isNodeType) {
+ name = c.getOwnerName() + "." + name;
+ }
+ log.debug("the capabilty {} belongs to resource {} ", name, component.getUniqueId());
+ ToscaCapability toscaCapability = new ToscaCapability();
+ toscaCapability.setDescription(c.getDescription());
+ toscaCapability.setType(c.getType());
+
+ List<Object> occurences = new ArrayList<>();
+ occurences.add(Integer.valueOf(c.getMinOccurrences()));
+ if (c.getMaxOccurrences().equals(CapabilityData.MAX_OCCURRENCES)) {
+ occurences.add(c.getMaxOccurrences());
+ } else {
+ occurences.add(Integer.valueOf(c.getMaxOccurrences()));
+ }
+ toscaCapability.setOccurrences(occurences);
+
+ toscaCapability.setValid_source_types(c.getValidSourceTypes());
+ List<ComponentInstanceProperty> properties = c.getProperties();
+ if (properties != null && !properties.isEmpty()) {
+ Map<String, ToscaProperty> toscaProperties = new HashMap<>();
+ for (PropertyDefinition property : properties) {
+ ToscaProperty toscaProperty = PropertyConvertor.getInstance().convertProperty(dataTypes, property, true);
+ toscaProperties.put(property.getName(), toscaProperty);
+ }
+ toscaCapability.setProperties(toscaProperties);
+ }
+ toscaCapabilities.put(name, toscaCapability);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
new file mode 100644
index 0000000000..c8aa188e30
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -0,0 +1,649 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.io.IOException;
+import org.apache.commons.codec.binary.Base64;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperation;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.openecomp.sdc.generator.data.Artifact;
+import org.openecomp.sdc.generator.data.ArtifactType;
+import org.openecomp.sdc.generator.data.GenerationData;
+import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
+import com.google.gson.Gson;
+
+import fj.data.Either;
+
+/**
+ * @author tg851x
+ *
+ */
+@org.springframework.stereotype.Component("csar-utils")
+public class CsarUtils {
+ private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
+
+ @Autowired
+ private ArtifactCassandraDao artifactCassandraDao;
+ @Autowired
+ private ComponentsUtils componentsUtils;
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+ @Autowired
+ private ArtifactsBusinessLogic artifactsBusinessLogic;
+ @Autowired
+ protected ServiceOperation serviceOperation;
+
+ @javax.annotation.Resource
+ private ServiceBusinessLogic serviceBusinessLogic;
+
+ private Gson gson = new Gson();
+
+ private static final String DEFINITIONS_PATH = "Definitions/";
+ private static final String ARTIFACTS_PATH = "Artifacts/";
+ private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta";
+ private static final String TOSCA_META_VERSION = "1.0";
+ private static final String CSAR_VERSION = "1.1";
+
+ /**
+ *
+ * @param component
+ * @param getFromCS
+ * @param isInCertificationRequest
+ * @param shouldLock
+ * @param inTransaction
+ * @return
+ */
+ public Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest, boolean shouldLock, boolean inTransaction) {
+ return createCsar(component, getFromCS, isInCertificationRequest, false, shouldLock, inTransaction);
+ }
+
+ private Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+ final String CREATED_BY = component.getCreatorFullName();
+
+ String fileName;
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ fileName = artifactDefinition.getArtifactName();
+
+ String toscaBlock0 = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, CREATED_BY, fileName);
+
+ byte[] toscaBlock0Byte = toscaBlock0.getBytes();
+
+ Either<byte[], ResponseFormat> generateCsarZipResponse = generateCsarZip(toscaBlock0Byte, component, getFromCS, isInCertificationRequest, mockGenerator, shouldLock, inTransaction);
+
+ if (generateCsarZipResponse.isRight()) {
+ return Either.right(generateCsarZipResponse.right().value());
+ }
+
+ return Either.left(generateCsarZipResponse.left().value());
+ }
+
+ private Either<byte[], ResponseFormat> generateCsarZip(byte[] toscaBlock0Byte, Component component, boolean getFromCS, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+
+ ZipOutputStream zip = null;
+ ByteArrayOutputStream out = null;
+ try {
+ out = new ByteArrayOutputStream();
+ zip = new ZipOutputStream(out);
+
+ zip.putNextEntry(new ZipEntry(TOSCA_META_PATH_FILE_NAME));
+ zip.write(toscaBlock0Byte);
+ Either<ZipOutputStream, ResponseFormat> populateZip = populateZip(component, getFromCS, zip, isInCertificationRequest, mockGenerator, shouldLock, inTransaction);
+ if (populateZip.isRight()) {
+ log.debug("Failed to populate CSAR zip file {}", populateZip.right().value());
+ return Either.right(populateZip.right().value());
+ }
+ zip = populateZip.left().value();
+
+ zip.finish();
+ byte[] byteArray = out.toByteArray();
+
+ return Either.left(byteArray);
+ } catch (IOException e) {
+ log.debug("createCsar failed IOexception", e);
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(responseFormat);
+ } finally {
+ try {
+ if (zip != null) {
+ zip.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ } catch (Exception e) {
+ log.error("Failed to close resources ", e);
+ }
+ }
+ }
+
+ private Either<ZipOutputStream, ResponseFormat> populateZip(Component component, boolean getFromCS, ZipOutputStream zip, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+
+ LifecycleStateEnum lifecycleState = component.getLifecycleState();
+ String componentYaml = null;
+ Either<ToscaRepresentation, ToscaError> exportComponent = null;
+ byte[] mainYaml = null;
+ // <file name, esid, component>
+ List<Triple<String, String, Component>> dependencies = null;
+ List<ImmutablePair<Component, byte[]>> generatorInputs = new LinkedList<>();
+
+ String fileName;
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ fileName = artifactDefinition.getArtifactName();
+
+ if (getFromCS || !(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ String esId = artifactDefinition.getEsId();
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+ if (fromCassandra.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(fromCassandra.right().value());
+ return Either.right(responseFormat);
+ }
+ mainYaml = fromCassandra.left().value();
+
+ } else {
+ exportComponent = toscaExportUtils.exportComponent(component);
+ if (exportComponent.isRight()) {
+ log.debug("exportComponent failed", exportComponent.right().value());
+ ActionStatus convertedFromToscaError = componentsUtils.convertFromToscaError(exportComponent.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertedFromToscaError);
+ return Either.right(responseFormat);
+ }
+ ToscaRepresentation exportResult = exportComponent.left().value();
+ componentYaml = exportResult.getMainYaml();
+ mainYaml = componentYaml.getBytes();
+ dependencies = exportResult.getDependencies();
+ }
+
+ try {
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
+ zip.write(mainYaml);
+
+ generatorInputs.add(new ImmutablePair<Component, byte[]>(component, mainYaml));
+
+ if (dependencies == null) {
+ Either<ToscaTemplate, ToscaError> dependenciesRes = toscaExportUtils.getDependencies(component);
+ if (dependenciesRes.isRight()) {
+ log.debug("Failed to retrieve dependencies for component {}, error {}", component.getUniqueId(), dependenciesRes.right().value());
+ ActionStatus convertFromToscaError = componentsUtils.convertFromToscaError(dependenciesRes.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertFromToscaError);
+ return Either.right(responseFormat);
+ }
+ dependencies = dependenciesRes.left().value().getDependencies();
+ }
+ if (dependencies != null && !dependencies.isEmpty()) {
+ for (Triple<String, String, Component> d : dependencies) {
+ String esId = d.getMiddle();
+ Component childComponent = d.getRight();
+ fileName = d.getLeft();
+ Either<byte[], ActionStatus> entryData = getEntryData(esId, childComponent);
+
+ if (entryData.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
+ return Either.right(responseFormat);
+ }
+
+ byte[] content = entryData.left().value();
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
+ zip.write(content);
+
+ generatorInputs.add(new ImmutablePair<Component, byte[]>(childComponent, content));
+ }
+ }
+
+ List<ArtifactDefinition> aiiArtifactList = new LinkedList<>();
+ // Artifact Generation
+ if (component.getComponentType() == ComponentTypeEnum.SERVICE && (lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ Either<List<ArtifactDefinition>, ResponseFormat> handleAAIArtifacts = handleAAIArtifacts(component, zip, mockGenerator, shouldLock, inTransaction, generatorInputs);
+
+ if (handleAAIArtifacts.isLeft()) {
+ aiiArtifactList = handleAAIArtifacts.left().value();
+ } else {
+ log.debug("AAI Artifacts handling failed");
+ return Either.right(handleAAIArtifacts.right().value());
+ }
+
+ if (isInCertificationRequest) {
+ Either<ActionStatus, ResponseFormat> handleAllAAIArtifactsInDataModel = handleAllAAIArtifactsInDataModel(component, aiiArtifactList, shouldLock, inTransaction);
+
+ if (handleAllAAIArtifactsInDataModel.isRight()) {
+ log.debug("AAI Artifacts handling (create, update, delete) failed");
+ return Either.right(handleAllAAIArtifactsInDataModel.right().value());
+ }
+ }
+
+ }
+
+ // Collecting All Deployment Artifacts
+ Either<ZipOutputStream, ActionStatus> collectAndWriteToScarDeploymentArtifacts = collectAndWriteToScarDeploymentArtifacts(zip, component, aiiArtifactList);
+
+ if (collectAndWriteToScarDeploymentArtifacts.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ } catch (IOException e) {
+ log.debug("Failed to create CSAR zip for component {}", component.getUniqueId(), e);
+ }
+
+ return Either.left(zip);
+ }
+
+ private Either<ZipOutputStream, ActionStatus> collectAndWriteToScarDeploymentArtifacts(ZipOutputStream zip, Component component, List<ArtifactDefinition> aiiArtifactList) throws IOException {
+
+ Collection<ArtifactDefinition> deploymentArtifactsToAdd = null;
+ Collection<ArtifactDefinition> allArtifactsToAdd = new LinkedList<>();
+
+ if (component.getComponentType() == ComponentTypeEnum.SERVICE) {
+ Either<Service, StorageOperationStatus> getServiceResponse = serviceOperation.getService(component.getUniqueId());
+
+ if (getServiceResponse.isLeft()) {
+ Service service = getServiceResponse.left().value();
+
+ if (!aiiArtifactList.isEmpty()) {
+ deploymentArtifactsToAdd = service.getDeploymentArtifacts().values().stream().filter(e -> e.getGenerated() == null || !e.getGenerated()).collect(Collectors.toList());
+ allArtifactsToAdd.addAll(aiiArtifactList);
+ allArtifactsToAdd.addAll(deploymentArtifactsToAdd);
+ } else {
+ allArtifactsToAdd.addAll(service.getDeploymentArtifacts().values());
+ }
+ }
+ }
+
+ if (!allArtifactsToAdd.isEmpty()) {
+
+ for (ArtifactDefinition deploymentArtifactDefinition : allArtifactsToAdd) {
+ String artifactFileName = deploymentArtifactDefinition.getArtifactName();
+ byte[] payloadData = deploymentArtifactDefinition.getPayloadData();
+
+ if (payloadData == null) {
+ String esId = deploymentArtifactDefinition.getEsId();
+ if (esId != null) {
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+
+ if (fromCassandra.isRight()) {
+ return Either.right(fromCassandra.right().value());
+ }
+ payloadData = fromCassandra.left().value();
+ } else {
+ log.debug("Artifact {} payload not supplied in ArtifactDefinition and not found in DB", artifactFileName);
+ continue;
+ }
+ }
+
+ byte[] decodedPayload = null;
+
+ if (Base64.isBase64(payloadData)) {
+ // decodedPayload = Base64.getDecoder().decode(payloadData);
+ decodedPayload = Base64.decodeBase64(payloadData);
+ } else {
+ decodedPayload = payloadData;
+ }
+
+ zip.putNextEntry(new ZipEntry(ARTIFACTS_PATH + artifactFileName));
+ zip.write(decodedPayload);
+ }
+ }
+
+ return Either.left(zip);
+ }
+
+ private Either<List<ArtifactDefinition>, ResponseFormat> handleAAIArtifacts(Component component, ZipOutputStream zip, boolean mockGenerator, boolean shouldLock, boolean inTransaction, List<ImmutablePair<Component, byte[]>> generatorInputs) {
+
+ ComponentTypeEnum componentType = component.getComponentType();
+ List<Artifact> generatedArtifacts = null;
+ List<ArtifactDefinition> aaiArtifacts = null;
+
+ if (componentType == ComponentTypeEnum.SERVICE && !generatorInputs.isEmpty()) {
+ List<Artifact> convertedGeneratorInputs = convertToGeneratorArtifactsInput(generatorInputs);
+
+ Either<List<Artifact>, ResponseFormat> generatorResponse;
+
+ if (mockGenerator) {
+ generatorResponse = artifactGenerator(convertedGeneratorInputs, ArtifactType.OTHER, component);
+ } else {
+ generatorResponse = artifactGenerator(convertedGeneratorInputs, ArtifactType.AAI, component);
+ }
+
+ if (generatorResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), generatorResponse.toString());
+ return Either.right(responseFormat);
+ }
+
+ generatedArtifacts = generatorResponse.left().value();
+
+ aaiArtifacts = convertToArtifactDefinitionFromArtifactGeneratedData(generatedArtifacts);
+
+ }
+
+ return Either.left(aaiArtifacts);
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleAllAAIArtifactsInDataModel(Component component, List<ArtifactDefinition> artifactsFromAAI, boolean shouldLock, boolean inTransaction) {
+
+ Either<ActionStatus, ResponseFormat> handleAAIArtifactsResponse = null;
+ User lastComponentUpdater = null;
+
+ List<ArtifactDefinition> aaiArtifatcsToCreate = getAAIArtifatcsForCreate(artifactsFromAAI, component);
+ List<ArtifactDefinition> aaiArtifatcsToDelete = getAAIArtifatcsForDelete(artifactsFromAAI, component);
+ List<ArtifactDefinition> aaiArtifatcsToUpdate = getAAIArtifatcsForUpdate(artifactsFromAAI, component);
+
+ String lastUpdaterUserId = component.getLastUpdaterUserId();
+ Either<User, ResponseFormat> validateUserExists = artifactsBusinessLogic.validateUserExists(lastUpdaterUserId, "CSAR creation util", true);
+
+ if (validateUserExists.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), "User not found");
+ return Either.right(responseFormat);
+ }
+
+ lastComponentUpdater = validateUserExists.left().value();
+
+ handleAAIArtifactsResponse = handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToDelete, ArtifactOperation.Delete, lastComponentUpdater, shouldLock, inTransaction);
+
+ if (handleAAIArtifactsResponse.isRight()) {
+ return handleAAIArtifactsResponse;
+ }
+
+ handleAAIArtifactsResponse = handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToCreate, ArtifactOperation.Create, lastComponentUpdater, shouldLock, inTransaction);
+
+ if (handleAAIArtifactsResponse.isRight()) {
+ return handleAAIArtifactsResponse;
+ }
+
+ return handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToUpdate, ArtifactOperation.Update, lastComponentUpdater, shouldLock, inTransaction);
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForUpdate(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> componetDeploymentArtifactLables = component.getDeploymentArtifacts().keySet();
+ Set<String> componetInformationalArtifactLables = component.getArtifacts().keySet();
+
+ List<ArtifactDefinition> artifactsAaiUpdate = artifactsFromAAI.stream().filter(e -> (componetDeploymentArtifactLables.contains(e.getArtifactLabel()) || componetInformationalArtifactLables.contains(e.getArtifactLabel())))
+ .filter(e -> checkAaiForUpdate(component, e)).collect(Collectors.toList());
+
+ return artifactsAaiUpdate;
+ }
+
+ private boolean checkAaiForUpdate(Component component, ArtifactDefinition artifactDefinition) {
+ ArtifactDefinition artifactDefinitionComp = component.getDeploymentArtifacts().get(artifactDefinition.getArtifactLabel());
+
+ if (artifactDefinitionComp == null) {
+ log.warn("Failed to get {} artifact", artifactDefinition.getArtifactLabel());
+ return false;
+ }
+
+ // Old Artifacts before the generated flag introduction if contains "aai" ignore case prefix updated
+ if (artifactDefinitionComp.getGenerated() == null) {
+ if (artifactDefinitionComp.getArtifactLabel().toLowerCase().startsWith("aai")) {
+ return true;
+ } else {
+ log.warn("The artifact {} flag is null but AAI prefix is abssent Not updated", artifactDefinition.getArtifactLabel());
+ }
+ } else {
+ if (artifactDefinition.getGenerated()) {
+ return true;
+ } else {
+ log.warn("Generated artifact {} was already uploaded manually", artifactDefinition.getArtifactLabel());
+ }
+ }
+ return false;
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForDelete(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> aaiLabels = artifactsFromAAI.stream().map(e -> e.getArtifactLabel()).collect(Collectors.toSet());
+
+ List<ArtifactDefinition> artifactsForDeleteDeployment = component.getDeploymentArtifacts().values().stream().
+ // Filter Out Artifacts that are not contained in artifacts returned
+ // from AAI API
+ filter(e -> !aaiLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+
+ List<ArtifactDefinition> artifactsForDeleteInformational = component.getArtifacts().values().stream().
+ // Filter Out Artifacts that are not contained in artifacts returned
+ // from AAI API
+ filter(e -> !aaiLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+
+ artifactsForDeleteDeployment.addAll(artifactsForDeleteInformational);
+
+ return artifactsForDeleteDeployment.stream().filter(e -> (e.getGenerated() != null && e.getGenerated().equals(Boolean.TRUE)) || (e.getGenerated() == null && e.getArtifactLabel().toLowerCase().startsWith("aai"))).collect(Collectors.toList());
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForCreate(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> componentDeploymentLabels = component.getDeploymentArtifacts().keySet();
+ Set<String> componentInfoLabels = component.getArtifacts().keySet();
+
+ // If the artifact label does not exist in the service -
+ // store the artifact (generate uuid and version, "generated" flag is TRUE)
+ return artifactsFromAAI.stream().filter(e -> !componentDeploymentLabels.contains(e.getArtifactLabel()) && !componentInfoLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleAAIArtifactsInDataModelByOperationType(Component component, List<ArtifactDefinition> generatedArtifactsDefinitions, ArtifactOperation operationType, User user, boolean shouldLock,
+ boolean inTransaction) {
+
+ String componentUniqueId = component.getUniqueId();
+ ComponentTypeEnum componentType = component.getComponentType();
+
+ for (ArtifactDefinition artDef : generatedArtifactsDefinitions) {
+ String data = gson.toJson(artDef);
+ String dataMD5 = GeneralUtility.calculateMD5ByString(data);
+ String artifactUniqueId = null;
+
+ if (operationType.equals(ArtifactOperation.Update) || operationType.equals(ArtifactOperation.Delete)) {
+ String artifactLabel = artDef.getArtifactLabel();
+ ArtifactDefinition artifactDefinition = component.getDeploymentArtifacts().get(artifactLabel);
+ if (artifactDefinition != null) {
+ artifactUniqueId = artifactDefinition.getUniqueId();
+ }
+ }
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> validateAndHandleArtifact = artifactsBusinessLogic.validateAndHandleArtifact(componentUniqueId, componentType, operationType, artifactUniqueId, artDef, dataMD5, data, null,
+ null, null, user, component, shouldLock, inTransaction);
+
+ if (validateAndHandleArtifact.isRight()) {
+ if (ArtifactOperation.Create == operationType || ArtifactOperation.Update == operationType) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, componentType.getValue(), component.getName(), validateAndHandleArtifact.right().value().toString());
+
+ Either.right(responseFormat);
+ } else {
+ log.warn("Generated artifact {} could not be deleted", artDef.getArtifactLabel());
+ }
+ }
+ }
+
+ return Either.left(ActionStatus.OK);
+ }
+
+ private List<ArtifactDefinition> convertToArtifactDefinitionFromArtifactGeneratedData(List<Artifact> generatorOutput) {
+ List<ArtifactDefinition> artifactDefList = new LinkedList<>();
+
+ for (Artifact artifact : generatorOutput) {
+ ArtifactDefinition newEntry = new ArtifactDefinition();
+ newEntry.setArtifactName(artifact.getName());
+ newEntry.setArtifactType(artifact.getType());
+ newEntry.setArtifactGroupType(ArtifactGroupTypeEnum.findType(artifact.getGroupType()));
+ newEntry.setDescription(artifact.getDescription());
+
+ // Normalizing the artifact label to match those stored in DB
+ String normalizeArtifactLabel = ValidationUtils.normalizeArtifactLabel(artifact.getLabel());
+ newEntry.setArtifactLabel(normalizeArtifactLabel);
+ newEntry.setPayload(artifact.getPayload());
+ newEntry.setArtifactChecksum(artifact.getChecksum());
+ // Flag that set to true in case that the artifact is generated by AI&I generator
+ newEntry.setGenerated(Boolean.TRUE);
+
+ artifactDefList.add(newEntry);
+ }
+
+ return artifactDefList;
+ }
+
+ // List<ImmutablePair<Component, byte[] artifactBytes>>
+ // artifact stored by label
+ private List<Artifact> convertToGeneratorArtifactsInput(List<ImmutablePair<Component, byte[]>> inputs) {
+ List<Artifact> listOfArtifactsInput = new LinkedList<>();
+ for (ImmutablePair<Component, byte[]> triple : inputs) {
+ Component component = triple.getLeft();
+
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+
+ String artifactName = artifactDefinition.getArtifactName();
+ String artifactType = artifactDefinition.getArtifactType();
+ String artifactGroupType = artifactDefinition.getArtifactGroupType().getType();
+ String artifactDescription = artifactDefinition.getDescription();
+ String artifactLabel = artifactDefinition.getArtifactLabel();
+ byte[] right = triple.getRight();
+ // The md5 calculated on the uncoded data
+ String md5Hex = DigestUtils.md5Hex(right);
+ // byte[] payload = Base64.getEncoder().encode(right);
+ byte[] payload = Base64.encodeBase64(right);
+ String artifactVersion = artifactDefinition.getArtifactVersion();
+
+ Artifact convertedArtifact = new Artifact(artifactType, artifactGroupType, md5Hex, payload);
+ convertedArtifact.setName(artifactName);
+ convertedArtifact.setDescription(artifactDescription);
+ convertedArtifact.setLabel(artifactLabel);
+ convertedArtifact.setVersion(artifactVersion);
+
+ listOfArtifactsInput.add(convertedArtifact);
+ }
+
+ return listOfArtifactsInput;
+ }
+
+ private Either<byte[], ActionStatus> getEntryData(String esId, Component childComponent) {
+ byte[] content;
+ if (esId == null || esId.isEmpty()) {
+ Either<ToscaRepresentation, ToscaError> exportRes = toscaExportUtils.exportComponent(childComponent);
+ if (exportRes.isRight()) {
+ log.debug("Failed to export tosca template for child component {} error {}", childComponent.getUniqueId(), exportRes.right().value());
+ return Either.right(componentsUtils.convertFromToscaError(exportRes.right().value()));
+ }
+ content = exportRes.left().value().getMainYaml().getBytes();
+ } else {
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+ if (fromCassandra.isRight()) {
+ return Either.right(fromCassandra.right().value());
+ } else {
+ content = fromCassandra.left().value();
+ }
+ }
+ return Either.left(content);
+ }
+
+ private Either<byte[], ActionStatus> getFromCassandra(String esId) {
+ Either<ESArtifactData, CassandraOperationStatus> artifactResponse = artifactCassandraDao.getArtifact(esId);
+
+ if (artifactResponse.isRight()) {
+ log.debug("In createCsar fetching of artifact from CS failed");
+ log.debug("Failed to fetch from Cassandra by id {} error {} ", esId, artifactResponse.right().value());
+
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactResponse.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(convertedFromStorageResponse);
+ } else {
+ ESArtifactData artifactData = artifactResponse.left().value();
+ return Either.left(artifactData.getDataAsArray());
+
+ }
+ }
+
+ private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
+ final String BLOCK_0_TEMPLATE = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n";
+ String readyBlock = String.format(BLOCK_0_TEMPLATE, metaFileVersion, csarVersion, createdBy, entryDef);
+ return readyBlock;
+ }
+
+ private Either<List<Artifact>, ResponseFormat> artifactGenerator(List<Artifact> artifactList, ArtifactType type, Component component) {
+
+ ArtifactGenerationServiceImpl artifactGenerationServiceImpl = new ArtifactGenerationServiceImpl();
+ ArtifactTypes artifactTypes = new ArtifactTypes();
+ List<ArtifactType> artifactTypesList = new LinkedList<>();
+ ArtifactType otherType;
+
+ if (type == null) {
+ otherType = ArtifactType.OTHER;
+ } else {
+ otherType = type;
+ }
+
+ artifactTypesList.add(otherType);
+ artifactTypes.setArtifactTypes(artifactTypesList);
+
+ String configJson = gson.toJson(artifactTypes);
+ GenerationData generatedArtifacts = artifactGenerationServiceImpl.generateArtifact(artifactList, configJson);
+
+ Map<String, List<String>> errorData = generatedArtifacts.getErrorData();
+
+ if (!errorData.isEmpty()) {
+ Set<String> keySet = errorData.keySet();
+
+ for (String key : keySet) {
+ List<String> errorList = errorData.get(key);
+ log.debug("The Artifact Generator Failed - {} with following: {}", key, errorList);
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), errorData.toString());
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(generatedArtifacts.getResultData());
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
new file mode 100644
index 0000000000..544b85361d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter;
+import org.openecomp.sdc.be.model.tosca.converters.ToscaValueConverter;
+import org.openecomp.sdc.be.tosca.model.EntrySchema;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.stream.JsonReader;
+
+import fj.data.Either;
+
+public class PropertyConvertor {
+ private static PropertyConvertor instance;
+ private JsonParser jsonParser = new JsonParser();
+ private static Logger log = LoggerFactory.getLogger(PropertyConvertor.class.getName());
+
+ protected PropertyConvertor() {
+
+ }
+
+ public static synchronized PropertyConvertor getInstance() {
+ if (instance == null) {
+ instance = new PropertyConvertor();
+ }
+ return instance;
+ }
+
+ public Either<ToscaNodeType, ToscaError> convertProperties(Component component, ToscaNodeType toscaNodeType, Map<String, DataTypeDefinition> dataTypes) {
+
+ if (component instanceof Resource) {
+ Resource resource = (Resource) component;
+ List<PropertyDefinition> props = resource.getProperties();
+ if (props != null) {
+ Map<String, ToscaProperty> properties = new HashMap<>();
+
+ // take only the properties of this resource
+ props.stream().filter(p -> component.getUniqueId().equals(p.getParentUniqueId())).forEach(property -> {
+ ToscaProperty prop = convertProperty(dataTypes, property, false);
+
+ properties.put(property.getName(), prop);
+
+ });
+ if (!properties.isEmpty()) {
+ toscaNodeType.setProperties(properties);
+ }
+ }
+ }
+ return Either.left(toscaNodeType);
+ }
+
+ public ToscaProperty convertProperty(Map<String, DataTypeDefinition> dataTypes, PropertyDefinition property, boolean isCapabiltyProperty) {
+ ToscaProperty prop = new ToscaProperty();
+
+ String innerType = null;
+ SchemaDefinition schema = property.getSchema();
+ if (schema != null && schema.getProperty() != null && schema.getProperty().getType() != null && !schema.getProperty().getType().isEmpty()) {
+ innerType = schema.getProperty().getType();
+ EntrySchema eschema = new EntrySchema();
+ eschema.setType(innerType);
+ eschema.setDescription(schema.getProperty().getDescription());
+ prop.setEntry_schema(eschema);
+ }
+ log.debug("try to convert property {} from type {} with default value {}", property.getName(), property.getType(), property.getDefaultValue());
+ prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes));
+ prop.setType(property.getType());
+ prop.setDescription(property.getDescription());
+ if (isCapabiltyProperty) {
+ prop.setStatus(property.getStatus());
+ prop.setRequired(property.isRequired());
+ }
+ return prop;
+ }
+
+ public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ log.debug("try to convert propertyType {} , value {}, innerType {}", propertyType, value, innerType);
+ if (value == null) {
+ return value;
+ }
+
+ ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance();
+ ToscaValueConverter innerConverter = null;
+ Boolean isScalar = true;
+
+ ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
+ if (type == null) {
+ log.debug("isn't prederfined type, get from all data types");
+ DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
+ if (innerType == null) {
+ innerType = propertyType;
+ }
+
+ if ((type = mapConverterInst.isScalarType(dataTypeDefinition)) != null) {
+ log.debug("This is scalar type. get suitable converter for type {}", type);
+ innerConverter = type.getValueConverter();
+ } else {
+ isScalar = false;
+ }
+ } else {
+ ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(type.getType());
+ if (typeIfScalar == null) {
+ isScalar = false;
+ }
+
+ innerConverter = type.getValueConverter();
+ if (ToscaPropertyType.STRING.equals(type) && value.startsWith("/")) {
+ return innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ }
+ }
+ JsonElement jsonElement = null;
+ try {
+ StringReader reader = new StringReader(value);
+ JsonReader jsonReader = new JsonReader(reader);
+ jsonReader.setLenient(true);
+
+ jsonElement = jsonParser.parse(jsonReader);
+
+ if (value.equals("")) {
+ return value;
+ }
+
+ if (jsonElement.isJsonPrimitive() && isScalar) {
+ log.debug("It's well defined type. convert it");
+ ToscaValueConverter converter = type.getValueConverter();
+ return converter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ log.debug("It's data type or inputs in primitive type. convert as map");
+ Object convertedValue;
+ if (innerConverter != null && (ToscaPropertyType.MAP.equals(type) || ToscaPropertyType.LIST.equals(type))) {
+ convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ if (isScalar) {
+ // complex json for scalar type
+ convertedValue = mapConverterInst.handleComplexJsonValue(jsonElement);
+ } else {
+ if (innerConverter != null) {
+ convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ convertedValue = mapConverterInst.convertDataTypeToToscaMap(innerType, dataTypes, innerConverter, isScalar, jsonElement);
+ }
+ }
+ }
+ return convertedValue;
+ }
+
+ } catch (JsonSyntaxException e) {
+ log.debug("convertToToscaValue failed to parse json value :", e);
+ return null;
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java
new file mode 100644
index 0000000000..94dd559d2d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+public enum ToscaError {
+
+ NODE_TYPE_CAPABILITY_ERROR, NOT_SUPPORTED_TOSCA_TYPE, NODE_TYPE_REQUIREMENT_ERROR, GENERAL_ERROR
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
new file mode 100644
index 0000000000..1bf940ffc0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -0,0 +1,629 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.beans.IntrospectionException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
+import org.openecomp.sdc.be.tosca.model.VfModuleToscaMetadata;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.DumperOptions.FlowStyle;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.introspector.BeanAccess;
+import org.yaml.snakeyaml.introspector.Property;
+import org.yaml.snakeyaml.introspector.PropertyUtils;
+import org.yaml.snakeyaml.nodes.MappingNode;
+import org.yaml.snakeyaml.nodes.Node;
+import org.yaml.snakeyaml.nodes.NodeTuple;
+import org.yaml.snakeyaml.nodes.Tag;
+import org.yaml.snakeyaml.representer.Represent;
+import org.yaml.snakeyaml.representer.Representer;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("tosca-export-handler")
+public class ToscaExportHandler {
+
+ @Autowired
+ private ApplicationDataTypeCache dataTypeCache;
+
+ @Autowired
+ private IResourceOperation resourceOperation;
+
+ private CapabiltyRequirementConvertor capabiltyRequirementConvertor = CapabiltyRequirementConvertor.getInstance();
+ private PropertyConvertor propertyConvertor = PropertyConvertor.getInstance();
+
+ private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
+
+ public static final String TOSCA_VERSION = "tosca_simple_yaml_1_0";
+ public static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
+ public static final String IMPORTS_FILE_KEY = "file";
+ public static final String TOSCA_TEMPLATE_NAME = "-template.yml";
+ public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
+ public static final String VF_MODULE_TYPE_KEY = "vf_module_type";
+ public static final String VF_MODULE_DESC_KEY = "vf_module_description";
+ public static final String VOLUME_GROUP_KEY = "volume_group";
+ public static final String VF_MODULE_TYPE_BASE = "Base";
+ public static final String VF_MODULE_TYPE_EXPANSION = "Expansion";
+
+ public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
+
+ Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
+ if (toscaTemplateRes.isRight()) {
+ return Either.right(toscaTemplateRes.right().value());
+ }
+
+ CustomRepresenter representer = new CustomRepresenter();
+ DumperOptions options = new DumperOptions();
+ options.setAllowReadOnlyProperties(false);
+ options.setPrettyFlow(true);
+
+ options.setDefaultFlowStyle(FlowStyle.FLOW);
+ options.setCanonical(false);
+
+ ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
+ representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
+
+ representer.setPropertyUtils(new UnsortedPropertyUtils());
+ Yaml yaml = new Yaml(representer, options);
+
+ String yamlAsString = yaml.dumpAsMap(toscaTemplate);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
+ sb.append(yamlAsString);
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
+
+ ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
+ toscaRepresentation.setMainYaml(sb.toString());
+ toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
+
+ return Either.left(toscaRepresentation);
+ }
+
+ public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(null);
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports = fillImports(component, toscaTemplate);
+ if (fillImports.isRight()) {
+ return Either.right(fillImports.right().value());
+ }
+ return Either.left(fillImports.left().value().left);
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) {
+ log.debug("start tosca export for {}", component.getUniqueId());
+ ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
+
+ toscaTemplate.setMetadata(convertMetadata(component, false));
+
+ Map<String, ToscaNodeType> node_types = new HashMap<>();
+ if (ToscaUtils.isNodeType(component)) {
+ log.debug("convert component as node type");
+ return convertNodeType(component, toscaTemplate, node_types);
+ } else {
+ log.debug("convert component as topology template");
+ return convertToscaTemplate(component, toscaTemplate);
+ }
+
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
+
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component, toscaNode);
+ if (importsRes.isRight()) {
+ return Either.right(importsRes.right().value());
+ }
+ toscaNode = importsRes.left().value().left;
+
+ Map<String, Component> componentCache = importsRes.left().value().right;
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+
+ ToscaTopolgyTemplate topology_template = new ToscaTopolgyTemplate();
+
+ Either<ToscaTopolgyTemplate, ToscaError> inputs = fillInputs(component, topology_template, dataTypes);
+ if (inputs.isRight()) {
+ return Either.right(inputs.right().value());
+ }
+ topology_template = inputs.left().value();
+
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component.getComponentInstancesProperties();
+ List<GroupDefinition> groups = component.getGroups();
+ if (componentInstances != null && !componentInstances.isEmpty()) {
+
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> node_templates = convertNodeTemplates(component, componentInstances, componentInstancesProperties, componentCache, dataTypes);
+ if (node_templates.isRight()) {
+ return Either.right(node_templates.right().value());
+ }
+ log.debug("node templates converted");
+
+ topology_template.setNode_templates(node_templates.left().value());
+ }
+ if (groups != null && !groups.isEmpty()) {
+ Map<String, ToscaGroupTemplate> groupsMap = new HashMap<String, ToscaGroupTemplate>();
+ for (GroupDefinition group : groups) {
+ ToscaGroupTemplate toscaGroup = convertGroup(group, component);
+ groupsMap.put(group.getName(), toscaGroup);
+
+ }
+ topology_template.setGroups(groupsMap);
+ log.debug("groups converted");
+
+ }
+
+ SubstitutionMapping substitutionMapping = new SubstitutionMapping();
+ String toscaResourceName = null;
+ switch (component.getComponentType()) {
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName();
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
+ break;
+ default:
+ log.debug("Not supported component type {}", component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ }
+ substitutionMapping.setNode_type(toscaResourceName);
+
+ Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping, dataTypes);
+ if (capabilities.isRight()) {
+ return Either.right(capabilities.right().value());
+ }
+ substitutionMapping = capabilities.left().value();
+
+ Either<SubstitutionMapping, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, substitutionMapping);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ substitutionMapping = requirements.left().value();
+
+ topology_template.setSubstitution_mappings(substitutionMapping);
+
+ toscaNode.setTopology_template(topology_template);
+ return Either.left(toscaNode);
+ }
+
+ private Either<ToscaTopolgyTemplate, ToscaError> fillInputs(Component component, ToscaTopolgyTemplate topology_template, Map<String, DataTypeDefinition> dataTypes) {
+ if (log.isDebugEnabled())
+ log.debug("fillInputs for component {}", component.getUniqueId());
+ List<InputDefinition> inputDef = component.getInputs();
+ Map<String, ToscaProperty> inputs = new HashMap<>();
+
+ if (inputDef != null) {
+ inputDef.forEach(i -> {
+ ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
+ inputs.put(i.getName(), property);
+ });
+ if (inputs != null && !inputs.isEmpty()) {
+ topology_template.setInputs(inputs);
+ }
+ }
+ return Either.left(topology_template);
+ }
+
+ private ToscaMetadata convertMetadata(Component component, boolean isInstance) {
+ ToscaMetadata toscaMetadata = new ToscaMetadata();
+ toscaMetadata.setName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ toscaMetadata.setInvariantUUID(component.getInvariantUUID());
+ toscaMetadata.setUUID(component.getUUID());
+ toscaMetadata.setDescription(component.getDescription());
+
+ List<CategoryDefinition> categories = component.getCategories();
+ CategoryDefinition categoryDefinition = categories.get(0);
+ toscaMetadata.setCategory(categoryDefinition.getName());
+
+ if (isInstance) {
+ toscaMetadata.setVersion(component.getVersion());
+ }
+ switch (component.getComponentType()) {
+ case RESOURCE:
+ Resource resource = (Resource) component;
+ toscaMetadata.setType(resource.getResourceType().name());
+ toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
+ if (!isInstance) {
+ toscaMetadata.setResourceVendor(resource.getVendorName());
+ toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
+ }
+ break;
+ case SERVICE:
+ toscaMetadata.setType(component.getComponentType().getValue());
+ if (!isInstance) {
+ toscaMetadata.setServiceEcompNaming(false);
+ toscaMetadata.setServiceHoming(false);
+ }
+ break;
+ default:
+ log.debug("Not supported component type {}", component.getComponentType());
+ }
+ return toscaMetadata;
+ }
+
+ private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component, ToscaTemplate toscaTemplate) {
+ Map<String, Component> componentCache = new HashMap<>();
+ if (!ToscaUtils.isNodeType(component)) {
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ if (componentInstances != null && !componentInstances.isEmpty()) {
+ List<Map<String, Map<String, String>>> imports = new LinkedList<Map<String, Map<String, String>>>();
+ List<Triple<String, String, Component>> dependecies = new ArrayList<>();
+
+ componentInstances.forEach(ci -> {
+ createDependency(componentCache, imports, dependecies, ci);
+ });
+ toscaTemplate.setImports(imports);
+ toscaTemplate.setDependencies(dependecies);
+ }
+ } else {
+ log.debug("currently imports supported for VF and service only");
+ }
+ return Either.left(new ImmutablePair<ToscaTemplate, Map<String, Component>>(toscaTemplate, componentCache));
+ }
+
+ private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports, List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {
+ Map<String, String> files = new HashMap<>();
+ Map<String, Map<String, String>> importsListMember = new HashMap<>();
+
+ Component componentRI = componentCache.get(ci.getComponentUid());
+ if (componentRI == null) {
+ // all resource must be only once!
+ Either<Resource, StorageOperationStatus> resource = resourceOperation.getResource(ci.getComponentUid(), true);
+ if (resource.isRight()) {
+ log.debug("Failed to fetch resource with id {} for instance {}");
+ }
+ Resource fetchedComponent = resource.left().value();
+ componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
+ componentRI = fetchedComponent;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
+ if (artifactDefinition != null) {
+ String artifactName = artifactDefinition.getArtifactName();
+ files.put(IMPORTS_FILE_KEY, artifactName);
+ importsListMember.put(ci.getComponentName(), files);
+ dependecies.add(new ImmutableTriple<String, String, Component>(artifactName, artifactDefinition.getEsId(), fetchedComponent));
+ }
+ }
+ if (!importsListMember.isEmpty()) {
+ imports.add(importsListMember);
+ }
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertNodeType(Component component, ToscaTemplate toscaNode, Map<String, ToscaNodeType> node_types) {
+ log.debug("start convert node type for {}", component.getUniqueId());
+ ToscaNodeType toscaNodeType = createNodeType(component);
+
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+ Either<ToscaNodeType, ToscaError> properties = propertyConvertor.convertProperties(component, toscaNodeType, dataTypes);
+ if (properties.isRight()) {
+ return Either.right(properties.right().value());
+ }
+ toscaNodeType = properties.left().value();
+ log.debug("Properties converted for {}", component.getUniqueId());
+
+ Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(component, toscaNodeType, dataTypes);
+ if (capabilities.isRight()) {
+ return Either.right(capabilities.right().value());
+ }
+ toscaNodeType = capabilities.left().value();
+ log.debug("Capabilities converted for {}", component.getUniqueId());
+
+ Either<ToscaNodeType, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, toscaNodeType);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ toscaNodeType = requirements.left().value();
+ log.debug("Requirements converted for {}", component.getUniqueId());
+
+ String toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName();
+ node_types.put(toscaResourceName, toscaNodeType);
+ toscaNode.setNode_types(node_types);
+ log.debug("finish convert node type for {}", component.getUniqueId());
+ return Either.left(toscaNode);
+ }
+
+ private Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplates(Component component, List<ComponentInstance> componentInstances, Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
+ Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes) {
+ log.debug("start convert topology template for {} for type {}", component.getUniqueId(), component.getComponentType());
+ Map<String, ToscaNodeTemplate> node_templates = new HashMap<>();
+
+ for (ComponentInstance componentInstance : componentInstances) {
+ ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setType(componentInstance.getToscaComponentName());
+
+ Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component, componentInstance, component.getComponentInstancesRelations(), nodeTemplate);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ log.debug("Component instance Requirements converted for instance {}", componentInstance.getUniqueId());
+
+ nodeTemplate = requirements.left().value();
+
+ Component componentOfInstance = componentCache.get(componentInstance.getComponentUid());
+ nodeTemplate.setMetadata(convertMetadata(componentOfInstance, true));
+
+ Either<ToscaNodeTemplate, ToscaError> capabilties = capabiltyRequirementConvertor.convertComponentInstanceCapabilties(componentInstance, dataTypes, nodeTemplate);
+ if (capabilties.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ log.debug("Component instance Capabilties converted for instance {}", componentInstance.getUniqueId());
+
+ nodeTemplate = capabilties.left().value();
+
+ if (componentInstancesProperties.containsKey(componentInstance.getUniqueId())) {
+ Map<String, Object> props = null;
+ List<ComponentInstanceProperty> propList = componentInstancesProperties.get(componentInstance.getUniqueId());
+ List<ComponentInstanceProperty> collect = propList.stream().filter(e -> e.getValueUniqueUid() != null && !e.getValueUniqueUid().isEmpty()).collect(Collectors.toList());
+ if (collect != null && !collect.isEmpty()) {
+ props = new HashMap<String, Object>();
+ for (ComponentInstanceProperty prop : collect) {
+ Object convertedValue = convertInstanceProperty(dataTypes, componentInstance, prop);
+ props.put(prop.getName(), convertedValue);
+ }
+ }
+ if (props != null && !props.isEmpty()) {
+ nodeTemplate.setProperties(props);
+ }
+ }
+ node_templates.put(componentInstance.getName(), nodeTemplate);
+ }
+ log.debug("finish convert topology template for {} for type {}", component.getUniqueId(), component.getComponentType());
+ return Either.left(node_templates);
+ }
+
+ private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) {
+ log.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
+ String propertyType = prop.getType();
+ String innerType = null;
+ if (prop.getSchema() != null && prop.getSchema().getProperty() != null) {
+ innerType = prop.getSchema().getProperty().getType();
+ }
+ Object convertedValue = propertyConvertor.convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes);
+ return convertedValue;
+ }
+
+ private ToscaGroupTemplate convertGroup(GroupDefinition group, Component component) {
+ ToscaGroupTemplate toscaGroup = new ToscaGroupTemplate();
+ Map<String, String> members = group.getMembers();
+ toscaGroup.setType(group.getType());
+ if (members != null)
+ toscaGroup.setMembers(new ArrayList(members.keySet()));
+
+ boolean isVfModule = group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) ? true : false;
+ IToscaMetadata toscaMetadata;
+ if (!isVfModule) {
+ toscaMetadata = new ToscaMetadata();
+ } else {
+ toscaMetadata = new VfModuleToscaMetadata();
+ Map<String, Object> properties = new HashMap<>();
+
+ for (GroupProperty gp : group.getProperties()) {
+ if (gp.getName().equals(Constants.IS_BASE)) {
+ Boolean isBase = Boolean.parseBoolean(gp.getValue());
+ String type = isBase ? VF_MODULE_TYPE_BASE : VF_MODULE_TYPE_EXPANSION;
+ properties.put(VF_MODULE_TYPE_KEY, type);
+ break;
+ }
+ }
+ properties.put(VF_MODULE_DESC_KEY, group.getDescription());
+ boolean isVolume = false;
+ List<String> artifactsList = group.getArtifacts();
+ if (artifactsList != null && !artifactsList.isEmpty()) {
+
+ for (String artifactId : artifactsList) {
+ Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
+ Optional<ArtifactDefinition> findFirst = deploymentArtifacts.values().stream().filter(p -> p.getUniqueId().equals(artifactId)).findFirst();
+ if (findFirst.isPresent()) {
+ ArtifactDefinition artifactDefinition = findFirst.get();
+ if (artifactDefinition.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ isVolume = true;
+ break;
+ }
+ }
+ }
+ }
+ properties.put(VOLUME_GROUP_KEY, isVolume);
+ toscaGroup.setProperties(properties);
+ }
+ toscaMetadata.setName(group.getName());
+ toscaMetadata.setInvariantUUID(group.getInvariantUUID());
+ toscaMetadata.setUUID(group.getGroupUUID());
+ toscaMetadata.setVersion(group.getVersion());
+ toscaGroup.setMetadata(toscaMetadata);
+ return toscaGroup;
+ }
+
+ private ToscaNodeType createNodeType(Component component) {
+ ToscaNodeType toscaNodeType = new ToscaNodeType();
+ if (ToscaUtils.isNodeType(component) && ((Resource) component).getDerivedFrom() != null) {
+ toscaNodeType.setDerived_from(((Resource) component).getDerivedFrom().get(0));
+ }
+ toscaNodeType.setDescription(component.getDescription()); // or name??
+ return toscaNodeType;
+ }
+
+ private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component, ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations, ToscaNodeTemplate nodeTypeTemplate) {
+
+ List<ComponentInstance> instancesList = component.getComponentInstances();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, List<RequirementDefinition>> reqMap = componentInstance.getRequirements();
+
+ relations.stream().filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).forEach(req -> {
+ ComponentInstance toComponentInstance = instancesList.stream().filter(i -> req.getToNode().equals(i.getUniqueId())).findFirst().orElse(null);
+ if (toComponentInstance == null) {
+ log.debug("Faild to create relation between node {} to node {}", componentInstance.getName(), req.getToNode());
+ return;
+
+ }
+ RequirementAndRelationshipPair reqAndRelationshopPair = req.getRelationships().get(0);
+ ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
+ toscaRequirement.setRelationship(reqAndRelationshopPair.getRelationship().getType());
+ toscaRequirement.setNode(toComponentInstance.getName());
+ Optional<RequirementDefinition> findAny = reqMap.values().stream().flatMap(e -> e.stream()).filter(e -> e.getName().equals(reqAndRelationshopPair.getRequirement())).findAny();
+ if (findAny.isPresent()) {
+ RequirementDefinition regDefinition = findAny.get();
+ toscaRequirement.setCapability(regDefinition.getCapability());
+ } else {
+ log.debug("Faild to find relation between node {} to node {}", componentInstance.getName(), req.getToNode());
+ return;
+ }
+ Map<String, ToscaTemplateRequirement> reqmap = new HashMap<String, ToscaTemplateRequirement>();
+ reqmap.put(reqAndRelationshopPair.getRequirement(), toscaRequirement);
+ toscaRequirements.add(reqmap);
+
+ });
+
+ if (!toscaRequirements.isEmpty()) {
+ nodeTypeTemplate.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+ return Either.left(nodeTypeTemplate);
+ }
+
+ private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMapping, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, ToscaCapability> toscaCapabilities = capabiltyRequirementConvertor.convertCapabilities(component, dataTypes);
+ if (!toscaCapabilities.isEmpty()) {
+ substitutionMapping.setCapabilities(toscaCapabilities);
+ }
+ log.debug("Finish convert Capabilities for node type");
+
+ return Either.left(substitutionMapping);
+ }
+
+ private Either<ToscaNodeType, ToscaError> convertCapabilities(Component component, ToscaNodeType nodeType, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, ToscaCapability> toscaCapabilities = capabiltyRequirementConvertor.convertCapabilities(component, dataTypes);
+ if (!toscaCapabilities.isEmpty()) {
+ nodeType.setCapabilities(toscaCapabilities);
+ }
+ log.debug("Finish convert Capabilities for node type");
+
+ return Either.left(nodeType);
+ }
+
+ private static class CustomRepresenter extends Representer {
+ public CustomRepresenter() {
+ super();
+ // null representer is exceptional and it is stored as an instance
+ // variable.
+ this.nullRepresenter = new RepresentNull();
+
+ }
+
+ @Override
+ protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
+ if (propertyValue == null) {
+ return null;
+ } else {
+ // skip not relevant for Tosca property
+ if (property.getName().equals("dependencies")) {
+ return null;
+ }
+ NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
+
+ return property.getName().equals("_defaultp_") ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
+ }
+ }
+
+ @Override
+ protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
+ // remove the bean type from the output yaml (!! ...)
+ if (!classTags.containsKey(javaBean.getClass()))
+ addClassTag(javaBean.getClass(), Tag.MAP);
+
+ return super.representJavaBean(properties, javaBean);
+ }
+
+ private class RepresentNull implements Represent {
+ public Node representData(Object data) {
+ // possible values are here http://yaml.org/type/null.html
+ return representScalar(Tag.NULL, "");
+ }
+ }
+ }
+
+ private static class UnsortedPropertyUtils extends PropertyUtils {
+ @Override
+ protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess) throws IntrospectionException {
+ Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
+ Set<Property> result = new LinkedHashSet<Property>(fields);
+ return result;
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
new file mode 100644
index 0000000000..6b1895b6ec
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.List;
+
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaRepresentation {
+
+ private String mainYaml;
+ private List<Triple<String, String, Component>> dependencies;
+
+ public String getMainYaml() {
+ return mainYaml;
+ }
+
+ public void setMainYaml(String mainYaml) {
+ this.mainYaml = mainYaml;
+ }
+
+ public List<Triple<String, String, Component>> getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(List<Triple<String, String, Component>> dependancies) {
+ this.dependencies = dependancies;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
new file mode 100644
index 0000000000..db03ad2307
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaUtils {
+
+ public static boolean isNodeType(Component component) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ if (ComponentTypeEnum.RESOURCE.equals(componentType)) {
+ ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
+ if (ResourceTypeEnum.CP.equals(resourceType) || ResourceTypeEnum.VL.equals(resourceType) || ResourceTypeEnum.VFC.equals(resourceType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static Map<String, Object> objectToMap(Object objectToConvert, Class clazz) throws IllegalArgumentException, IllegalAccessException {
+ Map<String, Object> map = new HashMap<>();
+ List<Field> fields = new ArrayList<>();
+
+ fields = getAllFields(fields, clazz);
+
+ for (Field field : fields) {
+ field.setAccessible(true);
+ map.put(field.getName(), field.get(objectToConvert));
+ }
+ return map;
+ }
+
+ public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
+ fields.addAll(Arrays.asList(type.getDeclaredFields()));
+
+ if (type.getSuperclass() != null) {
+ fields = getAllFields(fields, type.getSuperclass());
+ }
+ return fields;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java
new file mode 100644
index 0000000000..0c586c7043
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class EntrySchema {
+ private String type;
+ private String description;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java
new file mode 100644
index 0000000000..46f4fd032e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public interface IToscaMetadata {
+
+ public void setName(String name);
+
+ public void setInvariantUUID(String invariantUUID);
+
+ public void setUUID(String uUID);
+
+ public void setVersion(String version);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
new file mode 100644
index 0000000000..0fd9daef7d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.Map;
+
+public class SubstitutionMapping {
+ private String node_type;
+
+ private Map<String, ToscaCapability> capabilities;
+ private Map<String, ToscaRequirement> requirements;
+
+ public SubstitutionMapping() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getNode_type() {
+ return node_type;
+ }
+
+ public void setNode_type(String node_type) {
+ this.node_type = node_type;
+ }
+
+ public Map<String, ToscaCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public Map<String, ToscaRequirement> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(Map<String, ToscaRequirement> requirements) {
+ this.requirements = requirements;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java
new file mode 100644
index 0000000000..2688e5e6b3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaCapability {
+
+ private String type;
+ private String description;
+
+ private List<Object> occurrences;
+
+ private List<String> valid_source_types;
+
+ private Map<String, ToscaProperty> properties;
+
+ public List<String> getValid_source_types() {
+ return valid_source_types;
+ }
+
+ public void setValid_source_types(List<String> valid_source_types) {
+ this.valid_source_types = valid_source_types;
+ }
+
+ public ToscaCapability() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public List<Object> getOccurrences() {
+ return occurrences;
+ }
+
+ public void setOccurrences(List<Object> occurrences) {
+ this.occurrences = occurrences;
+ }
+
+ public Map<String, ToscaProperty> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, ToscaProperty> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java
new file mode 100644
index 0000000000..b91cffa5be
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaGroupTemplate {
+ private String type;
+ List<String> members;
+ private IToscaMetadata metadata;
+ private Map<String, Object> properties;
+
+ public ToscaGroupTemplate() {
+ super();
+
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List<String> getMembers() {
+ return members;
+ }
+
+ public void setMembers(List<String> members) {
+ this.members = members;
+ }
+
+ public IToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(IToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
new file mode 100644
index 0000000000..38cd002726
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class ToscaMetadata implements IToscaMetadata {
+ private String invariantUUID;
+ private String UUID;
+ private String version;
+ private String name;
+ private String description;
+ private String type;
+ private String category;
+ private String subcategory;
+ private String resourceVendor;
+ private String resourceVendorRelease;
+ private Boolean serviceEcompNaming;
+ private Boolean serviceHoming;
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getInvariantUUID() {
+ return invariantUUID;
+ }
+
+ @Override
+ public void setInvariantUUID(String invariantUUID) {
+ this.invariantUUID = invariantUUID;
+ }
+
+ public String getUUID() {
+ return UUID;
+ }
+
+ @Override
+ public void setUUID(String uUID) {
+ UUID = uUID;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubcategory() {
+ return subcategory;
+ }
+
+ public void setSubcategory(String subcategory) {
+ this.subcategory = subcategory;
+ }
+
+ public String getResourceVendor() {
+ return resourceVendor;
+ }
+
+ public void setResourceVendor(String resourceVendor) {
+ this.resourceVendor = resourceVendor;
+ }
+
+ public String getResourceVendorRelease() {
+ return resourceVendorRelease;
+ }
+
+ public void setResourceVendorRelease(String resourceVendorRelease) {
+ this.resourceVendorRelease = resourceVendorRelease;
+ }
+
+ public Boolean isServiceEcompNaming() {
+ return serviceEcompNaming;
+ }
+
+ public void setServiceEcompNaming(Boolean serviceEcompNaming) {
+ this.serviceEcompNaming = serviceEcompNaming;
+ }
+
+ public Boolean isServiceHoming() {
+ return serviceHoming;
+ }
+
+ public void setServiceHoming(Boolean serviceHoming) {
+ this.serviceHoming = serviceHoming;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ @Override
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
new file mode 100644
index 0000000000..b2d7ef5ab6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaNodeTemplate {
+ private String type;
+ private ToscaMetadata metadata;
+ private Map<String, Object> properties;
+ private List<Map<String, ToscaTemplateRequirement>> requirements;
+ private Map<String, ToscaTemplateCapability> capabilities;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+ public List<Map<String, ToscaTemplateRequirement>> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(List<Map<String, ToscaTemplateRequirement>> requirements) {
+ this.requirements = requirements;
+ }
+
+ public Map<String, ToscaTemplateCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaTemplateCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
new file mode 100644
index 0000000000..df9070f49c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaNodeType {
+ public ToscaNodeType() {
+ }
+
+ private ToscaMetadata metadata;
+ private String derived_from;
+ private String description;
+
+ private Map<String, ToscaProperty> properties;
+ private Map<String, ToscaCapability> capabilities;
+
+ private List<Map<String, ToscaRequirement>> requirements;
+
+ public Map<String, ToscaProperty> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, ToscaProperty> properties) {
+ this.properties = properties;
+ }
+
+ public Map<String, ToscaCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public List<Map<String, ToscaRequirement>> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(List<Map<String, ToscaRequirement>> requirements) {
+ this.requirements = requirements;
+ }
+
+ public String getDerived_from() {
+ return derived_from;
+ }
+
+ public void setDerived_from(String derived_from) {
+ this.derived_from = derived_from;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java
new file mode 100644
index 0000000000..8b5c60b1d4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class ToscaProperty {
+
+ private String type;
+ private Object _defaultp_;
+ private String description;
+ private Boolean required;
+ private EntrySchema entry_schema;
+ private String status;
+
+ public EntrySchema getEntry_schema() {
+ return entry_schema;
+ }
+
+ public void setEntry_schema(EntrySchema entry_schema) {
+ this.entry_schema = entry_schema;
+ }
+
+ public ToscaProperty() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Object getDefaultp() {
+ return _defaultp_;
+ }
+
+ public void setDefaultp(Object defaultp) {
+ this._defaultp_ = defaultp;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Boolean getRequired() {
+ return required;
+ }
+
+ public void setRequired(Boolean required) {
+ this.required = required;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java
new file mode 100644
index 0000000000..21fdc9f722
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaRequirement extends ToscaTemplateRequirement {
+
+ private List<Object> occurrences;
+
+ public ToscaRequirement() {
+ }
+
+ public List<Object> getOccurrences() {
+ return occurrences;
+ }
+
+ public void setOccurrences(List<Object> occurrences) {
+ this.occurrences = occurrences;
+ }
+
+ public Map<String, Object> toMap() throws IllegalArgumentException, IllegalAccessException {
+ return super.toMap();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java
new file mode 100644
index 0000000000..e80d52167c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaTemplate {
+ private String tosca_definitions_version;
+ private ToscaMetadata metadata;
+ private List<Map<String, Map<String, String>>> imports;
+ private Map<String, ToscaNodeType> node_types;
+ private ToscaTopolgyTemplate topology_template;
+
+ private List<Triple<String, String, Component>> dependencies;
+
+ public ToscaTemplate(String tosca_definitions_version) {
+ this.tosca_definitions_version = tosca_definitions_version;
+ }
+
+ public Map<String, ToscaNodeType> getNode_types() {
+ return node_types;
+ }
+
+ public void setNode_types(Map<String, ToscaNodeType> node_types) {
+ this.node_types = node_types;
+ }
+
+ public List<Map<String, Map<String, String>>> getImports() {
+ return imports;
+ }
+
+ public void setImports(List<Map<String, Map<String, String>>> imports) {
+ this.imports = imports;
+ }
+
+ public String getTosca_definitions_version() {
+ return tosca_definitions_version;
+ }
+
+ public void setTosca_definitions_version(String tosca_definitions_version) {
+ this.tosca_definitions_version = tosca_definitions_version;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+ public ToscaTopolgyTemplate getTopology_template() {
+ return topology_template;
+ }
+
+ public void setTopology_template(ToscaTopolgyTemplate topology_template) {
+ this.topology_template = topology_template;
+ }
+
+ public List<Triple<String, String, Component>> getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(List<Triple<String, String, Component>> dependencies) {
+ this.dependencies = dependencies;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java
new file mode 100644
index 0000000000..9adb9edfe1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaTemplateCapability {
+ private List<String> valid_source_types;
+ private Map<String, Object> properties;
+
+ public List<String> getValid_source_types() {
+ return valid_source_types;
+ }
+
+ public void setValid_source_types(List<String> valid_source_types) {
+ this.valid_source_types = valid_source_types;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java
new file mode 100644
index 0000000000..71bae81f9c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ToscaTemplateRequirement {
+ private String capability;
+ private String node;
+ private String relationship;
+
+ public ToscaTemplateRequirement() {
+ }
+
+ public String getCapability() {
+ return capability;
+ }
+
+ public void setCapability(String capability) {
+ this.capability = capability;
+ }
+
+ public String getNode() {
+ return node;
+ }
+
+ public void setNode(String node) {
+ this.node = node;
+ }
+
+ public String getRelationship() {
+ return relationship;
+ }
+
+ public void setRelationship(String relationship) {
+ this.relationship = relationship;
+ }
+
+ public Map<String, Object> toMap() throws IllegalArgumentException, IllegalAccessException {
+ Map<String, Object> map = new HashMap<>();
+ Field[] fields = this.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ field.setAccessible(true);
+ map.put(field.getName(), field.get(this));
+ }
+ return map;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java
new file mode 100644
index 0000000000..6804bf6968
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.Map;
+
+public class ToscaTopolgyTemplate {
+ private Map<String, ToscaProperty> inputs;
+ private Map<String, ToscaNodeTemplate> node_templates;
+ private Map<String, ToscaGroupTemplate> groups;
+ private SubstitutionMapping substitution_mappings;
+
+ public Map<String, ToscaNodeTemplate> getNode_templates() {
+ return node_templates;
+ }
+
+ public void setNode_templates(Map<String, ToscaNodeTemplate> node_templates) {
+ this.node_templates = node_templates;
+ }
+
+ public Map<String, ToscaGroupTemplate> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Map<String, ToscaGroupTemplate> groups) {
+ this.groups = groups;
+ }
+
+ public SubstitutionMapping getSubstitution_mappings() {
+ return substitution_mappings;
+ }
+
+ public void setSubstitution_mappings(SubstitutionMapping substitution_mapping) {
+ this.substitution_mappings = substitution_mapping;
+ }
+
+ public Map<String, ToscaProperty> getInputs() {
+ return inputs;
+ }
+
+ public void setInputs(Map<String, ToscaProperty> inputs) {
+ this.inputs = inputs;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java
new file mode 100644
index 0000000000..5f978227ef
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class VfModuleToscaMetadata implements IToscaMetadata {
+
+ private String vfModuleModelName;
+ private String vfModuleModelInvariantUUID;
+ private String vfModuleModelUUID;
+ private String vfModuleModelVersion;
+
+ @Override
+ public void setName(String name) {
+ vfModuleModelName = name;
+ }
+
+ @Override
+ public void setInvariantUUID(String invariantUUID) {
+ vfModuleModelInvariantUUID = invariantUUID;
+ }
+
+ @Override
+ public void setUUID(String uUID) {
+ vfModuleModelUUID = uUID;
+ }
+
+ @Override
+ public void setVersion(String version) {
+ vfModuleModelVersion = version;
+ }
+
+ public String getVfModuleModelName() {
+ return vfModuleModelName;
+ }
+
+ public String getVfModuleModelInvariantUUID() {
+ return vfModuleModelInvariantUUID;
+ }
+
+ public String getVfModuleModelUUID() {
+ return vfModuleModelUUID;
+ }
+
+ public String getVfModuleModelVersion() {
+ return vfModuleModelVersion;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java
new file mode 100644
index 0000000000..5cfa4a12da
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.FunctionalMenuInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public interface IUserBusinessLogic {
+ public Either<User, ActionStatus> getUser(String userId, boolean inTransaction);
+
+ public Either<User, ResponseFormat> createUser(User modifier, User newUser);
+
+ public Either<User, ResponseFormat> updateUserRole(User modifier, String userIdToUpdate, String userRole);
+
+ public Either<List<User>, ResponseFormat> getAllAdminUsers(ServletContext context);
+
+ public Either<List<User>, ResponseFormat> getUsersList(String userId, List<String> roles, String rolesStr);
+
+ public Either<User, ResponseFormat> deActivateUser(User modifier, String userUniuqeIdToDeactive);
+
+ public Either<User, ResponseFormat> authorize(User authUser);
+
+ public Either<FunctionalMenuInfo, ActionStatus> getFunctionalMenu(String userId);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java
new file mode 100644
index 0000000000..ab58ea7bf0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+/*
+ * Warning changing the order of the Enum variables changes the ordianl() function output
+ * which may result in ecompRole id change
+ */
+public enum Role {
+ ADMIN, TESTER, DESIGNER, GOVERNOR, OPS, PRODUCT_MANAGER, PRODUCT_STRATEGIST
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminAction.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminAction.java
new file mode 100644
index 0000000000..ffc5e4f947
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminAction.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+public enum UserAdminAction {
+
+ ADD_USER, UPDATE_USER, DELET_USER
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminValidator.java
new file mode 100644
index 0000000000..8e736d4c0e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserAdminValidator.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class UserAdminValidator {
+
+ private Pattern emailPat;
+ private Pattern userIdPat;
+ private Matcher matcher;
+
+ private static UserAdminValidator userAdminValidator = null;
+
+ public static synchronized UserAdminValidator getInstance() {
+ if (userAdminValidator == null) {
+ userAdminValidator = new UserAdminValidator();
+ }
+ return userAdminValidator;
+ }
+
+ 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,})$";
+
+ //private static final String USER_ID_PATTERN = "[mM]{1}[0-9]{5}|[a-zA-Z]{2}[0-9]{4}|[a-zA-Z]{2}[0-9]{4}|[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{1}";
+ private static final String USER_ID_PATTERN = "^[\\s\\w_.-]{1,50}$";
+
+ private UserAdminValidator() {
+ emailPat = Pattern.compile(EMAIL_PATTERN);
+ userIdPat = Pattern.compile(USER_ID_PATTERN);
+ }
+
+ public boolean validateEmail(final String hex) {
+ matcher = emailPat.matcher(hex);
+ return matcher.matches();
+ }
+
+ public boolean validateUserId(String userId) {
+ matcher = userIdPat.matcher(userId);
+ return matcher.matches();
+ }
+
+ public boolean validateRole(String role) {
+ for (Role r : Role.values()) {
+ if (r.name().equals(role)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java
new file mode 100644
index 0000000000..8a910fc566
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java
@@ -0,0 +1,714 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.servlet.ServletContext;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.openecomp.portalsdk.core.onboarding.ueb.FunctionalMenu;
+import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.FunctionalMenuInfo;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.UserRoleEnum;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component("userBusinessLogic")
+public class UserBusinessLogic implements IUserBusinessLogic {
+
+ private static Logger log = LoggerFactory.getLogger(UserBusinessLogic.class.getName());
+ private static UserAdminValidator userAdminValidator = UserAdminValidator.getInstance();
+
+ @Resource
+ private IUserAdminOperation userAdminOperation;
+ @Resource
+ private ComponentsUtils componentsUtils;
+ @Autowired
+ private TitanGenericDao titanDao;
+
+ @Override
+ public Either<User, ActionStatus> getUser(String userId, boolean inTransaction) {
+ return userAdminOperation.getUserData(userId, inTransaction);
+ }
+
+ @Override
+ public Either<User, ResponseFormat> createUser(User modifier, User newUser) {
+
+ ResponseFormat responseFormat;
+ String modifierUserId = modifier.getUserId();
+
+ if (modifierUserId == null) {
+ modifier.setUserId("UNKNOWN");
+ log.debug("createUser method - user header is missing");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> eitherCreator = getUser(modifierUserId, false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ log.debug("createUser method - user is not listed. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+
+ modifier = eitherCreator.left().value();
+ if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
+ log.debug("createUser method - user is not admin={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+
+ // verify user not exist
+ User userFromDb = new User();
+ // boolean isUserAlreadyExist = false;
+ Either<User, ActionStatus> eitherUserInDB = getUser(newUser.getUserId(), false);
+ if (eitherUserInDB.isRight()) {
+ ActionStatus status = eitherUserInDB.right().value();
+ if (!ActionStatus.USER_NOT_FOUND.equals(status) && !ActionStatus.USER_INACTIVE.equals(status)) {
+ responseFormat = componentsUtils.getResponseFormat(eitherUserInDB.right().value(), newUser.getUserId());
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+ } else {// User exist in DB
+ userFromDb = eitherUserInDB.left().value();
+ // isUserAlreadyExist = true;
+ if (userFromDb.getStatus() == UserStatusEnum.ACTIVE) {
+ responseFormat = componentsUtils.getResponseFormatByUserId(ActionStatus.USER_ALREADY_EXIST, newUser.getUserId());
+ log.debug("createUser method - user already exist with id: {}", modifier.getUserId(), userFromDb.getUserId());
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+ }
+
+ newUser.setStatus(UserStatusEnum.ACTIVE);
+
+ // validate Email
+ if (newUser.getEmail() != null && !userAdminValidator.validateEmail(newUser.getEmail())) {
+ log.debug("createUser method - user has invalid email={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_EMAIL_ADDRESS, newUser.getEmail());
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+
+ // validate Role
+ if (newUser.getRole() == null || newUser.getRole().length() == 0) {
+ newUser.setRole(Role.DESIGNER.name());
+ } else {
+ if (!userAdminValidator.validateRole(newUser.getRole())) {
+ log.debug("createUser method - user has invalid role={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, newUser.getRole());
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+ }
+
+ // handle last login if user is import
+ if (newUser.getLastLoginTime() == null) {
+ newUser.setLastLoginTime(0L);
+ }
+
+ Either<User, StorageOperationStatus> addOrUpdateUserReq;
+
+ if (ActionStatus.USER_INACTIVE.equals(eitherUserInDB.right().value())) { // user
+ // exist
+ // with
+ // inactive
+ // state
+ // -
+ // update
+ // user
+ // data
+ newUser.setLastLoginTime(0L);
+ addOrUpdateUserReq = userAdminOperation.updateUserData(newUser);
+
+ } else { // user not exist - create new user
+ if (newUser.getUserId() != null && !userAdminValidator.validateUserId(newUser.getUserId())) {
+ log.debug("createUser method - user has invalid userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_USER_ID, newUser.getUserId());
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.right(responseFormat);
+ }
+ addOrUpdateUserReq = userAdminOperation.saveUserData(newUser);
+ }
+
+ if (addOrUpdateUserReq.isRight() || addOrUpdateUserReq.left().value() == null) {
+ log.debug("createUser method - failed to create user");
+ Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addOrUpdateUserReq.right().value())));
+ }
+ log.debug("createUser method - user created");
+ User createdUser = addOrUpdateUserReq.left().value();
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ handleAuditing(modifier, null, createdUser, responseFormat, AuditingActionEnum.ADD_USER);
+ return Either.left(createdUser);
+ }
+
+ @Override
+ public Either<User, ResponseFormat> updateUserRole(User modifier, String userIdToUpdate, String userRole) {
+
+ ResponseFormat responseFormat;
+ String modifierUserId = modifier.getUserId();
+
+ if (modifierUserId == null) {
+ modifier.setUserId("UNKNOWN");
+ log.debug("updateUserRole method - user header is missing");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> eitherCreator = getUser(modifierUserId, false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ log.debug("updateUserRole method - user is not listed. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ modifier = eitherCreator.left().value();
+ if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
+ log.debug("updateUserRole method - user is not admin. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ if (modifier.getUserId().equals(userIdToUpdate)) {
+ log.debug("updateUserRole method - admin role can only be updated by other admin. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.UPDATE_USER_ADMIN_CONFLICT);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> userToUpdateReq = getUser(userIdToUpdate, false);
+ if (userToUpdateReq.isRight() || userToUpdateReq.left().value() == null) {
+ log.debug("updateUserRole method - user not found. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userIdToUpdate);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ if (!userAdminValidator.validateRole(userRole)) {
+ log.debug("updateUserRole method - user has invalid role={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, userRole);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+
+ User newUser = new User();
+ newUser.setRole(userRole);
+ newUser.setUserId(userIdToUpdate);
+ User userToUpdate = userToUpdateReq.left().value();
+ // if(!userRole.equals(UserRoleEnum.ADMIN.getName())){ //this is in
+ // comment until admin will be able to do do check-in/check-out from the
+ // UI
+
+ Either<List<Edge>, StorageOperationStatus> userPendingTasksReq = getPandingUserPandingTasksWithCommit(userToUpdate);
+ if (userPendingTasksReq.isRight()) {
+ log.debug("updateUserRole method - failed to get user pending tasks list", userIdToUpdate);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(userPendingTasksReq.right().value())));
+ }
+
+ List<Edge> userPendingTasks = userPendingTasksReq.left().value();
+ if (userPendingTasks.size() > 0) {
+ log.debug("updateUserRole method - User canot be updated, user have panding projects", userIdToUpdate);
+ String userTasksStatusForErrorMessage = getUserPandingTaskStatusByRole(UserRoleEnum.valueOf(userToUpdate.getRole()));
+ String userInfo = userToUpdate.getFirstName() + " " + userToUpdate.getLastName() + '(' + userToUpdate.getUserId() + ')';
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS, userInfo, userTasksStatusForErrorMessage);
+ handleAuditing(modifier, userToUpdate, userToUpdate, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.right(responseFormat);
+ }
+ // }
+ Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(newUser);
+
+ if (updateUserReq.isRight() || updateUserReq.left().value() == null) {
+ log.debug("updateUser method - failed to update user data. userId={}", modifier.getUserId());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateUserReq.right().value())));
+ }
+
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ User updatedUser = updateUserReq.left().value();
+ handleAuditing(modifier, userToUpdate, updatedUser, responseFormat, AuditingActionEnum.UPDATE_USER);
+ return Either.left(updatedUser);
+ }
+
+ @Override
+ public Either<List<User>, ResponseFormat> getAllAdminUsers(ServletContext context) {
+ Either<List<User>, ActionStatus> response = userAdminOperation.getAllUsersWithRole(Role.ADMIN.name(), null);
+
+ if (response.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(response.right().value());
+ return Either.right(responseFormat);
+ }
+ return Either.left(response.left().value());
+ }
+
+ @Override
+ public Either<List<User>, ResponseFormat> getUsersList(String modifierAttId, List<String> roles, String rolesStr) {
+ ResponseFormat responseFormat;
+ User user = new User();
+ if (modifierAttId == null) {
+ user.setUserId("UNKNOWN");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleGetUsersListAuditing(user, responseFormat, rolesStr);
+ return Either.right(responseFormat);
+ }
+ Either<User, ActionStatus> userResult = getUser(modifierAttId, false);
+ if (userResult.isRight()) {
+ user.setUserId(modifierAttId);
+ if (userResult.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(userResult.right().value());
+ }
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeUserMissingError, "Get users per roles", modifierAttId);
+ BeEcompErrorManager.getInstance().logBeUserMissingError("Get users per roles", modifierAttId);
+
+ handleGetUsersListAuditing(user, responseFormat, rolesStr);
+ return Either.right(responseFormat);
+ }
+ user = userResult.left().value();
+ Either<List<User>, ResponseFormat> getResponse = null;
+ List<User> resultList = new ArrayList<>();
+ if (roles != null && !roles.isEmpty()) {
+ for (String role : roles) {
+ if (!userAdminValidator.validateRole(role)) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, role);
+ handleGetUsersListAuditing(user, responseFormat, rolesStr);
+ return Either.right(responseFormat);
+ }
+ getResponse = getUsersPerRole(role, user, rolesStr);
+ resultList.addAll(getResponse.left().value());
+ }
+ } else {
+ rolesStr = "All";
+ getResponse = getUsersPerRole(null, user, rolesStr);
+ resultList.addAll(getResponse.left().value());
+ }
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleGetUsersListAuditing(user, responseFormat, rolesStr);
+ return Either.left(resultList);
+ }
+
+ private Either<List<User>, ResponseFormat> getUsersPerRole(String role, User user, String rolesStr) {
+ ResponseFormat responseFormat;
+ Either<List<User>, ActionStatus> response = userAdminOperation.getAllUsersWithRole(role, UserStatusEnum.ACTIVE.name());
+ if (response.isRight()) {
+ responseFormat = componentsUtils.getResponseFormat(response.right().value());
+ handleGetUsersListAuditing(user, responseFormat, rolesStr);
+ return Either.right(responseFormat);
+ }
+ return Either.left(response.left().value());
+ }
+
+ private void handleGetUsersListAuditing(User user, ResponseFormat responseFormat, String details) {
+ componentsUtils.auditGetUsersList(AuditingActionEnum.GET_USERS_LIST, user, details, responseFormat);
+ }
+
+ private void handleAuditing(User modifier, User userBefor, User userAfter, ResponseFormat responseFormat, AuditingActionEnum actionName) {
+ componentsUtils.auditAdminUserAction(actionName, modifier, userBefor, userAfter, responseFormat);
+ }
+
+ private void handleUserAccessAuditing(User user, ResponseFormat responseFormat, AuditingActionEnum actionName) {
+ componentsUtils.auditUserAccess(actionName, user, responseFormat);
+ }
+
+ @Override
+ public Either<User, ResponseFormat> deActivateUser(User modifier, String userUniuqeIdToDeactive) {
+
+ ResponseFormat responseFormat;
+ String userId = modifier.getUserId();
+
+ if (userId == null) {
+ modifier.setUserId("UNKNOWN");
+ log.debug("deActivateUser method - user header is missing");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> eitherCreator = getUser(userId, false);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ log.debug("deActivateUser method - user is not listed. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ modifier = eitherCreator.left().value();
+
+ if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
+ log.debug("deActivateUser method - user is not admin. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ if (modifier.getUserId().equals(userUniuqeIdToDeactive)) {
+ log.debug("deActivateUser deActivateUser - admin can only be deactivate by other admin. userId={}", modifier.getUserId());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.DELETE_USER_ADMIN_CONFLICT);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> getUserToDeleteResponse = getUser(userUniuqeIdToDeactive, false);
+ if (getUserToDeleteResponse.isRight() || getUserToDeleteResponse.left().value() == null) {
+ log.debug("deActivateUser method - failed to get user by id {}", userUniuqeIdToDeactive);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userUniuqeIdToDeactive);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(componentsUtils.getResponseFormat(getUserToDeleteResponse.right().value(), userUniuqeIdToDeactive));
+ }
+
+ User userToDeactivate = getUserToDeleteResponse.left().value();
+ if (userToDeactivate.getStatus().equals(UserStatusEnum.INACTIVE)) {
+ log.debug("deActivateUser method - User already inactive", userUniuqeIdToDeactive);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userUniuqeIdToDeactive);
+ handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<List<Edge>, StorageOperationStatus> userPendingTasksReq = getPandingUserPandingTasksWithCommit(userToDeactivate);
+ if (userPendingTasksReq.isRight()) {
+ log.debug("deActivateUser method - failed to get user pending tasks list", userUniuqeIdToDeactive);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(userPendingTasksReq.right().value())));
+ }
+
+ List<Edge> userPendingTasks = userPendingTasksReq.left().value();
+ if (userPendingTasks.size() > 0) {
+ log.debug("deActivateUser method - User canot be deleted, user have panding projects", userUniuqeIdToDeactive);
+
+ String userTasksStatusForErrorMessage = getUserPandingTaskStatusByRole(UserRoleEnum.valueOf(userToDeactivate.getRole()));
+ String userInfo = userToDeactivate.getFirstName() + " " + userToDeactivate.getLastName() + '(' + userToDeactivate.getUserId() + ')';
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS, userInfo, userTasksStatusForErrorMessage);
+ handleAuditing(modifier, userToDeactivate, userToDeactivate, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, StorageOperationStatus> deactivateUserReq = userAdminOperation.deActivateUser(userToDeactivate);
+ if (deactivateUserReq.isRight()) {
+ log.debug("deActivateUser method - failed to deactivate user", userUniuqeIdToDeactive);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deactivateUserReq.right().value())));
+ }
+ User deactivateUser = deactivateUserReq.left().value();
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(modifier, userToDeactivate, null, responseFormat, AuditingActionEnum.DELETE_USER);
+ return Either.left(deactivateUser);
+ }
+
+ @Override
+ public Either<User, ResponseFormat> authorize(User authUser) {
+
+ ResponseFormat responseFormat;
+
+ String userId = authUser.getUserId();
+
+ if (userId == null) {
+ authUser.setUserId("UNKNOWN");
+ log.debug("deActivateUser method - user header is missing");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleUserAccessAuditing(authUser, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> eitherCreator = getUser(userId, false);
+ if (eitherCreator.isRight()) {
+ if (eitherCreator.right().value() == ActionStatus.USER_NOT_FOUND || eitherCreator.right().value() == ActionStatus.USER_INACTIVE) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
+ handleUserAccessAuditing(authUser, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(responseFormat);
+ } else {
+ return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), authUser));
+ }
+ } else {
+ if (eitherCreator.left().value() == null) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(responseFormat);
+ }
+ }
+
+ User user = eitherCreator.left().value();
+
+ String firstName = authUser.getFirstName();
+ if (firstName != null && firstName.isEmpty() == false && !firstName.equals(user.getFirstName())) {
+ user.setFirstName(firstName);
+ }
+
+ String lastName = authUser.getLastName();
+ if (lastName != null && lastName.isEmpty() == false && !lastName.equals(user.getLastName())) {
+ user.setLastName(lastName);
+ }
+
+ String email = authUser.getEmail();
+ if (email != null && false == email.isEmpty() && !email.equals(user.getEmail())) {
+ user.setEmail(email);
+ }
+
+ // last login time stamp handle
+ user.setLastLoginTime();
+
+ Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user);
+
+ if (updateUserReq.isRight()) {
+ responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user);
+ handleUserAccessAuditing(user, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user));
+ }
+
+ User updatedUser = updateUserReq.left().value();
+
+ Long lastLoginTime = user.getLastLoginTime();
+ if (lastLoginTime != null) {
+ updatedUser.setLastLoginTime(lastLoginTime);
+ } else {
+ updatedUser.setLastLoginTime(new Long(0));
+ }
+
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleUserAccessAuditing(updatedUser, responseFormat, AuditingActionEnum.USER_ACCESS);
+ ASDCKpiApi.countUsersAuthorizations();
+ return Either.left(updatedUser);
+ }
+
+ /*
+ * The method updates user credentials only, the role is neglected The role updated through updateRole method
+ */
+ public Either<User, ResponseFormat> updateUserCredentials(User updatedUserCred) {
+
+ ResponseFormat responseFormat;
+
+ String userId = updatedUserCred.getUserId();
+
+ if (userId == null) {
+ updatedUserCred.setUserId("UNKNOWN");
+ log.debug("updateUserCredentials method - user header is missing");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
+ handleUserAccessAuditing(updatedUserCred, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(responseFormat);
+ }
+
+ Either<User, ActionStatus> eitherCreator = getUser(userId, false);
+ if (eitherCreator.isRight()) {
+ ActionStatus status = eitherCreator.right().value();
+ if (status == ActionStatus.USER_NOT_FOUND || status == ActionStatus.USER_INACTIVE) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
+ handleUserAccessAuditing(updatedUserCred, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(responseFormat);
+ } else {
+ return Either.right(componentsUtils.getResponseFormatByUser(status, updatedUserCred));
+ }
+ } else {
+ if (eitherCreator.left().value() == null) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(responseFormat);
+ }
+ }
+
+ User user = eitherCreator.left().value();
+
+ String firstName = updatedUserCred.getFirstName();
+ if (firstName != null && firstName.isEmpty() == false && !firstName.equals(user.getFirstName())) {
+ user.setFirstName(firstName);
+ }
+
+ String lastName = updatedUserCred.getLastName();
+ if (lastName != null && lastName.isEmpty() == false && !lastName.equals(user.getLastName())) {
+ user.setLastName(lastName);
+ }
+
+ String email = updatedUserCred.getEmail();
+ if (email != null && false == email.isEmpty() && !email.equals(user.getEmail())) {
+ user.setEmail(email);
+ }
+
+ if (updatedUserCred.getLastLoginTime() != null && user.getLastLoginTime() != null) {
+ if (updatedUserCred.getLastLoginTime() > user.getLastLoginTime()) {
+ user.setLastLoginTime(updatedUserCred.getLastLoginTime());
+ }
+ } else if (updatedUserCred.getLastLoginTime() != null && user.getLastLoginTime() == null) {
+ user.setLastLoginTime(updatedUserCred.getLastLoginTime());
+ }
+
+ Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user);
+
+ if (updateUserReq.isRight()) {
+ responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user);
+ handleUserAccessAuditing(user, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user));
+ }
+
+ User updatedUser = updateUserReq.left().value();
+
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleUserAccessAuditing(updatedUser, responseFormat, AuditingActionEnum.USER_ACCESS);
+ return Either.left(updatedUser);
+ }
+
+ private Either<List<Edge>, StorageOperationStatus> getPandingUserPandingTasksWithCommit(User user) {
+
+ Either<List<Edge>, StorageOperationStatus> result = null;
+
+ try {
+ UserRoleEnum userRole = UserRoleEnum.valueOf(user.getRole());
+ Map<String, Object> properties = new HashMap<String, Object>();
+ switch (userRole) {
+ case DESIGNER:
+ case PRODUCT_STRATEGIST:
+ case PRODUCT_MANAGER:
+ properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ return userAdminOperation.getUserPandingTasksList(user, properties);
+ case TESTER:
+ properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name());
+ return userAdminOperation.getUserPandingTasksList(user, properties);
+ case ADMIN:
+ properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name());
+ properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ return userAdminOperation.getUserPandingTasksList(user, properties);
+ default:
+ return Either.left(new ArrayList<>());
+ }
+ } finally {
+ // commit will be perform outside!!!
+ if (result == null || result.isRight()) {
+ log.debug("getUserPandingTasksList failed to perform fetching");
+ titanDao.rollback();
+ } else {
+ titanDao.commit();
+ }
+ }
+ }
+
+ private String getUserPandingTaskStatusByRole(UserRoleEnum role) {
+
+ switch (role) {
+ case DESIGNER:
+ case PRODUCT_STRATEGIST:
+ case PRODUCT_MANAGER:
+ return "checked-out";
+
+ case TESTER:
+ return "in-certification";
+ case ADMIN:
+ return "in-certification/checked-out";
+ default:
+ return "";
+ }
+ }
+
+ /**
+ * return the functional menu of a given user
+ *
+ * @param userId
+ * @param inTransaction
+ * @return
+ */
+ public Either<FunctionalMenuInfo, ActionStatus> getFunctionalMenu(String userId) {
+
+ boolean toCommit = false;
+
+ FunctionalMenuInfo functionalMenuInfo = new FunctionalMenuInfo();
+
+ try {
+
+ Either<ImmutablePair<User, FunctionalMenuInfo>, ActionStatus> userResult = userAdminOperation.getUserDataWithFunctionalMenu(userId);
+ if (userResult.isRight()) {
+ ActionStatus actionStatus = userResult.right().value();
+ if (actionStatus == ActionStatus.USER_NOT_FOUND) {
+ actionStatus = ActionStatus.INVALID_USER_ID;
+ }
+ return Either.right(actionStatus);
+ }
+
+ ImmutablePair<User, FunctionalMenuInfo> immutablePair = userResult.left().value();
+ FunctionalMenuInfo currentFunctionalMenu = immutablePair.right;
+ String currentMenuStr = currentFunctionalMenu != null ? currentFunctionalMenu.getFunctionalMenu() : null;
+
+ String functionalMenu = getFunctionalMenuFromUeb(userId);
+
+ // functionalMenu can be null or since we catch UebException
+ if (functionalMenu != null && false == functionalMenu.isEmpty()) {
+ functionalMenuInfo.setFunctionalMenu(functionalMenu);
+ if (false == functionalMenu.equals(currentMenuStr)) {
+ log.debug("Going to update functional menu of user {}. Functional menu is {}", userId, functionalMenu);
+ userAdminOperation.createOrUpdateFunctionalMenu(userId, functionalMenu);
+ }
+ } else {
+ String menu = currentMenuStr;
+ if (menu == null) {
+ menu = "[]";
+ }
+ log.debug("Fetch functional menu from old request. Functional menu is {}", menu);
+ functionalMenuInfo.setFunctionalMenu(menu);
+ }
+
+ toCommit = true;
+
+ } finally {
+ if (toCommit) {
+ titanDao.commit();
+ } else {
+ titanDao.rollback();
+ }
+ }
+
+ return Either.left(functionalMenuInfo);
+ }
+
+ private String getFunctionalMenuFromUeb(String userId) {
+ String functionalMenu = null;
+ try {
+ log.debug("Before calling to FunctionalMenu method for user {}", userId);
+ functionalMenu = FunctionalMenu.get(userId);
+ log.debug("Functional menu fetched is {}", functionalMenu);
+
+ } catch (UebException e) {
+ log.debug("Failed to fetch 'functional menu' of user {} from ecomp portal(via UEB). {}", userId, e);
+ BeEcompErrorManager.getInstance().logInternalFlowError("FetchFunctionalMenu", "Failed to fetch 'functional menu'", ErrorSeverity.ERROR);
+ }
+ return functionalMenu;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java
new file mode 100644
index 0000000000..e70b33a938
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+
+public interface ICommitHandler extends IDBType {
+ DBActionCodeEnum doCommit();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java
new file mode 100644
index 0000000000..a36e5fe1b5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+public interface IDBAction {
+ <T> T doAction();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java
new file mode 100644
index 0000000000..4c19e41609
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+
+public interface IDBType {
+ DBTypeEnum getDBType();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
new file mode 100644
index 0000000000..5a10e9029c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionCodeEnum;
+
+import fj.data.Either;
+
+public interface ITransactionSdnc {
+ TransactionCodeEnum finishTransaction();
+
+ Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData);
+
+ <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction);
+
+ <T> Either<T, TransactionCodeEnum> invokeTitanAction(boolean isLastAction, IDBAction dbAction);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
new file mode 100644
index 0000000000..97a8083e88
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+import java.util.Stack;
+
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
+import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class RollbackHandler implements IDBType {
+ private static Logger log = LoggerFactory.getLogger(RollbackHandler.class.getName());
+ private Stack<IDBAction> dbActionRollbacks;
+
+ private Integer transactionId;
+ private String userId, actionType;
+
+ protected RollbackHandler(Integer transactionId, String userId, String actionType) {
+ if (isRollbackForPersistenceData()) {
+ dbActionRollbacks = new Stack<>();
+ }
+ this.transactionId = transactionId;
+ this.userId = userId;
+ this.actionType = actionType;
+ }
+
+ public MethodActivationStatusEnum addRollbackAction(IDBAction rollbackAction) {
+ MethodActivationStatusEnum result = MethodActivationStatusEnum.SUCCESS;
+ if (isRollbackForPersistenceData()) {
+ dbActionRollbacks.push(rollbackAction);
+ } else {
+ result = MethodActivationStatusEnum.NOT_ALLOWED;
+ }
+ return result;
+ }
+
+ public DBActionCodeEnum doRollback() {
+ DBActionCodeEnum result;
+
+ try {
+ if (isRollbackForPersistenceData()) {
+ result = doPersistenceDataRollback();
+ } else {
+ log.debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
+ log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
+ result = doNonPersistenceDataRollback();
+ }
+ if (result != DBActionCodeEnum.SUCCESS) {
+ log.error(LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
+ log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
+ }
+
+ } catch (Exception e) {
+ result = DBActionCodeEnum.FAIL_GENERAL;
+ log.error(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
+ log.debug(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType, e);
+ log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
+ }
+
+ return result;
+ }
+
+ private <T> DBActionCodeEnum doPersistenceDataRollback() {
+ DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
+ while (!dbActionRollbacks.empty()) {
+ log.debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
+ log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
+ IDBAction rollbackAction = dbActionRollbacks.pop();
+ T rollbackResult = rollbackAction.doAction();
+ if (!isRollbackResultValid(rollbackResult)) {
+ result = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Override for specific logic
+ *
+ * @param <T>
+ */
+ public <T> boolean isRollbackResultValid(T rollbackResult) {
+ return true;
+ }
+
+ /**
+ * Override for specific logic
+ */
+ public DBActionCodeEnum doNonPersistenceDataRollback() {
+ return DBActionCodeEnum.SUCCESS;
+ }
+
+ protected abstract boolean isRollbackForPersistenceData();
+
+ /**
+ * Only Used for Unit Tests !
+ */
+ public static void setLog(Logger log) {
+ RollbackHandler.log = log;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
new file mode 100644
index 0000000000..e90b9618d4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.api;
+
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public final class TransactionUtils {
+
+ private TransactionUtils() {
+
+ }
+
+ public enum DBTypeEnum {
+ ELASTIC_SEARCH, TITAN, MYSTERY, SWIFT
+ }
+
+ public enum TransactionCodeEnum {
+ ROLLBACK_SUCCESS, ROLLBACK_FAILED, SUCCESS, COMMIT_FAILED, MULTIPLE_LAST_ACTION, INTERNAL_ERROR, UNALLOWED_METHOD_USAGE, PREPARE_ROLLBACK_FAILED, TRANSACTION_CLOSED
+ }
+
+ public enum TransactionStatusEnum {
+ OPEN, CLOSED, FAILED_ROLLBACK
+ }
+
+ public enum DBActionCodeEnum {
+ SUCCESS, FAIL_GENERAL, FAIL_MULTIPLE_LAST_ACTION
+ }
+
+ public enum ESActionTypeEnum {
+ ADD_ARTIFACT, UPDATE_ARTIFACT, REMOVE_ARTIFACT
+ }
+
+ public enum ActionTypeEnum {
+ ADD_ARTIFACT, REMOVE_ARTIFACT, UPDATE_ARTIFACT, CREATE_RESOURCE, UPDATE_RESOURCE, DELETE_RESOURCE
+ }
+
+ public static final int MAX_SIZE_TRANSACTION_LIST = 1000;
+
+ public static final int TRANSACTION_ID_RESET_LIMIT = MAX_SIZE_TRANSACTION_LIST * 10;
+
+ public static final String TRANSACTION_MARKER_STR = "TRANSACTION_MARKER";
+
+ public static final String DUMMY_USER = "udummy";
+
+ public static final Marker TRANSACTION_MARKER = MarkerFactory.getMarker(TRANSACTION_MARKER_STR);
+
+ public static class LogMessages {
+ public static final String PRE_INVOKE_ACTION = "About to add Action to SdncTransaction ID:{} for DB:{}, user:{}, action:{}";
+ public static final String INVOKE_ACTION = "invoking Action in SdncTransactionID:{}, on DB:{}, user:{}, action:{}";
+ public static final String COMMIT_ACTION_ALL_DB = "Starting Commit for SdncTransactionID:{} for all DBs, user:{}, action:{}";
+ public static final String COMMIT_ACTION_SPECIFIC_DB = "Starting Commit for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
+ public static final String COMMIT_ON_CLOSED_TRANSACTION = "Commit failed for SdncTransactionID:{} Transaction is in status:{}, user:{}, action:{}";
+ public static final String ACTION_ON_CLOSED_TRANSACTION = "Action failed for SdncTransactionID:{} Transaction is already closed, user:{}, action:{}";
+ public static final String DOUBLE_FINISH_FLAG_ACTION = "Transaction with SdncTransactionID:{} on DB:{} was called multiple times with last action flag, user:{}, action:{}";
+ public static final String DB_ACTION_FAILED_WITH_EXCEPTION = "Action on DB:{} has failed for SdncTransactionID:{}, message:{}, user:{}, action:{}";
+ public static final String ROLLBACK_SUCCEEDED_GENERAL = "Transaction rollback succeeded for SdncTransactionID:{}, user:{}, action:{}";
+ public static final String ROLLBACK_FAILED_GENERAL = "Transaction rollback failed for SdncTransactionID:{}, user:{}, action:{}";
+ public static final String ROLLBACK_FAILED_ON_DB = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
+ public static final String ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, exception message:{}, user:{}, action:{}";
+ public static final String ROLLBACK_PERSISTENT_ACTION = "About To Rollback Action on DB{} for TransactionID:{} ... user:{}, action:{}";
+ public static final String ROLLBACK_NON_PERSISTENT_ACTION = "About To Rollback Actions on DB{} for TransactionID:{} ... user:{}, action:{}";
+ public static final String CREATE_ROLLBACK_HANDLER = "creating new Rollback Handler For DB:{} in SdncTransaction ID:{}, user:{}, action:{}";
+ public static final String FAILED_CREATE_ROLLBACK = "failed to create new Rollback action For DB:{} with SdncTransactionID:{}, user:{}, action:{}";
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
new file mode 100644
index 0000000000..33a8d1163b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.impl;
+
+import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
+import org.openecomp.sdc.common.transaction.api.IDBAction;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
+
+public class ESAction implements IDBAction {
+
+ private ESCatalogDAO esCatalogDao;
+ private ESArtifactData artifactData;
+ private ESActionTypeEnum esActionType;
+
+ public ESAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
+ this.esCatalogDao = esCatalogDao;
+ this.artifactData = artifactData;
+ this.esActionType = esActiontype;
+ }
+
+ @Override
+ public DBActionCodeEnum doAction() {
+ DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
+ try {
+ if (esActionType == ESActionTypeEnum.ADD_ARTIFACT || esActionType == ESActionTypeEnum.UPDATE_ARTIFACT) {
+ esCatalogDao.writeArtifact(artifactData);
+ } else if (esActionType == ESActionTypeEnum.REMOVE_ARTIFACT) {
+ esCatalogDao.deleteArtifact(artifactData.getId());
+ }
+
+ } catch (ResourceDAOException daoException) {
+ result = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
new file mode 100644
index 0000000000..b9fb0d31b7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.impl;
+
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.transaction.api.RollbackHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
+import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
+
+import fj.data.Either;
+
+public class ESRollbackHandler extends RollbackHandler {
+
+ public ESRollbackHandler(Integer transactionId, String userId, String actionType) {
+ super(transactionId, userId, actionType);
+ }
+
+ public DBTypeEnum getDBType() {
+ return DBTypeEnum.ELASTIC_SEARCH;
+ }
+
+ protected boolean isRollbackForPersistenceData() {
+ return true;
+ }
+
+ public boolean isRollbackResultValid(DBActionCodeEnum rollbackResult) {
+ return rollbackResult == DBActionCodeEnum.SUCCESS;
+ }
+
+ public Either<ESAction, MethodActivationStatusEnum> buildEsRollbackAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
+ Either<ESAction, MethodActivationStatusEnum> result;
+
+ try {
+ ESAction esRollbackAction = null;
+ Either<ESArtifactData, ResourceUploadStatus> either = esCatalogDao.getArtifact(artifactData.getId());
+
+ switch (esActiontype) {
+ case ADD_ARTIFACT:
+
+ if (either.isRight() && either.right().value() == ResourceUploadStatus.NOT_EXIST) {
+ esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.REMOVE_ARTIFACT);
+ }
+ break;
+ case REMOVE_ARTIFACT:
+ if (either.isLeft()) {
+ esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.ADD_ARTIFACT);
+ }
+ break;
+ case UPDATE_ARTIFACT:
+
+ if (either.isLeft()) {
+ ESArtifactData originalArtifactData = either.left().value();
+ esRollbackAction = new ESAction(esCatalogDao, originalArtifactData, ESActionTypeEnum.UPDATE_ARTIFACT);
+ }
+ break;
+
+ }
+ if (esRollbackAction != null) {
+ result = Either.left(esRollbackAction);
+ } else {
+ result = Either.right(MethodActivationStatusEnum.FAILED);
+ }
+ } catch (Exception e) {
+ result = Either.right(MethodActivationStatusEnum.FAILED);
+ }
+
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanCommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanCommitHandler.java
new file mode 100644
index 0000000000..0d2ec387cf
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanCommitHandler.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.impl;
+
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.common.transaction.api.ICommitHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+
+public class TitanCommitHandler implements ICommitHandler {
+
+ private TitanGenericDao titanGenericDao;
+
+ public TitanCommitHandler(TitanGenericDao titanGenericDao) {
+ this.titanGenericDao = titanGenericDao;
+ }
+
+ @Override
+ public DBActionCodeEnum doCommit() {
+ DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
+ TitanOperationStatus titanStatus = titanGenericDao.commit();
+ if (titanStatus != TitanOperationStatus.OK) {
+ result = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ return result;
+ }
+
+ @Override
+ public DBTypeEnum getDBType() {
+ return DBTypeEnum.TITAN;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanRollbackHandler.java
new file mode 100644
index 0000000000..c0c686723c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/TitanRollbackHandler.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.impl;
+
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.common.transaction.api.RollbackHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+
+public class TitanRollbackHandler extends RollbackHandler {
+
+ private TitanGenericDao titanGenericDao;
+
+ public TitanRollbackHandler(Integer transactionId, String userId, String actionType, TitanGenericDao titanGenericDao) {
+ super(transactionId, userId, actionType);
+ this.titanGenericDao = titanGenericDao;
+ }
+
+ public DBTypeEnum getDBType() {
+ return DBTypeEnum.TITAN;
+ }
+
+ protected boolean isRollbackForPersistenceData() {
+ return false;
+ }
+
+ public DBActionCodeEnum doNonPersistenceDataRollback() {
+ DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
+ TitanOperationStatus titanStatus = titanGenericDao.rollback();
+ if (titanStatus != TitanOperationStatus.OK) {
+ result = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
new file mode 100644
index 0000000000..e802e58f27
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.mngr;
+
+import java.util.List;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.transaction.api.ICommitHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CommitManager {
+ private List<ICommitHandler> commitHandlers;
+ private Integer transactionId;
+ private String userId, actionType;
+ private static Logger log = LoggerFactory.getLogger(CommitManager.class.getName());
+
+ CommitManager(Integer transactionId, String userId, String actionType, List<ICommitHandler> commitHandlers) {
+ this.commitHandlers = commitHandlers;
+ this.transactionId = transactionId;
+ this.userId = userId;
+ this.actionType = actionType;
+
+ }
+
+ public DBActionCodeEnum transactionCommit() {
+ log.debug(LogMessages.COMMIT_ACTION_ALL_DB, transactionId, userId, actionType);
+ DBActionCodeEnum commitResult = DBActionCodeEnum.SUCCESS;
+ ICommitHandler lastHandler = null;
+ try {
+ for (ICommitHandler handler : commitHandlers) {
+ lastHandler = handler;
+ log.debug(LogMessages.COMMIT_ACTION_SPECIFIC_DB, transactionId, handler.getDBType().name(), userId, actionType);
+ DBActionCodeEnum commitCode = handler.doCommit();
+ if (commitCode == DBActionCodeEnum.FAIL_GENERAL) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "transactionCommit on DB " + handler.getDBType().name());
+ BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit on DB " + handler.getDBType().name());
+ log.debug("Commit failed for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
+ commitResult = DBActionCodeEnum.FAIL_GENERAL;
+ break;
+ }
+ log.debug("Commit succeeded for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "transactionCommit - on DB " + getDBName(lastHandler));
+ BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit - on DB " + getDBName(lastHandler));
+ log.debug("Commit failed for SdncTransactionID:{} on DB:{}, Exception message:{}", transactionId, getDBName(lastHandler), e.getMessage(), e);
+ log.info(TransactionUtils.TRANSACTION_MARKER, "Commit failed for SdncTransactionID:{} on DB:{}", transactionId, getDBName(lastHandler));
+ commitResult = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ return commitResult;
+ }
+
+ private String getDBName(ICommitHandler lastHandler) {
+ String dbName = "Unknown";
+ if (lastHandler != null) {
+ dbName = lastHandler.getDBType().name();
+ }
+ return dbName;
+ }
+
+ static void setLog(Logger log) {
+ CommitManager.log = log;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
new file mode 100644
index 0000000000..0641524038
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.mngr;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.common.transaction.api.RollbackHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
+
+import fj.data.Either;
+
+public class RollbackManager {
+ private Map<DBTypeEnum, RollbackHandler> rollBackHandlersMap;
+ private Integer transactionId;
+ private String userId, actionType;
+
+ RollbackManager(Integer transactionId, String userId, String actionType, List<RollbackHandler> roleBackHandlers) {
+ this.transactionId = transactionId;
+ this.userId = userId;
+ this.actionType = actionType;
+ rollBackHandlersMap = new HashMap<>();
+ for (RollbackHandler handler : roleBackHandlers) {
+ rollBackHandlersMap.put(handler.getDBType(), handler);
+ }
+
+ }
+
+ public DBActionCodeEnum transactionRollback() {
+ DBActionCodeEnum rollbackResult = DBActionCodeEnum.SUCCESS;
+ Iterator<RollbackHandler> handlersItr = rollBackHandlersMap.values().iterator();
+ while (handlersItr.hasNext()) {
+ RollbackHandler handler = handlersItr.next();
+ DBActionCodeEnum rollbackCode = handler.doRollback();
+ if (rollbackCode == DBActionCodeEnum.FAIL_GENERAL) {
+ rollbackResult = DBActionCodeEnum.FAIL_GENERAL;
+ }
+ }
+
+ return rollbackResult;
+ }
+
+ protected Either<RollbackHandler, MethodActivationStatusEnum> addRollbackHandler(RollbackHandler rollbackHandler) {
+ Either<RollbackHandler, MethodActivationStatusEnum> result;
+ if (rollBackHandlersMap.containsKey(rollbackHandler.getDBType())) {
+ result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED);
+ } else {
+ rollBackHandlersMap.put(rollbackHandler.getDBType(), rollbackHandler);
+ result = Either.left(rollbackHandler);
+ }
+ return result;
+
+ }
+
+ protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(DBTypeEnum dbType) {
+
+ final DBTypeEnum dbTypeFinal = dbType;
+ RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) {
+
+ @Override
+ public DBTypeEnum getDBType() {
+ return dbTypeFinal;
+ }
+
+ @Override
+ protected boolean isRollbackForPersistenceData() {
+ return true;
+ }
+ };
+ Either<RollbackHandler, MethodActivationStatusEnum> result = addRollbackHandler(rollbackHandler);
+
+ return result;
+ }
+
+ protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) {
+ Either<RollbackHandler, MethodActivationStatusEnum> result;
+ if (rollBackHandlersMap.containsKey(dbType)) {
+ result = Either.left(rollBackHandlersMap.get(dbType));
+ } else {
+ result = Either.right(MethodActivationStatusEnum.NOT_FOUND);
+ }
+ return result;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
new file mode 100644
index 0000000000..c401586383
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.mngr;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Resource;
+
+import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.common.datastructure.CapList;
+import org.openecomp.sdc.common.transaction.api.ITransactionSdnc;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component("transactionManager")
+public class TransactionManager {
+
+ private static Logger log = LoggerFactory.getLogger(TransactionManager.class.getName());
+
+ private AtomicInteger transactionIDCounter = new AtomicInteger(0);
+
+ private List<ITransactionSdnc> transactions;
+ @Resource
+ private ESCatalogDAO esCatalogDao;
+ @Resource
+ private TitanGenericDao titanGenericDao;
+
+ /**
+ * userId and actionType parameters are used only for logging purposes.
+ */
+ public ITransactionSdnc getTransaction(String userId, ActionTypeEnum actionType) {
+ if (transactions == null) {
+ init();
+ }
+ log.debug("TransactionManager creating new SdncTransaction");
+ ITransactionSdnc tx = new TransactionSdncImpl(generateTransactionID(), userId, actionType, esCatalogDao, titanGenericDao);
+ transactions.add(tx);
+
+ return tx;
+
+ }
+
+ private Integer generateTransactionID() {
+ boolean generatedSuccessfully = false;
+ int nextId = 0;
+
+ while (!generatedSuccessfully) {
+ int prevId = transactionIDCounter.get();
+ if (prevId > TransactionUtils.TRANSACTION_ID_RESET_LIMIT) {
+ resetTransactionId();
+ }
+ nextId = prevId + 1;
+ generatedSuccessfully = transactionIDCounter.compareAndSet(prevId, nextId);
+ }
+ return nextId;
+ }
+
+ private void resetTransactionId() {
+
+ boolean resetSuccessfully = false;
+ while (!resetSuccessfully) {
+ int prevId = transactionIDCounter.get();
+ resetSuccessfully = transactionIDCounter.compareAndSet(prevId, 0);
+ }
+
+ }
+
+ private synchronized void init() {
+ if (transactions == null) {
+ log.info("TransactionManager Initialized");
+ transactions = new CapList<>(TransactionUtils.MAX_SIZE_TRANSACTION_LIST);
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
new file mode 100644
index 0000000000..55eff24fa9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
@@ -0,0 +1,313 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.mngr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.config.EcompErrorName;
+import org.openecomp.sdc.common.transaction.api.ICommitHandler;
+import org.openecomp.sdc.common.transaction.api.IDBAction;
+import org.openecomp.sdc.common.transaction.api.ITransactionSdnc;
+import org.openecomp.sdc.common.transaction.api.RollbackHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionStatusEnum;
+import org.openecomp.sdc.common.transaction.impl.ESAction;
+import org.openecomp.sdc.common.transaction.impl.ESRollbackHandler;
+import org.openecomp.sdc.common.transaction.impl.TitanCommitHandler;
+import org.openecomp.sdc.common.transaction.impl.TitanRollbackHandler;
+import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class TransactionSdncImpl implements ITransactionSdnc {
+ private boolean lastActionAlreadyCalled;
+ private RollbackManager rollbackManager;
+ private CommitManager commitManager;
+ private ESCatalogDAO esCatalogDao;
+ private TitanGenericDao titanGenericDao;
+ private Integer transactionId;
+ private TransactionStatusEnum status;
+ private String userId, actionType;
+ private static Logger log = LoggerFactory.getLogger(TransactionSdncImpl.class.getName());
+
+ TransactionSdncImpl(Integer transactionId, String userId, ActionTypeEnum actionTypeEnum, ESCatalogDAO esCatalogDao, TitanGenericDao titanGenericDao) {
+ this.esCatalogDao = esCatalogDao;
+ this.titanGenericDao = titanGenericDao;
+ this.transactionId = transactionId;
+ this.userId = userId;
+ actionType = actionTypeEnum.name();
+ rollbackManager = new RollbackManager(transactionId, userId, actionType, initRollbackHandlers());
+ commitManager = new CommitManager(transactionId, userId, actionType, initCommitHandlers());
+ status = TransactionStatusEnum.OPEN;
+
+ }
+
+ private List<ICommitHandler> initCommitHandlers() {
+ List<ICommitHandler> commitHandlers = new ArrayList<>();
+ commitHandlers.add(new TitanCommitHandler(titanGenericDao));
+ return commitHandlers;
+ }
+
+ private List<RollbackHandler> initRollbackHandlers() {
+ List<RollbackHandler> rolebackHandlers = new ArrayList<>();
+ rolebackHandlers.add(new TitanRollbackHandler(transactionId, userId, actionType, titanGenericDao));
+ rolebackHandlers.add(new ESRollbackHandler(transactionId, userId, actionType));
+ return rolebackHandlers;
+ }
+
+ private <T> Either<T, TransactionCodeEnum> invokeAction(boolean isLastAction, IDBAction dbAction, DBTypeEnum dbType) {
+
+ Either<T, DBActionCodeEnum> actionResult;
+ log.debug(LogMessages.INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
+ if (isLastAction) {
+ actionResult = getLastActionResult(dbAction, dbType);
+ } else {
+ actionResult = getActionResult(dbAction, dbType);
+ }
+
+ Either<T, TransactionCodeEnum> result;
+ boolean isRollbackNedded = actionResult.isRight();
+ if (isRollbackNedded) {
+ TransactionCodeEnum transactionCode = transactionRollback();
+ result = Either.right(transactionCode);
+ } else {
+ result = Either.left(actionResult.left().value());
+ }
+ return result;
+ }
+
+ private TransactionCodeEnum transactionRollback() {
+
+ TransactionCodeEnum result;
+ DBActionCodeEnum transactionRollback = rollbackManager.transactionRollback();
+ if (transactionRollback == DBActionCodeEnum.SUCCESS) {
+ result = TransactionCodeEnum.ROLLBACK_SUCCESS;
+ log.info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
+ log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
+
+ } else {
+ result = TransactionCodeEnum.ROLLBACK_FAILED;
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "transactionCommit for transaction " + transactionId);
+ BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit for transaction " + transactionId);
+
+ log.info(LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
+ log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
+ }
+ return result;
+ }
+
+ public <T> Either<T, TransactionCodeEnum> invokeTitanAction(boolean isLastAction, IDBAction dbAction) {
+ Either<T, TransactionCodeEnum> result;
+ if (status == TransactionStatusEnum.OPEN) {
+ result = invokeAction(isLastAction, dbAction, DBTypeEnum.TITAN);
+ } else {
+ result = handleActionOnClosedTransaction();
+ }
+ updateTransactionStatus(result);
+ return result;
+ }
+
+ public <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction) {
+
+ Either<T, TransactionCodeEnum> result;
+ MethodActivationStatusEnum addingHandlerResult;
+ if (status == TransactionStatusEnum.OPEN) {
+ log.debug(LogMessages.PRE_INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
+ Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.getRollbackHandler(dbType);
+
+ if (eitherRollbackHandler.isLeft()) {
+ RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
+ addingHandlerResult = rollbackHandler.addRollbackAction(dbRollbackAction);
+ } else {
+ addingHandlerResult = addToNewRollbackHandler(dbType, dbRollbackAction);
+ }
+
+ if (addingHandlerResult == MethodActivationStatusEnum.SUCCESS) {
+ result = invokeAction(isLastAction, dbAction, dbType);
+ } else {
+ result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
+ }
+ } else {
+ result = handleActionOnClosedTransaction();
+ }
+ updateTransactionStatus(result);
+ return result;
+ }
+
+ private MethodActivationStatusEnum addToNewRollbackHandler(DBTypeEnum dbType, IDBAction dbRollbackAction) {
+ log.debug(LogMessages.CREATE_ROLLBACK_HANDLER, dbType.name(), transactionId, userId, actionType);
+ MethodActivationStatusEnum result;
+
+ Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.createRollbackHandler(dbType);
+ if (eitherRollbackHandler.isRight()) {
+ result = eitherRollbackHandler.right().value();
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "TransactionManager - addToNewRollbackHandler");
+ BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - addToNewRollbackHandler");
+ log.info(LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
+ log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
+ } else {
+ RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
+ rollbackHandler.addRollbackAction(dbRollbackAction);
+ result = MethodActivationStatusEnum.SUCCESS;
+ }
+
+ return result;
+ }
+
+ public Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData) {
+
+ Either<DBActionCodeEnum, TransactionCodeEnum> result;
+ if (status == TransactionStatusEnum.OPEN) {
+ Either<RollbackHandler, MethodActivationStatusEnum> eitherEsHandler = rollbackManager.getRollbackHandler(DBTypeEnum.ELASTIC_SEARCH);
+ if (eitherEsHandler.isRight()) {
+ result = Either.right(TransactionCodeEnum.INTERNAL_ERROR);
+ } else {
+ ESRollbackHandler esHandler = (ESRollbackHandler) eitherEsHandler.left().value();
+
+ Either<ESAction, MethodActivationStatusEnum> eitherEsRollbackAction = esHandler.buildEsRollbackAction(esCatalogDao, artifactData, esActiontype);
+ if (eitherEsRollbackAction.isLeft()) {
+ esHandler.addRollbackAction(eitherEsRollbackAction.left().value());
+ result = invokeAction(isLastAction, new ESAction(esCatalogDao, artifactData, esActiontype), DBTypeEnum.ELASTIC_SEARCH);
+ } else {
+ result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
+ }
+
+ }
+ } else {
+ result = handleActionOnClosedTransaction();
+ }
+ updateTransactionStatus(result);
+ return result;
+ }
+
+ private <T> void updateTransactionStatus(Either<T, TransactionCodeEnum> result) {
+ if (result.isRight()) {
+ updateTransactionStatus(result.right().value());
+ }
+
+ }
+
+ private <T> Either<T, TransactionCodeEnum> handleActionOnClosedTransaction() {
+ Either<T, TransactionCodeEnum> result = Either.right(TransactionCodeEnum.TRANSACTION_CLOSED);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "TransactionManager - handleActionOnClosedTransaction");
+ log.debug(LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
+ log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
+ return result;
+ }
+
+ private <T> Either<T, DBActionCodeEnum> getLastActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
+ Either<T, DBActionCodeEnum> result;
+ if (isLastActionAlreadyCalled()) {
+ result = Either.right(DBActionCodeEnum.FAIL_MULTIPLE_LAST_ACTION);
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "TransactionManager - getLastActionResult");
+ BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getLastActionResult");
+ log.debug(LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
+ log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
+ } else {
+ setLastActionAlreadyCalled(true);
+ result = getActionResult(dataBaseAction, dbType);
+ }
+ return result;
+ }
+
+ private <T> Either<T, DBActionCodeEnum> getActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
+ Either<T, DBActionCodeEnum> result;
+ try {
+ T doAction = dataBaseAction.doAction();
+ result = Either.left(doAction);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "TransactionManager - getActionResult");
+ BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getActionResult");
+ log.debug(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType, e);
+ log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType);
+
+ result = Either.right(DBActionCodeEnum.FAIL_GENERAL);
+ }
+ return result;
+ }
+
+ public TransactionCodeEnum finishTransaction() {
+ TransactionCodeEnum result;
+ if (status == TransactionStatusEnum.OPEN) {
+ DBActionCodeEnum transactionCommit = commitManager.transactionCommit();
+ if (transactionCommit == DBActionCodeEnum.SUCCESS) {
+ result = TransactionCodeEnum.SUCCESS;
+ status = TransactionStatusEnum.CLOSED;
+ } else {
+ result = transactionRollback();
+ }
+ } else {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "TransactionManager - finishTransaction");
+ BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - finishTransaction");
+ log.debug(LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
+ log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
+ result = TransactionCodeEnum.TRANSACTION_CLOSED;
+ }
+ updateTransactionStatus(result);
+ return result;
+ }
+
+ private void updateTransactionStatus(TransactionCodeEnum result) {
+ switch (result) {
+ case SUCCESS:
+ status = TransactionStatusEnum.CLOSED;
+ break;
+ case ROLLBACK_SUCCESS:
+ status = TransactionStatusEnum.CLOSED;
+ break;
+ case ROLLBACK_FAILED:
+ status = TransactionStatusEnum.FAILED_ROLLBACK;
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ private boolean isLastActionAlreadyCalled() {
+ return lastActionAlreadyCalled;
+ }
+
+ private void setLastActionAlreadyCalled(boolean lastAction) {
+ this.lastActionAlreadyCalled = lastAction;
+ }
+
+ static void setLog(Logger log) {
+ TransactionSdncImpl.log = log;
+ }
+
+ TransactionStatusEnum getStatus() {
+ return status;
+ }
+}
diff --git a/catalog-be/src/main/resources/application-context.xml b/catalog-be/src/main/resources/application-context.xml
new file mode 100644
index 0000000000..da0a49f6e2
--- /dev/null
+++ b/catalog-be/src/main/resources/application-context.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+
+ <context:annotation-config />
+ <aop:aspectj-autoproxy proxy-target-class="true" />
+
+ <context:component-scan
+ base-package="org.openecomp.sdc.be.dao.impl,
+ org.openecomp.sdc.be.dao.es,
+ org.openecomp.sdc.be.resources.impl,
+ org.openecomp.sdc.be.dao.neo4j,
+ org.openecomp.sdc.be.model.operations.impl,
+ org.openecomp.sdc.be.model.cache,
+ org.openecomp.sdc.be.dao.titan,
+ org.openecomp.sdc.be.user,
+ org.openecomp.sdc.be.impl,
+ org.openecomp.sdc.be.auditing.impl,
+ org.openecomp.sdc.be.components.impl,
+ org.openecomp.sdc.be.components.distribution.engine,
+ org.openecomp.sdc.be.distribution,
+ org.openecomp.sdc.be.components.clean,
+ org.openecomp.sdc.be.dao.cassandra,
+ org.openecomp.sdc.be.switchover.detector,
+ org.openecomp.sdc.be.tosca,
+ org.openecomp.sdc.be.externalapi.servlet
+ ">
+
+ </context:component-scan>
+
+ <bean id="resourceImportManager" class="org.openecomp.sdc.be.components.impl.ResourceImportManager" />
+ <bean id="capabilityTypeImportManager" class="org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager" />
+ <bean id="servletUtils" class="org.openecomp.sdc.be.impl.ServletUtils" />
+ <bean id="resourceBusinessLogic" class="org.openecomp.sdc.be.components.impl.ResourceBusinessLogic" />
+ <bean id="serviceBusinessLogic" class="org.openecomp.sdc.be.components.impl.ServiceBusinessLogic" />
+ <bean id="productBusinessLogic" class="org.openecomp.sdc.be.components.impl.ProductBusinessLogic" />
+ <bean id="artifactBusinessLogic" class="org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic" />
+ <bean id="lifecycleBusinessLogic" class="org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic" />
+ <bean id="serviceComponentInstanceBusinessLogic" class="org.openecomp.sdc.be.components.impl.ServiceComponentInstanceBusinessLogic" />
+ <bean id="productComponentInstanceBusinessLogic" class="org.openecomp.sdc.be.components.impl.ProductComponentInstanceBusinessLogic" />
+ <bean id="vfComponentInstanceBusinessLogic" class="org.openecomp.sdc.be.components.impl.VFComponentInstanceBusinessLogic" />
+ <bean id="transactionManager" class="org.openecomp.sdc.common.transaction.mngr.TransactionManager" />
+ <bean id="userBusinessLogic" class="org.openecomp.sdc.be.user.UserBusinessLogic" />
+ <bean id="elementsBusinessLogic" class="org.openecomp.sdc.be.components.impl.ElementBusinessLogic" />
+ <bean id="propertyBusinessLogic" class="org.openecomp.sdc.be.components.impl.PropertyBusinessLogic" />
+ <bean id="auditingManager" class="org.openecomp.sdc.be.auditing.impl.AuditingManager" />
+ <bean id="distributionBusinessLogic" class="org.openecomp.sdc.be.distribution.DistributionBusinessLogic" />
+ <bean id="interfaceLifecycleTypeImportManager" class="org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager" />
+ <bean id="distributionMonitoringBusinessLogic" class="org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic" />
+ <bean id="additionalInformationBusinessLogic" class="org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic" />
+ <bean id="distribution-engine-cluster-health" class="org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth" />
+ <bean id="categoriesImportManager" class="org.openecomp.sdc.be.components.impl.CategoriesImportManager" />
+ <bean id="asset-metadata-utils" class="org.openecomp.sdc.be.externalapi.servlet.AssetMetadataConverter" />
+
+
+
+ <util:properties id="elasticsearchConfig" location="file:${config.home}/elasticsearch.yml" />
+
+</beans>
diff --git a/catalog-be/src/main/resources/config/configuration.yaml b/catalog-be/src/main/resources/config/configuration.yaml
new file mode 100644
index 0000000000..b8e80dc17c
--- /dev/null
+++ b/catalog-be/src/main/resources/config/configuration.yaml
@@ -0,0 +1,478 @@
+identificationHeaderFields:
+ - HTTP_IV_USER
+ - HTTP_CSP_FIRSTNAME
+ - HTTP_CSP_LASTNAME
+ - HTTP_IV_REMOTE_ADDRESS
+ - HTTP_CSP_WSTYPE
+
+
+
+# catalog backend hostname
+beFqdn: localhost
+
+# catalog backend http port
+beHttpPort: 8080
+
+# catalog backend http context
+beContext: /sdc/rest/config/get
+
+# catalog backend protocol
+beProtocol: http
+
+# catalog backend ssl port
+beSslPort: 8443
+
+version: 1.0
+released: 2012-11-30
+
+titanCfgFile: /home/vagrant/catalog-be/config/catalog-be/titan.properties
+titanInMemoryGraph: false
+titanLockTimeout: 1800
+titanReconnectIntervalInSeconds: 3
+titanHealthCheckReadTimeout: 1
+esReconnectIntervalInSeconds: 3
+uebHealthCheckReconnectIntervalInSeconds: 15
+uebHealthCheckReadTimeout: 4
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd
+
+neo4j:
+ host: neo4jhost
+ port: 7474
+ user: neo4j
+ password: "12345"
+
+
+#Application-specific settings of ES
+elasticSearch:
+ # Mapping of index prefix to time-based frame. For example, if below is configured:
+ #
+ # - indexPrefix: auditingevents
+ # creationPeriod: minute
+ #
+ # then ES object of type which is mapped to "auditingevents-*" template, and created on 2015-12-23 13:24:54, will enter "auditingevents-2015-12-23-13-24" index.
+ # Another object created on 2015-12-23 13:25:54, will enter "auditingevents-2015-12-23-13-25" index.
+ # If creationPeriod: month, both of the above will enter "auditingevents-2015-12" index.
+ #
+ # PLEASE NOTE: the timestamps are created in UTC/GMT timezone! This is needed so that timestamps will be correctly presented in Kibana.
+ #
+ # Legal values for creationPeriod - year, month, day, hour, minute, none (meaning no time-based behaviour).
+ #
+ # If no creationPeriod is configured for indexPrefix, default behavour is creationPeriod: month.
+
+ indicesTimeFrequency:
+ - indexPrefix: auditingevents
+ creationPeriod: month
+ - indexPrefix: monitoring_events
+ creationPeriod: month
+
+artifactTypes:
+ - CHEF
+ - PUPPET
+ - SHELL
+ - YANG
+ - YANG_XML
+ - HEAT
+ - BPEL
+ - DG_XML
+ - MURANO_PKG
+ - WORKFLOW
+ - NETWORK_CALL_FLOW
+ - TOSCA_TEMPLATE
+ - TOSCA_CSAR
+ - AAI_SERVICE_MODEL
+ - AAI_VF_MODEL
+ - AAI_VF_MODULE_MODEL
+ - AAI_VF_INSTANCE_MODEL
+ - OTHER
+
+licenseTypes:
+ - User
+ - Installation
+ - CPU
+
+#Deployment artifacts placeHolder
+resourceTypes: &allResourceTypes
+ - VFC
+ - CP
+ - VL
+ - VF
+
+# validForResourceTypes usage
+# validForResourceTypes:
+# - VF
+# - VL
+deploymentResourceArtifacts:
+# heat:
+# displayName: "Base HEAT Template"
+# type: HEAT
+# validForResourceTypes: *allResourceTypes
+# heatVol:
+# displayName: "Volume HEAT Template"
+# type: HEAT_VOL
+# validForResourceTypes: *allResourceTypes
+# heatNet:
+# displayName: "Network HEAT Template"
+# type: HEAT_NET
+# validForResourceTypes: *allResourceTypes
+
+deploymentResourceInstanceArtifacts:
+ heatEnv:
+ displayName: "HEAT ENV"
+ type: HEAT_ENV
+ description: "Auto-generated HEAT Environment deployment artifact"
+ fileExtension: "env"
+
+#tosca artifacts placeholders
+toscaArtifacts:
+ assetToscaTemplate:
+ artifactName: -template.yml
+ displayName: Tosca Template
+ type: TOSCA_TEMPLATE
+ description: TOSCA representation of the asset
+ assetToscaCsar:
+ artifactName: -csar.csar
+ displayName: Tosca Model
+ type: TOSCA_CSAR
+ description: TOSCA definition package of the asset
+
+
+#Informational artifacts placeHolder
+excludeResourceCategory:
+ - Generic
+informationalResourceArtifacts:
+ features:
+ displayName: Features
+ type: OTHER
+ capacity:
+ displayName: Capacity
+ type: OTHER
+ vendorTestResult:
+ displayName: Vendor Test Result
+ type: OTHER
+ testScripts:
+ displayName: Test Scripts
+ type: OTHER
+ cloudQuestionnaire:
+ displayName: Cloud Questionnaire (completed)
+ type: OTHER
+ HEATTemplateFromVendor:
+ displayName: HEAT Template from Vendor
+ type: HEAT
+ resourceSecurityTemplate:
+ displayName: Resource Security Template
+ type: OTHER
+
+excludeServiceCategory:
+
+informationalServiceArtifacts:
+ serviceArtifactPlan:
+ displayName: Service Artifact Plan
+ type: OTHER
+ summaryOfImpactsToECOMPElements:
+ displayName: Summary of impacts to ECOMP elements,OSSs, BSSs
+ type: OTHER
+ controlLoopFunctions:
+ displayName: Control Loop Functions
+ type: OTHER
+ dimensioningInfo:
+ displayName: Dimensioning Info
+ type: OTHER
+ affinityRules:
+ displayName: Affinity Rules
+ type: OTHER
+ operationalPolicies:
+ displayName: Operational Policies
+ type: OTHER
+ serviceSpecificPolicies:
+ displayName: Service-specific Policies
+ type: OTHER
+ engineeringRules:
+ displayName: Engineering Rules (ERD)
+ type: OTHER
+ distributionInstructions:
+ displayName: Distribution Instructions
+ type: OTHER
+ certificationTestResults:
+ displayName: TD Certification Test Results
+ type: OTHER
+ deploymentVotingRecord:
+ displayName: Deployment Voting Record
+ type: OTHER
+ serviceQuestionnaire:
+ displayName: Service Questionnaire
+ type: OTHER
+ serviceSecurityTemplate:
+ displayName: Service Security Template
+ type: OTHER
+
+serviceApiArtifacts:
+ configuration:
+ displayName: Configuration
+ type: OTHER
+ instantiation:
+ displayName: Instantiation
+ type: OTHER
+ monitoring:
+ displayName: Monitoring
+ type: OTHER
+ reporting:
+ displayName: Reporting
+ type: OTHER
+ logging:
+ displayName: Logging
+ type: OTHER
+ testing:
+ displayName: Testing
+ type: OTHER
+
+
+additionalInformationMaxNumberOfKeys: 50
+
+systemMonitoring:
+ enabled: false
+ isProxy: false
+ probeIntervalInSeconds: 15
+
+defaultHeatArtifactTimeoutMinutes: 60
+
+serviceDeploymentArtifacts:
+ YANG_XML:
+ acceptedTypes:
+ - xml
+ VNF_CATALOG:
+ acceptedTypes:
+ - xml
+ MODEL_INVENTORY_PROFILE:
+ acceptedTypes:
+ - xml
+ MODEL_QUERY_SPEC:
+ acceptedTypes:
+ - xml
+#AAI Artifacts
+ AAI_SERVICE_MODEL:
+ acceptedTypes:
+ - xml
+ AAI_VF_MODULE_MODEL:
+ acceptedTypes:
+ - xml
+ AAI_VF_INSTANCE_MODEL:
+ acceptedTypes:
+ - xml
+ OTHER:
+ acceptedTypes:
+
+resourceDeploymentArtifacts:
+ HEAT:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_VOL:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_NESTED:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_ARTIFACT:
+ acceptedTypes:
+ validForResourceTypes: *allResourceTypes
+ HEAT_NET:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ YANG_XML:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VNF_CATALOG:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VF_LICENSE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VENDOR_LICENSE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ MODEL_INVENTORY_PROFILE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ MODEL_QUERY_SPEC:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ #APPC Artifatcs
+ APPC_CONFIG:
+ acceptedTypes:
+ validForResourceTypes:
+ - VF
+ #DCAE Artifacts
+ DCAE_TOSCA:
+ acceptedTypes:
+ - yml
+ - yaml
+ validForResourceTypes:
+ - VF
+ DCAE_JSON:
+ acceptedTypes:
+ - json
+ validForResourceTypes:
+ - VF
+ DCAE_POLICY:
+ acceptedTypes:
+ - emf
+ validForResourceTypes:
+ - VF
+ DCAE_DOC:
+ acceptedTypes:
+ validForResourceTypes:
+ - VF
+ DCAE_EVENT:
+ acceptedTypes:
+ validForResourceTypes:
+ - VF
+#AAI Artifacts
+ AAI_VF_MODEL:
+ acceptedTypes:
+ - xml
+ validForResourceTypes:
+ - VF
+ AAI_VF_MODULE_MODEL:
+ acceptedTypes:
+ - xml
+ validForResourceTypes:
+ - VF
+ OTHER:
+ acceptedTypes:
+ validForResourceTypes: *allResourceTypes
+
+resourceInstanceDeploymentArtifacts:
+ HEAT_ENV:
+ acceptedTypes:
+ - env
+ VF_MODULES_METADATA:
+ acceptedTypes:
+ - json
+#DCAE_VF Instance Artifacts
+ DCAE_INVENTORY_TOSCA:
+ acceptedTypes:
+ - yml
+ - yaml
+ DCAE_INVENTORY_JSON:
+ acceptedTypes:
+ - json
+ DCAE_INVENTORY_POLICY:
+ acceptedTypes:
+ - emf
+ DCAE_INVENTORY_DOC:
+ acceptedTypes:
+ DCAE_INVENTORY_BLUEPRINT:
+ acceptedTypes:
+ DCAE_INVENTORY_EVENT:
+ acceptedTypes:
+
+
+resourceInformationalDeployedArtifacts:
+
+
+requirementsToFulfillBeforeCert:
+
+capabilitiesToConsumeBeforeCert:
+
+unLoggedUrls:
+ - /sdc2/rest/healthCheck
+
+cleanComponentsConfiguration:
+ cleanIntervalInMinutes: 1440
+ componentsToClean:
+ - Resource
+ - Service
+
+artifactsIndex: resources
+
+cassandraConfig:
+ cassandraHosts: ['localhost']
+ localDataCenter:
+ reconnectTimeout : 30000
+ authenticate: false
+ username: koko
+ password: bobo
+ ssl: false
+ truststorePath : /path/path
+ truststorePassword : 123123
+ keySpaces:
+ - { name: sdcaudit, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: sdcartifact, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: sdccomponent, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+
+
+switchoverDetector:
+ gBeFqdn:
+ gFeFqdn:
+ beVip: 1.2.3.4
+ feVip: 1.2.3.4
+ beResolveAttempts: 3
+ feResolveAttempts: 3
+ enabled: false
+ interval: 60
+ changePriorityUser: ecompasdc
+ changePriorityPassword: ecompasdc123
+ publishNetworkUrl: "http://localhost/crt/CipDomain.ECOMP-ASDC-DEVST/config/update_network?user=root"
+ publishNetworkBody: '{"note":"publish network"}'
+ groups:
+ beSet: { changePriorityUrl: "http://localhost/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-BE.ecomp.idns.cip?user=root",
+ changePriorityBody: '{"name":"AIO-BE.ecomp.idns.cip","uri":"/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-BE.ecomp.idns.cip","no_ad_redirection":false,"v4groups":{"failover_groups":["/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_mg_be","/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_bs_be"],"failover_policy":["FAILALL"]},"comment":"AIO BE G-fqdn","intended_app_proto":"DNS"}'}
+ feSet: { changePriorityUrl: "http://cora.web/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-FE.ecomp.idns.cip?user=root",
+ changePriorityBody: '{"comment":"AIO G-fqdn","name":"AIO-FE.ecomp.idns.cip","v4groups":{"failover_groups":["/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_mg_fe","/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_bs_fe"],"failover_policy":["FAILALL"]},"no_ad_redirection":false,"intended_app_proto":"DNS","uri":"/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-FE.ecomp.idns.cip"}'}
+
+
+heatEnvArtifactHeader:
+ ""
+heatEnvArtifactFooter:
+ ""
+
+onboarding:
+ protocol: http
+ host: localhost
+ port: 8080
+ downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
+ #downloadCsarUri: "/onboardingci/onbrest/onboarding-api/v1.0/vendor-software-products/packages"
+
+applicationL1Cache:
+ datatypes:
+ enabled: true
+ firstRunDelay: 10
+ pollIntervalInSec: 60
+
+applicationL2Cache:
+ enabled: true
+ catalogL1Cache:
+ enabled: true
+ resourcesSizeInCache: 300
+ servicesSizeInCache: 200
+ productsSizeInCache: 100
+ queue:
+ syncIntervalInSecondes: 43200
+ waitOnShutDownInMinutes: 10
+ numberOfCacheWorkers: 4
+
+toscaValidators:
+ stringMaxLength: 65536
+disableAudit: false \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml b/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml
new file mode 100644
index 0000000000..8c56a26785
--- /dev/null
+++ b/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml
@@ -0,0 +1,46 @@
+uebServers:
+ - uebsb91sfdc.it.att.com:3904
+ - uebsb92sfdc.it.att.com:3904
+ - uebsb93sfdc.it.att.com:3904
+
+# prev Kansas City Sandbox uebPublicKey: 8F3MDAtMSBwwpSMy
+uebPublicKey: sSJc5qiBnKy2qrlc
+
+# prev Kansas City Sandbox uebSecretKey: gzFmsTxSCtO5RQfAccM6PqqX
+uebSecretKey: 4ZRPzNJfEUK0sSNBvccd2m7X
+
+distributionNotifTopicName: ASDC-DISTR-NOTIF-TOPIC
+distributionStatusTopicName: ASDC-DISTR-STATUS-TOPIC
+
+initRetryIntervalSec: 5
+initMaxIntervalSec: 60
+
+distribNotifServiceArtifactTypes:
+ info:
+ - MURANO-PKG
+
+distribNotifResourceArtifactTypes:
+ lifecycle:
+ - HEAT
+ - DG-XML
+
+environments:
+ - PROD
+
+distributionStatusTopic:
+ pollingIntervalSec: 60
+ fetchTimeSec: 15
+ consumerGroup: asdc
+ consumerId: asdc-id
+
+distributionNotificationTopic:
+ minThreadPoolSize: 0
+ maxThreadPoolSize: 10
+ maxWaitingAfterSendingSeconds: 5
+
+
+createTopic:
+ partitionCount: 1
+ replicationCount: 1
+
+startDistributionEngine: true \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/ecomp-error-configuration.yaml b/catalog-be/src/main/resources/config/ecomp-error-configuration.yaml
new file mode 100644
index 0000000000..9d7cd74a2b
--- /dev/null
+++ b/catalog-be/src/main/resources/config/ecomp-error-configuration.yaml
@@ -0,0 +1,383 @@
+###########################################
+# Note the conventions of the field values:
+# type can be one of: CONFIG_ERROR, SYSTEM_ERROR, DATA_ERROR, CONNECTION_PROBLEM, AUTHENTICATION_PROBLEM
+# severity can be one of: WARN, ERROR, FATAL
+# alarmSeverity can be one of: CRITICAL,MAJOR,MINOR,INFORMATIONAL,NONE
+# code is a unique integer in range of 3003-9999 (3000-3002 are occupied for internal usage)
+# The above enumeration values are out-of-the-box and can be changed in code.
+# In case of config and code mismatch, the appropriate error will be printed to log
+#
+## Range of BE codes - 3010-7999
+
+errors:
+
+ BeRestApiGeneralError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4000,
+ severity: ERROR,
+ description: "Unexpected error during BE REST API execution",
+ alarmSeverity: CRITICAL
+ }
+
+ BeHealthCheckError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3010,
+ severity: ERROR,
+ description: "Error during BE Health Check",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInitializationError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4019,
+ severity: ERROR,
+ description: "Catalog-BE was not initialized properly",
+ alarmSeverity: CRITICAL
+ }
+
+ BeResourceMissingError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3011,
+ severity: ERROR,
+ description: "Mandatory resource %s cannot be found in repository",
+ alarmSeverity: MAJOR
+ }
+
+ BeServiceMissingError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3012,
+ severity: ERROR,
+ description: "Mandatory service %s cannot be found in repository",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedAddingResourceInstanceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3013,
+ severity: ERROR,
+ description: "Failed to add resource instance of resource %s to service %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeIncorrectServiceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3014,
+ severity: ERROR,
+ description: "Service %s is not valid",
+ alarmSeverity: MAJOR
+ }
+
+ BeRepositoryDeleteError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3015,
+ severity: ERROR,
+ description: "Failed to delete object %s from repository",
+ alarmSeverity: CRITICAL
+ }
+
+ BeRepositoryQueryError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3016,
+ severity: ERROR,
+ description: "Failed to fetch from repository %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeInvalidConfigurationError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3017,
+ severity: FATAL,
+ description: "Configuration parameter %s is invalid. Value configured is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebConnectionError: {
+ type: CONNECTION_PROBLEM,
+ code: ASDC_4001,
+ severity: ERROR,
+ description: "Connection problem towards U-EB server. Reason: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3019,
+ severity: ERROR,
+ description: "Error occured during access to U-EB Server. Operation: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebObjectNotFoundError: {
+ type: DATA_ERROR,
+ code: ASDC_4005,
+ severity: ERROR,
+ description: "Error occured during access to U-EB Server. Data not found: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionEngineSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3021,
+ severity: ERROR,
+ description: "Error occured in Distribution Engine. Failed operation: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebAuthenticationError: {
+ type: AUTHENTICATION_PROBLEM,
+ code: ASDC_4003,
+ severity: ERROR,
+ description: "Authentication problem towards U-EB server. Reason: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebUnkownHostError: {
+ type: CONNECTION_PROBLEM,
+ code: ASDC_4002,
+ severity: ERROR,
+ description: "Connection problem towards U-EB server. Cannot reach host %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionEngineInvalidArtifactType: {
+ type: DATA_ERROR,
+ code: ASDC_4006,
+ severity: WARN,
+ description: "The artifact type %s does not appear in the list of valid artifacts %s",
+ alarmSeverity: MAJOR
+ }
+ BeInvalidTypeError: {
+ type: DATA_ERROR,
+ code: ASDC_4008,
+ severity: WARN,
+ description: "The type %s of %s is invalid",
+ alarmSeverity: MAJOR
+ }
+ BeInvalidValueError: {
+ type: DATA_ERROR,
+ code: ASDC_3028,
+ severity: WARN,
+ description: "The value %s of %s from type %s is invalid",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedDeletingResourceInstanceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3029,
+ severity: ERROR,
+ description: "Failed to delete resource instance %s from service %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeMissingConfigurationError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3030,
+ severity: FATAL,
+ description: "Configuration parameter %s is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeConfigurationInvalidListSizeError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3031,
+ severity: FATAL,
+ description: "Configuration parameter %s is invalid. At least %s values shall be configured",
+ alarmSeverity: MAJOR
+ }
+
+ ErrorConfigFileFormat: {
+ type: CONFIG_ERROR,
+ code: ASDC_3032,
+ severity: ERROR,
+ description: "Error element not found in YAML name: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeMissingArtifactInformationError: {
+ type: DATA_ERROR,
+ code: ASDC_4010,
+ severity: ERROR,
+ description: "Artifact uploaded has missing information. Missing %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4011,
+ severity: ERROR,
+ description: "Artifact %s requested is not found",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactPayloadInvalid: {
+ type: DATA_ERROR,
+ code: ASDC_4012,
+ severity: ERROR,
+ description: "Payload of artifact uploaded is invalid (invalid MD5 or encryption)",
+ alarmSeverity: MAJOR
+ }
+
+ BeUserMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4009,
+ severity: ERROR,
+ description: "User %s requested is not found",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactInformationInvalidError: {
+ type: DATA_ERROR,
+ code: ASDC_4013,
+ severity: ERROR,
+ description: "Input for artifact metadata is invalid",
+ alarmSeverity: MAJOR
+ }
+ BeFailedAddingCapabilityTypeError: {
+ type: DATA_ERROR,
+ code: ASDC_4015,
+ severity: ERROR,
+ description: "Failed adding capability type",
+ alarmSeverity: CRITICAL
+ }
+
+ BeCapabilityTypeMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4016,
+ severity: ERROR,
+ description: "Capability Type %s not found",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInterfaceMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4020,
+ severity: ERROR,
+ description: "Interface %s required is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeDaoSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4014,
+ severity: ERROR,
+ description: "Operation towards database failed",
+ alarmSeverity: CRITICAL
+ }
+
+ BeSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4017,
+ severity: ERROR,
+ description: "Unexpected error during operation",
+ alarmSeverity: CRITICAL
+ }
+
+ BeFailedLockObjectError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4007,
+ severity: WARN,
+ description: "Failed to lock object for update",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInvalidJsonInput: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4018,
+ severity: ERROR,
+ description: "Failed to convert json input to object",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4021,
+ severity: ERROR,
+ description: "Distribution %s required is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeHealthCheckRecovery: {
+ type: RECOVERY,
+ code: ASDC_4022,
+ severity: INFO,
+ description: "BE Health Check Recovery",
+ alarmSeverity: INFORMATIONAL
+ }
+ BeFailedCreateNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6000,
+ severity: ERROR,
+ description: "Failed to create node %s on graph. status is %s",
+ alarmSeverity: MAJOR
+ }
+ BeFailedUpdateNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6001,
+ severity: ERROR,
+ description: "Failed to update node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedDeleteNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6002,
+ severity: ERROR,
+ description: "Failed to delete node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedRetrieveNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6003,
+ severity: ERROR,
+ description: "Failed to retrieve node %s from graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeExecuteRollbackError: {
+ type: DATA_ERROR,
+ code: ASDC_6004,
+ severity: ERROR,
+ description: "Going to execute rollback on graph.",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindParentError: {
+ type: DATA_ERROR,
+ code: ASDC_6005,
+ severity: ERROR,
+ description: "Failed to find parent node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAllNodesError: {
+ type: DATA_ERROR,
+ code: ASDC_6006,
+ severity: ERROR,
+ description: "Failed to fetch all nodes with type %s of parent node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAssociationError: {
+ type: DATA_ERROR,
+ code: ASDC_6007,
+ severity: ERROR,
+ description: "Cannot find node with type %s associated with node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAssociationError: {
+ type: DATA_ERROR,
+ code: ASDC_6008,
+ severity: ERROR,
+ description: "Cannot find node with type %s associated with node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+ BeComponentCleanerSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_6009,
+ severity: ERROR,
+ description: "Error occured in Component Cleaner Task. Failed operation: %s",
+ alarmSeverity: MAJOR
+ }
+ \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
new file mode 100644
index 0000000000..0054ce2be9
--- /dev/null
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -0,0 +1,1694 @@
+# Errors
+errors:
+ OK: {
+ code: 200,
+ message: "OK"
+ }
+ CREATED: {
+ code: 201,
+ message: "OK"
+ }
+ NO_CONTENT: {
+ code: 204,
+ message: "No Content"
+ }
+#--------POL4050-----------------------------
+ NOT_ALLOWED: {
+ code: 405,
+ message: "Error: Method not allowed.",
+ messageId: "POL4050"
+ }
+#--------POL5000-----------------------------
+ GENERAL_ERROR: {
+ code: 500,
+ message: "Error: Internal Server Error. Please try again later.",
+ messageId: "POL5000"
+ }
+#---------POL5001------------------------------
+ MISSING_X_ECOMP_INSTANCE_ID: {
+ code: 400 ,
+ message: "Error: Missing 'X-ECOMP-InstanceID' HTTP header.",
+ messageId: "POL5001"
+ }
+#---------POL5002------------------------------
+ AUTH_REQUIRED: {
+ code: 401 ,
+ message: "Error: Authentication is required to use the API.",
+ messageId: "POL5002"
+ }
+#---------POL5003------------------------------
+ AUTH_FAILED: {
+ code: 403 ,
+ message: "Error: Not authorized to use the API.",
+ messageId: "POL5003"
+ }
+#---------SVC4000-----------------------------
+ INVALID_CONTENT: {
+ code: 400,
+ message: "Error: Invalid content.",
+ messageId: "SVC4000"
+ }#---------SVC4000-----------------------------
+ INVALID_CONTENT: {
+ code: 400,
+ message: "Error: Invalid content.",
+ messageId: "SVC4000"
+ }
+#---------SVC4002-----------------------------
+ MISSING_INFORMATION: {
+ code: 403,
+ message: "Error: Missing information.",
+ messageId: "SVC4002"
+ }
+#---------SVC4003------------------------------
+# %1 - Users's USER_ID
+ USER_NOT_FOUND: {
+ code: 404,
+ message: "Error: User '%1' was not found.",
+ messageId: "SVC4003"
+ }
+#---------SVC4004-----------------------------
+# %1 - Users's email address
+ INVALID_EMAIL_ADDRESS: {
+ code: 400,
+ message: "Error: Invalid email address '%1'.",
+ messageId: "SVC4004"
+ }
+#---------SVC4005------------------------------
+# %1 - role
+ INVALID_ROLE: {
+ code: 400,
+ message: "Error: Invalid role '%1'.",
+ messageId: "SVC4005"
+ }
+#---------SVC4006------------------------------
+# %1 - Users's USER_ID
+ USER_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: User with '%1' ID already exists.",
+ messageId: "SVC4006"
+ }
+#---------SVC4007------------------------------
+ DELETE_USER_ADMIN_CONFLICT: {
+ code: 409,
+ message: "Error: An administrator can only be deleted by another administrator.",
+ messageId: "SVC4007"
+ }
+#---------SVC4008-----------------------------
+# %1 - Users's userId
+ INVALID_USER_ID: {
+ code: 400,
+ message: "Error: Invalid userId '%1'.",
+ messageId: "SVC4008"
+ }
+#---------SVC4049------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_CONTACT: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 contact id.",
+ messageId: "SVC4049"
+ }
+#---------SVC4050-----------------------------
+# %1 - Service/Resource/Additional parameter
+# %2 - service/resource/label name
+ COMPONENT_NAME_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: %1 with name '%2' already exists.",
+ messageId: "SVC4050"
+ }
+#---------SVC4051------------------------------
+# %1 - resource/service
+ COMPONENT_MISSING_CATEGORY: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 category.",
+ messageId: "SVC4051"
+ }
+
+#---------SVC4052------------------------------
+ COMPONENT_MISSING_TAGS: {
+ code: 400,
+ message: "Error: Invalid Content. At least one tag has to be specified.",
+ messageId: "SVC4052"
+ }
+
+#---------SVC4053------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_DESCRIPTION: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 description.",
+ messageId: "SVC4053"
+ }
+#---------SVC4054------------------------------
+# %1 - resource/service
+ COMPONENT_INVALID_CATEGORY: {
+ code: 400,
+ message: "Error: Invalid Content. Invalid %1 category.",
+ messageId: "SVC4054"
+ }
+#---------SVC4055------------------------------
+ MISSING_VENDOR_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. Missing vendor name.",
+ messageId: "SVC4055"
+ }
+#---------SVC4056------------------------------
+ MISSING_VENDOR_RELEASE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing vendor release.",
+ messageId: "SVC4056"
+ }
+
+#---------SVC4057------------------------------
+ MISSING_DERIVED_FROM_TEMPLATE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing derived from template specification.",
+ messageId: "SVC4057"
+ }
+
+#---------SVC4058------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_ICON: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 icon.",
+ messageId: "SVC4058"
+ }
+#---------SVC4059------------------------------
+# %1 - service/resource
+ COMPONENT_INVALID_ICON: {
+ code: 400,
+ message: "Error: Invalid Content. Invalid %1 icon.",
+ messageId: "SVC4059"
+ }
+#---------SVC4060------------------------------
+ PARENT_RESOURCE_NOT_FOUND: {
+ code: 400,
+ message: "Error: Invalid Content. Derived from resource template was not found.",
+ messageId: "SVC4060"
+ }
+#---------SVC4061------------------------------
+ MULTIPLE_PARENT_RESOURCE_FOUND: {
+ code: 400,
+ message: "Error: Invalid Content. Multiple derived from resource template is not allowed.",
+ messageId: "SVC4061"
+ }
+
+#---------SVC4062------------------------------
+# %1 - service/resource
+ MISSING_COMPONENT_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 name.",
+ messageId: "SVC4062"
+ }
+#---------SVC4063------------------------------
+ #%1  -  resource/service name
+ RESOURCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' resource was not found.",
+ messageId: "SVC4063"
+ }
+
+#---------SVC4064------------------------------
+# %1 - Service/Resource
+ COMPONENT_INVALID_DESCRIPTION: {
+ code: 400,
+ message: "Error: Invalid Content. %1 description contains non-english characters.",
+ messageId: "SVC4064"
+ }
+#---------SVC4065------------------------------
+# %1 - Service/Resource
+# %2 - max resource/service name length
+ COMPONENT_DESCRIPTION_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 description exceeds limit of %2 characters.",
+ messageId: "SVC4065"
+ }
+#---------SVC4066------------------------------
+# %1 - max length
+ COMPONENT_TAGS_EXCEED_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Tags overall length exceeds limit of %1 characters.",
+ messageId: "SVC4066"
+ }
+#---------SVC4067------------------------------
+# %1 - max length
+ VENDOR_NAME_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Vendor name exceeds limit of %1 characters.",
+ messageId: "SVC4067"
+ }
+#---------SVC4068------------------------------
+# %1 - max length
+ VENDOR_RELEASE_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Vendor release exceeds limit of %1 characters.",
+ messageId: "SVC4068"
+ }
+
+#---------SVC4069------------------------------
+# %1 - Service/Resource/Product
+ COMPONENT_INVALID_CONTACT_ID: {
+ code: 400,
+ message: "Error: Invalid Content. %1 contact id should be in format 'mnnnnnn' or 'aannna' or 'aannnn', where m=m ,a=a-zA-Z and n=0-9",
+ messageId: "SVC4069"
+ }
+#---------SVC4070------------------------------
+# %1 - Service/Resource
+ INVALID_COMPONENT_NAME: {
+ code: 400,
+ message: 'Error: Invalid Content. %1 name is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4070"
+ }
+
+#---------SVC4071------------------------------
+ INVALID_VENDOR_NAME: {
+ code: 400,
+ message: 'Error: Invalid Content. Vendor name is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4071"
+ }
+#---------SVC4072------------------------------
+ INVALID_VENDOR_RELEASE: {
+ code: 400,
+ message: 'Error: Invalid Content. Vendor release is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4072"
+ }
+#---------SVC4073------------------------------
+# %1 - Service/Resource
+# %2 - max resource/service name
+ COMPONENT_NAME_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 name exceeds limit of %2 characters.",
+ messageId: "SVC4073"
+ }
+#---------SVC4080------------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_IN_CHECKOUT_STATE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is locked for modification by %3 %4(%5).",
+ messageId: "SVC4080"
+ }
+#---------SVC4081-----------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_IN_CERT_IN_PROGRESS_STATE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is locked for certification by %3 %4(%5).",
+ messageId: "SVC4081"
+ }
+
+#-----------SVC4082---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_SENT_FOR_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is sent for certification by %3 %4(%5).",
+ messageId: "SVC4082"
+ }
+#-----------SVC4083---------------------------
+ COMPONENT_VERSION_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Version of this %1 was already promoted.",
+ messageId: "SVC4083"
+ }
+#-----------SVC4084---------------------------
+# %1 - resource/service/product name
+# %2 - resource/service/product
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_ALREADY_CHECKED_IN: {
+ code: 409,
+ message: "Error: The current version of '%1' %2 was already checked-in by %3 %4(%5).",
+ messageId: "SVC4084"
+ }
+#-----------SVC4085---------------------------
+# %1 - resource/service/product name
+# %2 - resource/service/product
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_CHECKOUT_BY_ANOTHER_USER: {
+ code: 403,
+ message: "Error: %1 %2 has already been checked out by %3 %4(%5).",
+ messageId: "SVC4085"
+ }
+#-----------SVC4086---------------------------
+# %1  - resource/service name
+# %2  - resource/service
+ COMPONENT_IN_USE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is in use by another user.",
+ messageId: "SVC4086"
+ }
+#-----------SVC4087---------------------------
+# %1 - component name
+# %2 - resource/service/product
+ COMPONENT_HAS_NEWER_VERSION: {
+ code: 409,
+ message: "Error: Checking out of the requested version of the '%1' %2 is not allowed as a newer version exists.",
+ messageId: "SVC4087"
+ }
+#-----------SVC4088---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_ALREADY_CERTIFIED: {
+ code: 403,
+ message: "Error: Requested %1 %2 has already been certified by %3 %4(%5).",
+ messageId: "SVC4088"
+ }
+#-----------SVC4089---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+ COMPONENT_NOT_READY_FOR_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is not ready for certification.",
+ messageId: "SVC4089"
+ }
+#-----------SVC4100---------------------------
+#%1 - property name
+ PROPERTY_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' property was not found.",
+ messageId: "SVC4100"
+ }
+#-----------SVC4101---------------------------
+#%1 - property name
+ PROPERTY_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Property with '%1' name already exists.",
+ messageId: "SVC4101"
+ }
+
+#-----------SVC4102---------------------------
+# %1 - capability type name
+ CAPABILITY_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Capability Type with name '%1' already exists.",
+ messageId: "SVC4102"
+ }
+#-----------SVC4114---------------------------
+ AUTH_FAILED_INVALIDE_HEADER: {
+ code: 400,
+ message: "Error: Invalid Authorization header.",
+ messageId: "SVC4114"
+ }
+#-----------SVC4115---------------------------
+# %1 - capability type name
+ MISSING_CAPABILITY_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing Capability Type '%1'.",
+ messageId: "SVC4115"
+ }
+ RESOURCE_INSTANCE_BAD_REQUEST: {
+ code: 400,
+ message: "Error: Invalid Content.",
+ messageId: "SVC4116"
+ }
+#-----------SVC4117---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_MATCH_NOT_FOUND: {
+ code: 404,
+ message: "Error: Match not found between resource instance '%1' and resource instance '%2' for requirement '%3'.",
+ messageId: "SVC4117"
+ }
+#-----------SVC4118---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Resource instances '%1' and '%2' are already associated with requirement '%3'.",
+ messageId: "SVC4118"
+ }
+#-----------SVC4119---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_RELATION_NOT_FOUND: {
+ code: 404,
+ message: "Error: No relation found between resource instances '%1' and '%2' for requirement '%3'.",
+ messageId: "SVC4119"
+ }
+#-----------SVC4120---------------------------
+# %1 - User's USER_ID
+ USER_INACTIVE: {
+ code: 404,
+ message: "Error: User %1 was not found.",
+ messageId: "SVC4120"
+ }
+#-----------SVC4121---------------------------
+# %1 - User's USER_ID
+ USER_HAS_ACTIVE_ELEMENTS: {
+ code: 403,
+ message: "Error: User with %1 ID can not be deleted since it has active elements(resources/services/artifacts).",
+ messageId: "SVC4121"
+ }
+#-----------SVC4122---------------------------
+# %1 - artifact type
+ ARTIFACT_TYPE_NOT_SUPPORTED: {
+ code: 400,
+ message: "Error: Invalid artifact type '%1'.",
+ messageId: "SVC4122"
+ }
+#-----------SVC4123---------------------------
+ ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Artifact logical name cannot be changed.",
+ messageId: "SVC4123"
+ }
+#-----------SVC4124---------------------------
+ MISSING_ARTIFACT_TYPE: {
+ code: 400,
+ message: "Error: Missing artifact type.",
+ messageId: "SVC4124"
+ }
+#-----------SVC4125---------------------------
+# %1-artifact name
+ ARTIFACT_EXIST: {
+ code: 400,
+ message: "Error: Artifact '%1' already exists.",
+ messageId: "SVC4125"
+ }
+#---------SVC4126------------------------------
+# %1 - resource/service/product/...
+# %2 - field (tag, vendor name...)
+ INVALID_FIELD_FORMAT: {
+ code: 400,
+ message: "Error: Invalid %1 %2 format.",
+ messageId: "SVC4126"
+ }
+#-----------SVC4127---------------------------
+ ARTIFACT_INVALID_MD5: {
+ code: 400,
+ message: "Error: Invalid artifact checksum.",
+ messageId: "SVC4127"
+ }
+#-----------SVC4128---------------------------
+ MISSING_ARTIFACT_NAME: {
+ code: 400,
+ message: "Error: Invalid content. Missing artifact name.",
+ messageId: "SVC4128"
+ }
+#-----------SVC4129---------------------------
+ MISSING_PROJECT_CODE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing PROJECT_CODE number.",
+ messageId: "SVC4129"
+ }
+#-----------SVC4130---------------------------
+ INVALID_PROJECT_CODE: {
+ code: 400,
+ message: "Error: Invalid Content. PROJECT_CODE number must be numeric from 5 up to 10 digits.",
+ messageId: "SVC4130"
+ }
+#-----------SVC4131---------------------------
+# %1-resource/service
+# %2-srtifact/artifacts
+# %3-semicolomn separated list of artifact
+ COMPONENT_MISSING_MANDATORY_ARTIFACTS: {
+ code: 403,
+ message: "Error: Missing mandatory informational %1 %2: [%3].",
+ messageId: "SVC4131"
+ }
+#-----------SVC4132---------------------------
+# %1 - lifecycle type name
+ LIFECYCLE_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Lifecycle Type with name '%1' already exists.",
+ messageId: "SVC4132"
+ }
+#-----------SVC4133---------------------------
+# %1 - service version
+# %2 - service name
+ SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION: {
+ code: 403,
+ message: "Error: Version %1 of '%2' service is not available for distribution.",
+ messageId: "SVC4133"
+ }
+#-----------SVC4134---------------------------
+ MISSING_LIFECYCLE_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing interface life-cycle type.",
+ messageId: "SVC4134"
+ }
+#---------SVC4135------------------------------
+ SERVICE_CATEGORY_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Service category cannot be changed once the service is certified.",
+ messageId: "SVC4135"
+ }
+#---------SVC4136------------------------------
+# %1 - distribution environment name
+ DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE: {
+ code: 500,
+ message: "Error: Requested distribution environment '%1' is not available.",
+ messageId: "SVC4136"
+ }
+#---------SVC4137------------------------------
+# %1 - distribution environment name
+ DISTRIBUTION_ENVIRONMENT_NOT_FOUND: {
+ code: 400,
+ message: "Error: Requested distribution environment '%1' was not found.",
+ messageId: "SVC4137"
+ }
+#---------SVC4138------------------------------
+ DISTRIBUTION_ENVIRONMENT_INVALID: {
+ code: 400,
+ message: "Error: Invalid distribution environment.",
+ messageId: "SVC4138"
+ }
+#---------SVC4139------------------------------
+# %1 - service name
+ DISTRIBUTION_ARTIFACT_NOT_FOUND: {
+ code: 409,
+ message: "Error: Service '%1' cannot be distributed due to missing deployment artifacts.",
+ messageId: "SVC4139"
+ }
+#---------SVC4200------------------------------
+# %1 - Service/Resource
+# %2 - max icon name length
+ COMPONENT_ICON_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 icon name exceeds limit of %2 characters.",
+ messageId: "SVC4200"
+ }
+#---------SVC4300------------------------------
+ RESTRICTED_ACCESS: {
+ code: 403,
+ message: "Error: Restricted access.",
+ messageId: "SVC4300"
+ }
+#---------SVC4301------------------------------
+ RESTRICTED_OPERATION: {
+ code: 409,
+ message: "Error: Restricted operation.",
+ messageId: "SVC4301"
+ }
+#---------SVC4500------------------------------
+ MISSING_BODY: {
+ code: 400 ,
+ message: "Error: Missing request body.",
+ messageId: "SVC4500"
+ }
+#---------SVC4501------------------------------
+ MISSING_PUBLIC_KEY: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'apiPublicKey'." ,
+ messageId: "SVC4501"
+ }
+#---------SVC4502------------------------------
+ DISTRIBUTION_ENV_DOES_NOT_EXIST: {
+ code: 400 ,
+ message: "Error: Invalid Body : Missing mandatory parameter 'distrEnvName'." ,
+ messageId: "SVC4502"
+ }
+#-----------SVC4503---------------------------
+# %1 - service name
+ SERVICE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' service was not found.",
+ messageId: "SVC4503"
+ }
+
+#---------SVC4504------------------------------
+# %1 - Service/Resource
+# %2 - service/resource version
+ COMPONENT_VERSION_NOT_FOUND: {
+ code: 404,
+ message: "Error: %1 version %2 was not found.",
+ messageId: "SVC4504"
+ }
+#-----------SVC4505---------------------------
+ #%1-artifact name
+
+ ARTIFACT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Artifact '%1' was not found.",
+ messageId: "SVC4505"
+ }
+#---------SVC4506------------------------------
+ MISSING_ENV_NAME: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'distrEnvName'.",
+ messageId: "SVC4506"
+ }
+#---------SVC4507------------------------------
+ COMPONENT_INVALID_TAGS_NO_COMP_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. One of the tags should be the component name.",
+ messageId: "SVC4507"
+ }
+
+#---------SVC4508------------------------------
+ SERVICE_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Service name cannot be changed once the service is certified.",
+ messageId: "SVC4508"
+ }
+
+#---------SVC4509------------------------------
+ SERVICE_ICON_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Icon cannot be changed once the service is certified.",
+ messageId: "SVC4509"
+ }
+#---------SVC4510------------------------------
+# %1 - icon name max length
+ SERVICE_ICON_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Icon name exceeds limit of %1 characters.",
+ messageId: "SVC4510"
+ }
+#---------SVC4511------------------------------
+ DISTRIBUTION_REQUESTED_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested distribution was not found.",
+ messageId: "SVC4511"
+ }
+#---------SVC4512------------------------------
+# %1 - Distribution ID
+ DISTRIBUTION_REQUESTED_FAILED: {
+ code: 403,
+ message: "Error: Requested distribution '%1' failed.",
+ messageId: "SVC4512"
+ }
+#---------SVC4513------------------------------
+ RESOURCE_CATEGORY_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Resource category cannot be changed once the resource is certified.",
+ messageId: "SVC4513"
+ }
+#---------SVC4514------------------------------
+ RESOURCE_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Resource name cannot be changed once the resource is certified.",
+ messageId: "SVC4514"
+ }
+#---------SVC4515------------------------------
+ RESOURCE_ICON_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Icon cannot be changed once the resource is certified.",
+ messageId: "SVC4515"
+ }
+#---------SVC4516------------------------------
+ RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Vendor name cannot be changed once the resource is certified.",
+ messageId: "SVC4516"
+ }
+#---------SVC4517------------------------------
+ RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Derived from resource template cannot be changed once the resource is certified.",
+ messageId: "SVC4517"
+ }
+#---------SVC4518------------------------------
+# %1 - max length
+ COMPONENT_SINGLE_TAG_EXCEED_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Single tag exceeds limit of %1 characters.",
+ messageId: "SVC4518"
+ }
+#---------SVC4519------------------------------
+ INVALID_DEFAULT_VALUE: {
+ code: 400,
+ message: "Error: mismatch in data-type occurred for property %1. data type is %2 and default value found is %3.",
+ messageId: "SVC4519"
+ }
+#---------SVC4520------------------------------
+# %1 - service or resource
+ ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED: {
+ code: 409,
+ message: "Error: Maximal number of additional %1 parameters was reached.",
+ messageId: "SVC4520"
+ }
+#---------SVC4521------------------------------
+ ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED: {
+ code: 400,
+ message: "Error: Invalid Content. The Additional information label and value cannot be empty.",
+ messageId: "SVC4521"
+ }
+#---------SVC4522------------------------------
+# %1 - label/value
+# %2 - Maximal length of %1
+ ADDITIONAL_INFORMATION_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Additional information %1 exceeds limit of %2 characters.",
+ messageId: "SVC4522"
+ }
+#---------SVC4523------------------------------
+ ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS: {
+ code: 400,
+ message: 'Error: Invalid Content. Additional information label is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4523"
+ }
+#---------SVC4524------------------------------
+ ADDITIONAL_INFORMATION_NOT_FOUND: {
+ code: 409,
+ message: "Error: Requested additional information was not found.",
+ messageId: "SVC4524"
+ }
+#---------SVC4525------------------------------
+ ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS: {
+ code: 400,
+ message: 'Error: Invalid Content. Additional information contains non-english characters.',
+ messageId: "SVC4525"
+ }
+#---------SVC4526------------------------------
+ RESOURCE_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' resource instance was not found.",
+ messageId: "SVC4526"
+ }
+#---------SVC4527------------------------------
+ ASDC_VERSION_NOT_FOUND: {
+ code: 500,
+ message: 'Error: ASDC version cannot be displayed.',
+ messageId: "SVC4527"
+ }
+#---------SVC4528------------------------------
+# %1-artifact url/artifact label/artifact description/VNF Service Indicator
+ MISSING_DATA: {
+ code: 400,
+ message: "Error: Invalid content. Missing %1.",
+ messageId: "SVC4528"
+ }
+#---------SVC4529------------------------------
+# %1-artifact url/artifact label/artifact description/artifact name
+# %2 - Maximal length of %1
+ EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 exceeds limit of %2 characters.",
+ messageId: "SVC4529"
+ }
+#---------SVC4530------------------------------
+ ARTIFACT_INVALID_TIMEOUT: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact Timeout should be set to valid positive non-zero number of minutes.",
+ messageId: "SVC4530"
+ }
+#---------SVC4531------------------------------
+ SERVICE_IS_VNF_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: VNF Indicator cannot be updated for certified service.",
+ messageId: "SVC4531"
+ }
+ #---------SVC4532------------------------------
+ RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE: {
+ code: 404,
+ message: "Error: Requested '%1' resource instance was not found on the service '%2.",
+ messageId: "SVC4532"
+ }
+ #---------SVC4533------------------------------
+ # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
+ WRONG_ARTIFACT_FILE_EXTENSION: {
+ code: 400,
+ message: "Error: Invalid file extension for %1 artifact type.",
+ messageId: "SVC4533"
+ }
+
+#---------SVC4534------------------------------
+# %1 - "HEAT"/"HEAT_ENV"
+ INVALID_YAML: {
+ code: 400,
+ message: "Error: Uploaded YAML file for %1 artifact is invalid.",
+ messageId: "SVC4534"
+ }
+
+#---------SVC4535------------------------------
+# %1 - "HEAT"
+ INVALID_DEPLOYMENT_ARTIFACT_HEAT: {
+ code: 400,
+ message: "Error: Invalid %1 artifact.",
+ messageId: "SVC4535"
+ }
+#---------SVC4536------------------------------
+# %1 - "Resource"/"Service"
+# %2 - resource/service name
+# %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
+# %4 - "HEAT"/"HEAT_ENV"/"MURANO_PKG
+ DEPLOYMENT_ARTIFACT_OF_TYPE_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: %1 '%2' already has a deployment artifact of %3 type .Please delete or update an existing %4 artifact.",
+ messageId: "SVC4536"
+ }
+
+#---------SVC4537------------------------------
+ MISSING_HEAT: {
+ code: 400,
+ message: "Error: Missing HEAT artifact. HEAT_ENV artifact cannot be uploaded without corresponding HEAT template.",
+ messageId: "SVC4537"
+ }
+#---------SVC4538------------------------------
+ MISMATCH_HEAT_VS_HEAT_ENV: {
+ code: 400,
+ message: "Error: Invalid artifact content. Parameter's set in HEAT_ENV '%1' artifact doesn't match the parameters in HEAT '%2' artifact.",
+ messageId: "SVC4538"
+ }
+#---------SVC4539------------------------------
+ INVALID_RESOURCE_PAYLOAD: {
+ code: 400,
+ message: "Error: Invalid resource payload.",
+ messageId: "SVC4539"
+ }
+#---------SVC4540------------------------------
+ INVALID_TOSCA_FILE_EXTENSION: {
+ code: 400,
+ message: "Error: Invalid file extension for TOSCA template.",
+ messageId: "SVC4540"
+ }
+#---------SVC4541------------------------------
+ INVALID_YAML_FILE: {
+ code: 400,
+ message: "Error: Invalid YAML file.",
+ messageId: "SVC4541"
+ }
+#---------SVC4542------------------------------
+ INVALID_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: Invalid TOSCA template.",
+ messageId: "SVC4542"
+ }
+#---------SVC4543------------------------------
+ NOT_RESOURCE_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: Imported Service TOSCA template.",
+ messageId: "SVC4543"
+ }
+#---------SVC4544------------------------------
+ NOT_SINGLE_RESOURCE: {
+ code: 400,
+ message: "Error: Imported TOSCA template should contain one resource definition.",
+ messageId: "SVC4544"
+ }
+#---------SVC4545------------------------------
+ INVALID_RESOURCE_NAMESPACE: {
+ code: 400,
+ message: "Error: Invalid resource namespace.",
+ messageId: "SVC4545"
+ }
+#---------SVC4546------------------------------
+ RESOURCE_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: Imported resource already exists in ASDC Catalog.",
+ messageId: "SVC4546"
+ }
+#---------SVC4549------------------------------
+ INVALID_RESOURCE_CHECKSUM: {
+ code: 400,
+ message: "Error: Invalid resource checksum.",
+ messageId: "SVC4549"
+ }
+#---------SVC4550------------------------------
+ #%1  -  Consumer salt
+ INVALID_LENGTH: {
+ code: 400,
+ message: "Error: Invalid %1 length.",
+ messageId: "SVC4550"
+ }
+ #---------SVC4551------------------------------
+ #%1  -  ECOMP User name
+ ECOMP_USER_NOT_FOUND: {
+ code: 404,
+ message: "Error: ECOMP User '%1' was not found.",
+ messageId: "SVC4551"
+ }
+#---------SVC4552------------------------------
+ CONSUMER_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: ECOMP User already exists.",
+ messageId: "SVC4552"
+ }
+#---------SVC4553-----------------------------
+ #%1  -  Consumer name / Consumer password/ Consumer salt
+ INVALID_CONTENT_PARAM: {
+ code: 400,
+ message: "Error: %1 is invalid.",
+ messageId: "SVC4553"
+ }
+ #---------SVC4554------------------------------
+# %1 - "Resource"/"Service"
+ COMPONENT_ARTIFACT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested artifact doesn't belong to specified %1.",
+ messageId: "SVC4554"
+ }
+#---------SVC4554------------------------------
+# %1 - "Service name"
+ SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND: {
+ code: 403,
+ message: "Error: Requested '%1' service is not ready for certification. Service has to have at least one deployment artifact.",
+ messageId: "SVC4554"
+ }
+#---------SVC4555------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category"
+ COMPONENT_ELEMENT_INVALID_NAME_LENGTH: {
+ code: 400,
+ message: "Error: Invalid %1 %2 name length.",
+ messageId: "SVC4555"
+ }
+#---------SVC4556------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category"
+ COMPONENT_ELEMENT_INVALID_NAME_FORMAT: {
+ code: 400,
+ message: "Error: Invalid %1 %2 name format.",
+ messageId: "SVC4556"
+ }
+#---------SVC4557------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category name"
+ COMPONENT_CATEGORY_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: %1 category name '%2' already exists.",
+ messageId: "SVC4557"
+ }
+#---------SVC4558------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ VALIDATED_RESOURCE_NOT_FOUND: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource.",
+ messageId: "SVC4558"
+ }
+#---------SVC4559------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ FOUND_ALREADY_VALIDATED_RESOURCE: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use already available validated resource version.",
+ messageId: "SVC4559"
+ }
+#---------SVC4560------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ FOUND_LIST_VALIDATED_RESOURCES: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use one of available validated resource versions.",
+ messageId: "SVC4560"
+ }
+#---------SVC4561------------------------------
+# %1 - "resource"/"product"
+# %2 - "category"
+# %3 - "category name"
+ COMPONENT_CATEGORY_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested %1 %2 '%3' was not found.",
+ messageId: "SVC4561"
+ }
+#---------SVC4562------------------------------
+# %1 - "Resource"/"Product"
+# %2 - "sub-category name"
+# %3 - "category name"
+ COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY: {
+ code: 409,
+ message: "Error: %1 sub-category '%2' already exists under '%3' category.",
+ messageId: "SVC4562"
+ }
+#---------SVC4563------------------------------
+# %1 - "Product"
+# %2 - "grouping name"
+# %3 - "sub-category name"
+ COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY: {
+ code: 409,
+ message: "Error: %1 grouping '%2' already exists under '%3' sub-category.",
+ messageId: "SVC4563"
+ }
+#---------SVC4564------------------------------
+# %1 - product name
+ PRODUCT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' product was not found.",
+ messageId: "SVC4564"
+ }
+#---------SVC4565------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
+# %3 - parameter name
+ INVALID_HEAT_PARAMETER_VALUE: {
+ code: 400,
+ message: "Error: Invalid %1 artifact. Invalid %2 value set for '%3' parameter.",
+ messageId: "SVC4565"
+ }
+#---------SVC4566------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
+ INVALID_HEAT_PARAMETER_TYPE: {
+ code: 400,
+ message: "Error: Invalid %1 artifact. Unsupported '%2' parameter type.",
+ messageId: "SVC4566"
+ }
+#---------SVC4567------------------------------
+# %1 - "YANG_XML"
+ INVALID_XML: {
+ code: 400,
+ message: "Error: Uploaded XML file for %1 artifact is invalid.",
+ messageId: "SVC4567"
+ }
+#---------SVC4567------------------------------
+# %1 - "User Name and userId"
+# %2 -"checked-out"/"in-certification"
+ CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS: {
+ code: 409,
+ message: "Error: User cannot be deleted. User '%1' has %2 projects.",
+ messageId: "SVC4567"
+ }
+#---------SVC4568------------------------------
+# %1 - "User Name and userId"
+# %2 -"checked-out"/"in-certification"
+ CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS: {
+ code: 409,
+ message: "Error: Role cannot be changed. User '%1' has %2 projects.",
+ messageId: "SVC4568"
+ }
+#---------SVC4570------------------------------
+ UPDATE_USER_ADMIN_CONFLICT: {
+ code: 409,
+ message: "Error: An administrator is not allowed to change his/her role.",
+ messageId: "SVC4570"
+ }
+#---------SVC4571------------------------------
+ SERVICE_CANNOT_CONTAIN_SUBCATEGORY: {
+ code: 400,
+ message: "Error: Sub category cannot be defined for service",
+ messageId: "SVC4571"
+ }
+#---------SVC4572------------------------------
+# %1 - "Resource"/"Service"
+ COMPONENT_TOO_MUCH_CATEGORIES: {
+ code: 400,
+ message: "Error: %1 must have only 1 category",
+ messageId: "SVC4572"
+ }
+#---------SVC4574------------------------------
+ RESOURCE_TOO_MUCH_SUBCATEGORIES: {
+ code: 400,
+ message: "Error: Resource must have only 1 sub category",
+ messageId: "SVC4574"
+ }
+#---------SVC4575------------------------------
+ COMPONENT_MISSING_SUBCATEGORY: {
+ code: 400,
+ message: "Error: Missing sub category",
+ messageId: "SVC4575"
+ }
+ #---------SVC4576------------------------------
+# %1 - "component type"
+ UNSUPPORTED_ERROR: {
+ code: 400,
+ message: "Error : Requested component type %1 is unsupported.",
+ messageId: "SVC4576"
+ }
+ #---------SVC4577------------------------------
+# %1 - "resource type"
+ RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES: {
+ code: 409,
+ message: "Error : Resource of type %1 cannot contain resource instances.",
+ messageId: "SVC4577"
+ }
+#---------SVC4578------------------------------
+# %1 - "Resource"/"Service"
+# %2 - resource/service name
+# %3 - "artifact name"
+ DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: %1 '%2' already has a deployment artifact named '%3'.",
+ messageId: "SVC4578"
+ }
+#---------SVC4579------------------------------
+# %1 - "Category"/"Sub-Category"/"Group"
+# %2 - category/sub-category/grouping name.
+ INVALID_GROUP_ASSOCIATION: {
+ code: 400,
+ message: "Error: Invalid group association. %1 '%2' was not found.",
+ messageId: "SVC4579"
+ }
+#---------SVC4580------------------------------
+ EMPTY_PRODUCT_CONTACTS_LIST: {
+ code: 400,
+ message: "Error: Invalid content. At least one Product Contact has to be specified.",
+ messageId: "SVC4580"
+ }
+#---------SVC4581------------------------------
+# %1 - userId
+ INVALID_PRODUCT_CONTACT: {
+ code: 400,
+ message: "Error: Invalid content. User '%1' cannot be set as Product Contact.",
+ messageId: "SVC4581"
+ }
+#---------SVC4582------------------------------
+# %1 - Product
+# %2 - "abbreviated"/"full"
+ MISSING_ONE_OF_COMPONENT_NAMES: {
+ code: 400,
+ message: "Error: Invalid content. Missing %1 %2 name.",
+ messageId: "SVC4582"
+ }
+#---------SVC4583------------------------------
+# %1 - "Icon"
+# %2 - "resource"/"service"/"product"
+ COMPONENT_PARAMETER_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: %1 cannot be changed once the %2 is certified.",
+ messageId: "SVC4583"
+ }
+#---------SVC4584------------------------------
+# %1 - service/VF name
+# %2 - "service" /"VF"
+# %3 - resource instance origin type
+# %4 - resource instance name
+# %5 - requirement/capability
+# %6 - requirement/capability name
+# %7 - "fulfilled" (for req)/"consumed (for cap)"
+ REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is not ready for certification. %3 '%4' has to have %5 '%6' %7.",
+ messageId: "SVC4584"
+ }
+#---------SVC4585------------------------------
+ INVALID_OCCURRENCES: {
+ code: 400,
+ message: "Error: Invalid occurrences format.",
+ messageId: "SVC4585"
+ }
+#---------SVC4586------------------------------
+#---------SVC4586------------------------------
+ INVALID_SERVICE_API_URL: {
+ code: 400,
+ message: 'Error: Invalid Service API URL. Please check whether your URL has a valid domain extension and does not contain the following characters - #?&@%+;,=$<>~^`\[]{}|"*!',
+ messageId: "SVC4586"
+ }
+#---------SVC4587------------------------------
+# %1 - Data type name
+ DATA_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: 'Error: Data type %1 already exists.',
+ messageId: "SVC4587"
+ }
+#---------SVC4588------------------------------
+# %1 - Data type name
+ DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM: {
+ code: 400,
+ message: 'Error: Invalid Data type %1. Data type must have either a valid derived from declaration or at least one valid property',
+ messageId: "SVC4588"
+ }
+#---------SVC4589------------------------------
+# %1 - Data type name
+ DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Data type %1. 'properties' parameter cannot be empty if provided.",
+ messageId: "SVC4589"
+ }
+#---------SVC4590------------------------------
+# %1 - Property type name
+# %2 - Property name
+ INVALID_PROPERTY_TYPE: {
+ code: 400,
+ message: "Error: Invalid Property type %1 in property %2.",
+ messageId: "SVC4590"
+ }
+#---------SVC4591------------------------------
+# %1 - Property inner type
+# %2 - Property name
+ INVALID_PROPERTY_INNER_TYPE: {
+ code: 400,
+ message: "Error: Invalid property inner type %1, in property %2",
+ messageId: "SVC4591"
+ }
+#---------SVC4592------------------------------
+# %1 - component instance name
+# %2 - "resource instance"/"service instance"
+ COMPONENT_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' %2 was not found.",
+ messageId: "SVC4592"
+ }
+#---------SVC4593------------------------------
+# %1 - component instance name
+# %2 - "resource instance"/"service instance"
+# %3 - "resource/"service"/"product"
+# %4 - container name
+ COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER: {
+ code: 404,
+ message: "Error: Requested '%1' %2 was not found on the %3 '%4'.",
+ messageId: "SVC4593"
+ }
+#---------SVC4594------------------------------
+#%1 - requirement / capability
+#%2 - requirement name
+ IMPORT_DUPLICATE_REQ_CAP_NAME: {
+ code: 400,
+ message: "Error: Imported TOSCA template contains more than one %1 named '%2'.",
+ messageId: "SVC4594"
+ }
+#---------SVC4595------------------------------
+#%1 - requirement / capability
+#%2 - requirement name
+#%3 - parent containing the requirement
+ IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED: {
+ code: 400,
+ message: "Error: Imported TOSCA template contains %1 '%2' that is already defined by derived template %3.",
+ messageId: "SVC4595"
+ }
+#---------SVC4596------------------------------
+# %1 - Data type name
+ DATA_TYPE_DERIVED_IS_MISSING: {
+ code: 400,
+ message: "Error: Invalid Content. The ancestor data type %1 cannot be found in the system.",
+ messageId: "SVC4596"
+ }
+#---------SVC4597------------------------------
+# %1 - Data type name
+# %2 - Property names
+ DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains properties named %2 which are already defined in one of its ancestors.",
+ messageId: "SVC4597"
+ }
+#---------SVC4598------------------------------
+# %1 - Data type name
+ DATA_TYPE_DUPLICATE_PROPERTY: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains duplicate property.",
+ messageId: "SVC4598"
+ }
+#---------SVC4599------------------------------
+# %1 - Data type name
+# %2 - Property names
+ DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains properties %2 which their type is this data type.",
+ messageId: "SVC4599"
+ }
+#---------SVC4600------------------------------
+# %1 - Data type name
+ DATA_TYPE_CANNOT_HAVE_PROPERTIES: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 cannot have properties since it is of type scalar",
+ messageId: "SVC4600"
+ }
+#---------SVC4601------------------------------
+ NOT_TOPOLOGY_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain 'topology_template.",
+ messageId: "SVC4601"
+ }
+#---------SVC4602--------------------------------
+# %1 - yaml file name
+# %2 - node_template label
+# %3 - node_template type
+ INVALID_NODE_TEMPLATE: {
+ code: 400,
+ message: "Error: TOSCA yaml file '%1' contains node_template '%2' of type '%3' that does not represent existing VFC/CP/VL",
+ messageId: "SVC4602"
+ }
+#---------SVC4603------------------------------
+# %1 - component type
+# %2 - component name
+# %3 - state
+ ILLEGAL_COMPONENT_STATE: {
+ code: 403,
+ message: "Error: Component instance of %1 can not be created because the component '%2' is in an illegal state %3.",
+ messageId: "SVC4603"
+ }
+#---------SVC4604------------------------------
+# %1 - csar file name
+ CSAR_INVALID: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is invalid. 'TOSCA-Metadata/Tosca.meta' file must be provided.",
+ messageId: "SVC4604"
+ }
+#---------SVC4605------------------------------
+# %1 - csar file name
+ CSAR_INVALID_FORMAT: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is invalid. Invalid 'TOSCA-Metadata/Tosca.meta' file format.",
+ messageId: "SVC4605"
+ }
+#---------SVC4606------------------------------
+# %1 - property name
+# %2 - property type
+# %3 - property innerType
+# %4 - default value is
+ INVALID_COMPLEX_DEFAULT_VALUE: {
+ code: 400,
+ message: "Error: Invalid default value of property %1. Data type is %2 with inner type %3 and default value found is %4.",
+ messageId: "SVC4606"
+ }
+#---------SVC4607------------------------------
+# %1 - csar file name
+ CSAR_NOT_FOUND: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is not found.",
+ messageId: "SVC4607"
+ }
+#---------SVC4608------------------------------
+# %1 - artifact name
+# %2 - component type
+# %3 - actual component type
+ MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE: {
+ code: 400,
+ message: "Error: Artifact %1 is only compatible with component of type %2, but component type is %3.",
+ messageId: "SVC4608"
+ }
+
+#---------SVC4609------------------------------
+# %1 - "INVALID_JSON"
+ INVALID_JSON: {
+ code: 400,
+ message: "Error: Uploaded JSON file for %1 artifact is invalid.",
+ messageId: "SVC4609"
+ }
+#---------SVC4610------------------------------
+# %1 - csar file name
+# %2 - missing file name
+ YAML_NOT_FOUND_IN_CSAR: {
+ code: 400,
+ message: "Error - TOSCA CSAR %1 is invalid. TOSCA-Metadata/Tosca.meta refers to file %2 that is not provided.",
+ messageId: "SVC4610"
+ }
+#---------SVC4611------------------------------
+# %1 - group name
+ GROUP_MEMBER_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Content. Group %1 member list was provided but does not have values",
+ messageId: "SVC4611"
+ }
+#---------SVC4612------------------------------
+# %1 - group name
+ GROUP_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: 'Error: Group type %1 already exists.',
+ messageId: "SVC4612"
+ }
+#---------SVC4613------------------------------
+# %1 - group name
+# %2 - VF name(component name)
+# %3 - actual component type [VF]
+ GROUP_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Group with name '%1' already exists in %2 %3.",
+ messageId: "SVC4613"
+ }
+#---------SVC4614------------------------------
+# %1 - group type
+ GROUP_TYPE_IS_INVALID: {
+ code: 400,
+ message: "Error: Invalid content. Group type %1 does not exist",
+ messageId: "SVC4614"
+ }
+#---------SVC4615------------------------------
+# %1 - group name
+ GROUP_MISSING_GROUP_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing Group Type for group '%1'",
+ messageId: "SVC4615"
+ }
+#---------SVC4616------------------------------
+# %1 - member name
+# %2 - group name
+# %3 - VF name
+# %4 - component type [VF ]
+ GROUP_INVALID_COMPONENT_INSTANCE: {
+ code: 400,
+ message: "Error: Member '%1' listed in group '%2' is not part of '%3' %4.",
+ messageId: "SVC4616"
+ }
+#---------SVC4617------------------------------
+# %1 - member name
+# %2 - group name
+# %3 - group type
+ GROUP_INVALID_TOSCA_NAME_OF_COMPONENT_INSTANCE: {
+ code: 400,
+ message: "Error: member %1 listed in group %2 is not part of allowed members of group type %3.",
+ messageId: "SVC4617"
+ }
+#---------SVC4618------------------------------
+# %1 - missing file name
+# %2 - csar file name
+ ARTIFACT_NOT_FOUND_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
+ messageId: "SVC4618"
+ }
+#---------SVC4619------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - existing artifact type
+ ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 in type %2 already exists in type %3.",
+ messageId: "SVC4619"
+ }
+#---------SVC4620------------------------------
+ FAILED_RETRIVE_ARTIFACTS_TYPES: {
+ code: 400,
+ message: "Error: Failed to retrieve list of suported artifact types.",
+ messageId: "SVC4620"
+ }
+#---------SVC4621------------------------------
+# %1 - artifact name
+# %2 - master
+ ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 already exists in master %2 .",
+ messageId: "SVC4621"
+ }
+#---------SVC4622------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - master name
+# %4 - master type
+ ARTIFACT_NOT_VALID_IN_MASTER: {
+ code: 400,
+ message: "Error: artifact %1 in type %2 can not be exists under master %3 in type %4.",
+ messageId: "SVC4622"
+ }
+#---------SVC4623------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - env name
+# %4 - existing env
+ ARTIFACT_NOT_VALID_ENV: {
+ code: 400,
+ message: "Error: Artifact %1 in type %2 with env %3 already exists with another env %4",
+ messageId: "SVC4623"
+ }
+#---------SVC4624------------------------------
+# %1 - groups names
+# %2 - VF name
+# %3 - component type [VF ]
+ GROUP_IS_MISSING: {
+ code: 400,
+ message: "Error: Invalid Content. The groups '%1' cannot be found under %2 %3.",
+ messageId: "SVC4624"
+ }
+#---------SVC4625------------------------------
+# %1 - groups name
+ GROUP_ARTIFACT_ALREADY_ASSOCIATED: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact already associated to group '%1'.",
+ messageId: "SVC4625"
+ }
+#---------SVC4626------------------------------
+# %1 - groups name
+ GROUP_ARTIFACT_ALREADY_DISSOCIATED: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact already dissociated from group '%1'.",
+ messageId: "SVC4626"
+ }
+#---------SVC4627------------------------------
+# %1 - property name
+# %2 - group name
+# %3 - group type name
+ GROUP_PROPERTY_NOT_FOUND: {
+ code: 400,
+ message: "Error: property %1 listed in group %2 is not exist in group type %3.",
+ messageId: "SVC4627"
+ }
+#---------SVC4628------------------------------
+# %1 - csarUUID
+# %2 - VF name
+ VSP_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: The VSP with UUID %1 was already imported for VF %2. Please select another or update the existing VF.",
+ messageId: "SVC4628"
+ }
+#---------SVC4629------------------------------
+# %1 - VF name
+ MISSING_CSAR_UUID: {
+ code: 400,
+ message: "Error: The Csar UUID or payload name is missing for VF %1.",
+ messageId: "SVC4629"
+ }
+#---------SVC4630------------------------------
+# %1 - VF name
+# %2 - new csarUUID
+# %3 - old csarUUID
+ RESOURCE_LINKED_TO_DIFFERENT_VSP: {
+ code: 400,
+ message: "Error: Resource %1 cannot be updated using CsarUUID %2 since the resource is linked to a different VSP with csarUUID %3.",
+ messageId: "SVC4630"
+ }
+#---------SVC4631------------------------------
+# %1 - policy name
+ POLICY_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Policy type %1 already exists.",
+ messageId: "SVC4631"
+ }
+#---------SVC4632------------------------------
+# %1 - target name
+# %2 - policy type name
+ TARGETS_NON_VALID: {
+ code: 400,
+ message: "Error: target %1 listed in policy type %2 is not a group or resource.",
+ messageId: "SVC4632"
+ }
+#---------SVC4633------------------------------
+# %1 - policy name
+ TARGETS_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Content. Policy %1 target list was provided but does not have values",
+ messageId: "SVC4633"
+ }
+#---------SVC4634------------------------------
+ DATA_TYPE_CANNOT_BE_EMPTY: {
+ code: 500,
+ message: "Error: Data types are empty. Please import the data types.",
+ messageId: "SVC4634"
+ }
+#---------SVC4635------------------------------
+# %1 - csar uuid
+ RESOURCE_FROM_CSAR_NOT_FOUND: {
+ code: 400,
+ message: "Error: resource from csar uuid %1 not found",
+ messageId: "SVC4635"
+ }
+#---------SVC4636------------------------------
+# %1 - Data type name
+ DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST: {
+ code: 400,
+ message: 'Error: Data type %1 cannot be upgraded. The new data type does not contain old properties or the type of one of the properties has been changed.',
+ messageId: "SVC4636"
+ }
+#-----------SVC4637---------------------------
+#%1 - attribute name
+ ATTRIBUTE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' attribute was not found.",
+ messageId: "SVC4637"
+ }
+#-----------SVC4638---------------------------
+#%1 - attribute name
+ ATTRIBUTE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Attribute with '%1' name already exists.",
+ messageId: "SVC4638"
+ }
+#-----------SVC4639---------------------------
+#%1 - property name
+ PROPERTY_NAME_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Property with '%1' name and different type already exists.",
+ messageId: "SVC4639"
+ }
+#-----------SVC4640---------------------------
+#%1 - property name
+ INVALID_PROPERTY: {
+ code: 409,
+ message: "Error: Invalid property received.",
+ messageId: "SVC4640"
+ }
+#---------SVC4641-----------------------------
+#%1 - invalid filter
+#%2 - valid filters
+ INVALID_FILTER_KEY: {
+ code: 400,
+ message: "Error: The filter %1 is not applicable. Please use one of the following filters: %2",
+ messageId: "SVC4641"
+ }
+#---------SVC4642-----------------------------
+#%1 - asset type
+#%2 - filter
+ NO_ASSETS_FOUND: {
+ code: 404,
+ message: "No %1 were found to match criteria %2",
+ messageId: "SVC4642"
+ }
+#---------SVC4643------------------------------
+# %1 - "Resource"/"Product"
+# %2 - "sub-category name"
+# %3 - "category name"
+ COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY: {
+ code: 404,
+ message: "Error: %1 sub-category '%2' not found under category '%3'.",
+ messageId: "SVC4643"
+ }
+#---------SVC4644------------------------------
+# %1 - Format
+ CORRUPTED_FORMAT: {
+ code: 400,
+ message: "Error: %1 format is corrupted.",
+ messageId: "SVC4644"
+ }
+#---------SVC4645------------------------------
+# %1 - "groupType"
+ INVALID_VF_MODULE_TYPE: {
+ code: 400,
+ message: "Error: Invalid group type '%1' (should be VfModule).",
+ messageId: "SVC4645"
+ }
+#---------SVC4646------------------------------
+# %1 - "groupName"
+ INVALID_VF_MODULE_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. VF Module name '%1' contains invalid characters",
+ messageId: "SVC4646"
+ }
+
+#---------SVC4647------------------------------
+# %1 - "modifiedName"
+ INVALID_VF_MODULE_NAME_MODIFICATION: {
+ code: 400,
+ message: "Error: Invalid VF Module name modification, can not modify '%1'",
+ messageId: "SVC4647"
+ }
+#---------SVC4648------------------------------
+# %1 - "inputId"
+# %2 - "componentId"
+ INPUT_IS_NOT_CHILD_OF_COMPONENT: {
+ code: 400,
+ message: "Error: Input id: '%1' is not child of component id: '%2'",
+ messageId: "SVC4648"
+ }
+#---------SVC4649------------------------------
+# %1 - "groupName"
+ GROUP_HAS_CYCLIC_DEPENDENCY: {
+ code: 400,
+ message: "Error: The group '%1' has cyclic dependency",
+ messageId: "SVC4649"
+ }
+#---------SVC4650------------------------------
+# %1 - "Component Type"
+# %2 - <ServiceName>
+# %3 - error description
+ AAI_ARTIFACT_GENERATION_FAILED: {
+ code: 500,
+ message: "Error: %1 %2 automatic generation of artifacts failed. Description: %3",
+ messageId: "SVC4650"
+ }
diff --git a/catalog-be/src/main/resources/config/logback.xml b/catalog-be/src/main/resources/config/logback.xml
new file mode 100644
index 0000000000..5d5e4c670d
--- /dev/null
+++ b/catalog-be/src/main/resources/config/logback.xml
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="5 seconds">
+
+ <property scope="system" name="ECOMP-component-name" value="ASDC" />
+ <property scope="system" name="ECOMP-subcomponent-name" value="ASDC-BE" />
+ <property file="${config.home}/catalog-be/configuration.yaml" />
+ <property scope="context" name="enable-all-log" value="false" />
+
+ <!-- value used by pattern field list (| - is inter-field separator, || - unavailable or not applicable field value) (m - mandatory, o- optional)-->
+ <!--timestamp(m)| requestID(m)| serviceInstanceID(o)| threadID(m)| physicalServerName(o)| serviceName(m)| userID(m)| logLevel(m)| severity(o)| serverIpAddress(m)| serverName(m)| clientIpAddress(o)| className(m)| timer(o)| detailedMessage(o)-->
+ <property name="default-log-pattern"
+ value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{uuid}|%X{serviceInstanceID}|%thread||${ECOMP-subcomponent-name}|%X{userId}|%level|%X{alarmSeverity}|%X{localAddr}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
+
+ <!-- All log -->
+ <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
+ <then>
+ <appender name="ALL_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log
+ </file>
+
+ <rollingPolicy
+ class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ASYNC_ALL" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="ALL_ROLLING" />
+ </appender>
+ </then>
+ </if>
+
+ <!-- Error log -->
+ <appender name="ERROR_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log
+ </file>
+
+ <!-- Audit messages filter - deny audit messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>AUDIT_MARKER</marker>
+ </evaluator>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>DENY</onMatch>
+ </filter>
+
+ <!-- Transaction messages filter - deny Transaction messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>TRANSACTION_MARKER</marker>
+ </evaluator>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>DENY</onMatch>
+ </filter>
+
+ <!-- deny all events with a level below INFO, that is TRACE and DEBUG -->
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>INFO</level>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!-- Debug log -->
+ <appender name="DEBUG_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log
+ </file>
+
+ <!-- No need to deny audit messages - they are INFO only, will be denied
+ anyway -->
+ <!-- Transaction messages filter - deny Transaction messages, there are
+ some DEBUG level messages among them -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>TRANSACTION_MARKER</marker>
+ </evaluator>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>DENY</onMatch>
+ </filter>
+
+ <!-- accept DEBUG and TRACE level -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
+ <expression>
+ e.level.toInt() &lt;= DEBUG.toInt()
+ </expression>
+ </evaluator>
+ <OnMismatch>DENY</OnMismatch>
+ <OnMatch>NEUTRAL</OnMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!-- Audit log -->
+ <appender name="AUDIT_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log
+ </file>
+
+ <!-- Audit messages filter - accept audit messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>AUDIT_MARKER</marker>
+ </evaluator>
+ <onMismatch>DENY</onMismatch>
+ <onMatch>ACCEPT</onMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!-- SdncTransaction log -->
+ <appender name="TRANSACTION_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log
+ </file>
+
+ <!-- Transaction messages filter - accept audit messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>TRANSACTION_MARKER</marker>
+ </evaluator>
+ <onMismatch>DENY</onMismatch>
+ <onMatch>ACCEPT</onMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!-- Asynchronicity Configurations -->
+ <appender name="ASYNC_DEBUG" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="DEBUG_ROLLING" />
+ </appender>
+
+ <appender name="ASYNC_TRANSACTION" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="TRANSACTION_ROLLING" />
+ </appender>
+
+ <appender name="ASYNC_ERROR" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="ERROR_ROLLING" />
+ </appender>
+
+
+ <root level="INFO">
+ <appender-ref ref="ASYNC_ERROR" />
+ <appender-ref ref="ASYNC_DEBUG" />
+ <appender-ref ref="AUDIT_ROLLING" />
+ <appender-ref ref="ASYNC_TRANSACTION" />
+ <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
+ <then>
+ <appender-ref ref="ALL_ROLLING" />
+ </then>
+ </if>
+ </root>
+
+ <logger name="org.openecomp.sdc" level="INFO" />
+</configuration> \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/neo4j-errors-configuration.yaml b/catalog-be/src/main/resources/config/neo4j-errors-configuration.yaml
new file mode 100644
index 0000000000..7a0d6dbfd4
--- /dev/null
+++ b/catalog-be/src/main/resources/config/neo4j-errors-configuration.yaml
@@ -0,0 +1,60 @@
+# Errors
+errors:
+ Neo_ClientError_General_ReadOnly: "This is a read only database, writing or modifying the database is not allowed."
+ Neo_ClientError_LegacyIndex_NoSuchIndex: "The request (directly or indirectly) referred to a index that does not exist."
+ Neo_ClientError_Request_Invalid: "The client provided an invalid Request."
+ Neo_ClientError_Request_InvalidFormat: "The client provided a request that was missing required fields, or had values that are not allowed."
+ Neo_ClientError_Schema_ConstraintAlreadyExists: "Unable to perform operation because it would clash with a pre-existing constraint."
+ Neo_ClientError_Schema_ConstraintVerificationFailure: "Unable to create constraint because data that exists in the database violates it."
+ Neo_ClientError_Schema_ConstraintViolation: "A constraint imposed by the database was violated."
+ Neo_ClientError_Schema_IllegalTokenName: "A token name, such as a label, relationship type or property key, used is not valid. Tokens cannot be empty strings and cannot be null."
+ Neo_ClientError_Schema_IndexAlreadyExists: "Unable to perform operation because it would clash with a pre-existing index."
+ Neo_ClientError_Schema_IndexBelongsToConstraint: "A requested operation can not be performed on the specified index because the index is part of a constraint. If you want to drop the index, for instance, you must drop the constraint."
+ Neo_ClientError_Schema_IndexLimitReached: "The maximum number of index entries supported has been reached, no more entities can be indexed."
+ Neo_ClientError_Schema_LabelLimitReached: "The maximum number of labels supported has been reached, no more labels can be created."
+ Neo_ClientError_Schema_NoSuchConstraint: "The request (directly or indirectly) referred to a constraint that does not exist."
+ Neo_ClientError_Schema_NoSuchIndex: "The request (directly or indirectly) referred to an index that does not exist."
+ Neo_ClientError_Security_AuthenticationFailed: "The client provided an incorrect username and/or password."
+ Neo_ClientError_Security_AuthenticationRateLimit: "The client has provided incorrect authentication details too many times in a row."
+ Neo_ClientError_Security_AuthorizationFailed: "The client does not have privileges to perform the operation requested."
+ Neo_ClientError_Statement_ArithmeticError: "Invalid use of arithmetic, such as dividing by zero."
+ Neo_ClientError_Statement_ConstraintViolation: "A constraint imposed by the statement is violated by the data in the database."
+ Neo_ClientError_Statement_EntityNotFound: "The statement is directly referring to an entity that does not exist."
+ Neo_ClientError_Statement_InvalidArguments: "The statement is attempting to perform operations using invalid arguments"
+ Neo_ClientError_Statement_InvalidSemantics: "The statement is syntactically valid, but expresses something that the database cannot do."
+ Neo_ClientError_Statement_InvalidSyntax: "The statement contains invalid or unsupported syntax."
+ Neo_ClientError_Statement_InvalidType: "The statement is attempting to perform operations on values with types that are not supported by the operation."
+ Neo_ClientError_Statement_NoSuchLabel: "The statement is referring to a label that does not exist."
+ Neo_ClientError_Statement_NoSuchProperty: "The statement is referring to a property that does not exist."
+ Neo_ClientError_Statement_ParameterMissing: "The statement is referring to a parameter that was not provided in the Request."
+ Neo_ClientError_Transaction_ConcurrentRequest: "There were concurrent requests accessing the same transaction, which is not allowed."
+ Neo_ClientError_Transaction_EventHandlerThrewException: "A transaction event handler threw an exception. The transaction will be rolled back."
+ Neo_ClientError_Transaction_HookFailed: "Transaction hook failure."
+ Neo_ClientError_Transaction_InvalidType: "The transaction is of the wrong type to service the Request_ For instance, a transaction that has had schema modifications performed in it cannot be used to subsequently perform data operations, and vice versa."
+ Neo_ClientError_Transaction_MarkedAsFailed: "Transaction was marked as both successful and failed. Failure takes precedence and so this transaction was rolled back although it may have looked like it was going to be committed"
+ Neo_ClientError_Transaction_UnknownId: "The request referred to a transaction that does not exist."
+ Neo_ClientError_Transaction_ValidationFailed: "Transaction changes did not pass validation checks"
+ Neo_DatabaseError_General_CorruptSchemaRule: "A malformed schema rule was encountered. Please contact your support representative."
+ Neo_DatabaseError_General_FailedIndex: "The request (directly or indirectly) referred to an index that is in a failed state. The index needs to be dropped and recreated manually."
+ Neo_DatabaseError_General_UnknownFailure: "An unknown failure occurred."
+ Neo_DatabaseError_Schema_ConstraintCreationFailure: "Creating a requested constraint failed."
+ Neo_DatabaseError_Schema_ConstraintDropFailure: "The database failed to drop a requested constraint."
+ Neo_DatabaseError_Schema_IndexCreationFailure: "Failed to create an index."
+ Neo_DatabaseError_Schema_IndexDropFailure: "The database failed to drop a requested index."
+ Neo_DatabaseError_Schema_NoSuchLabel: "The request accessed a label that did not exist."
+ Neo_DatabaseError_Schema_NoSuchPropertyKey: "The request accessed a property that does not exist."
+ Neo_DatabaseError_Schema_NoSuchRelationshipType: "The request accessed a relationship type that does not exist."
+ Neo_DatabaseError_Schema_NoSuchSchemaRule: "The request referred to a schema rule that does not exist."
+ Neo_DatabaseError_Statement_ExecutionFailure: "The database was unable to execute the Statement."
+ Neo_DatabaseError_Transaction_CouldNotBegin: "The database was unable to start the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotCommit: "The database was unable to commit the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotRollback: "The database was unable to roll back the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotWriteToLog: "The database was unable to write transaction to log."
+ Neo_DatabaseError_Transaction_ReleaseLocksFailed: "The transaction was unable to release one or more of its locks."
+ Neo_TransientError_General_DatabaseUnavailable: "The database is not currently available to serve your request, refer to the database logs for more details. Retrying your request at a later time may succeed."
+ Neo_TransientError_Network_UnknownFailure: "An unknown network failure occurred, a retry may resolve the issue."
+ Neo_TransientError_Schema_ModifiedConcurrently: "The database schema was modified while this transaction was running, the transaction should be retried."
+ Neo_TransientError_Security_ModifiedConcurrently: "The user was modified concurrently to this Request."
+ Neo_TransientError_Statement_ExternalResourceFailure: "The external resource is not available"
+ Neo_TransientError_Transaction_AcquireLockTimeout: "The transaction was unable to acquire a lock, for instance due to a timeout or the transaction thread being interrupted."
+ Neo_TransientError_Transaction_DeadlockDetected: "This transaction, and at least one more transaction, has acquired locks in a way that it will wait indefinitely, and the database has aborted it. Retrying this transaction will most likely be successful." \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/titan.properties b/catalog-be/src/main/resources/config/titan.properties
new file mode 100644
index 0000000000..7eb57235c7
--- /dev/null
+++ b/catalog-be/src/main/resources/config/titan.properties
@@ -0,0 +1,10 @@
+storage.backend=cassandra
+storage.hostname=localhost
+storage.port=9160
+
+cache.db-cache = false
+cache.db-cache-clean-wait = 20
+cache.db-cache-time = 180000
+cache.db-cache-size = 0.5
+
+cache.tx-cache-size = 500000
diff --git a/catalog-be/src/main/resources/elasticsearch.yml b/catalog-be/src/main/resources/elasticsearch.yml
new file mode 100644
index 0000000000..b4634c8213
--- /dev/null
+++ b/catalog-be/src/main/resources/elasticsearch.yml
@@ -0,0 +1,393 @@
+
+cluster.name: elasticsearch_1_5_2
+
+discovery.zen.ping.unicast.hosts: elasticsearch_host
+
+http.cors.enabled: true
+#plugin.types: "DeleteByQueryPlugin"
+#path.home: "/home/vagrant/catalog-be/config"
+
+elasticSearch.transportclient: true
+
+transport.client.initial_nodes:
+ - elasticsearch_host:9300
+
+##################### Elasticsearch Configuration Example #####################
+
+# This file contains an overview of various configuration settings,
+# targeted at operations staff. Application developers should
+# consult the guide at <http://elasticsearch.org/guide>.
+#
+# The installation procedure is covered at
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
+#
+# Elasticsearch comes with reasonable defaults for most settings,
+# so you can try it out without bothering with configuration.
+#
+# Most of the time, these defaults are just fine for running a production
+# cluster. If you're fine-tuning your cluster, or wondering about the
+# effect of certain configuration option, please _do ask_ on the
+# mailing list or IRC channel [http://elasticsearch.org/community].
+
+# Any element in the configuration can be replaced with environment variables
+# by placing them in ${...} notation. For example:
+#
+# node.rack: ${RACK_ENV_VAR}
+
+# For information on supported formats and syntax for the config file, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html>
+
+
+################################### Cluster ###################################
+
+# Cluster name identifies your cluster for auto-discovery. If you're running
+# multiple clusters on the same network, make sure you're using unique names.
+#
+# cluster.name: elasticsearch
+
+
+#################################### Node #####################################
+
+# Node names are generated dynamically on startup, so you're relieved
+# from configuring them manually. You can tie this node to a specific name:
+#
+# node.name: "Franz Kafka"
+
+# Every node can be configured to allow or deny being eligible as the master,
+# and to allow or deny to store the data.
+#
+# Allow this node to be eligible as a master node (enabled by default):
+#
+# node.master: true
+#
+# Allow this node to store data (enabled by default):
+#
+# node.data: true
+
+# You can exploit these settings to design advanced cluster topologies.
+#
+# 1. You want this node to never become a master node, only to hold data.
+# This will be the "workhorse" of your cluster.
+#
+# node.master: false
+# node.data: true
+#
+# 2. You want this node to only serve as a master: to not store any data and
+# to have free resources. This will be the "coordinator" of your cluster.
+#
+# node.master: true
+# node.data: false
+#
+# 3. You want this node to be neither master nor data node, but
+# to act as a "search load balancer" (fetching data from nodes,
+# aggregating results, etc.)
+#
+# node.master: false
+# node.data: false
+
+# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
+# Node Info API [http://localhost:9200/_nodes] or GUI tools
+# such as <http://www.elasticsearch.org/overview/marvel/>,
+# <http://github.com/karmi/elasticsearch-paramedic>,
+# <http://github.com/lukas-vlcek/bigdesk> and
+# <http://mobz.github.com/elasticsearch-head> to inspect the cluster state.
+
+# A node can have generic attributes associated with it, which can later be used
+# for customized shard allocation filtering, or allocation awareness. An attribute
+# is a simple key value pair, similar to node.key: value, here is an example:
+#
+# node.rack: rack314
+
+# By default, multiple nodes are allowed to start from the same installation location
+# to disable it, set the following:
+# node.max_local_storage_nodes: 1
+
+
+#################################### Index ####################################
+
+# You can set a number of options (such as shard/replica options, mapping
+# or analyzer definitions, translog settings, ...) for indices globally,
+# in this file.
+#
+# Note, that it makes more sense to configure index settings specifically for
+# a certain index, either when creating it or by using the index templates API.
+#
+# See <http://elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules.html> and
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
+# for more information.
+
+# Set the number of shards (splits) of an index (5 by default):
+#
+# index.number_of_shards: 5
+
+# Set the number of replicas (additional copies) of an index (1 by default):
+#
+# index.number_of_replicas: 1
+
+# Note, that for development on a local machine, with small indices, it usually
+# makes sense to "disable" the distributed features:
+#
+index.number_of_shards: 1
+index.number_of_replicas: 0
+
+# These settings directly affect the performance of index and search operations
+# in your cluster. Assuming you have enough machines to hold shards and
+# replicas, the rule of thumb is:
+#
+# 1. Having more *shards* enhances the _indexing_ performance and allows to
+# _distribute_ a big index across machines.
+# 2. Having more *replicas* enhances the _search_ performance and improves the
+# cluster _availability_.
+#
+# The "number_of_shards" is a one-time setting for an index.
+#
+# The "number_of_replicas" can be increased or decreased anytime,
+# by using the Index Update Settings API.
+#
+# Elasticsearch takes care about load balancing, relocating, gathering the
+# results from nodes, etc. Experiment with different settings to fine-tune
+# your setup.
+
+# Use the Index Status API (<http://localhost:9200/A/_status>) to inspect
+# the index status.
+
+
+#################################### Paths ####################################
+
+# Path to directory containing configuration (this file and logging.yml):
+#
+path.conf: /src/test/resources
+#path.home: /src/test/resources
+
+# Path to directory where to store index data allocated for this node.
+#
+path.data: target/esdata
+#
+# Can optionally include more than one location, causing data to be striped across
+# the locations (a la RAID 0) on a file level, favouring locations with most free
+# space on creation. For example:
+#
+# path.data: /path/to/data1,/path/to/data2
+
+# Path to temporary files:
+#
+path.work: /target/eswork
+
+# Path to log files:
+#
+path.logs: /target/eslogs
+
+# Path to where plugins are installed:
+#
+# path.plugins: /path/to/plugins
+
+
+#################################### Plugin ###################################
+
+# If a plugin listed here is not installed for current node, the node will not start.
+#
+# plugin.mandatory: mapper-attachments,lang-groovy
+
+
+################################### Memory ####################################
+
+# Elasticsearch performs poorly when JVM starts swapping: you should ensure that
+# it _never_ swaps.
+#
+# Set this property to true to lock the memory:
+#
+# bootstrap.mlockall: true
+
+# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
+# to the same value, and that the machine has enough memory to allocate
+# for Elasticsearch, leaving enough memory for the operating system itself.
+#
+# You should also make sure that the Elasticsearch process is allowed to lock
+# the memory, eg. by using `ulimit -l unlimited`.
+
+
+############################## Network And HTTP ###############################
+
+# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
+# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
+# communication. (the range means that if the port is busy, it will automatically
+# try the next port).
+
+# Set the bind address specifically (IPv4 or IPv6):
+#
+# network.bind_host: 192.168.0.1
+
+# Set the address other nodes will use to communicate with this node. If not
+# set, it is automatically derived. It must point to an actual IP address.
+#
+# network.publish_host: 192.168.0.1
+
+# Set both 'bind_host' and 'publish_host':
+#
+# network.host: 192.168.0.1
+
+# Set a custom port for the node to node communication (9300 by default):
+#
+# transport.tcp.port: 9300
+
+# Enable compression for all communication between nodes (disabled by default):
+#
+# transport.tcp.compress: true
+
+# Set a custom port to listen for HTTP traffic:
+#
+# http.port: 9200
+
+# Set a custom allowed content length:
+#
+# http.max_content_length: 100mb
+
+# Disable HTTP completely:
+#
+# http.enabled: false
+
+
+################################### Gateway ###################################
+
+# The gateway allows for persisting the cluster state between full cluster
+# restarts. Every change to the state (such as adding an index) will be stored
+# in the gateway, and when the cluster starts up for the first time,
+# it will read its state from the gateway.
+
+# There are several types of gateway implementations. For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-gateway.html>.
+
+# The default gateway type is the "local" gateway (recommended):
+#
+# gateway.type: local
+
+# Settings below control how and when to start the initial recovery process on
+# a full cluster restart (to reuse as much local data as possible when using shared
+# gateway).
+
+# Allow recovery process after N nodes in a cluster are up:
+#
+gateway.recover_after_nodes: 1
+
+# Set the timeout to initiate the recovery process, once the N nodes
+# from previous setting are up (accepts time value):
+#
+# gateway.recover_after_time: 5m
+
+# Set how many nodes are expected in this cluster. Once these N nodes
+# are up (and recover_after_nodes is met), begin recovery process immediately
+# (without waiting for recover_after_time to expire):
+#
+gateway.expected_nodes: 1
+
+
+############################# Recovery Throttling #############################
+
+# These settings allow to control the process of shards allocation between
+# nodes during initial recovery, replica allocation, rebalancing,
+# or when adding and removing nodes.
+
+# Set the number of concurrent recoveries happening on a node:
+#
+# 1. During the initial recovery
+#
+# cluster.routing.allocation.node_initial_primaries_recoveries: 4
+#
+# 2. During adding/removing nodes, rebalancing, etc
+#
+# cluster.routing.allocation.node_concurrent_recoveries: 2
+
+# Set to throttle throughput when recovering (eg. 100mb, by default 20mb):
+#
+# indices.recovery.max_bytes_per_sec: 20mb
+
+# Set to limit the number of open concurrent streams when
+# recovering a shard from a peer:
+#
+# indices.recovery.concurrent_streams: 5
+
+
+################################## Discovery ##################################
+
+# Discovery infrastructure ensures nodes can be found within a cluster
+# and master node is elected. Multicast discovery is the default.
+
+# Set to ensure a node sees N other master eligible nodes to be considered
+# operational within the cluster. Its recommended to set it to a higher value
+# than 1 when running more than 2 nodes in the cluster.
+#
+# discovery.zen.minimum_master_nodes: 1
+
+# Set the time to wait for ping responses from other nodes when discovering.
+# Set this option to a higher value on a slow or congested network
+# to minimize discovery failures:
+#
+# discovery.zen.ping.timeout: 3s
+
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html>
+
+# Unicast discovery allows to explicitly control which nodes will be used
+# to discover the cluster. It can be used when multicast is not present,
+# or to restrict the cluster communication-wise.
+#
+# 1. Disable multicast discovery (enabled by default):
+#
+# discovery.zen.ping.multicast.enabled: false
+#
+# 2. Configure an initial list of master nodes in the cluster
+# to perform discovery when new nodes (master or data) are started:
+#
+# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]
+
+# EC2 discovery allows to use AWS EC2 API in order to perform discovery.
+#
+# You have to install the cloud-aws plugin for enabling the EC2 discovery.
+#
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html>
+#
+# See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/>
+# for a step-by-step tutorial.
+
+# GCE discovery allows to use Google Compute Engine API in order to perform discovery.
+#
+# You have to install the cloud-gce plugin for enabling the GCE discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>.
+
+# Azure discovery allows to use Azure API in order to perform discovery.
+#
+# You have to install the cloud-azure plugin for enabling the Azure discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
+
+################################## Slow Log ##################################
+
+# Shard level query and fetch threshold logging.
+
+#index.search.slowlog.threshold.query.warn: 10s
+#index.search.slowlog.threshold.query.info: 5s
+#index.search.slowlog.threshold.query.debug: 2s
+#index.search.slowlog.threshold.query.trace: 500ms
+
+#index.search.slowlog.threshold.fetch.warn: 1s
+#index.search.slowlog.threshold.fetch.info: 800ms
+#index.search.slowlog.threshold.fetch.debug: 500ms
+#index.search.slowlog.threshold.fetch.trace: 200ms
+
+#index.indexing.slowlog.threshold.index.warn: 10s
+#index.indexing.slowlog.threshold.index.info: 5s
+#index.indexing.slowlog.threshold.index.debug: 2s
+#index.indexing.slowlog.threshold.index.trace: 500ms
+
+################################## GC Logging ################################
+
+#monitor.jvm.gc.young.warn: 1000ms
+#monitor.jvm.gc.young.info: 700ms
+#monitor.jvm.gc.young.debug: 400ms
+
+#monitor.jvm.gc.old.warn: 10s
+#monitor.jvm.gc.old.info: 5s
+#monitor.jvm.gc.old.debug: 2s
+
diff --git a/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.yml b/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.yml
new file mode 100644
index 0000000000..d8d9f20d40
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.yml
@@ -0,0 +1,204 @@
+tosca.capabilities.Root:
+ description: The TOSCA root Capability Type all other TOSCA base Capability Types derive from
+tosca.capabilities.Attachment:
+ derived_from: tosca.capabilities.Root
+tosca.capabilities.Node:
+ derived_from: tosca.capabilities.Root
+tosca.capabilities.Container:
+ derived_from: tosca.capabilities.Root
+ properties:
+ num_cpus:
+ type: integer
+ required: false
+ constraints:
+ - greater_or_equal: 1
+ cpu_frequency:
+ type: scalar-unit.frequency
+ required: false
+ constraints:
+ - greater_or_equal: 0.1 GHz
+ disk_size:
+ type: scalar-unit.size
+ required: false
+ constraints:
+ - greater_or_equal: 0 MB
+ mem_size:
+ type: scalar-unit.size
+ required: false
+ constraints:
+ - greater_or_equal: 0 MB
+tosca.capabilities.Endpoint:
+ derived_from: tosca.capabilities.Root
+ properties:
+ protocol:
+ type: string
+ default: tcp
+ port:
+ type: PortDef
+ required: false
+ secure:
+ type: boolean
+ default: false
+ url_path:
+ type: string
+ required: false
+ port_name:
+ type: string
+ required: false
+ network_name:
+ type: string
+ required: false
+ default: PRIVATE
+ initiator:
+ type: string
+ default: source
+ constraints:
+ - valid_values: [ source, target, peer ]
+ ports:
+ type: map
+ required: false
+ constraints:
+ - min_length: 1
+ entry_schema:
+ type: PortSpec
+ attributes:
+ ip_address:
+ type: string
+tosca.capabilities.DatabaseEndpoint:
+ derived_from: tosca.capabilities.Endpoint
+tosca.capabilities.Endpoint.Public:
+ derived_from: tosca.capabilities.Endpoint
+ properties:
+ # Change the default network_name to use the first public network found
+ network_name: PUBLIC
+ floating:
+ description: >
+ indicates that the public address should be allocated from a pool of floating IPs that are associated with the network.
+ type: boolean
+ default: false
+ status: experimental
+ dns_name:
+ description: The optional name to register with DNS
+ type: string
+ required: false
+ status: experimental
+tosca.capabilities.Endpoint.Admin:
+ derived_from: tosca.capabilities.Endpoint
+ # Change Endpoint secure indicator to true from its default of false
+ properties:
+ secure: true
+tosca.capabilities.Endpoint.Database:
+ derived_from: tosca.capabilities.Endpoint
+tosca.capabilities.OperatingSystem:
+ derived_from: tosca.capabilities.Root
+ properties:
+ architecture:
+ type: string
+ required: false
+ type:
+ type: string
+ required: false
+ distribution:
+ type: string
+ required: false
+ version:
+ type: version
+ required: false
+tosca.capabilities.Scalable:
+ derived_from: tosca.capabilities.Root
+ properties:
+ min_instances:
+ type: integer
+ default: 1
+ max_instances:
+ type: integer
+ default: 1
+ default_instances:
+ type: integer
+tosca.capabilities.network.Bindable:
+ derived_from: tosca.capabilities.Node
+
+
+tosca.capabilities.Container.Docker:
+ derived_from: tosca.capabilities.Container
+ properties:
+ version:
+ type: list
+ required: false
+ entry_schema: version
+ publish_all:
+ type: boolean
+ default: false
+ required: false
+ publish_ports:
+ type: list
+ entry_schema: PortSpec
+ required: false
+ expose_ports:
+ type: list
+ entry_schema: PortSpec
+ required: false
+ volumes:
+ type: list
+ entry_schema: string
+ required: false
+tosca.capabilities.network.Linkable:
+ derived_from: tosca.capabilities.Root
+tosca.capabilities.nfv.Metric:
+ derived_from: tosca.capabilities.Endpoint
+org.openecomp.capabilities.Metric:
+ derived_from: tosca.capabilities.nfv.Metric
+ description: A node type that includes the Metric capability indicates that it can be monitored.
+ properties:
+ unit:
+ type: string
+ description: Unit of the metric value
+ required: true
+ status: SUPPORTED
+ description:
+ type: string
+ description: Description of the metric
+ required: false
+ status: SUPPORTED
+ type:
+ type: string
+ description: Type of the metric value, for an example, Cumulative, Delta, Gauge and etc.
+ required: true
+ status: SUPPORTED
+ category:
+ type: string
+ description: Category of the metric, for an example, compute, disk, network, storage and etc.
+ required: false
+ status: SUPPORTED
+ attributes:
+ value:
+ type: string
+ description: Runtime monitored value
+ status: SUPPORTED
+org.openecomp.capabilities.metric.Ceilometer:
+ derived_from: org.openecomp.capabilities.Metric
+ description: A node type that includes the Metric capability indicates that it can be monitored using ceilometer.
+ properties:
+ name:
+ type: string
+ description: Ceilometer metric type name to monitor. (The name ceilometer is using)
+ required: true
+ status: SUPPORTED
+org.openecomp.capabilities.metric.SnmpPolling:
+ derived_from: org.openecomp.capabilities.Metric
+ description: A node type that includes the Metric capability indicates that it can be monitored using snmp polling.
+ properties:
+ oid:
+ type: string
+ description: Object Id of the metric
+ required: true
+ status: SUPPORTED
+org.openecomp.capabilities.metric.SnmpTrap:
+ derived_from: org.openecomp.capabilities.Metric
+ description: A node type that includes the Metric capability indicates that it can be monitored using snmp trap.
+ properties:
+ oid:
+ type: string
+ description: Object Id of the metric
+ required: true
+ status: SUPPORTED
diff --git a/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.zip b/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.zip
new file mode 100644
index 0000000000..add3a8ce1f
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/capability-types/capabilityTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.yml b/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.yml
new file mode 100644
index 0000000000..9ddce45e4e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.yml
@@ -0,0 +1,116 @@
+services:
+ Mobility:
+ name: "Mobility"
+ icons: ['mobility']
+ Network_L1_3:
+ name: "Network L1-3"
+ icons: ['network_l_1-3']
+ Network_L4:
+ name: "Network L4+"
+ icons: ['network_l_4']
+ VoIP_Call_Control:
+ name: "VoIP Call Control"
+ icons: ['call_controll']
+resources:
+ NetworkLayer23:
+ name: "Network L2-3"
+ subcategories:
+ Router:
+ name: "Router"
+ icons: ['router','vRouter']
+ Gateway:
+ name: "Gateway"
+ icons: ['gateway']
+ WAN_Connectors:
+ name: "WAN Connectors"
+ icons: ['network','connector','port']
+ LAN_Connectors:
+ name: "LAN Connectors"
+ icons: ['network','connector','port']
+ Infrastructure:
+ name: "Infrastructure"
+ icons: ['ucpe']
+ NetworkLayer4:
+ name: "Network L4+"
+ subcategories:
+ Common_Network_Resources:
+ name: "Common Network Resources"
+ icons: ['network']
+ ApplicationLayer4:
+ name: "Application L4+"
+ subcategories:
+ Border_Element:
+ name: "Border Element"
+ icons: ['borderElement']
+ Application_Server:
+ name: "Application Server"
+ icons: ['applicationServer']
+ Web_Server:
+ name: "Web Server"
+ icons: ['applicationServer']
+ Call_Control:
+ name: "Call Control"
+ icons: ['call_controll']
+ Media_Servers:
+ name: "Media Servers"
+ icons: ['applicationServer']
+ Load_Balancer:
+ name: "Load Balancer"
+ icons: ['loadBalancer']
+ Database:
+ name: "Database"
+ icons: ['database']
+ Firewall:
+ name: "Firewall"
+ icons: ['firewall']
+ Generic:
+ name: "Generic"
+ subcategories:
+ Infrastructure:
+ name: "Infrastructure"
+ icons: ['connector']
+ Abstract:
+ name: "Abstract"
+ icons: ['objectStorage', 'compute']
+ Network_Elements:
+ name: "Network Elements"
+ icons: ['network', 'connector']
+ Database:
+ name: "Database"
+ icons: ['database']
+ Rules:
+ name: "Rules"
+ icons: ['networkrules','securityrules']
+ NetworkConnectivity:
+ name: "Network Connectivity"
+ subcategories:
+ ConnectionPoints:
+ name: "Connection Points"
+ icons: ['cp']
+ VirtualLinks:
+ name: "Virtual Links"
+ icons: ['vl']
+ DcaeComponent:
+ name: "DCAE Component"
+ subcategories:
+ Source:
+ name: "Source"
+ icons: ['dcae_source']
+ Collector:
+ name: "Collector"
+ icons: ['dcae_collector']
+ Utility:
+ name: "Utility"
+ icons: ['dcae_utilty']
+ Microservice:
+ name: "Microservice"
+ icons: ['dcae_microservice']
+ Analytics:
+ name: "Analytics"
+ icons: ['dcae_analytics']
+ Database:
+ name: "Database"
+ icons: ['dcae_database']
+ Policy:
+ name: "Policy"
+ icons: ['dcae_policy'] \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.zip b/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.zip
new file mode 100644
index 0000000000..c04a2faefc
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/categories/categoryTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml
new file mode 100644
index 0000000000..1fdc3a2cd2
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml
@@ -0,0 +1,821 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+string:
+ derived_from: tosca.datatypes.Root
+
+boolean:
+ derived_from: tosca.datatypes.Root
+
+float:
+ derived_from: tosca.datatypes.Root
+
+json:
+ derived_from: tosca.datatypes.Root
+
+list:
+ derived_from: tosca.datatypes.Root
+
+map:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false
+ token_type:
+ type: string
+ default: password
+ token:
+ type: string
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: string
+ user:
+ type: string
+ required: false
+
+tosca.datatypes.TimeInterval:
+ derived_from: tosca.datatypes.Root
+ properties:
+ start_time:
+ type: timestamp
+ required: true
+ end_time:
+ type: timestamp
+ required: true
+
+tosca.datatypes.network.NetworkInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ network_name:
+ type: string
+ network_id:
+ type: string
+ addresses:
+ type: list
+ entry_schema:
+ type: string
+
+tosca.datatypes.network.PortInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ port_name:
+ type: string
+ port_id:
+ type: string
+ network_id:
+ type: string
+ mac_address:
+ type: string
+ addresses:
+ type: list
+ entry_schema:
+ type: string
+
+tosca.datatypes.network.PortDef:
+ derived_from: integer
+ constraints:
+ - in_range: [ 1, 65535 ]
+
+tosca.datatypes.network.PortSpec:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: true
+ default: tcp
+ constraints:
+ - valid_values: [ udp, tcp, igmp ]
+ target:
+ type: tosca.datatypes.network.PortDef
+ target_range:
+ type: range
+ constraints:
+ - in_range: [ 1, 65535 ]
+ source:
+ type: tosca.datatypes.network.PortDef
+ source_range:
+ type: range
+ constraints:
+ - in_range: [ 1, 65535 ]
+
+
+
+org.openecomp.datatypes.heat.network.AddressPair:
+ derived_from: tosca.datatypes.Root
+ description: MAC/IP address pairs
+ properties:
+ mac_address:
+ type: string
+ description: MAC address
+ required: false
+ status: SUPPORTED
+ ip_address:
+ type: string
+ description: IP address
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.network.subnet.HostRoute:
+ derived_from: tosca.datatypes.Root
+ description: Host route info for the subnet
+ properties:
+ destination:
+ type: string
+ description: The destination for static route
+ required: false
+ status: SUPPORTED
+ nexthop:
+ type: string
+ description: The next hop for the destination
+ required: false
+ status: SUPPORTED
+
+org.openecomp.datatypes.heat.network.AllocationPool:
+ derived_from: tosca.datatypes.Root
+ description: The start and end addresses for the allocation pool
+ properties:
+ start:
+ type: string
+ description: Start address for the allocation pool
+ required: false
+ status: SUPPORTED
+ end:
+ type: string
+ description: End address for the allocation pool
+ required: false
+ status: SUPPORTED
+
+org.openecomp.datatypes.heat.network.neutron.Subnet:
+ derived_from: tosca.datatypes.Root
+ description: A subnet represents an IP address block that can be used for assigning IP addresses to virtual instances
+ properties:
+ tenant_id:
+ type: string
+ description: The ID of the tenant who owns the network
+ required: false
+ status: SUPPORTED
+ enable_dhcp:
+ type: boolean
+ description: Set to true if DHCP is enabled and false if DHCP is disabled
+ required: false
+ default: true
+ status: SUPPORTED
+ ipv6_address_mode:
+ type: string
+ description: IPv6 address mode
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - dhcpv6-stateful
+ - dhcpv6-stateless
+ - slaac
+ ipv6_ra_mode:
+ type: string
+ description: IPv6 RA (Router Advertisement) mode
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - dhcpv6-stateful
+ - dhcpv6-stateless
+ - slaac
+ value_specs:
+ type: map
+ description: Extra parameters to include in the request
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ allocation_pools:
+ type: list
+ description: The start and end addresses for the allocation pools
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.AllocationPool
+ subnetpool:
+ type: string
+ description: The name or ID of the subnet pool
+ required: false
+ status: SUPPORTED
+ dns_nameservers:
+ type: list
+ description: A specified set of DNS name servers to be used
+ required: false
+ default: [
+ ]
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ host_routes:
+ type: list
+ description: The gateway IP address
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.subnet.HostRoute
+ ip_version:
+ type: integer
+ description: The gateway IP address
+ required: false
+ default: 4
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - '4'
+ - '6'
+ name:
+ type: string
+ description: The name of the subnet
+ required: false
+ status: SUPPORTED
+ prefixlen:
+ type: integer
+ description: Prefix length for subnet allocation from subnet pool
+ required: false
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 0
+ cidr:
+ type: string
+ description: The CIDR
+ required: false
+ status: SUPPORTED
+ gateway_ip:
+ type: string
+ description: The gateway IP address
+ required: false
+ status: SUPPORTED
+
+org.openecomp.datatypes.heat.novaServer.network.PortExtraProperties:
+ derived_from: tosca.datatypes.Root
+ description: Nova server network expand properties for port
+ properties:
+ port_security_enabled:
+ type: boolean
+ description: Flag to enable/disable port security on the port
+ required: false
+ status: SUPPORTED
+ mac_address:
+ type: string
+ description: MAC address to give to this port
+ required: false
+ status: SUPPORTED
+ admin_state_up:
+ type: boolean
+ description: The administrative state of this port
+ required: false
+ default: true
+ status: SUPPORTED
+ qos_policy:
+ type: string
+ description: The name or ID of QoS policy to attach to this port
+ required: false
+ status: SUPPORTED
+ allowed_address_pairs:
+ type: list
+ description: Additional MAC/IP address pairs allowed to pass through the port
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.AddressPair
+ binding:vnic_type:
+ type: string
+ description: The vnic type to be bound on the neutron port
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - macvtap
+ - direct
+ - normal
+ value_specs:
+ type: map
+ description: Extra parameters to include in the request
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+org.openecomp.datatypes.heat.novaServer.network.AddressInfo:
+ derived_from: tosca.datatypes.network.NetworkInfo
+ description: Network addresses with corresponding port id
+ properties:
+ port_id:
+ type: string
+ description: Port id
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.neutron.port.FixedIps:
+ derived_from: tosca.datatypes.Root
+ description: subnet/ip_address
+ properties:
+ subnet:
+ type: string
+ description: Subnet in which to allocate the IP address for this port
+ required: false
+ status: SUPPORTED
+ ip_address:
+ type: string
+ description: IP address desired in the subnet for this port
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.FileInfo:
+ derived_from: tosca.datatypes.Root
+ description: Heat File Info
+ properties:
+ file:
+ type: string
+ description: The required URI string (relative or absolute) which can be used to locate the file
+ required: true
+ status: SUPPORTED
+ file_type:
+ type: string
+ description: The type of the file
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - base
+ - env
+ - volume
+ - network
+org.openecomp.datatypes.heat.contrail.network.rule.PortPairs:
+ derived_from: tosca.datatypes.Root
+ description: source and destination port pairs
+ properties:
+ start_port:
+ type: string
+ description: Start port
+ required: false
+ status: SUPPORTED
+ end_port:
+ type: string
+ description: End port
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrail.network.rule.Rule:
+ derived_from: tosca.datatypes.Root
+ description: policy rule
+ properties:
+ src_ports:
+ type: list
+ description: Source ports
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrail.network.rule.PortPairs
+ protocol:
+ type: string
+ description: Protocol
+ required: false
+ status: SUPPORTED
+ dst_addresses:
+ type: list
+ description: Destination addresses
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork
+ apply_service:
+ type: string
+ description: Service to apply
+ required: false
+ status: SUPPORTED
+ dst_ports:
+ type: list
+ description: Destination ports
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrail.network.rule.PortPairs
+ src_addresses:
+ type: list
+ description: Source addresses
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork
+ direction:
+ type: string
+ description: Direction
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrail.network.rule.RuleList:
+ derived_from: tosca.datatypes.Root
+ description: list of policy rules
+ properties:
+ policy_rule:
+ type: list
+ description: Contrail network rule
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: corg.openecomp.datatypes.heat.contrail.network.rule.Rule
+org.openecomp.datatypes.heat.contrail.network.rule.VirtualNetwork:
+ derived_from: tosca.datatypes.Root
+ description: source and destination addresses
+ properties:
+ virtual_network:
+ type: string
+ description: Virtual network
+ required: false
+ status: SUPPORTED
+
+org.openecomp.datatypes.heat.network.neutron.SecurityRules.Rule:
+ derived_from: tosca.datatypes.Root
+ description: Rules Pairs
+ properties:
+ remote_group_id:
+ type: string
+ description: The remote group ID to be associated with this security group rule
+ required: false
+ status: SUPPORTED
+ protocol:
+ type: string
+ description: The protocol that is matched by the security group rule
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - tcp
+ - udp
+ - icmp
+ ethertype:
+ type: string
+ description: Ethertype of the traffic
+ required: false
+ default: IPv4
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - IPv4
+ - IPv6
+ port_range_max:
+ type: integer
+ description: 'The maximum port number in the range that is matched by the
+ security group rule. '
+ required: false
+ status: SUPPORTED
+ constraints:
+ - in_range:
+ - 0
+ - 65535
+ remote_ip_prefix:
+ type: string
+ description: The remote IP prefix (CIDR) to be associated with this security group rule
+ required: false
+ status: SUPPORTED
+ remote_mode:
+ type: string
+ description: Whether to specify a remote group or a remote IP prefix
+ required: false
+ default: remote_ip_prefix
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - remote_ip_prefix
+ - remote_group_id
+ direction:
+ type: string
+ description: The direction in which the security group rule is applied
+ required: false
+ default: ingress
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - egress
+ - ingress
+ port_range_min:
+ type: integer
+ description: The minimum port number in the range that is matched by the security group rule.
+ required: false
+ status: SUPPORTED
+ constraints:
+ - in_range:
+ - 0
+ - 65535
+org.openecomp.datatypes.heat.substitution.SubstitutionFiltering:
+ derived_from: tosca.datatypes.Root
+ description: Substitution Filter
+ properties:
+ substitute_service_template:
+ type: string
+ description: Substitute Service Template
+ required: true
+ status: SUPPORTED
+ index_value:
+ type: integer
+ description: Index value of the substitution service template runtime instance
+ required: false
+ default: 0
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 0
+ count:
+ type: string
+ description: Count
+ required: false
+ default: 1
+ status: SUPPORTED
+ scaling_enabled:
+ type: boolean
+ description: Indicates whether service scaling is enabled
+ required: false
+ default: true
+ status: SUPPORTED
+ mandatory:
+ type: boolean
+ description: Mandatory
+ required: false
+ default: true
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.RefDataSequence:
+ derived_from: tosca.datatypes.Root
+ description: network policy refs data sequence
+ properties:
+ network_policy_refs_data_sequence_major:
+ type: integer
+ description: Network Policy ref data sequence Major
+ required: false
+ status: SUPPORTED
+ network_policy_refs_data_sequence_minor:
+ type: integer
+ description: Network Policy ref data sequence Minor
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.RefData:
+ derived_from: tosca.datatypes.Root
+ description: network policy refs data
+ properties:
+ network_policy_refs_data_sequence:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.RefDataSequence
+ description: Network Policy ref data sequence
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.ref.data.IpamSubnet:
+ derived_from: tosca.datatypes.Root
+ description: Network Ipam Ref Data Subnet
+ properties:
+ network_ipam_refs_data_ipam_subnets_subnet_ip_prefix_len:
+ type: string
+ description: Network ipam refs data ipam subnets ip prefix len
+ required: false
+ status: SUPPORTED
+ network_ipam_refs_data_ipam_subnets_subnet_ip_prefix:
+ type: string
+ description: Network ipam refs data ipam subnets ip prefix
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.ref.data.IpamSubnetList:
+ derived_from: tosca.datatypes.Root
+ description: Network Ipam Ref Data Subnet List
+ properties:
+ network_ipam_refs_data_ipam_subnets_subnet:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.ref.data.IpamSubnet
+ description: Network ipam refs data ipam subnets
+ required: false
+ status: SUPPORTED
+ network_ipam_refs_data_ipam_subnets_addr_from_start:
+ type: string
+ description: Network ipam refs data ipam subnets addr from start
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.IpamRefData:
+ derived_from: tosca.datatypes.Root
+ description: Network Ipam Ref Data
+ properties:
+ network_ipam_refs_data_ipam_subnets:
+ type: list
+ description: Network ipam refs data ipam subnets
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.ref.data.IpamSubnetList
+org.openecomp.datatypes.heat.contrailV2.network.rule.SrcVirtualNetwork:
+ derived_from: tosca.datatypes.Root
+ description: source addresses
+ properties:
+ network_policy_entries_policy_rule_src_addresses_virtual_network:
+ type: string
+ description: Source addresses Virtual network
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.network.rule.DstVirtualNetwork:
+ derived_from: tosca.datatypes.Root
+ description: destination addresses
+ properties:
+ network_policy_entries_policy_rule_dst_addresses_virtual_network:
+ type: string
+ description: Destination addresses Virtual network
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.network.rule.DstPortPairs:
+ derived_from: tosca.datatypes.Root
+ description: destination port pairs
+ properties:
+ network_policy_entries_policy_rule_dst_ports_start_port:
+ type: string
+ description: Start port
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_dst_ports_end_port:
+ type: string
+ description: End port
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.network.rule.SrcPortPairs:
+ derived_from: tosca.datatypes.Root
+ description: source port pairs
+ properties:
+ network_policy_entries_policy_rule_src_ports_start_port:
+ type: string
+ description: Start port
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_src_ports_end_port:
+ type: string
+ description: End port
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.network.rule.ActionList:
+ derived_from: tosca.datatypes.Root
+ description: Action List
+ properties:
+ network_policy_entries_policy_rule_action_list_simple_action:
+ type: string
+ description: Simple Action
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_action_list_apply_service:
+ type: list
+ description: Apply Service
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+org.openecomp.datatypes.heat.contrailV2.network.rule.ActionList:
+ derived_from: tosca.datatypes.Root
+ description: Action List
+ properties:
+ network_policy_entries_policy_rule_action_list_simple_action:
+ type: string
+ description: Simple Action
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_action_list_apply_service:
+ type: list
+ description: Apply Service
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+org.openecomp.datatypes.heat.contrailV2.network.rule.Rule:
+ derived_from: tosca.datatypes.Root
+ description: policy rule
+ properties:
+ network_policy_entries_policy_rule_dst_addresses:
+ type: list
+ description: Destination addresses
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.DstVirtualNetwork
+ network_policy_entries_policy_rule_dst_ports:
+ type: list
+ description: Destination ports
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.DstPortPairs
+ network_policy_entries_policy_rule_protocol:
+ type: string
+ description: Protocol
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_src_addresses:
+ type: list
+ description: Source addresses
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.SrcVirtualNetwork
+ network_policy_entries_policy_rule_direction:
+ type: string
+ description: Direction
+ required: false
+ status: SUPPORTED
+ network_policy_entries_policy_rule_src_ports:
+ type: list
+ description: Source ports
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.SrcPortPairs
+ network_policy_entries_policy_rule_action_list:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.ActionList
+ description: Action list
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.network.rule.RuleList:
+ derived_from: tosca.datatypes.Root
+ description: list of policy rules
+ properties:
+ network_policy_entries_policy_rule:
+ type: list
+ description: Contrail network rule
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.Rule
+org.openecomp.datatypes.heat.network.contrail.port.StaticRoute:
+ derived_from: tosca.datatypes.Root
+ description: static route
+ properties:
+ prefix:
+ type: string
+ description: Route prefix
+ required: false
+ status: SUPPORTED
+ next_hop:
+ type: string
+ description: Next hop
+ required: false
+ status: SUPPORTED
+ next_hop_type:
+ type: string
+ description: Next hop type
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.network.contrail.AddressPair:
+ derived_from: tosca.datatypes.Root
+ description: Address Pair
+ properties:
+ address_mode:
+ type: string
+ description: Address mode active-active or active-standy
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - active-active
+ - active-standby
+ prefix:
+ type: string
+ description: IP address prefix
+ required: false
+ status: SUPPORTED
+ mac_address:
+ type: string
+ description: Mac address
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.network.contrail.InterfaceData:
+ derived_from: tosca.datatypes.Root
+ description: Interface Data
+ properties:
+ static_routes:
+ type: list
+ description: An ordered list of static routes to be added to this interface
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.contrail.port.StaticRoute
+ virtual_network:
+ type: string
+ description: Virtual Network for this interface
+ required: true
+ status: SUPPORTED
+ allowed_address_pairs:
+ type: list
+ description: List of allowed address pair for this interface
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.contrail.AddressPair
+ ip_address:
+ type: string
+ description: IP for this interface
+ required: false
+ status: SUPPORTED
+org.openecomp.datatypes.heat.contrailV2.virtual.machine.interface.Properties:
+ derived_from: tosca.datatypes.Root
+ description: Virtual Machine Interface Properties.
+ properties:
+ virtual_machine_interface_properties_service_interface_type:
+ type: string
+ description: Service Interface Type.
+ required: false
+ status: SUPPORTED \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip
new file mode 100644
index 0000000000..2249a8bd5c
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.yml b/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.yml
new file mode 100644
index 0000000000..1df2cbdd04
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.yml
@@ -0,0 +1,30 @@
+org.openecomp.groups.heat.HeatStack:
+ derived_from: tosca.groups.Root
+ description: Grouped all heat resources which are in the same heat stack
+ properties:
+ heat_file:
+ type: string
+ description: Heat file which associate to this group/heat stack
+ required: true
+ status: SUPPORTED
+ description:
+ type: string
+ description: group description
+ required: true
+ status: SUPPORTED
+org.openecomp.groups.VfModule:
+ derived_from: tosca.groups.Root
+ description: Grouped all heat resources which are in the same VF Module
+ properties:
+ isBase:
+ type: boolean
+ description: Whether this module should be deployed before other modules
+ required: true
+ default: false
+ status: SUPPORTED
+tosca.groups.Root:
+ description: The TOSCA Group Type all other TOSCA Group Types derive from
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Standard
+
diff --git a/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.zip b/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.zip
new file mode 100644
index 0000000000..e386507c92
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/group-types/groupTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.json b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.json
new file mode 100644
index 0000000000..40f96f466e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "abstractSubstitute.yml",
+ "contactId": "jh0003",
+ "name": "AbstractSubstitute",
+ "description": "Abstract node to be derived by nested elements.",
+ "resourceIconPath": "defaulticon",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "AbstractSubstitute"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.yml b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.yml
new file mode 100644
index 0000000000..48db2b609a
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: AbstractSubstituteGlobalTypes
+ template_version: 1.0.0
+description: Abstract Substitute Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.abstract.nodes.AbstractSubstitute:
+ derived_from: tosca.nodes.Root
+ properties:
+ service_template_filter:
+ type: org.openecomp.datatypes.heat.substitution.SubstitutionFiltering
+ description: Substitution Filter
+ required: true
+ status: SUPPORTED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.zip b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.zip
new file mode 100644
index 0000000000..07e4941e6b
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/abstractSubstitute/abstractSubstitute.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.json b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.json
new file mode 100644
index 0000000000..249ee0f959
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "cinderVolume.yml",
+ "contactId": "jh0003",
+ "name": "CinderVolume",
+ "description": "Represents a server-local block storage device that provides persistent storage to guest virtual machines. ",
+ "resourceIconPath": "objectStorage",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "CinderVolume"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.yml b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.yml
new file mode 100644
index 0000000000..3bb227d1ec
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.yml
@@ -0,0 +1,177 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: CinderVolumeGlobalTypes
+ template_version: 1.0.0
+description: Cinder Volume TOSCA Global Types
+relationship_types:
+ org.openecomp.relationships.cinder.VolumeAttachesTo:
+ derived_from: tosca.relationships.AttachesTo
+ description: This type represents an attachment relationship for associating volume
+ properties:
+ volume_id:
+ type: string
+ description: The ID of the volume to be attached
+ required: true
+ status: SUPPORTED
+ location:
+ type: string
+ description: The location where the volume is exposed on the instance, mountpoint
+ required: false
+ status: SUPPORTED
+ instance_uuid:
+ type: string
+ description: The ID of the server to which the volume attaches
+ required: true
+ status: SUPPORTED
+ attributes:
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+node_types:
+ org.openecomp.resource.vfc.nodes.heat.cinder.Volume:
+ derived_from: tosca.nodes.BlockStorage
+ properties:
+ availability_zone:
+ type: string
+ description: The availability zone in which the volume will be created
+ required: false
+ status: SUPPORTED
+ image:
+ type: string
+ description: If specified, the name or ID of the image to create the volume from
+ required: false
+ status: SUPPORTED
+ metadata:
+ type: map
+ description: Key/value pairs to associate with the volume
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ volume_type:
+ type: string
+ description: If specified, the type of volume to use, mapping to a specific backend
+ required: false
+ status: SUPPORTED
+ description:
+ type: string
+ description: A description of the volume
+ required: false
+ status: SUPPORTED
+ device_type:
+ type: string
+ description: Device type
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - cdrom
+ - disk
+ disk_bus:
+ type: string
+ description: 'Bus of the device: hypervisor driver chooses a suitable default if omitted'
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - ide
+ - lame_bus
+ - scsi
+ - usb
+ - virtio
+ backup_id:
+ type: string
+ description: If specified, the backup to create the volume from
+ required: false
+ status: SUPPORTED
+ source_volid:
+ type: string
+ description: If specified, the volume to use as source
+ required: false
+ status: SUPPORTED
+ boot_index:
+ type: integer
+ description: Integer used for ordering the boot disks
+ required: false
+ status: SUPPORTED
+ size:
+ type: scalar-unit.size
+ description: The requested storage size (default unit is MB)
+ required: false
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 1 GB
+ read_only:
+ type: boolean
+ description: Enables or disables read-only access mode of volume
+ required: false
+ status: SUPPORTED
+ name:
+ type: string
+ description: A name used to distinguish the volume
+ required: false
+ status: SUPPORTED
+ scheduler_hints:
+ type: map
+ description: Arbitrary key-value pairs specified by the client to help the Cinder scheduler creating a volume
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ swap_size:
+ type: scalar-unit.size
+ description: The size of the swap, in MB
+ required: false
+ status: SUPPORTED
+ delete_on_termination:
+ type: boolean
+ description: Indicate whether the volume should be deleted when the server is terminated
+ required: false
+ status: SUPPORTED
+ multiattach:
+ type: boolean
+ description: Whether allow the volume to be attached more than once
+ required: false
+ status: SUPPORTED
+ attributes:
+ display_description:
+ type: string
+ description: Description of the volume
+ status: SUPPORTED
+ attachments:
+ type: string
+ description: The list of attachments of the volume
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ encrypted:
+ type: boolean
+ description: Boolean indicating if the volume is encrypted or not
+ status: SUPPORTED
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+ created_at:
+ type: timestamp
+ description: The timestamp indicating volume creation
+ status: SUPPORTED
+ display_name:
+ type: string
+ description: Name of the volume
+ status: SUPPORTED
+ metadata_values:
+ type: map
+ description: Key/value pairs associated with the volume in raw dict form
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ bootable:
+ type: boolean
+ description: Boolean indicating if the volume can be booted or not
+ status: SUPPORTED
+ status:
+ type: string
+ description: The current status of the volume
+ status: SUPPORTED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.zip b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.zip
new file mode 100644
index 0000000000..88506743ac
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/cinderVolume/cinderVolume.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.json
new file mode 100644
index 0000000000..5742445784
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.json
@@ -0,0 +1,17 @@
+{
+ "payloadName": "contrailAbstractSubstitute.yml",
+ "contactId": "jh0003",
+ "name": "ContrailAbstractSubstitute",
+ "description": "Abstract node to be derived by contrail nested elements when using Contrail Service Instance",
+ "resourceIconPath": "defaulticon",
+ "resourceType": "VFC",
+ "categories": [{
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }],
+ "tags": ["ContrailAbstractSubstitute"]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.yml
new file mode 100644
index 0000000000..5bdee932a3
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.yml
@@ -0,0 +1,137 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailAbstractSubstituteGlobalTypes
+ template_version: 1.0.0
+description: Contrail Abstract Substitute Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.abstract.nodes.contrail.AbstractSubstitute:
+ derived_from: org.openecomp.resource.abstract.nodes.AbstractSubstitute
+ properties:
+ availability_zone:
+ type: string
+ description: Availability zone to create servers in
+ required: false
+ status: SUPPORTED
+ static_routes_list:
+ type: list
+ description: Static routes enabled
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: boolean
+ availability_zone_enable:
+ type: boolean
+ description: Indicates availability zone is enabled
+ required: false
+ default: false
+ status: SUPPORTED
+ service_template_name:
+ type: string
+ description: Service template name
+ required: false
+ status: SUPPORTED
+ ordered_interfaces:
+ type: boolean
+ description: Indicates if service interface are ordered
+ required: false
+ default: false
+ status: SUPPORTED
+ flavor:
+ type: string
+ description: flavor
+ required: false
+ status: SUPPORTED
+ image_name:
+ type: string
+ description: Image name
+ required: true
+ status: SUPPORTED
+ service_type:
+ type: string
+ description: Service type
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - firewall
+ - analyzer
+ - source-nat
+ - loadbalancer
+ service_interface_type_list:
+ type: list
+ description: List of interface types
+ required: true
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ constraints:
+ - valid_values:
+ - management
+ - left
+ - right
+ - other
+ service_instance_name:
+ type: string
+ description: Service instance name
+ required: true
+ status: SUPPORTED
+ interface_list:
+ type: list
+ description: List of interfaces
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.contrail.InterfaceData
+ service_mode:
+ type: string
+ description: Service mode
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - transparent
+ - in-network
+ - in-network-nat
+ shared_ip_list:
+ type: list
+ description: Shared ips enabled
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: boolean
+ attributes:
+ tenant_id:
+ type: string
+ description: Tenant id of the Service Instance
+ status: SUPPORTED
+ fq_name:
+ type: string
+ description: The FQ name of the service instance
+ status: SUPPORTED
+ service_template_name:
+ type: string
+ description: Service Template of the Service Instance
+ status: SUPPORTED
+ show:
+ type: string
+ description: All attributes
+ status: SUPPORTED
+ active_vms:
+ type: string
+ description: Number of service VMs active for this Service Instance
+ status: SUPPORTED
+ service_instance_name:
+ type: string
+ description: The name of the service instance
+ status: SUPPORTED
+ virtual_machines:
+ type: string
+ description: Service VMs for the Service Instance
+ status: SUPPORTED
+ status:
+ type: string
+ description: Status of the service instance
+ status: SUPPORTED \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.zip
new file mode 100644
index 0000000000..6a2094bb9a
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailAbstractSubstitute/contrailAbstractSubstitute.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.json
new file mode 100644
index 0000000000..144136acd1
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.json
@@ -0,0 +1,15 @@
+{
+ "payloadName": "contrailCompute.yml",
+ "contactId": "jh0003",
+ "name": "ContrailCompute",
+ "description": "Represents a virtual machine for contrail service template. The information provided will be used to create a VM that matches characteristics.",
+ "resourceIconPath": "compute",
+ "resourceType": "VFC",
+ "categories": [{
+ "name": "Generic",
+ "subcategories": [{
+ "name": "Infrastructure"
+ }]
+ }],
+ "tags": ["ContrailCompute"]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.yml
new file mode 100644
index 0000000000..d6ad4f953c
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.yml
@@ -0,0 +1,89 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailComputeGlobalTypes
+ template_version: 1.0.0
+description: Contrail Compute TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vfc.nodes.heat.contrail.Compute:
+ derived_from: tosca.nodes.Compute
+ properties:
+ flavor:
+ type: string
+ description: flavor
+ required: false
+ status: SUPPORTED
+ image_name:
+ type: string
+ description: Image name
+ required: true
+ status: SUPPORTED
+ availability_zone:
+ type: string
+ description: Availability zone to create servers in
+ required: false
+ status: SUPPORTED
+ service_type:
+ type: string
+ description: Service type
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - firewall
+ - analyzer
+ - source-nat
+ - loadbalancer
+ availability_zone_enable:
+ type: boolean
+ description: Indicates availability zone is enabled
+ required: false
+ default: false
+ status: SUPPORTED
+ service_template_name:
+ type: string
+ description: Service template name
+ required: false
+ status: SUPPORTED
+ service_instance_name:
+ type: string
+ description: Service instance name
+ required: true
+ status: SUPPORTED
+ service_mode:
+ type: string
+ description: Service mode
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - transparent
+ - in-network
+ - in-network-nat
+ attributes:
+ tenant_id:
+ type: string
+ description: Tenant id of the VM
+ status: SUPPORTED
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
+ show:
+ type: string
+ description: All attributes
+ status: SUPPORTED
+ active_vms:
+ type: string
+ description: Number of active VMs
+ status: SUPPORTED
+ virtual_machines:
+ type: string
+ description: VMs of this compute
+ status: SUPPORTED
+ status:
+ type: string
+ description: status of the compute
+ status: SUPPORTED \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.zip
new file mode 100644
index 0000000000..c9e3c8a062
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailCompute/contrailCompute.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.json
new file mode 100644
index 0000000000..e1987b9449
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "contrailNetworkRules.yml",
+ "contactId": "jh0003",
+ "name": "ContrailNetworkRules",
+ "description": "Configuration of policy rules to be applied over the network.",
+ "resourceIconPath": "networkrules",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Rules"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ContrailNetworkRules"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.yml
new file mode 100644
index 0000000000..b9d61e7769
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.yml
@@ -0,0 +1,49 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailNetworkRuleGlobalType
+ template_version: 1.0.0
+description: Contrail Network Rule Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vfc.rules.nodes.heat.network.contrail.NetworkRules:
+ derived_from: tosca.nodes.Root
+ properties:
+ entries:
+ type: org.openecomp.datatypes.heat.contrail.network.rule.RuleList
+ description: A symbolic name for this contrail network rule
+ required: false
+ status: SUPPORTED
+ name:
+ type: string
+ description: A symbolic name for this contrail network rule
+ required: false
+ status: SUPPORTED
+ attributes:
+ tenant_id:
+ type: string
+ description: tenant_id
+ status: SUPPORTED
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
+ show:
+ type: string
+ description: All attributes.
+ status: SUPPORTED
+ rules:
+ type: list
+ description: List of rules
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ requirements:
+ - network:
+ capability: tosca.capabilities.Attachment
+ node: tosca.nodes.network.Network
+ relationship: org.openecomp.relationships.AttachesTo
+ occurrences:
+ - 0
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.zip
new file mode 100644
index 0000000000..b687616cd8
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailNetworkRules/contrailNetworkRules.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.json
new file mode 100644
index 0000000000..6edc7083b0
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "contrailPort.yml",
+ "contactId": "jh0003",
+ "name": "ContrailPort",
+ "description": "Represents a logical entity that associates between Compute and Network normative types for contrail.",
+ "resourceIconPath": "port",
+ "resourceType": "CP",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ContrailPort"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.yml
new file mode 100644
index 0000000000..a3e43a2fd1
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.yml
@@ -0,0 +1,64 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailPortGlobalTypes
+ template_version: 1.0.0
+description: Contrail Port TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.cp.nodes.heat.network.contrail.Port:
+ derived_from: tosca.nodes.network.Port
+ properties:
+ static_routes:
+ type: list
+ description: An ordered list of static routes to be added to this interface
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.contrail.port.StaticRoute
+ virtual_network:
+ type: string
+ description: Virtual Network for this interface
+ required: true
+ status: SUPPORTED
+ static_route:
+ type: boolean
+ description: Static route enabled
+ required: false
+ default: false
+ status: SUPPORTED
+ allowed_address_pairs:
+ type: list
+ description: List of allowed address pair for this interface
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.contrail.AddressPair
+ shared_ip:
+ type: boolean
+ description: Shared ip enabled
+ required: false
+ default: false
+ status: SUPPORTED
+ ip_address:
+ type: string
+ description: IP for this interface
+ required: false
+ status: SUPPORTED
+ interface_type:
+ type: string
+ description: Interface type
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - management
+ - left
+ - right
+ - other
+ attributes:
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.zip
new file mode 100644
index 0000000000..f9e5c415ae
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailPort/contrailPort.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.json
new file mode 100644
index 0000000000..13717b7da3
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "contrailV2NetworkRules.yml",
+ "contactId": "jh0003",
+ "name": "ContrailV2NetworkRules",
+ "description": "Configuration of policy rules to be applied over the network for contrail V2.",
+ "resourceIconPath": "networkrules",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Rules"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ContrailV2NetworkRules"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.yml
new file mode 100644
index 0000000000..ccc6d3a2ab
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.yml
@@ -0,0 +1,35 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailV2NetworkRuleGlobalType
+ template_version: 1.0.0
+description: Contrail V2 Network Rule Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vfc.rules.nodes.heat.network.contrailV2.NetworkRules:
+ derived_from: tosca.nodes.Root
+ properties:
+ name:
+ type: string
+ description: A symbolic name for this contrail v2 network rule
+ required: false
+ status: SUPPORTED
+ network_policy_entries:
+ type: org.openecomp.datatypes.heat.contrailV2.network.rule.RuleList
+ description: A symbolic name for this contrail v2 network rule
+ required: false
+ status: SUPPORTED
+ attributes:
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
+ requirements:
+ - network:
+ capability: tosca.capabilities.Attachment
+ node: tosca.nodes.network.Network
+ relationship: org.openecomp.relationships.AttachesTo
+ occurrences:
+ - 0
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.zip
new file mode 100644
index 0000000000..eac99b3b90
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2NetworkRules/contrailV2NetworkRules.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.json
new file mode 100644
index 0000000000..5c7a725190
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.json
@@ -0,0 +1,15 @@
+{
+ "payloadName": "contrailV2VirtualMachineInterface.yml",
+ "contactId": "jh0003",
+ "name": "ContrailV2VirtualMachineInterface",
+ "description": "Represents a network interface. The interfaces are defined with specific MAC addresses and ports.",
+ "resourceIconPath": "network",
+ "resourceType": "VFC",
+ "categories": [{
+ "name": "Generic",
+ "subcategories": [{
+ "name": "Network Elements"
+ }]
+ }],
+ "tags": ["ContrailV2VirtualMachineInterface"]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.yml
new file mode 100644
index 0000000000..ba324cf51a
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.yml
@@ -0,0 +1,59 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailV2VirtualMachineInterfaceGlobalType
+ template_version: 1.0.0
+description: Contrail Virtual Machine Interface TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.cp.nodes.heat.contrailV2.VirtualMachineInterface:
+ derived_from: tosca.nodes.network.Port
+ properties:
+ virtual_machine_intefrace_mac_addresses:
+ type: list
+ description: List of mac addresses.
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ name:
+ type: string
+ description: Virtual Machine Interface name
+ required: false
+ status: SUPPORTED
+ security_group_refs:
+ type: list
+ description: List of security groups.
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ virtual_network_refs:
+ type: list
+ description: List of virtual networks.
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ virtual_machine_interface_properties:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.machine.interface.Properties
+ description: virtual machine interface properties.
+ required: false
+ status: SUPPORTED
+ port_tuple_refs:
+ type: list
+ description: List of port tuples.
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ attributes:
+ fq_name:
+ type: string
+ description: The FQ name of the Virtual Network.
+ status: SUPPORTED
+ show:
+ type: string
+ description: All attributes.
+ status: SUPPORTED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.zip
new file mode 100644
index 0000000000..4b48a6838d
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualMachineInterface/contrailV2VirtualMachineInterface.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.json
new file mode 100644
index 0000000000..c7802d2529
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "contrailV2VirtualNetwork.yml",
+ "contactId": "jh0003",
+ "name": "ContrailV2VirtualNetwork",
+ "description": "Represents a network service with optional subnets and advanced configurations for contrail V2.",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ContrailV2VirtualNetwork"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.yml
new file mode 100644
index 0000000000..1ff1402411
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.yml
@@ -0,0 +1,76 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailV2VirtualNetworkGlobalType
+ template_version: 1.0.0
+description: Contrail V2 Virtual Network Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vl.nodes.heat.network.contrailV2.VirtualNetwork:
+ derived_from: tosca.nodes.network.Network
+ properties:
+ network_ipam_refs_data:
+ type: list
+ description: IPAM references Data
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.IpamRefData
+ network_policy_refs_data:
+ type: list
+ description: Policy references data
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.contrailV2.virtual.network.rule.RefData
+ network_ipam_refs:
+ type: list
+ description: IPAM references
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ network_policy_refs:
+ type: list
+ description: Policy references
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets:
+ type: map
+ description: Network related subnets
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ attributes:
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
+ subnets_name:
+ type: list
+ description: Subnets name of this network
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets_show:
+ type: map
+ description: Detailed information about each subnet
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets:
+ type: map
+ description: Network related subnets
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
+ occurrences:
+ - 1
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.zip
new file mode 100644
index 0000000000..637e78da25
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailV2VirtualNetwork/contrailV2VirtualNetwork.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.json b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.json
new file mode 100644
index 0000000000..523315edcb
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "contrailVirtualNetwork.yml",
+ "contactId": "jh0003",
+ "name": "ContrailVirtualNetwork",
+ "description": "Represents a network service with optional subnets and advanced configurations.",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ContrailVirtualNetwork"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.yml b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.yml
new file mode 100644
index 0000000000..a5424c3c83
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.yml
@@ -0,0 +1,84 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: ContrailVirtualNetworkGlobalType
+ template_version: 1.0.0
+description: Contrail Virtual Network Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vl.nodes.heat.network.contrail.VirtualNetwork:
+ derived_from: tosca.nodes.network.Network
+ properties:
+ shared:
+ type: string
+ description: Is virtual network shared
+ required: false
+ status: SUPPORTED
+ forwarding_mode:
+ type: string
+ description: forwarding mode of the virtual network
+ required: false
+ status: SUPPORTED
+ external:
+ type: string
+ description: Is virtual network external
+ required: false
+ status: SUPPORTED
+ allow_transit:
+ type: string
+ description: Whether this network should be transitive.
+ required: false
+ status: SUPPORTED
+ flood_unknown_unicast:
+ type: string
+ description: flood L2 packets on network
+ required: false
+ status: SUPPORTED
+ route_targets:
+ type: list
+ description: route targets associated with the virtual network
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets:
+ type: map
+ description: Network related subnets
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ attributes:
+ fq_name:
+ type: string
+ description: fq_name
+ status: SUPPORTED
+ show:
+ type: string
+ description: All attributes.
+ status: SUPPORTED
+ subnets_name:
+ type: list
+ description: Subnets name of this network
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets_show:
+ type: map
+ description: Detailed information about each subnet
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets:
+ type: map
+ description: Network related subnets
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
+ occurrences:
+ - 1
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.zip b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.zip
new file mode 100644
index 0000000000..17b32db41a
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/contrailVirtualNetwork/contrailVirtualNetwork.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.json b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.json
new file mode 100644
index 0000000000..f6f0ecb308
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "eline.yml",
+ "contactId": "jh0003",
+ "name": "VL ELINE",
+ "description": "The node represents an E-Line virtual link entity.",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Network Connectivity",
+ "subcategories": [
+ {
+ "name": "Virtual Links"
+ }
+ ]
+ }
+],
+ "tags": [
+ "VL ELINE"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.yml b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.yml
new file mode 100644
index 0000000000..21241369c7
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.yml
@@ -0,0 +1,9 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+
+node_types:
+ org.openecomp.resource.vl.ELine:
+ derived_from: org.openecomp.resource.vl.VL
+ capabilities:
+ virtual_linkable:
+ type: tosca.capabilities.network.Linkable
+ occurrences: [0,2]
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.zip b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.zip
new file mode 100644
index 0000000000..132c5eebc5
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/eline/eline.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.json b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.json
new file mode 100644
index 0000000000..073e935871
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "neutronNet.yml",
+ "contactId": "jh0003",
+ "name": "NeutronNet",
+ "description": "Represents a network service with optional subnets and advanced configurations.",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "NeutronNet"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.yml b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.yml
new file mode 100644
index 0000000000..e80e2727c7
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.yml
@@ -0,0 +1,97 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: NeutronNetGlobalTypes
+ template_version: 1.0.0
+description: Neutron Network TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vl.nodes.heat.network.neutron.Net:
+ derived_from: tosca.nodes.network.Network
+ properties:
+ dhcp_agent_ids:
+ type: list
+ description: The IDs of the DHCP agent to schedule the network
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ tenant_id:
+ type: string
+ description: The ID of the tenant which will own the network
+ required: false
+ status: SUPPORTED
+ port_security_enabled:
+ type: boolean
+ description: Flag to enable/disable port security on the network
+ required: false
+ status: SUPPORTED
+ shared:
+ type: boolean
+ description: Whether this network should be shared across all tenants
+ required: false
+ default: false
+ status: SUPPORTED
+ admin_state_up:
+ type: boolean
+ description: A boolean value specifying the administrative status of the network
+ required: false
+ default: true
+ status: SUPPORTED
+ qos_policy:
+ type: string
+ description: The name or ID of QoS policy to attach to this network
+ required: false
+ status: SUPPORTED
+ subnets:
+ type: map
+ description: Network related subnets
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ value_specs:
+ type: map
+ description: Extra parameters to include in the request
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ attributes:
+ qos_policy_id:
+ type: string
+ description: The QoS policy ID attached to this network
+ status: SUPPORTED
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+ subnets_name:
+ type: list
+ description: Subnets name of this network
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ subnets:
+ type: map
+ description: Network related subnets
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.Subnet
+ mtu:
+ type: scalar-unit.size
+ description: The maximum transmission unit size(in bytes) for the network
+ status: SUPPORTED
+ status:
+ type: string
+ description: The status of the network
+ status: SUPPORTED
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
+ occurrences:
+ - 1
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.zip b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.zip
new file mode 100644
index 0000000000..0cefe8a184
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronNet/neutronNet.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.json b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.json
new file mode 100644
index 0000000000..db782fa536
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "neutronPort.yml",
+ "contactId": "jh0003",
+ "name": "NeutronPort",
+ "description": "Represents a logical entity that associates between Compute and Network normative types.",
+ "resourceIconPath": "port",
+ "resourceType": "CP",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "NeutronPort"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.yml b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.yml
new file mode 100644
index 0000000000..898615c6ce
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.yml
@@ -0,0 +1,136 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: NeutronPortGlobalTypes
+ template_version: 1.0.0
+description: Neutron Port TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.cp.nodes.heat.network.neutron.Port:
+ derived_from: tosca.nodes.network.Port
+ properties:
+ port_security_enabled:
+ type: boolean
+ description: Flag to enable/disable port security on the network
+ required: false
+ status: SUPPORTED
+ device_id:
+ type: string
+ description: Device ID of this port
+ required: false
+ status: SUPPORTED
+ qos_policy:
+ type: string
+ description: The name or ID of QoS policy to attach to this network
+ required: false
+ status: SUPPORTED
+ allowed_address_pairs:
+ type: list
+ description: Additional MAC/IP address pairs allowed to pass through the port
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.AddressPair
+ binding:vnic_type:
+ type: string
+ description: The vnic type to be bound on the neutron port
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - macvtap
+ - direct
+ - normal
+ value_specs:
+ type: map
+ description: Extra parameters to include in the request
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ device_owner:
+ type: string
+ description: Name of the network owning the port
+ required: false
+ status: SUPPORTED
+ network:
+ type: string
+ description: Network this port belongs to
+ required: false
+ status: SUPPORTED
+ replacement_policy:
+ type: string
+ description: Policy on how to respond to a stack-update for this resource
+ required: false
+ default: AUTO
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - REPLACE_ALWAYS
+ - AUTO
+ security_groups:
+ type: list
+ description: List of security group names or IDs
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ fixed_ips:
+ type: list
+ description: Desired IPs for this port
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.neutron.port.FixedIps
+ mac_address:
+ type: string
+ description: MAC address to give to this port
+ required: false
+ status: SUPPORTED
+ admin_state_up:
+ type: boolean
+ description: A boolean value specifying the administrative status of the network
+ required: false
+ default: true
+ status: SUPPORTED
+ name:
+ type: string
+ description: A symbolic name for this port
+ required: false
+ status: SUPPORTED
+ attributes:
+ tenant_id:
+ type: string
+ description: Tenant owning the port
+ status: SUPPORTED
+ network_id:
+ type: string
+ description: Unique identifier for the network owning the port
+ status: SUPPORTED
+ qos_policy_id:
+ type: string
+ description: The QoS policy ID attached to this network
+ status: SUPPORTED
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+ subnets:
+ type: list
+ description: Subnets of this network
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ status:
+ type: string
+ description: The status of the network
+ status: SUPPORTED
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
+ occurrences:
+ - 1
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.zip b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.zip
new file mode 100644
index 0000000000..f120afb16e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/neutronPort/neutronPort.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.json b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.json
new file mode 100644
index 0000000000..007106b61e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.json
@@ -0,0 +1,24 @@
+{
+ "payloadName": "novaServer.yml",
+ "contactId": "jh0003",
+ "name": "NovaServer",
+ "description": "Represents a real or virtual machine or server. Information specified on the Compute
+ node will be used to find the machine that fits the given requirements in the cloud
+ available machines. If no sizing information are specified the cloud provider default
+ machine will be used. It is strongly recommended to specify the required CPUs and memory
+ at least.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "NovaServer"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.yml b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.yml
new file mode 100644
index 0000000000..0ec79f5229
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.yml
@@ -0,0 +1,249 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: NovaServerGlobalTypes
+ template_version: 1.0.0
+description: Nova Server TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+data_types:
+ org.openecomp.datatypes.heat.novaServer.network.PortExtraProperties:
+ derived_from: tosca.datatypes.Root
+ description: Nova server network expand properties for port
+ properties:
+ port_security_enabled:
+ type: boolean
+ description: Flag to enable/disable port security on the port
+ required: false
+ status: SUPPORTED
+ mac_address:
+ type: string
+ description: MAC address to give to this port
+ required: false
+ status: SUPPORTED
+ admin_state_up:
+ type: boolean
+ description: The administrative state of this port
+ required: false
+ default: true
+ status: SUPPORTED
+ qos_policy:
+ type: string
+ description: The name or ID of QoS policy to attach to this port
+ required: false
+ status: SUPPORTED
+ allowed_address_pairs:
+ type: list
+ description: Additional MAC/IP address pairs allowed to pass through the port
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.AddressPair
+ binding:vnic_type:
+ type: string
+ description: The vnic type to be bound on the neutron port
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - macvtap
+ - direct
+ - normal
+ value_specs:
+ type: map
+ description: Extra parameters to include in the request
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ org.openecomp.datatypes.heat.novaServer.network.AddressInfo:
+ derived_from: tosca.datatypes.network.NetworkInfo
+ description: Network addresses with corresponding port id
+ properties:
+ port_id:
+ type: string
+ description: Port id
+ required: false
+ status: SUPPORTED
+node_types:
+ org.openecomp.resource.vfc.nodes.heat.nova.Server:
+ derived_from: tosca.nodes.Compute
+ properties:
+ admin_pass:
+ type: string
+ description: The administrator password for the server
+ required: false
+ status: SUPPORTED
+ availability_zone:
+ type: string
+ description: Availability zone to create servers in
+ required: false
+ status: SUPPORTED
+ image:
+ type: string
+ description: The ID or name of the image to boot with
+ required: false
+ status: SUPPORTED
+ image_update_policy:
+ type: string
+ description: Policy on how to apply an image-id update
+ required: false
+ default: REBUILD
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - REBUILD_PRESERVE_EPHEMERAL
+ - REPLACE
+ - REBUILD
+ metadata:
+ type: json
+ description: Arbitrary JSON metadata to store for this server
+ required: false
+ status: SUPPORTED
+ contrail_service_instance_ind:
+ type: boolean
+ description: Nova server related to service instance indicator
+ required: false
+ default: false
+ status: SUPPORTED
+ user_data_update_policy:
+ type: string
+ description: Policy on how to apply a user_data update
+ required: false
+ default: REPLACE
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - REPLACE
+ - IGNORE
+ flavor_update_policy:
+ type: string
+ description: Policy on how to apply a flavor update
+ required: false
+ default: RESIZE
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - RESIZE
+ - REPLACE
+ user_data:
+ type: string
+ description: User data script to be executed by cloud-init
+ required: false
+ default: ''
+ status: SUPPORTED
+ flavor:
+ type: string
+ description: The ID or name of the flavor to boot onto
+ required: true
+ status: SUPPORTED
+ key_name:
+ type: string
+ description: Name of keypair to inject into the server
+ required: false
+ status: SUPPORTED
+ reservation_id:
+ type: string
+ description: A UUID for the set of servers being requested
+ required: false
+ status: SUPPORTED
+ security_groups:
+ type: list
+ description: List of security group names or IDs
+ required: false
+ default: [
+ ]
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ config_drive:
+ type: boolean
+ description: enable config drive on the server
+ required: false
+ status: SUPPORTED
+ personality:
+ type: map
+ description: A map of files to create/overwrite on the server upon boot
+ required: false
+ default: {
+ }
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ software_config_transport:
+ type: string
+ description: How the server should receive the metadata required for software configuration
+ required: false
+ default: POLL_SERVER_CFN
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - POLL_SERVER_CFN
+ - POLL_SERVER_HEAT
+ - POLL_TEMP_URL
+ - ZAQAR_MESSAGE
+ user_data_format:
+ type: string
+ description: How the user_data should be formatted for the server
+ required: false
+ default: HEAT_CFNTOOLS
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - SOFTWARE_CONFIG
+ - RAW
+ - HEAT_CFNTOOLS
+ diskConfig:
+ type: string
+ description: Control how the disk is partitioned when the server is created
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - AUTO
+ - MANUAL
+ name:
+ type: string
+ description: Server name
+ required: false
+ status: SUPPORTED
+ scheduler_hints:
+ type: map
+ description: Arbitrary key-value pairs specified by the client to help boot a server
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: string
+ attributes:
+ accessIPv4:
+ type: string
+ description: The manually assigned alternative public IPv4 address of the server
+ status: SUPPORTED
+ addresses:
+ type: map
+ description: A dict of all network addresses with corresponding port_id
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.novaServer.network.AddressInfo
+ accessIPv6:
+ type: string
+ description: The manually assigned alternative public IPv6 address of the server
+ status: SUPPORTED
+ instance_name:
+ type: string
+ description: AWS compatible instance name
+ status: SUPPORTED
+ name:
+ type: string
+ description: Name of the server
+ status: SUPPORTED
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+ console_urls:
+ type: string
+ description: URLs of servers consoles
+ status: SUPPORTED \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.zip b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.zip
new file mode 100644
index 0000000000..aafefbc6b5
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/novaServer/novaServer.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.json b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.json
new file mode 100644
index 0000000000..14d25a0ac2
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "securityRules.yml",
+ "contactId": "jh0003",
+ "name": "SecurityRules",
+ "description": "Configuration of policy rules to be applied on ports.",
+ "resourceIconPath": "securityrules",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Rules"
+ }
+ ]
+ }
+],
+ "tags": [
+ "SecurityRules"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.yml b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.yml
new file mode 100644
index 0000000000..29e87e15fc
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.yml
@@ -0,0 +1,42 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: NeutronSecurityRulesGlobalTypes
+ template_version: 1.0.0
+description: Neutron Security Rules TOSCA Global Types
+imports:
+ common_definitions:
+ file: CommonGlobalTypesServiceTemplate.yaml
+node_types:
+ org.openecomp.resource.vfc.rules.nodes.heat.network.neutron.SecurityRules:
+ derived_from: tosca.nodes.Root
+ properties:
+ description:
+ type: string
+ description: Description of the security group
+ required: false
+ status: SUPPORTED
+ name:
+ type: string
+ description: A symbolic name for this security group, which is not required to be unique.
+ required: false
+ status: SUPPORTED
+ rules:
+ type: list
+ description: List of security group rules
+ required: false
+ status: SUPPORTED
+ entry_schema:
+ type: org.openecomp.datatypes.heat.network.neutron.SecurityRules.Rule
+ attributes:
+ show:
+ type: string
+ description: Detailed information about resource
+ status: SUPPORTED
+ requirements:
+ - port:
+ capability: tosca.capabilities.Attachment
+ node: org.openecomp.resource.cp.nodes.heat.network.neutron.Port
+ relationship: corg.openecomp.relationships.AttachesTo
+ occurrences:
+ - 0
+ - UNBOUNDED
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.zip b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.zip
new file mode 100644
index 0000000000..b1524a2d8f
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/securityRules/securityRules.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.json b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.json
new file mode 100644
index 0000000000..5dd26b48ad
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "vl.yml",
+ "contactId": "jh0003",
+ "name": "VL",
+ "description": " Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). ",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Network Connectivity",
+ "subcategories": [
+ {
+ "name": "Virtual Links"
+ }
+ ]
+ }
+],
+ "tags": [
+ "VL"
+ ]
+}
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.yml b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.yml
new file mode 100644
index 0000000000..f2042f7798
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.yml
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+
+node_types:
+ org.openecomp.resource.vl.VL:
+ derived_from: tosca.nodes.network.Network
+ properties:
+ vendor:
+ type: string
+ required: false
+ vl_name:
+ type: string
+ required: false
+
+ capabilities:
+ virtual_linkable:
+ type: tosca.capabilities.network.Linkable
+ end_point:
+ type: tosca.capabilities.Endpoint \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.zip b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.zip
new file mode 100644
index 0000000000..c1889a9803
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vl/vl.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml b/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml
new file mode 100644
index 0000000000..1b67118934
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.yml
@@ -0,0 +1,11 @@
+tosca.interfaces.node.lifecycle.Standard:
+ create:
+ description: Standard lifecycle create operation.
+ configure:
+ description: Standard lifecycle configure operation.
+ start:
+ description: Standard lifecycle start operation.
+ stop:
+ description: Standard lifecycle stop operation.
+ delete:
+ description: Standard lifecycle delete operation. \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip b/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip
new file mode 100644
index 0000000000..9bcf93ab7d
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/interface-lifecycle-types/interfaceLifecycleTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.json b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.json
new file mode 100644
index 0000000000..addef2ae4b
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "DBMS.yml",
+ "contactId": "jh0003",
+ "name": "DBMS",
+ "description": "Represents a typical relational, SQL Database Management System software component or service.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "DBMS"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.yml b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.yml
new file mode 100644
index 0000000000..28919d38e4
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.DBMS:
+ derived_from: tosca.nodes.SoftwareComponent
+ properties:
+ root_password:
+ type: string
+ required: false
+ description: the optional root password for the DBMS service
+ port:
+ type: integer
+ required: false
+ description: the port the DBMS service will listen to for data and requests
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [ tosca.nodes.Database ]
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.zip b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.zip
new file mode 100644
index 0000000000..7f88b3ba53
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/DBMS/DBMS.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.json b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.json
new file mode 100644
index 0000000000..30e3d74bc9
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "blockStorage.yml",
+ "contactId": "jh0003",
+ "name": "BlockStorage",
+ "description": "Represents a server-local block storage device (i.e., not shared) offering evenly sized blocks of data from which raw storage volumes can be created.",
+ "resourceIconPath": "objectStorage",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "BlockStorage"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.yml b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.yml
new file mode 100644
index 0000000000..a82965215f
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.yml
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.BlockStorage:
+ derived_from: tosca.nodes.Root
+ properties:
+ size:
+ type: scalar-unit.size
+ constraints:
+ - greater_or_equal: 1 MB
+ volume_id:
+ type: string
+ required: false
+ snapshot_id:
+ type: string
+ required: false
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.zip b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.zip
new file mode 100644
index 0000000000..b26f9e2c0e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/blockStorage/blockStorage.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.json b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.json
new file mode 100644
index 0000000000..31bb27be16
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.json
@@ -0,0 +1,24 @@
+{
+ "payloadName": "compute.yml",
+ "contactId": "jh0003",
+ "name": "Compute",
+ "description": "Represents a real or virtual machine or server. Information specified on the Compute
+ node will be used to find the machine that fits the given requirements in the cloud
+ available machines. If no sizing information are specified the cloud provider default
+ machine will be used. It is strongly recommended to specify the required CPUs and memory
+ at least.",
+ "resourceIconPath": "compute",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Compute"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.yml b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.yml
new file mode 100644
index 0000000000..00b07fb908
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.yml
@@ -0,0 +1,35 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Compute:
+ derived_from: tosca.nodes.Root
+ attributes:
+ private_address:
+ type: string
+ public_address:
+ type: string
+ networks:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.NetworkInfo
+ ports:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.PortInfo
+ requirements:
+ - local_storage:
+ capability: tosca.capabilities.Attachment
+ node: tosca.nodes.BlockStorage
+ relationship: tosca.relationships.AttachesTo
+ occurrences: [0, UNBOUNDED]
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [tosca.nodes.SoftwareComponent]
+ endpoint :
+ type: tosca.capabilities.Endpoint.Admin
+ os:
+ type: tosca.capabilities.OperatingSystem
+ scalable:
+ type: tosca.capabilities.Scalable
+ binding:
+ type: tosca.capabilities.network.Bindable
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.zip b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.zip
new file mode 100644
index 0000000000..6c008e866f
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/compute/compute.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.json b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.json
new file mode 100644
index 0000000000..cd0a1386be
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "containerApplication.yml",
+ "contactId": "jh0003",
+ "name": "Application",
+ "description": "Represents an application that requires Container-level virtualization technology.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Application"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.yml b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.yml
new file mode 100644
index 0000000000..8813f26e04
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.yml
@@ -0,0 +1,9 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Container.Application:
+ derived_from: tosca.nodes.Root
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.Container
+ relationship: tosca.relationships.HostedOn
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.zip b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.zip
new file mode 100644
index 0000000000..cec3e5df6c
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerApplication/containerApplication.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.json b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.json
new file mode 100644
index 0000000000..85a0c63257
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "containerRuntime.yml",
+ "contactId": "jh0003",
+ "name": "Runtime",
+ "description": "Represents operating system-level virtualization technology used to run multiple application services on a single Compute host.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Runtime"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.yml b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.yml
new file mode 100644
index 0000000000..86a10a0185
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.yml
@@ -0,0 +1,9 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Container.Runtime:
+ derived_from: tosca.nodes.SoftwareComponent
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ scalable:
+ type: tosca.capabilities.Scalable
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.zip b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.zip
new file mode 100644
index 0000000000..c30aff4098
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/containerRuntime/containerRuntime.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/database/database.json b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.json
new file mode 100644
index 0000000000..f9cf01eb04
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "database.yml",
+ "contactId": "jh0003",
+ "name": "Database",
+ "description": "Represents a logical database that can be managed and hosted by a DBMS node.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Database"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Database"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/database/database.yml b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.yml
new file mode 100644
index 0000000000..5166150c73
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.yml
@@ -0,0 +1,27 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Database:
+ derived_from: tosca.nodes.Root
+ properties:
+ name:
+ type: string
+ description: the logical name of the database
+ port:
+ type: integer
+ description: the port the underlying database service will listen to for data
+ user:
+ type: string
+ description: the optional user account name for DB administration
+ required: false
+ password:
+ type: string
+ description: the optional password for the DB user account
+ required: false
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.DBMS
+ relationship: tosca.relationships.HostedOn
+ capabilities:
+ database_endpoint:
+ type: tosca.capabilities.Endpoint.Database
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/database/database.zip b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.zip
new file mode 100644
index 0000000000..289e7e5ec1
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/database/database.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.json b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.json
new file mode 100644
index 0000000000..d108ee1cbb
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "loadBalancer.yml",
+ "contactId": "jh0003",
+ "name": "LoadBalancer",
+ "description": "Represents logical function that be used in conjunction with a Floating Address to distribute an application’s traffic (load) across a number of instances of the application (e.g., for a clustered or scaled application).",
+ "resourceIconPath": "loadBalancer",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "LoadBalancer"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.yml b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.yml
new file mode 100644
index 0000000000..d577a2aa83
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.yml
@@ -0,0 +1,20 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.LoadBalancer:
+ derived_from: tosca.nodes.Root
+ properties:
+ # TBD
+ algorithm :
+ type: string
+ required: false
+ status: experimental
+ capabilities :
+ client:
+ type: tosca.capabilities.Endpoint.Public
+ occurrences: [0, UNBOUNDED]
+ description: the Floating (IP) client’s on the public network can connect to
+ requirements:
+ - application:
+ capability: tosca.capabilities.Endpoint
+ relationship: tosca.relationships.RoutesTo
+ occurrences: [0, UNBOUNDED]
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.zip b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.zip
new file mode 100644
index 0000000000..3a847c6f56
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/loadBalancer/loadBalancer.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/network/network.json b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.json
new file mode 100644
index 0000000000..4ba8311ce4
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "network.yml",
+ "contactId": "jh0003",
+ "name": "Network",
+ "description": "Represents a simple , logical network service.",
+ "resourceIconPath": "network",
+ "resourceType": "VL",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Network"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/network/network.yml b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.yml
new file mode 100644
index 0000000000..9a71e80600
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.yml
@@ -0,0 +1,45 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.network.Network:
+ derived_from: tosca.nodes.Root
+ properties:
+ ip_version:
+ type: integer
+ required: false
+ default: 4
+ constraints:
+ - valid_values: [ 4, 6 ]
+ cidr:
+ type: string
+ required: false
+ start_ip:
+ type: string
+ required: false
+ end_ip:
+ type: string
+ required: false
+ gateway_ip:
+ type: string
+ required: false
+ network_name:
+ type: string
+ required: false
+ network_id:
+ type: string
+ required: false
+ segmentation_id:
+ type: string
+ required: false
+ network_type:
+ type: string
+ required: false
+ physical_network:
+ type: string
+ required: false
+ dhcp_enabled:
+ type: boolean
+ required: false
+ default: true
+ capabilities:
+ link:
+ type: tosca.capabilities.network.Linkable
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/network/network.zip b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.zip
new file mode 100644
index 0000000000..61788a9e39
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/network/network.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.json b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.json
new file mode 100644
index 0000000000..dca5a4b89d
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "objectStorage.yml",
+ "contactId": "jh0003",
+ "name": "ObjectStorage",
+ "description": "Represents storage that provides the ability to store data as objects (or BLOBs of data) without consideration for the underlying filesystem or devices.",
+ "resourceIconPath": "objectStorage",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Infrastructure"
+ }
+ ]
+ }
+],
+ "tags": [
+ "ObjectStorage"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.yml b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.yml
new file mode 100644
index 0000000000..9c338c3400
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.yml
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.ObjectStorage:
+ derived_from: tosca.nodes.Root
+ properties:
+ name:
+ type: string
+ size:
+ type: scalar-unit.size
+ constraints:
+ - greater_or_equal: 0 GB
+ maxsize:
+ type: scalar-unit.size
+ constraints:
+ - greater_or_equal: 0 GB
+ capabilities:
+ storage_endpoint:
+ type: tosca.capabilities.Endpoint
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.zip b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.zip
new file mode 100644
index 0000000000..6b15346064
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/objectStorage/objectStorage.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/port/port.json b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.json
new file mode 100644
index 0000000000..2475bef065
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "port.yml",
+ "contactId": "jh0003",
+ "name": "Port",
+ "description": "Represents a logical entity that associates between Compute and Network normative types.",
+ "resourceIconPath": "port",
+ "resourceType": "CP",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Network Elements"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Port"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/port/port.yml b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.yml
new file mode 100644
index 0000000000..2d1540b27b
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.yml
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.network.Port:
+ derived_from: tosca.nodes.Root
+ properties:
+ ip_address:
+ type: string
+ required: false
+ order:
+ type: integer
+ required: true
+ default: 0
+ constraints:
+ - greater_or_equal: 0
+ is_default:
+ type: boolean
+ required: false
+ default: false
+ ip_range_start:
+ type: string
+ required: false
+ ip_range_end:
+ type: string
+ required: false
+ requirements:
+ - link:
+ capability: tosca.capabilities.network.Linkable
+ relationship: tosca.relationships.network.LinksTo
+ - binding:
+ capability: tosca.capabilities.network.Bindable
+ relationship: tosca.relationships.network.BindsTo
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/port/port.zip b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.zip
new file mode 100644
index 0000000000..0bf97333ce
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/port/port.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/root/root.json b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.json
new file mode 100644
index 0000000000..48846bc8be
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "root.yml",
+ "contactId": "jh0003",
+ "name": "Root",
+ "description": "Represents a generic software component that can be managed and run by a Compute Node Type.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Root"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/root/root.yml b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.yml
new file mode 100644
index 0000000000..e9b1de9518
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.yml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from
+ attributes:
+ tosca_id:
+ type: string
+ tosca_name:
+ type: string
+ state:
+ type: string
+ capabilities:
+ feature:
+ type: tosca.capabilities.Node
+ requirements:
+ - dependency :
+ capability: tosca.capabilities.Node
+ node: tosca.nodes.Root
+ relationship: tosca.relationships.DependsOn
+ occurrences: [ 0, UNBOUNDED ]
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Standard
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/root/root.zip b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.zip
new file mode 100644
index 0000000000..b336a9dca3
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/root/root.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.json b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.json
new file mode 100644
index 0000000000..ab8eda95eb
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "softwareComponent.yml",
+ "contactId": "jh0003",
+ "name": "SoftwareComponent",
+ "description": "Represents a generic software component that can be managed and run by a Compute Node Type.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "SoftwareComponent"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.yml b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.yml
new file mode 100644
index 0000000000..a154632c74
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.SoftwareComponent:
+ derived_from: tosca.nodes.Root
+ properties:
+ # domain-specific software component version
+ component_version:
+ type: version
+ required: false
+ admin_credential:
+ type: tosca.datatypes.Credential
+ required: false
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.Compute
+ relationship: tosca.relationships.HostedOn
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.zip b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.zip
new file mode 100644
index 0000000000..f77816b83f
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/softwareComponent/softwareComponent.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.json b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.json
new file mode 100644
index 0000000000..63c2936648
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "webApplication.yml",
+ "contactId": "jh0003",
+ "name": "WebApplication",
+ "description": "Represents a software application that can be managed and run by a Web Server node. Specific types of web applications such as Java, etc. could be derived from this type.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "WebApplication"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.yml b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.yml
new file mode 100644
index 0000000000..5f9a775fe0
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.yml
@@ -0,0 +1,15 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.WebApplication:
+ derived_from: tosca.nodes.Root
+ properties:
+ context_root:
+ type: string
+ capabilities:
+ app_endpoint:
+ type: tosca.capabilities.Endpoint
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.WebServer
+ relationship: tosca.relationships.HostedOn
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.zip b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.zip
new file mode 100644
index 0000000000..0b1889bd8e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webApplication/webApplication.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.json b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.json
new file mode 100644
index 0000000000..058af97664
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.json
@@ -0,0 +1,20 @@
+{
+ "payloadName": "webServer.yml",
+ "contactId": "jh0003",
+ "name": "WebServer",
+ "description": "Represents an abstract software component or service that is capable of hosting and providing management operations for one or more Web Application nodes.",
+ "resourceIconPath": "defaulticon",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "WebServer"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.yml b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.yml
new file mode 100644
index 0000000000..7c957b5247
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.yml
@@ -0,0 +1,11 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.WebServer:
+ derived_from: tosca.nodes.SoftwareComponent
+ capabilities:
+ # Private, layer 4 endpoints
+ data_endpoint: tosca.capabilities.Endpoint
+ admin_endpoint: tosca.capabilities.Endpoint.Admin
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [ tosca.nodes.WebApplication ] \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.zip b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.zip
new file mode 100644
index 0000000000..45bee47eff
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/normative-types/webServer/webServer.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.yml b/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.yml
new file mode 100644
index 0000000000..ceb22da2af
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.yml
@@ -0,0 +1,94 @@
+tosca.policies.Root:
+ description: The TOSCA Policy Type all other TOSCA Policy Types derive from
+tosca.policies.Placement:
+ derived_from: tosca.policies.Root
+ description: The TOSCA Policy Type definition that is used to govern placement of TOSCA nodes or groups of nodes.
+tosca.policies.Scaling:
+ derived_from: tosca.policies.Root
+ description: The TOSCA Policy Type definition that is used to govern scaling of TOSCA nodes or groups of nodes.
+tosca.policies.Update:
+ derived_from: tosca.policies.Root
+ description: The TOSCA Policy Type definition that is used to govern update of TOSCA nodes or groups of nodes.
+tosca.policies.Performance:
+ derived_from: tosca.policies.Root
+ description: The TOSCA Policy Type definition that is used to declare performance requirements for TOSCA nodes or groups of nodes.
+org.openecomp.policies.placement.Antilocate:
+ derived_from: tosca.policy.placement
+ description: My placement policy for separation based upon container type value
+ properties:
+ name:
+ type: string
+ description: The name of the policy
+ required: false
+ status: SUPPORTED
+ container_type:
+ type: string
+ description: container type
+ required: false
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - host
+ - region
+ - compute
+org.openecomp.policies.placement.Colocate:
+ derived_from: tosca.policy.placement
+ description: Keep associated nodes (groups of nodes) based upon affinity value
+ properties:
+ name:
+ type: string
+ description: The name of the policy
+ required: false
+ status: SUPPORTED
+ affinity:
+ type: string
+ description: affinity
+ required: true
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - host
+ - region
+ - compute
+org.openecomp.policies.placement.valet.Diversity:
+ derived_from: tosca.policy.placement
+ description: Valet Diversity
+ properties:
+ level:
+ type: string
+ description: diversity
+ required: false
+ default: host
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - host
+ - rack
+org.openecomp.policies.placement.valet.Exclusivity:
+ derived_from: tosca.policy.placement
+ description: Valet Exclusivity
+ properties:
+ level:
+ type: string
+ description: exclusivity
+ required: false
+ default: host
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - host
+ - rack
+org.openecomp.policies.placement.valet.Affinity:
+ derived_from: tosca.policy.placement
+ description: Valet Affinity
+ properties:
+ level:
+ type: string
+ description: affinity
+ required: false
+ default: host
+ status: SUPPORTED
+ constraints:
+ - valid_values:
+ - host
+ - rack \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.zip b/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.zip
new file mode 100644
index 0000000000..a6c38ef9de
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/policy-types/policyTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/users/importUsers.yaml b/catalog-be/src/main/resources/import/tosca/users/importUsers.yaml
new file mode 100644
index 0000000000..368a2b06f3
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/users/importUsers.yaml
@@ -0,0 +1,13 @@
+---
+users:
+ jh0003:
+ firstName: Jimmy
+ lastName: Hendrix
+ role: ADMIN
+ email: admin@att.com
+ jh0006:
+ firstName: Jimmy
+ lastName: Hendrix
+ role: DESIGNER1
+ email: admin@att.com
+
diff --git a/catalog-be/src/main/resources/jetty-ssl.xml b/catalog-be/src/main/resources/jetty-ssl.xml
new file mode 100644
index 0000000000..9b375087f1
--- /dev/null
+++ b/catalog-be/src/main/resources/jetty-ssl.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
+
+<!-- ============================================================= -->
+<!-- Configure a TLS (SSL) Context Factory -->
+<!-- This configuration must be used in conjunction with jetty.xml -->
+<!-- and either jetty-https.xml or jetty-spdy.xml (but not both) -->
+<!-- ============================================================= -->
+<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
+ <Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="etc/keystore"/></Set>
+ <Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
+ <Set name="KeyManagerPassword"><Property name="jetty.keymanager.password" default="OBF:1u2u1wml1z7s1z7a1wnl1u2g"/></Set>
+ <Set name="TrustStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.truststore" default="etc/keystore"/></Set>
+ <Set name="TrustStorePassword"><Property name="jetty.truststore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
+ <Set name="EndpointIdentificationAlgorithm"></Set>
+ <Set name="NeedClientAuth"><Property name="jetty.ssl.needClientAuth" default="false"/></Set>
+ <Set name="WantClientAuth"><Property name="jetty.ssl.wantClientAuth" default="false"/></Set>
+ <Set name="ExcludeCipherSuites">
+ <Array type="String">
+ <Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
+ <Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
+ <Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
+ <Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
+ <Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
+ <Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
+ <Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
+ </Array>
+ </Set>
+
+ <!-- =========================================================== -->
+ <!-- Create a TLS specific HttpConfiguration based on the -->
+ <!-- common HttpConfiguration defined in jetty.xml -->
+ <!-- Add a SecureRequestCustomizer to extract certificate and -->
+ <!-- session information -->
+ <!-- =========================================================== -->
+ <New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
+ <Arg><Ref refid="httpConfig"/></Arg>
+ <Call name="addCustomizer">
+ <Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
+ </Call>
+ </New>
+
+ <Set name="ExcludeProtocols">
+ <Array type="java.lang.String">
+ <Item>SSLv3</Item>
+ <Item>SSLv2</Item>
+ </Array>
+ </Set>
+
+
+</Configure>
diff --git a/catalog-be/src/main/resources/keystore/README.txt b/catalog-be/src/main/resources/keystore/README.txt
new file mode 100644
index 0000000000..bbbbd07e27
--- /dev/null
+++ b/catalog-be/src/main/resources/keystore/README.txt
@@ -0,0 +1,16 @@
+keytool -genkeypair -keystore catalogbe.jks -alias catalogbe -keypass Aa123456 -storepass Aa123456 -keyalg RSA -keysize 2048 -validity 3650 -dname "CN=Catalog BE, OU=Development, O=AT&T, L=TLV, C=IL"
+
+
+3650 – 10 years validity
+Eyal Sofer – creator
+Development – Organization unit
+AT&T – Organization
+TLV- City
+IL – Country code
+
+
+catalogbe.jks – name of keystore
+Aa123456 - password
+
+#In order to generate the password OBF:..., run the following command:
+java -cp ../jetty-distribution-9.2.7.v20150116/lib/jetty-http-9.2.7.v20150116.jar:../jetty-distribution-9.2.7.v20150116/lib/jetty-util-9.2.7.v20150116.jar org.eclipse.jetty.util.security.Password Aa123456 \ No newline at end of file
diff --git a/catalog-be/src/main/resources/keystore/catalogbe.jks b/catalog-be/src/main/resources/keystore/catalogbe.jks
new file mode 100644
index 0000000000..8493a46aca
--- /dev/null
+++ b/catalog-be/src/main/resources/keystore/catalogbe.jks
Binary files differ
diff --git a/catalog-be/src/main/resources/keystore/catalogbe.jks.pwd b/catalog-be/src/main/resources/keystore/catalogbe.jks.pwd
new file mode 100644
index 0000000000..b113d7d888
--- /dev/null
+++ b/catalog-be/src/main/resources/keystore/catalogbe.jks.pwd
@@ -0,0 +1 @@
+OBF:1cp61iuj194s194u194w194y1is31cok \ No newline at end of file
diff --git a/catalog-be/src/main/resources/portal.properties b/catalog-be/src/main/resources/portal.properties
new file mode 100644
index 0000000000..33ae0dac94
--- /dev/null
+++ b/catalog-be/src/main/resources/portal.properties
@@ -0,0 +1,25 @@
+# Portal REST URL, ends "/auxapi"
+ecomp_rest_url = https://localhost/ecompportal/auxapi
+
+# Java implementation of interface
+portal.api.impl.class = org.openecomp.sdc.be.ecomp.EcompIntImpl
+
+# CSP-SSO URL
+ecomp_redirect_url = https://localhost/ecomp_portal_ist/ecompportal/process_csp
+# Cookie set by CSP-SSO
+csp_cookie_name = attESSec
+# CSP setting, most use PROD; DEV also recognized
+csp_gate_keeper_prod_key = PROD
+
+# Comma-separated list of UEB server names
+ueb_url_list =
+# UEB topic where Portal listens
+ecomp_portal_inbox_name = ECOMP-PORTAL-INBOX-TEST
+# UEB key generated while on-boarding
+ueb_app_key = app_key_here
+# UEB secret generated while on-boarding
+ueb_app_secret = app_secret_here
+# UEB topic where App listens
+ueb_app_mailbox_name = app_topic_name_here
+# Consumer group name; most Apps should use {UUID}
+ueb_app_consumer_group_name = {UUID} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
new file mode 100644
index 0000000000..aca21754e8
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importCategoryTypes.py
@@ -0,0 +1,74 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+
+from importCommon import *
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importCategories(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/categories", "categoryTypes", "categoriesZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ errorAndExit(0, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importCategories(beHost, bePort, adminUser, True, "../../../import/tosca/categories/")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
new file mode 100644
index 0000000000..acdb067849
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importCommon.py
@@ -0,0 +1,43 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+
+###############################################################################################################
+#
+#
+###############################################################################################################
+
+debugFlag = True
+
+def join_strings(lst):
+ concat = ""
+ for string in lst:
+ if (string != None):
+ if (type(string) == int):
+ string = str(string)
+ concat += (string + " ")
+ return concat
+
+def debug(desc, *args):
+ 'print only if debug enabled'
+ if (debugFlag == True):
+ print desc, join_strings(args)
+
+def log(desc, arg=None):
+ 'print log info'
+ print desc, arg
+
+def errorAndExit(errorCode, errorDesc):
+ if ( errorCode > 0 ):
+ print "status={0}. {1}".format(errorCode, '' if errorDesc == None else errorDesc)
+ else:
+ print "status={0}".format(errorCode)
+ sys.exit(errorCode)
+
+def printNameAndReturnCode(name, code):
+ print "{0:30} | {1:6}".format(name, code)
+
+def printFrameLine():
+ print "----------------------------------------"
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
new file mode 100644
index 0000000000..5d7f5b7576
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importDataTypes.py
@@ -0,0 +1,74 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+
+from importCommon import *
+################################################################################################################################################
+# #
+# Import tosca data types #
+# #
+# activation : #
+# python importDataTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importDataTypes.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importDataTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/datatypes", "dataTypes", "dataTypesZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ errorAndExit(0, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importDataTypes(beHost, bePort, adminUser, True, "../../../import/tosca/data-types/")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
new file mode 100644
index 0000000000..2b6a5db6f8
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importGroupTypes.py
@@ -0,0 +1,74 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+
+from importCommon import *
+################################################################################################################################################
+# #
+# Import tosca data types #
+# #
+# activation : #
+# python importGroupTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importGroupTypes.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importGroupTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/grouptypes", "groupTypes", "groupTypesZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ errorAndExit(0, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importGroupTypes(beHost, bePort, adminUser, True, "../../../import/tosca/group-types/")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
new file mode 100644
index 0000000000..07eacf8d61
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
@@ -0,0 +1,113 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+from importNormativeTypes import *
+import importCommon
+
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def importHeatTypes(beHost, bePort, adminUser, fileDir, updateversion):
+
+ heatTypes = [ "cinderVolume",
+# "contrailVirtualNetwork",
+ "neutronNet",
+ "neutronPort",
+ "novaServer",
+ "vl",
+ "eline",
+ "abstractSubstitute",
+# "contrailNetworkRules",
+# "contrailPort",
+# "contrailV2NetworkRules",
+# "contrailV2VirtualNetwork",
+ "securityRules"
+# "contrailAbstractSubstitute",
+# "contrailCompute",
+# "contrailV2VirtualMachineInterface"
+ ]
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ results = []
+ for heatType in heatTypes:
+ result = createNormativeType(beHost, bePort, adminUser, fileDir, heatType, updateversion)
+ results.append(result)
+ if ( result[1] == None or result[1] not in responseCodes) :
+ print "Failed creating heat type " + heatType + ". " + str(result[1])
+ return results
+
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ updateversion = 'true'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-v", "--updateversion"):
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ results = importHeatTypes(beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion)
+
+ print "-----------------------------"
+ for result in results:
+ print "{0:20} | {1:6}".format(result[0], result[1])
+ print "-----------------------------"
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedNormatives) > 0):
+ errorAndExit(1, None)
+ else:
+ errorAndExit(0, None)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
new file mode 100644
index 0000000000..f35cc7bcee
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
@@ -0,0 +1,156 @@
+import pycurl
+import sys, getopt, os
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+import importCommon
+import zipfile
+################################################################################################################################################
+# #
+################################################################################################################################################
+
+def createZipFromYml(ymlFile, zipFile):
+ zip = zipfile.ZipFile(zipFile, 'w', zipfile.ZIP_DEFLATED)
+
+ zip.write(ymlFile, os.path.basename(ymlFile))
+ zip.close()
+
+def createUserNormativeType(beHost, bePort, adminUser, fileDir, ELEMENT_NAME):
+
+ try:
+ log("in create normative type ", ELEMENT_NAME)
+ debug("userId", adminUser)
+ debug("fileDir", fileDir)
+
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+ c.setopt(pycurl.HTTPHEADER, [adminHeader])
+
+ ymlFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".yml"
+ zipFile = fileDir + ELEMENT_NAME + "/normative-types-new-" + ELEMENT_NAME + ".zip"
+ debug(ymlFile)
+ debug(zipFile)
+ path = zipFile
+ debug("path=" + path)
+ CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json"
+ debug(CURRENT_JSON_FILE)
+ jsonFile = open(CURRENT_JSON_FILE)
+
+ debug("before load json")
+ json_data = json.load(jsonFile, strict=False)
+ debug(json_data)
+
+ jsonAsStr = json.dumps(json_data)
+ debug(path)
+ send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
+ debug(send)
+ c.setopt(pycurl.HTTPPOST, send)
+
+ c.setopt(c.WRITEFUNCTION, buffer.write)
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ if (httpRes != None):
+ debug("http response=", httpRes)
+ #print('Status: ' + str(responseCode))
+ debug(buffer.getvalue())
+ c.close()
+
+ return (ELEMENT_NAME, httpRes, buffer.getvalue())
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return (ELEMENT_NAME, None, None)
+
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-l <directory base location> | --location=<directory base location>] [-e <element name> | --element=<element name>]'
+ print "----------------- Example -------------------"
+ print "python importNodeType.py -d false -l /home/vagrant/catalog-be-1604.0.2.15.6-SNAPSHOT/scripts/import/tosca/../../../import/tosca/user-normative-types/ -e root1"
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ debugf = None
+ location = None
+ element = None
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:d:l:e:h",["ip=","port=","user=","location=","element=", "debug="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-l", "--location"):
+ location = arg
+ elif opt in ("-e", "--element"):
+ element = arg
+ elif opt in ("-d", "--debug"):
+ print arg
+ debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ if (debugf != None):
+ print 'set debug mode to ' + str(debugf)
+ importCommon.debugFlag = debugf
+
+ if (location == None):
+ print 'Missing file location'
+ usage()
+ sys.exit(3)
+
+ if (element == None):
+ print 'Missing element name. E.g. root, compute, ...'
+ usage()
+ sys.exit(3)
+
+ #pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+
+ #baseFileLocation = pathdir + "/../../../import/tosca/"
+ #fileDir = baseFileLocation + "user-normative-types/"
+
+ #normativeType = "root1"
+
+ result = createUserNormativeType(beHost, bePort, adminUser, location, element)
+ #result = createUserNormativeType(beHost, bePort, adminUser, fileDir, normativeType)
+ print "---------------------------------------"
+ print "{0:30} | {1:6}".format(result[0], result[1])
+ print "---------------------------------------"
+
+ if ( result[1] == None or result[1] not in [200, 201] ) :
+ print "Failed creating normative type " + element + ". " + str(result[1])
+ errorAndExit(1, None)
+
+ errorAndExit(0, None)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
new file mode 100644
index 0000000000..ec9e93e6e4
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
@@ -0,0 +1,135 @@
+import pycurl
+import sys, getopt, os
+from StringIO import StringIO
+import json
+import copy
+import time
+#from importNormativeElements import createNormativeElement
+from importNormativeElements import *
+from importNormativeTypes import importNormativeTypes
+from importHeatTypes import importHeatTypes
+from importNormativeCapabilities import importNormativeCapabilities
+from importCategoryTypes import importCategories
+from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
+from importDataTypes import importDataTypes
+from importGroupTypes import importGroupTypes
+from importPolicyTypes import importPolicyTypes
+from importCommon import *
+import importCommon
+
+#################################################################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importNormativeAll.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] #
+# [-v <true|false> | --updateversion=<true|false>] #
+# #
+# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
+# python importNormativeAll.py #
+# #
+#################################################################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+
+def handleResults(results, updateversion):
+ printFrameLine()
+ for result in results:
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedResults) > 0):
+ errorAndExit(1, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ debugf = None
+ updateversion = 'true'
+ importCommon.debugFlag = False
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:d:v:h",["ip=","port=","user=","debug=","updateversion="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-d", "--debug"):
+ print arg
+ debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
+ elif opt in ("-v", "--updateversion"):
+ print arg
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
+
+ if (debugf != None):
+ print 'set debug mode to ' + str(debugf)
+ importCommon.debugFlag = debugf
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ print sys.argv[0]
+ pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + pathdir)
+
+ baseFileLocation = pathdir + "/../../../import/tosca/"
+
+ fileLocation = baseFileLocation + "data-types/"
+ importDataTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ print 'sleep until data type cache is updated'
+ time.sleep( 70 )
+
+ fileLocation = baseFileLocation + "capability-types/"
+ importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "interface-lifecycle-types/"
+ importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "categories/"
+ importCategories(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "normative-types/"
+ results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
+ handleResults(results, updateversion)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
+ handleResults(resultsHeat, updateversion)
+
+ fileLocation = baseFileLocation + "group-types/"
+ importGroupTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "policy-types/"
+ importPolicyTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ errorAndExit(0, None)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
new file mode 100644
index 0000000000..bda02ddda9
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeCapabilities.py
@@ -0,0 +1,77 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+from importCommon import *
+import importCommon
+
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importNormativeCapabilities(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", "capabilityTypeZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ importCommon.errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ importCommon.errorAndExit(0, None)
+
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ importCommon.errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importNormativeCapabilities(beHost, bePort, adminUser, True, "../../../import/tosca/capability-types/")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
new file mode 100644
index 0000000000..af643da4f4
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
@@ -0,0 +1,65 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def createNormativeElement(beHost, bePort, adminUser, fileDir, urlSuffix, ELEMENT_NAME, elementFormName):
+
+ try:
+ log("in create normative element ", ELEMENT_NAME)
+
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = 'http://' + beHost + ':' + bePort + urlSuffix
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+ c.setopt(pycurl.HTTPHEADER, [adminHeader])
+
+
+ path = fileDir + "/" + ELEMENT_NAME + ".zip"
+ debug(path)
+
+ send = [(elementFormName, (pycurl.FORM_FILE, path))]
+ debug(send)
+ c.setopt(pycurl.HTTPPOST, send)
+
+ #data = json.dumps(user)
+ #c.setopt(c.POSTFIELDS, data)
+
+ #c.setopt(c.WRITEFUNCTION, lambda x: None)
+ c.setopt(c.WRITEFUNCTION, buffer.write)
+ #print("before perform")
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ if (httpRes != None):
+ debug("http response=", httpRes)
+ #print('Status: ' + str(responseCode))
+ debug("response buffer", buffer.getvalue())
+ c.close()
+
+ return (ELEMENT_NAME, httpRes, buffer.getvalue())
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return (ELEMENT_NAME, None, None)
+
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
new file mode 100644
index 0000000000..33f1cc42de
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeInterfaceLifecycleTypes.py
@@ -0,0 +1,75 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+from importCommon import *
+
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", "interfaceLifecycleTypes", "interfaceLifecycleTypeZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ errorAndExit(0, None)
+
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, True, "../../../import/tosca/interface-lifecycle-types//")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
new file mode 100644
index 0000000000..76bae682c0
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
@@ -0,0 +1,159 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+import importCommon
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# [-v <true|false> | --updateversion=<true|false>] #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def createNormativeType(beHost, bePort, adminUser, fileDir, ELEMENT_NAME, updateversion):
+
+ try:
+ log("in create normative type ", ELEMENT_NAME)
+ debug("userId", adminUser)
+ debug("fileDir", fileDir)
+
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
+ if updateversion != None:
+ url += '?createNewVersion=' + updateversion
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+ c.setopt(pycurl.HTTPHEADER, [adminHeader])
+
+
+ path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".zip"
+ debug(path)
+ CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json"
+ #sed -i 's/"userId": ".*",/"userId": "'${ATT_UID}'",/' ${CURRENT_JSON_FILE}
+
+ jsonFile = open(CURRENT_JSON_FILE)
+
+ debug("before load json")
+ json_data = json.load(jsonFile, strict=False)
+ debug(json_data)
+
+ jsonAsStr = json.dumps(json_data)
+
+ send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
+ debug(send)
+ c.setopt(pycurl.HTTPPOST, send)
+
+ #data = json.dumps(user)
+ #c.setopt(c.POSTFIELDS, data)
+
+ #c.setopt(c.WRITEFUNCTION, lambda x: None)
+ c.setopt(c.WRITEFUNCTION, buffer.write)
+ #print("before perform")
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ if (httpRes != None):
+ debug("http response=", httpRes)
+ #print('Status: ' + str(responseCode))
+ debug(buffer.getvalue())
+ c.close()
+
+ return (ELEMENT_NAME, httpRes, buffer.getvalue())
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return (ELEMENT_NAME, None, None)
+
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-v <true|false> | --updateversion=<true|false>]'
+
+
+def importNormativeTypes(beHost, bePort, adminUser, fileDir, updateversion):
+
+ normativeTypes = [ "root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database", "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer", "port", "network"]
+ #normativeTypes = [ "root" ]
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ results = []
+ for normativeType in normativeTypes:
+ result = createNormativeType(beHost, bePort, adminUser, fileDir, normativeType, updateversion)
+ results.append(result)
+ if ( result[1] == None or result[1] not in responseCodes ):
+ print "Failed creating normative type " + normativeType + ". " + str(result[1])
+ return results
+
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ updateversion = 'true'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-v", "--updateversion"):
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', updateversion =', updateversion
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ results = importNormativeTypes(beHost, bePort, adminUser, "../../../import/tosca/normative-types/", updateversion)
+
+ print "-----------------------------"
+ for result in results:
+ print "{0:20} | {1:6}".format(result[0], result[1])
+ print "-----------------------------"
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedNormatives) > 0):
+ errorAndExit(1, None)
+ else:
+ errorAndExit(0, None)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
new file mode 100644
index 0000000000..c01e159264
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importPolicyTypes.py
@@ -0,0 +1,74 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importNormativeElements import createNormativeElement
+
+from importCommon import *
+################################################################################################################################################
+# #
+# Import tosca data types #
+# #
+# activation : #
+# python importPolicyTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importPolicyTypes.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+
+
+def importPolicyTypes(beHost, bePort, adminUser, exitOnSuccess, fileDir):
+ result = createNormativeElement(beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/policytypes", "policyTypes", "policyTypesZip")
+
+ printFrameLine()
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ errorAndExit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ errorAndExit(0, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:",["ip=","port=","user="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importPolicyTypes(beHost, bePort, adminUser, True, "../../../import/tosca/policy-types/")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
new file mode 100644
index 0000000000..8509855f38
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
@@ -0,0 +1,221 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+import yaml
+
+########################################################################################################################################################
+# #
+# Import all users from a given YAML file #
+# #
+# activation : #
+# python importUsersFromYaml.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsersFromYaml.py [-f <input file> | --ifile=<input file> ] #
+# #
+# PyYAML module shall be added to python. #
+# pip install PyYAML>=3.1.0 --proxy=http://one.proxy.att.com:8080 #
+########################################################################################################################################################
+
+
+def importUsers(beHost, bePort, users, adminUser):
+
+ result = []
+
+ for user in users:
+
+ #print("Going to add user " + user['userId'])
+
+ getRes = getUser(beHost, bePort, user)
+ userId = getRes[0]
+ error = getRes[1]
+ #print error
+ if ( error != None and error == 404 ):
+ res = createUser(beHost, bePort, user ,adminUser)
+ result.append(res)
+ else:
+ if ( error == 200 ):
+ curResult = (userId, 409)
+ result.append(curResult)
+ else:
+ result.append(getRes)
+
+ return result
+
+
+def getUser(beHost, bePort, user):
+
+ if (user.get('userId') == None):
+ print "Ignoring record", user
+ return ('NotExist', 200)
+ userId = user['userId']
+ try:
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ #print type(userId)
+ url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user/' + str(userId)
+ c.setopt(c.URL, url)
+
+ #adminHeader = 'USER_ID: ' + adminUser
+ c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json'])
+ c.setopt(c.WRITEFUNCTION, lambda x: None)
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ #print("After get response code")
+ responseCode = c.getinfo(c.RESPONSE_CODE)
+
+ #print('Status: ' + str(responseCode))
+
+ c.close()
+
+ return (userId, httpRes)
+
+ except Exception as inst:
+ print(inst)
+ return (userId, None)
+
+
+
+def createUser(beHost, bePort, user, adminUser):
+
+ if (user.get('userId') == None):
+ print "Ignoring record", user
+ return ('NotExist', 200)
+
+ userId = user['userId']
+ try:
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user'
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+
+ data = json.dumps(user)
+ c.setopt(c.POSTFIELDS, data)
+
+ c.setopt(c.WRITEFUNCTION, lambda x: None)
+ #print("before perform")
+ res = c.perform()
+ #print(res)
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ #print("After get response code")
+ responseCode = c.getinfo(c.RESPONSE_CODE)
+
+ #print('Status: ' + str(responseCode))
+
+ c.close()
+
+ return (userId, httpRes)
+
+ except Exception as inst:
+ print(inst)
+ return (userId, None)
+
+
+def errorAndExit(errorCode, errorDesc):
+ if ( errorCode > 0 ):
+ print("status=" + str(errorCode) + ". " + errorDesc)
+ else:
+ print("status=" + str(errorCode))
+ sys.exit(errorCode)
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]'
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ inputfile = None
+
+ adminUser = 'jh0003'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:f:h:",["ip=","port=","ifile="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-f", "--ifile"):
+ inputfile = arg
+
+ print 'be host =',beHost,', be port =', bePort,', users file =',inputfile
+
+ if ( inputfile == None ):
+ usage()
+ sys.exit(3)
+
+ print 'Input file is ', inputfile
+
+
+ usersAsYamlFile = open(inputfile, 'r')
+ usersDoc = yaml.load(usersAsYamlFile)
+ print usersDoc
+
+ cloneUsers = []
+ for users in usersDoc.values():
+ for x,y in users.items():
+ copiedUser = y
+ copiedUser['userId'] = x
+ #print copiedUser
+ cloneUsers.append(copiedUser)
+
+ print cloneUsers
+
+ usersAsYamlFile.close()
+
+ #activeUsers = filter(lambda x: x.get('status') == None or x['status'] == 'ACTIVE', cloneUsers)
+
+ resultTable = importUsers(beHost, bePort, cloneUsers, adminUser)
+
+ g = lambda x: x[1] != 201 and x[1] != 409
+
+ result = filter(g, resultTable)
+
+ if ( len(result) > 0 ):
+ #print("ERROR: Failed to load the users " + ', '.join(map(lambda x: x[0],result)))
+ errorAndExit(3, "Failed to load the users " + ', '.join(map(lambda x: x[0],result)))
+
+ g = lambda x: x[1] == 409
+ result = filter(g, resultTable)
+
+ print("-------------------------------------------")
+ print("Existing users: " + ', '.join(map(lambda x: x[0],result)))
+
+ result = filter(lambda x: x[1] == 201, resultTable)
+ if ( len(result) == 0 ):
+ print("-------------------------------------------")
+ print("No NEW user was loaded. All users are already exist")
+ print("-------------------------------------------")
+ else:
+ print("-------------------------------------------")
+ print("Loaded users: " + ', '.join(map(lambda x: x[0],result)))
+ print("-------------------------------------------")
+
+ errorAndExit(0, None)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
new file mode 100644
index 0000000000..e6bb620692
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
@@ -0,0 +1,114 @@
+import pycurl
+import sys, getopt, os
+from StringIO import StringIO
+import json
+import copy
+import time
+from importCategoryTypes import importCategories
+from importHeatTypes import importHeatTypes
+from importNormativeCapabilities import importNormativeCapabilities
+from importDataTypes import importDataTypes
+from importGroupTypes import importGroupTypes
+from importPolicyTypes import importPolicyTypes
+from importCommon import *
+import importCommon
+
+#################################################################################################################################################################################################
+# #
+# Upgrades the normative types #
+# #
+# activation : #
+# python upgradeNormative.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] #
+# #
+# #
+# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
+# python upgradeNormative.py #
+# #
+#################################################################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
+
+def handleResults(results, updateversion):
+ printFrameLine()
+ for result in results:
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
+ if (len(failedResults) > 0):
+ errorAndExit(1, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ debugf = None
+ updateversion = 'false'
+ importCommon.debugFlag = False
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-d", "--debug"):
+ print arg
+ debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
+
+ if (debugf != None):
+ print 'set debug mode to ' + str(debugf)
+ importCommon.debugFlag = debugf
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ print sys.argv[0]
+ pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + pathdir)
+
+ baseFileLocation = pathdir + "/../../../import/tosca/"
+
+ fileLocation = baseFileLocation + "categories/"
+ importCategories(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "data-types/"
+ importDataTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ print 'sleep until data type cache is updated'
+ time.sleep( 70 )
+ fileLocation = baseFileLocation + "capability-types/"
+ importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "group-types/"
+ importGroupTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "policy-types/"
+ importPolicyTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
+ handleResults(resultsHeat, 'false')
+
+ errorAndExit(0, None)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
new file mode 100644
index 0000000000..0f70174173
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersion.py
@@ -0,0 +1,143 @@
+import pycurl
+import sys, getopt, os
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+from importNormativeTypes import createNormativeType
+import importCommon
+
+#################################################################################################################################################################################################
+# #
+# Upgrades the normative types #
+# #
+# activation : #
+# python upgradeNormative.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] #
+# #
+# #
+# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
+# python upgradeNormative.py #
+# #
+#################################################################################################################################################################################################
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]'
+
+def handleResults(results, updateversion):
+ printFrameLine()
+ for result in results:
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
+ if (len(failedResults) > 0):
+ errorAndExit(1, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ debugf = None
+ updateversion = 'true'
+ importCommon.debugFlag = False
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-d", "--debug"):
+ print arg
+ debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf
+
+ if (debugf != None):
+ print 'set debug mode to ' + str(debugf)
+ importCommon.debugFlag = debugf
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ print sys.argv[0]
+ pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + pathdir)
+
+ baseFileLocation = pathdir + "/../../../import/tosca/"
+ results = []
+
+
+ ##########################################################################
+ #---------------------------------for release 1610---------------------- #
+ ##########################################################################
+
+ fileLocation = baseFileLocation + "normative-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "compute", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "normative-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "network", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "abstractSubstitute", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailAbstractSubstitute", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailNetworkRules", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "novaServer", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "neutronPort", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailVirtualNetwork", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "neutronNet", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "vl", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "contrailV2VirtualNetwork", updateversion)
+ results.append(result)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ result = createNormativeType(beHost, bePort, adminUser, fileLocation, "securityRules", updateversion)
+ results.append(result)
+
+ handleResults(results, 'false')
+
+ errorAndExit(0, None)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
new file mode 100644
index 0000000000..72198ceab6
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormativeVersionAll.py
@@ -0,0 +1,93 @@
+import pycurl
+import sys, getopt, os
+from StringIO import StringIO
+import json
+import copy
+import time
+from importNormativeTypes import importNormativeTypes
+from importHeatTypes import importHeatTypes
+from importCommon import *
+import importCommon
+
+def usage():
+ print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
+
+def handleResults(results, updateversion):
+ printFrameLine()
+ for result in results:
+ printNameAndReturnCode(result[0], result[1])
+ printFrameLine()
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedResults) > 0):
+ errorAndExit(1, None)
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ debugf = None
+ updateversion = 'true'
+ importCommon.debugFlag = False
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:d:v:h",["ip=","port=","user=","debug=","updateversion="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-d", "--debug"):
+ print arg
+ debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
+ elif opt in ("-v", "--updateversion"):
+ print arg
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
+
+ if (debugf != None):
+ print 'set debug mode to ' + str(debugf)
+ importCommon.debugFlag = debugf
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ print sys.argv[0]
+ pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ debug("path dir =" + pathdir)
+
+ baseFileLocation = pathdir + "/../../../import/tosca/"
+
+ fileLocation = baseFileLocation + "normative-types/"
+ results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
+ handleResults(results, updateversion)
+
+ fileLocation = baseFileLocation + "heat-types/"
+ resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
+ handleResults(resultsHeat, updateversion)
+
+ errorAndExit(0, None)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/swagger/css/print.css b/catalog-be/src/main/resources/swagger/css/print.css
new file mode 100644
index 0000000000..b4fc18036e
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/css/print.css
@@ -0,0 +1,1155 @@
+/* Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org> */
+.swagger-section pre code {
+ display: block;
+ padding: 0.5em;
+ background: #F0F0F0;
+}
+.swagger-section pre code,
+.swagger-section pre .subst,
+.swagger-section pre .tag .title,
+.swagger-section pre .lisp .title,
+.swagger-section pre .clojure .built_in,
+.swagger-section pre .nginx .title {
+ color: black;
+}
+.swagger-section pre .string,
+.swagger-section pre .title,
+.swagger-section pre .constant,
+.swagger-section pre .parent,
+.swagger-section pre .tag .value,
+.swagger-section pre .rules .value,
+.swagger-section pre .rules .value .number,
+.swagger-section pre .preprocessor,
+.swagger-section pre .ruby .symbol,
+.swagger-section pre .ruby .symbol .string,
+.swagger-section pre .aggregate,
+.swagger-section pre .template_tag,
+.swagger-section pre .django .variable,
+.swagger-section pre .smalltalk .class,
+.swagger-section pre .addition,
+.swagger-section pre .flow,
+.swagger-section pre .stream,
+.swagger-section pre .bash .variable,
+.swagger-section pre .apache .tag,
+.swagger-section pre .apache .cbracket,
+.swagger-section pre .tex .command,
+.swagger-section pre .tex .special,
+.swagger-section pre .erlang_repl .function_or_atom,
+.swagger-section pre .markdown .header {
+ color: #800;
+}
+.swagger-section pre .comment,
+.swagger-section pre .annotation,
+.swagger-section pre .template_comment,
+.swagger-section pre .diff .header,
+.swagger-section pre .chunk,
+.swagger-section pre .markdown .blockquote {
+ color: #888;
+}
+.swagger-section pre .number,
+.swagger-section pre .date,
+.swagger-section pre .regexp,
+.swagger-section pre .literal,
+.swagger-section pre .smalltalk .symbol,
+.swagger-section pre .smalltalk .char,
+.swagger-section pre .go .constant,
+.swagger-section pre .change,
+.swagger-section pre .markdown .bullet,
+.swagger-section pre .markdown .link_url {
+ color: #080;
+}
+.swagger-section pre .label,
+.swagger-section pre .javadoc,
+.swagger-section pre .ruby .string,
+.swagger-section pre .decorator,
+.swagger-section pre .filter .argument,
+.swagger-section pre .localvars,
+.swagger-section pre .array,
+.swagger-section pre .attr_selector,
+.swagger-section pre .important,
+.swagger-section pre .pseudo,
+.swagger-section pre .pi,
+.swagger-section pre .doctype,
+.swagger-section pre .deletion,
+.swagger-section pre .envvar,
+.swagger-section pre .shebang,
+.swagger-section pre .apache .sqbracket,
+.swagger-section pre .nginx .built_in,
+.swagger-section pre .tex .formula,
+.swagger-section pre .erlang_repl .reserved,
+.swagger-section pre .prompt,
+.swagger-section pre .markdown .link_label,
+.swagger-section pre .vhdl .attribute,
+.swagger-section pre .clojure .attribute,
+.swagger-section pre .coffeescript .property {
+ color: #8888ff;
+}
+.swagger-section pre .keyword,
+.swagger-section pre .id,
+.swagger-section pre .phpdoc,
+.swagger-section pre .title,
+.swagger-section pre .built_in,
+.swagger-section pre .aggregate,
+.swagger-section pre .css .tag,
+.swagger-section pre .javadoctag,
+.swagger-section pre .phpdoc,
+.swagger-section pre .yardoctag,
+.swagger-section pre .smalltalk .class,
+.swagger-section pre .winutils,
+.swagger-section pre .bash .variable,
+.swagger-section pre .apache .tag,
+.swagger-section pre .go .typename,
+.swagger-section pre .tex .command,
+.swagger-section pre .markdown .strong,
+.swagger-section pre .request,
+.swagger-section pre .status {
+ font-weight: bold;
+}
+.swagger-section pre .markdown .emphasis {
+ font-style: italic;
+}
+.swagger-section pre .nginx .built_in {
+ font-weight: normal;
+}
+.swagger-section pre .coffeescript .javascript,
+.swagger-section pre .javascript .xml,
+.swagger-section pre .tex .formula,
+.swagger-section pre .xml .javascript,
+.swagger-section pre .xml .vbscript,
+.swagger-section pre .xml .css,
+.swagger-section pre .xml .cdata {
+ opacity: 0.5;
+}
+.swagger-section .swagger-ui-wrap {
+ line-height: 1;
+ font-family: "Droid Sans", sans-serif;
+ max-width: 960px;
+ margin-left: auto;
+ margin-right: auto;
+}
+.swagger-section .swagger-ui-wrap b,
+.swagger-section .swagger-ui-wrap strong {
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap q,
+.swagger-section .swagger-ui-wrap blockquote {
+ quotes: none;
+}
+.swagger-section .swagger-ui-wrap p {
+ line-height: 1.4em;
+ padding: 0 0 10px;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap q:before,
+.swagger-section .swagger-ui-wrap q:after,
+.swagger-section .swagger-ui-wrap blockquote:before,
+.swagger-section .swagger-ui-wrap blockquote:after {
+ content: none;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu h1,
+.swagger-section .swagger-ui-wrap .heading_with_menu h2,
+.swagger-section .swagger-ui-wrap .heading_with_menu h3,
+.swagger-section .swagger-ui-wrap .heading_with_menu h4,
+.swagger-section .swagger-ui-wrap .heading_with_menu h5,
+.swagger-section .swagger-ui-wrap .heading_with_menu h6 {
+ display: block;
+ clear: none;
+ float: left;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ box-sizing: border-box;
+ width: 60%;
+}
+.swagger-section .swagger-ui-wrap table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+.swagger-section .swagger-ui-wrap table thead tr th {
+ padding: 5px;
+ font-size: 0.9em;
+ color: #666666;
+ border-bottom: 1px solid #999999;
+}
+.swagger-section .swagger-ui-wrap table tbody tr:last-child td {
+ border-bottom: none;
+}
+.swagger-section .swagger-ui-wrap table tbody tr.offset {
+ background-color: #f0f0f0;
+}
+.swagger-section .swagger-ui-wrap table tbody tr td {
+ padding: 6px;
+ font-size: 0.9em;
+ border-bottom: 1px solid #cccccc;
+ vertical-align: top;
+ line-height: 1.3em;
+}
+.swagger-section .swagger-ui-wrap ol {
+ margin: 0px 0 10px;
+ padding: 0 0 0 18px;
+ list-style-type: decimal;
+}
+.swagger-section .swagger-ui-wrap ol li {
+ padding: 5px 0px;
+ font-size: 0.9em;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap ol,
+.swagger-section .swagger-ui-wrap ul {
+ list-style: none;
+}
+.swagger-section .swagger-ui-wrap h1 a,
+.swagger-section .swagger-ui-wrap h2 a,
+.swagger-section .swagger-ui-wrap h3 a,
+.swagger-section .swagger-ui-wrap h4 a,
+.swagger-section .swagger-ui-wrap h5 a,
+.swagger-section .swagger-ui-wrap h6 a {
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap h1 a:hover,
+.swagger-section .swagger-ui-wrap h2 a:hover,
+.swagger-section .swagger-ui-wrap h3 a:hover,
+.swagger-section .swagger-ui-wrap h4 a:hover,
+.swagger-section .swagger-ui-wrap h5 a:hover,
+.swagger-section .swagger-ui-wrap h6 a:hover {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap h1 span.divider,
+.swagger-section .swagger-ui-wrap h2 span.divider,
+.swagger-section .swagger-ui-wrap h3 span.divider,
+.swagger-section .swagger-ui-wrap h4 span.divider,
+.swagger-section .swagger-ui-wrap h5 span.divider,
+.swagger-section .swagger-ui-wrap h6 span.divider {
+ color: #aaaaaa;
+}
+.swagger-section .swagger-ui-wrap a {
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap a img {
+ border: none;
+}
+.swagger-section .swagger-ui-wrap article,
+.swagger-section .swagger-ui-wrap aside,
+.swagger-section .swagger-ui-wrap details,
+.swagger-section .swagger-ui-wrap figcaption,
+.swagger-section .swagger-ui-wrap figure,
+.swagger-section .swagger-ui-wrap footer,
+.swagger-section .swagger-ui-wrap header,
+.swagger-section .swagger-ui-wrap hgroup,
+.swagger-section .swagger-ui-wrap menu,
+.swagger-section .swagger-ui-wrap nav,
+.swagger-section .swagger-ui-wrap section,
+.swagger-section .swagger-ui-wrap summary {
+ display: block;
+}
+.swagger-section .swagger-ui-wrap pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #fcf6db;
+ border: 1px solid #e5e0c6;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap pre code {
+ line-height: 1.6em;
+ background: none;
+}
+.swagger-section .swagger-ui-wrap .content > .content-type > div > label {
+ clear: both;
+ display: block;
+ color: #0F6AB4;
+ font-size: 1.1em;
+ margin: 0;
+ padding: 15px 0 5px;
+}
+.swagger-section .swagger-ui-wrap .content pre {
+ font-size: 12px;
+ margin-top: 5px;
+ padding: 5px;
+}
+.swagger-section .swagger-ui-wrap .icon-btn {
+ cursor: pointer;
+}
+.swagger-section .swagger-ui-wrap .info_title {
+ padding-bottom: 10px;
+ font-weight: bold;
+ font-size: 25px;
+}
+.swagger-section .swagger-ui-wrap p.big,
+.swagger-section .swagger-ui-wrap div.big p {
+ font-size: 1em;
+ margin-bottom: 10px;
+}
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.string input,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.url input,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.text textarea,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.numeric input {
+ width: 500px !important;
+}
+.swagger-section .swagger-ui-wrap .info_license {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_tos {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .message-fail {
+ color: #cc0000;
+}
+.swagger-section .swagger-ui-wrap .info_url {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_email {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_name {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_description {
+ padding-bottom: 10px;
+ font-size: 15px;
+}
+.swagger-section .swagger-ui-wrap .markdown ol li,
+.swagger-section .swagger-ui-wrap .markdown ul li {
+ padding: 3px 0px;
+ line-height: 1.4em;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input {
+ display: block;
+ padding: 4px;
+ width: auto;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input.title,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input.title,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input.title {
+ font-size: 1.3em;
+}
+.swagger-section .swagger-ui-wrap table.fullwidth {
+ width: 100%;
+}
+.swagger-section .swagger-ui-wrap .model-signature {
+ font-family: "Droid Sans", sans-serif;
+ font-size: 1em;
+ line-height: 1.5em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav a {
+ text-decoration: none;
+ color: #AAA;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav a:hover {
+ text-decoration: underline;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav .selected {
+ color: black;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propType {
+ color: #5555aa;
+}
+.swagger-section .swagger-ui-wrap .model-signature pre:hover {
+ background-color: #ffffdd;
+}
+.swagger-section .swagger-ui-wrap .model-signature pre {
+ font-size: .85em;
+ line-height: 1.2em;
+ overflow: auto;
+ max-height: 200px;
+ cursor: pointer;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav {
+ display: block;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li:last-child {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li {
+ float: left;
+ margin: 0 5px 5px 0;
+ padding: 2px 5px 2px 0;
+ border-right: 1px solid #ddd;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propOpt {
+ color: #555;
+}
+.swagger-section .swagger-ui-wrap .model-signature .snippet small {
+ font-size: 0.75em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propOptKey {
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .strong {
+ font-weight: bold;
+ color: #000;
+ font-size: .9em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description div {
+ font-size: 0.9em;
+ line-height: 1.5em;
+ margin-left: 1em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .stronger {
+ font-weight: bold;
+ color: #000;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper {
+ border-spacing: 0;
+ position: absolute;
+ background-color: #ffffff;
+ border: 1px solid #bbbbbb;
+ display: none;
+ font-size: 11px;
+ max-width: 400px;
+ line-height: 30px;
+ color: black;
+ padding: 5px;
+ margin-left: 10px;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th {
+ text-align: center;
+ background-color: #eeeeee;
+ border: 1px solid #bbbbbb;
+ font-size: 11px;
+ color: #666666;
+ font-weight: bold;
+ padding: 5px;
+ line-height: 15px;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propName {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-container {
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap .body-textarea {
+ width: 300px;
+ height: 100px;
+ border: 1px solid #aaa;
+}
+.swagger-section .swagger-ui-wrap .markdown p code,
+.swagger-section .swagger-ui-wrap .markdown li code {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #f0f0f0;
+ color: black;
+ padding: 1px 3px;
+}
+.swagger-section .swagger-ui-wrap .required {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap input.parameter {
+ width: 300px;
+ border: 1px solid #aaa;
+}
+.swagger-section .swagger-ui-wrap h1 {
+ color: black;
+ font-size: 1.5em;
+ line-height: 1.3em;
+ padding: 10px 0 10px 0;
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu ul {
+ display: block;
+ clear: none;
+ float: right;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ box-sizing: border-box;
+ margin-top: 10px;
+}
+.swagger-section .swagger-ui-wrap h2 {
+ color: black;
+ font-size: 1.3em;
+ padding: 10px 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap h2 a {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap h2 span.sub {
+ font-size: 0.7em;
+ color: #999999;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap h2 span.sub a {
+ color: #777777;
+}
+.swagger-section .swagger-ui-wrap span.weak {
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap .message-success {
+ color: #89BF04;
+}
+.swagger-section .swagger-ui-wrap caption,
+.swagger-section .swagger-ui-wrap th,
+.swagger-section .swagger-ui-wrap td {
+ text-align: left;
+ font-weight: normal;
+ vertical-align: middle;
+}
+.swagger-section .swagger-ui-wrap .code {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.text textarea {
+ font-family: "Droid Sans", sans-serif;
+ height: 250px;
+ padding: 4px;
+ display: block;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.select select {
+ display: block;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean label {
+ display: block;
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean input {
+ display: block;
+ float: left;
+ clear: none;
+ margin: 0 5px 0 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.required label {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label {
+ display: block;
+ clear: both;
+ width: auto;
+ padding: 0 0 3px;
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label abbr {
+ padding-left: 3px;
+ color: #888888;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li p.inline-hints {
+ margin-left: 0;
+ font-style: italic;
+ font-size: 0.9em;
+ margin: 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.buttons {
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap span.blank,
+.swagger-section .swagger-ui-wrap span.empty {
+ color: #888888;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap .markdown h3 {
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap .markdown h4 {
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap .markdown pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #fcf6db;
+ border: 1px solid #e5e0c6;
+ padding: 10px;
+ margin: 0 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap .markdown pre code {
+ line-height: 1.6em;
+}
+.swagger-section .swagger-ui-wrap div.gist {
+ margin: 20px 0 25px 0 !important;
+}
+.swagger-section .swagger-ui-wrap ul#resources {
+ font-family: "Droid Sans", sans-serif;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource {
+ border-bottom: 1px solid #dddddd;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading h2 a,
+.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading h2 a {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading ul.options li a,
+.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading ul.options li a {
+ color: #555555;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:last-child {
+ border-bottom: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading {
+ border: 1px solid transparent;
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options {
+ overflow: hidden;
+ padding: 0;
+ display: block;
+ clear: none;
+ float: right;
+ margin: 14px 10px 0 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li {
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 2px 10px;
+ border-right: 1px solid #dddddd;
+ color: #666666;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a {
+ color: #aaaaaa;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover {
+ text-decoration: underline;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:active,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a.active {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.last {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 {
+ color: #999999;
+ padding-left: 0;
+ display: block;
+ clear: none;
+ float: left;
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a {
+ color: #999999;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+ margin: 0 0 10px;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 {
+ display: block;
+ clear: none;
+ float: left;
+ width: auto;
+ margin: 0;
+ padding: 0;
+ line-height: 1.1em;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path {
+ padding-left: 10px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a {
+ color: black;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a:hover {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ text-decoration: none;
+ color: white;
+ display: inline-block;
+ width: 50px;
+ font-size: 0.7em;
+ text-align: center;
+ padding: 7px 0 4px;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ -o-border-radius: 2px;
+ -ms-border-radius: 2px;
+ -khtml-border-radius: 2px;
+ border-radius: 2px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span {
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options {
+ overflow: hidden;
+ padding: 0;
+ display: block;
+ clear: none;
+ float: right;
+ margin: 6px 10px 0 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li {
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 2px 10px;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content {
+ border-top: none;
+ padding: 10px;
+ -moz-border-radius-bottomleft: 6px;
+ -webkit-border-bottom-left-radius: 6px;
+ -o-border-bottom-left-radius: 6px;
+ -ms-border-bottom-left-radius: 6px;
+ -khtml-border-bottom-left-radius: 6px;
+ border-bottom-left-radius: 6px;
+ -moz-border-radius-bottomright: 6px;
+ -webkit-border-bottom-right-radius: 6px;
+ -o-border-bottom-right-radius: 6px;
+ -ms-border-bottom-right-radius: 6px;
+ -khtml-border-bottom-right-radius: 6px;
+ border-bottom-right-radius: 6px;
+ margin: 0 0 20px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content h4 {
+ font-size: 1.1em;
+ margin: 0;
+ padding: 15px 0 5px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header a {
+ padding: 4px 0 0 10px;
+ display: inline-block;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header input.submit {
+ display: block;
+ clear: none;
+ float: left;
+ padding: 6px 8px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
+ background-image: url('../images/throbber.gif');
+ width: 128px;
+ height: 16px;
+ display: block;
+ clear: none;
+ float: right;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content form input[type='text'].error {
+ outline: 2px solid black;
+ outline-color: #cc0000;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.response div.block pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ padding: 10px;
+ font-size: 0.9em;
+ max-height: 400px;
+ overflow-y: auto;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading {
+ background-color: #f9f2e9;
+ border: 1px solid #f0e0ca;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading h3 span.http_method a {
+ background-color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #f0e0ca;
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li a {
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content {
+ background-color: #faf5ee;
+ border: 1px solid #f0e0ca;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content h4 {
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content div.sandbox_header a {
+ color: #dcb67f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading {
+ background-color: #fcffcd;
+ border: 1px solid black;
+ border-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ background-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #ffd20f;
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li a {
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content {
+ background-color: #fcffcd;
+ border: 1px solid black;
+ border-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content h4 {
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content div.sandbox_header a {
+ color: #6fc992;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading {
+ background-color: #f5e8e8;
+ border: 1px solid #e8c6c7;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ background-color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #e8c6c7;
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li a {
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content {
+ background-color: #f7eded;
+ border: 1px solid #e8c6c7;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content h4 {
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content div.sandbox_header a {
+ color: #c8787a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading {
+ background-color: #e7f6ec;
+ border: 1px solid #c3e8d1;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading h3 span.http_method a {
+ background-color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3e8d1;
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li a {
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content {
+ background-color: #ebf7f0;
+ border: 1px solid #c3e8d1;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content h4 {
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content div.sandbox_header a {
+ color: #6fc992;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading {
+ background-color: #FCE9E3;
+ border: 1px solid #F5D5C3;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 span.http_method a {
+ background-color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #f0cecb;
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li a {
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content {
+ background-color: #faf0ef;
+ border: 1px solid #f0cecb;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content h4 {
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content div.sandbox_header a {
+ color: #dcb67f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading {
+ background-color: #e7f0f7;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading h3 span.http_method a {
+ background-color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3d9ec;
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li a {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content h4 {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content div.sandbox_header a {
+ color: #6fa5d2;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading {
+ background-color: #e7f0f7;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading h3 span.http_method a {
+ background-color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3d9ec;
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li a {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content h4 {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content div.sandbox_header a {
+ color: #6fa5d2;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content {
+ border-top: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li.last {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:hover,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:active,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a.active {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap p#colophon {
+ margin: 0 15px 40px 15px;
+ padding: 10px 0;
+ font-size: 0.8em;
+ border-top: 1px solid #dddddd;
+ font-family: "Droid Sans", sans-serif;
+ color: #999999;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap p#colophon a {
+ text-decoration: none;
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap h3 {
+ color: black;
+ font-size: 1.1em;
+ padding: 10px 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap .markdown ol,
+.swagger-section .swagger-ui-wrap .markdown ul {
+ font-family: "Droid Sans", sans-serif;
+ margin: 5px 0 10px;
+ padding: 0 0 0 18px;
+ list-style-type: disc;
+}
+.swagger-section .swagger-ui-wrap form.form_box {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap form.form_box label {
+ color: #0f6ab4 !important;
+}
+.swagger-section .swagger-ui-wrap form.form_box input[type=submit] {
+ display: block;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap form.form_box p.weak {
+ font-size: 0.8em;
+}
+.swagger-section .swagger-ui-wrap form.form_box p {
+ font-size: 0.9em;
+ padding: 0 0 15px;
+ color: #7e7b6d;
+}
+.swagger-section .swagger-ui-wrap form.form_box p a {
+ color: #646257;
+}
+.swagger-section .swagger-ui-wrap form.form_box p strong {
+ color: black;
+}
+.swagger-section .title {
+ font-style: bold;
+}
+.swagger-section .secondary_form {
+ display: none;
+}
+.swagger-section .main_image {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+}
+.swagger-section .oauth_body {
+ margin-left: 100px;
+ margin-right: 100px;
+}
+.swagger-section .oauth_submit {
+ text-align: center;
+}
+.swagger-section .api-popup-dialog {
+ z-index: 10000;
+ position: absolute;
+ width: 500px;
+ background: #FFF;
+ padding: 20px;
+ border: 1px solid #ccc;
+ border-radius: 5px;
+ display: none;
+ font-size: 13px;
+ color: #777;
+}
+.swagger-section .api-popup-dialog .api-popup-title {
+ font-size: 24px;
+ padding: 10px 0;
+}
+.swagger-section .api-popup-dialog .api-popup-title {
+ font-size: 24px;
+ padding: 10px 0;
+}
+.swagger-section .api-popup-dialog p.error-msg {
+ padding-left: 5px;
+ padding-bottom: 5px;
+}
+.swagger-section .api-popup-dialog button.api-popup-authbtn {
+ height: 30px;
+}
+.swagger-section .api-popup-dialog button.api-popup-cancel {
+ height: 30px;
+}
+.swagger-section .api-popup-scopes {
+ padding: 10px 20px;
+}
+.swagger-section .api-popup-scopes li {
+ padding: 5px 0;
+ line-height: 20px;
+}
+.swagger-section .api-popup-scopes .api-scope-desc {
+ padding-left: 20px;
+ font-style: italic;
+}
+.swagger-section .api-popup-scopes li input {
+ position: relative;
+ top: 2px;
+}
+.swagger-section .api-popup-actions {
+ padding-top: 10px;
+}
+#header {
+ display: none;
+}
+.swagger-section .swagger-ui-wrap .model-signature pre {
+ max-height: none;
+}
+.swagger-section .swagger-ui-wrap .body-textarea {
+ width: 100px;
+}
+.swagger-section .swagger-ui-wrap input.parameter {
+ width: 100px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options {
+ display: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints {
+ display: block !important;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content {
+ display: block !important;
+}
diff --git a/catalog-be/src/main/resources/swagger/css/reset.css b/catalog-be/src/main/resources/swagger/css/reset.css
new file mode 100644
index 0000000000..b2b078943c
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/css/reset.css
@@ -0,0 +1,125 @@
+/* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */
+html,
+body,
+div,
+span,
+applet,
+object,
+iframe,
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+p,
+blockquote,
+pre,
+a,
+abbr,
+acronym,
+address,
+big,
+cite,
+code,
+del,
+dfn,
+em,
+img,
+ins,
+kbd,
+q,
+s,
+samp,
+small,
+strike,
+strong,
+sub,
+sup,
+tt,
+var,
+b,
+u,
+i,
+center,
+dl,
+dt,
+dd,
+ol,
+ul,
+li,
+fieldset,
+form,
+label,
+legend,
+table,
+caption,
+tbody,
+tfoot,
+thead,
+tr,
+th,
+td,
+article,
+aside,
+canvas,
+details,
+embed,
+figure,
+figcaption,
+footer,
+header,
+hgroup,
+menu,
+nav,
+output,
+ruby,
+section,
+summary,
+time,
+mark,
+audio,
+video {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-size: 100%;
+ font: inherit;
+ vertical-align: baseline;
+}
+/* HTML5 display-role reset for older browsers */
+article,
+aside,
+details,
+figcaption,
+figure,
+footer,
+header,
+hgroup,
+menu,
+nav,
+section {
+ display: block;
+}
+body {
+ line-height: 1;
+}
+ol,
+ul {
+ list-style: none;
+}
+blockquote,
+q {
+ quotes: none;
+}
+blockquote:before,
+blockquote:after,
+q:before,
+q:after {
+ content: '';
+ content: none;
+}
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
diff --git a/catalog-be/src/main/resources/swagger/css/screen.css b/catalog-be/src/main/resources/swagger/css/screen.css
new file mode 100644
index 0000000000..32b199b17b
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/css/screen.css
@@ -0,0 +1,1256 @@
+/* Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org> */
+.swagger-section pre code {
+ display: block;
+ padding: 0.5em;
+ background: #F0F0F0;
+}
+.swagger-section pre code,
+.swagger-section pre .subst,
+.swagger-section pre .tag .title,
+.swagger-section pre .lisp .title,
+.swagger-section pre .clojure .built_in,
+.swagger-section pre .nginx .title {
+ color: black;
+}
+.swagger-section pre .string,
+.swagger-section pre .title,
+.swagger-section pre .constant,
+.swagger-section pre .parent,
+.swagger-section pre .tag .value,
+.swagger-section pre .rules .value,
+.swagger-section pre .rules .value .number,
+.swagger-section pre .preprocessor,
+.swagger-section pre .ruby .symbol,
+.swagger-section pre .ruby .symbol .string,
+.swagger-section pre .aggregate,
+.swagger-section pre .template_tag,
+.swagger-section pre .django .variable,
+.swagger-section pre .smalltalk .class,
+.swagger-section pre .addition,
+.swagger-section pre .flow,
+.swagger-section pre .stream,
+.swagger-section pre .bash .variable,
+.swagger-section pre .apache .tag,
+.swagger-section pre .apache .cbracket,
+.swagger-section pre .tex .command,
+.swagger-section pre .tex .special,
+.swagger-section pre .erlang_repl .function_or_atom,
+.swagger-section pre .markdown .header {
+ color: #800;
+}
+.swagger-section pre .comment,
+.swagger-section pre .annotation,
+.swagger-section pre .template_comment,
+.swagger-section pre .diff .header,
+.swagger-section pre .chunk,
+.swagger-section pre .markdown .blockquote {
+ color: #888;
+}
+.swagger-section pre .number,
+.swagger-section pre .date,
+.swagger-section pre .regexp,
+.swagger-section pre .literal,
+.swagger-section pre .smalltalk .symbol,
+.swagger-section pre .smalltalk .char,
+.swagger-section pre .go .constant,
+.swagger-section pre .change,
+.swagger-section pre .markdown .bullet,
+.swagger-section pre .markdown .link_url {
+ color: #080;
+}
+.swagger-section pre .label,
+.swagger-section pre .javadoc,
+.swagger-section pre .ruby .string,
+.swagger-section pre .decorator,
+.swagger-section pre .filter .argument,
+.swagger-section pre .localvars,
+.swagger-section pre .array,
+.swagger-section pre .attr_selector,
+.swagger-section pre .important,
+.swagger-section pre .pseudo,
+.swagger-section pre .pi,
+.swagger-section pre .doctype,
+.swagger-section pre .deletion,
+.swagger-section pre .envvar,
+.swagger-section pre .shebang,
+.swagger-section pre .apache .sqbracket,
+.swagger-section pre .nginx .built_in,
+.swagger-section pre .tex .formula,
+.swagger-section pre .erlang_repl .reserved,
+.swagger-section pre .prompt,
+.swagger-section pre .markdown .link_label,
+.swagger-section pre .vhdl .attribute,
+.swagger-section pre .clojure .attribute,
+.swagger-section pre .coffeescript .property {
+ color: #8888ff;
+}
+.swagger-section pre .keyword,
+.swagger-section pre .id,
+.swagger-section pre .phpdoc,
+.swagger-section pre .title,
+.swagger-section pre .built_in,
+.swagger-section pre .aggregate,
+.swagger-section pre .css .tag,
+.swagger-section pre .javadoctag,
+.swagger-section pre .phpdoc,
+.swagger-section pre .yardoctag,
+.swagger-section pre .smalltalk .class,
+.swagger-section pre .winutils,
+.swagger-section pre .bash .variable,
+.swagger-section pre .apache .tag,
+.swagger-section pre .go .typename,
+.swagger-section pre .tex .command,
+.swagger-section pre .markdown .strong,
+.swagger-section pre .request,
+.swagger-section pre .status {
+ font-weight: bold;
+}
+.swagger-section pre .markdown .emphasis {
+ font-style: italic;
+}
+.swagger-section pre .nginx .built_in {
+ font-weight: normal;
+}
+.swagger-section pre .coffeescript .javascript,
+.swagger-section pre .javascript .xml,
+.swagger-section pre .tex .formula,
+.swagger-section pre .xml .javascript,
+.swagger-section pre .xml .vbscript,
+.swagger-section pre .xml .css,
+.swagger-section pre .xml .cdata {
+ opacity: 0.5;
+}
+.swagger-section .swagger-ui-wrap {
+ line-height: 1;
+ font-family: "Droid Sans", sans-serif;
+ max-width: 960px;
+ margin-left: auto;
+ margin-right: auto;
+}
+.swagger-section .swagger-ui-wrap b,
+.swagger-section .swagger-ui-wrap strong {
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap q,
+.swagger-section .swagger-ui-wrap blockquote {
+ quotes: none;
+}
+.swagger-section .swagger-ui-wrap p {
+ line-height: 1.4em;
+ padding: 0 0 10px;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap q:before,
+.swagger-section .swagger-ui-wrap q:after,
+.swagger-section .swagger-ui-wrap blockquote:before,
+.swagger-section .swagger-ui-wrap blockquote:after {
+ content: none;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu h1,
+.swagger-section .swagger-ui-wrap .heading_with_menu h2,
+.swagger-section .swagger-ui-wrap .heading_with_menu h3,
+.swagger-section .swagger-ui-wrap .heading_with_menu h4,
+.swagger-section .swagger-ui-wrap .heading_with_menu h5,
+.swagger-section .swagger-ui-wrap .heading_with_menu h6 {
+ display: block;
+ clear: none;
+ float: left;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ box-sizing: border-box;
+ width: 60%;
+}
+.swagger-section .swagger-ui-wrap table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+.swagger-section .swagger-ui-wrap table thead tr th {
+ padding: 5px;
+ font-size: 0.9em;
+ color: #666666;
+ border-bottom: 1px solid #999999;
+}
+.swagger-section .swagger-ui-wrap table tbody tr:last-child td {
+ border-bottom: none;
+}
+.swagger-section .swagger-ui-wrap table tbody tr.offset {
+ background-color: #f0f0f0;
+}
+.swagger-section .swagger-ui-wrap table tbody tr td {
+ padding: 6px;
+ font-size: 0.9em;
+ border-bottom: 1px solid #cccccc;
+ vertical-align: top;
+ line-height: 1.3em;
+}
+.swagger-section .swagger-ui-wrap ol {
+ margin: 0px 0 10px;
+ padding: 0 0 0 18px;
+ list-style-type: decimal;
+}
+.swagger-section .swagger-ui-wrap ol li {
+ padding: 5px 0px;
+ font-size: 0.9em;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap ol,
+.swagger-section .swagger-ui-wrap ul {
+ list-style: none;
+}
+.swagger-section .swagger-ui-wrap h1 a,
+.swagger-section .swagger-ui-wrap h2 a,
+.swagger-section .swagger-ui-wrap h3 a,
+.swagger-section .swagger-ui-wrap h4 a,
+.swagger-section .swagger-ui-wrap h5 a,
+.swagger-section .swagger-ui-wrap h6 a {
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap h1 a:hover,
+.swagger-section .swagger-ui-wrap h2 a:hover,
+.swagger-section .swagger-ui-wrap h3 a:hover,
+.swagger-section .swagger-ui-wrap h4 a:hover,
+.swagger-section .swagger-ui-wrap h5 a:hover,
+.swagger-section .swagger-ui-wrap h6 a:hover {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap h1 span.divider,
+.swagger-section .swagger-ui-wrap h2 span.divider,
+.swagger-section .swagger-ui-wrap h3 span.divider,
+.swagger-section .swagger-ui-wrap h4 span.divider,
+.swagger-section .swagger-ui-wrap h5 span.divider,
+.swagger-section .swagger-ui-wrap h6 span.divider {
+ color: #aaaaaa;
+}
+.swagger-section .swagger-ui-wrap a {
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap a img {
+ border: none;
+}
+.swagger-section .swagger-ui-wrap article,
+.swagger-section .swagger-ui-wrap aside,
+.swagger-section .swagger-ui-wrap details,
+.swagger-section .swagger-ui-wrap figcaption,
+.swagger-section .swagger-ui-wrap figure,
+.swagger-section .swagger-ui-wrap footer,
+.swagger-section .swagger-ui-wrap header,
+.swagger-section .swagger-ui-wrap hgroup,
+.swagger-section .swagger-ui-wrap menu,
+.swagger-section .swagger-ui-wrap nav,
+.swagger-section .swagger-ui-wrap section,
+.swagger-section .swagger-ui-wrap summary {
+ display: block;
+}
+.swagger-section .swagger-ui-wrap pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #fcf6db;
+ border: 1px solid #e5e0c6;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap pre code {
+ line-height: 1.6em;
+ background: none;
+}
+.swagger-section .swagger-ui-wrap .content > .content-type > div > label {
+ clear: both;
+ display: block;
+ color: #0F6AB4;
+ font-size: 1.1em;
+ margin: 0;
+ padding: 15px 0 5px;
+}
+.swagger-section .swagger-ui-wrap .content pre {
+ font-size: 12px;
+ margin-top: 5px;
+ padding: 5px;
+}
+.swagger-section .swagger-ui-wrap .icon-btn {
+ cursor: pointer;
+}
+.swagger-section .swagger-ui-wrap .info_title {
+ padding-bottom: 10px;
+ font-weight: bold;
+ font-size: 25px;
+}
+.swagger-section .swagger-ui-wrap p.big,
+.swagger-section .swagger-ui-wrap div.big p {
+ font-size: 1em;
+ margin-bottom: 10px;
+}
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.string input,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.url input,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.text textarea,
+.swagger-section .swagger-ui-wrap form.fullwidth ol li.numeric input {
+ width: 500px !important;
+}
+.swagger-section .swagger-ui-wrap .info_license {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_tos {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .message-fail {
+ color: #cc0000;
+}
+.swagger-section .swagger-ui-wrap .info_url {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_email {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_name {
+ padding-bottom: 5px;
+}
+.swagger-section .swagger-ui-wrap .info_description {
+ padding-bottom: 10px;
+ font-size: 15px;
+}
+.swagger-section .swagger-ui-wrap .markdown ol li,
+.swagger-section .swagger-ui-wrap .markdown ul li {
+ padding: 3px 0px;
+ line-height: 1.4em;
+ color: #333333;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input {
+ display: block;
+ padding: 4px;
+ width: auto;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input.title,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input.title,
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input.title {
+ font-size: 1.3em;
+}
+.swagger-section .swagger-ui-wrap table.fullwidth {
+ width: 100%;
+}
+.swagger-section .swagger-ui-wrap .model-signature {
+ font-family: "Droid Sans", sans-serif;
+ font-size: 1em;
+ line-height: 1.5em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav a {
+ text-decoration: none;
+ color: #AAA;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav a:hover {
+ text-decoration: underline;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-nav .selected {
+ color: black;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propType {
+ color: #5555aa;
+}
+.swagger-section .swagger-ui-wrap .model-signature pre:hover {
+ background-color: #ffffdd;
+}
+.swagger-section .swagger-ui-wrap .model-signature pre {
+ font-size: .85em;
+ line-height: 1.2em;
+ overflow: auto;
+ max-height: 200px;
+ cursor: pointer;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav {
+ display: block;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li:last-child {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li {
+ float: left;
+ margin: 0 5px 5px 0;
+ padding: 2px 5px 2px 0;
+ border-right: 1px solid #ddd;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propOpt {
+ color: #555;
+}
+.swagger-section .swagger-ui-wrap .model-signature .snippet small {
+ font-size: 0.75em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propOptKey {
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .strong {
+ font-weight: bold;
+ color: #000;
+ font-size: .9em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description div {
+ font-size: 0.9em;
+ line-height: 1.5em;
+ margin-left: 1em;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .stronger {
+ font-weight: bold;
+ color: #000;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper {
+ border-spacing: 0;
+ position: absolute;
+ background-color: #ffffff;
+ border: 1px solid #bbbbbb;
+ display: none;
+ font-size: 11px;
+ max-width: 400px;
+ line-height: 30px;
+ color: black;
+ padding: 5px;
+ margin-left: 10px;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th {
+ text-align: center;
+ background-color: #eeeeee;
+ border: 1px solid #bbbbbb;
+ font-size: 11px;
+ color: #666666;
+ font-weight: bold;
+ padding: 5px;
+ line-height: 15px;
+}
+.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .model-signature .propName {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .model-signature .signature-container {
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap .body-textarea {
+ width: 300px;
+ height: 100px;
+ border: 1px solid #aaa;
+}
+.swagger-section .swagger-ui-wrap .markdown p code,
+.swagger-section .swagger-ui-wrap .markdown li code {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #f0f0f0;
+ color: black;
+ padding: 1px 3px;
+}
+.swagger-section .swagger-ui-wrap .required {
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap input.parameter {
+ width: 300px;
+ border: 1px solid #aaa;
+}
+.swagger-section .swagger-ui-wrap h1 {
+ color: black;
+ font-size: 1.5em;
+ line-height: 1.3em;
+ padding: 10px 0 10px 0;
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap .heading_with_menu ul {
+ display: block;
+ clear: none;
+ float: right;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ box-sizing: border-box;
+ margin-top: 10px;
+}
+.swagger-section .swagger-ui-wrap h2 {
+ color: black;
+ font-size: 1.3em;
+ padding: 10px 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap h2 a {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap h2 span.sub {
+ font-size: 0.7em;
+ color: #999999;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap h2 span.sub a {
+ color: #777777;
+}
+.swagger-section .swagger-ui-wrap span.weak {
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap .message-success {
+ color: #89BF04;
+}
+.swagger-section .swagger-ui-wrap caption,
+.swagger-section .swagger-ui-wrap th,
+.swagger-section .swagger-ui-wrap td {
+ text-align: left;
+ font-weight: normal;
+ vertical-align: middle;
+}
+.swagger-section .swagger-ui-wrap .code {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.text textarea {
+ font-family: "Droid Sans", sans-serif;
+ height: 250px;
+ padding: 4px;
+ display: block;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.select select {
+ display: block;
+ clear: both;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean label {
+ display: block;
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean input {
+ display: block;
+ float: left;
+ clear: none;
+ margin: 0 5px 0 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.required label {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label {
+ display: block;
+ clear: both;
+ width: auto;
+ padding: 0 0 3px;
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label abbr {
+ padding-left: 3px;
+ color: #888888;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li p.inline-hints {
+ margin-left: 0;
+ font-style: italic;
+ font-size: 0.9em;
+ margin: 0;
+}
+.swagger-section .swagger-ui-wrap form.formtastic fieldset.buttons {
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap span.blank,
+.swagger-section .swagger-ui-wrap span.empty {
+ color: #888888;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap .markdown h3 {
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap .markdown h4 {
+ color: #666666;
+}
+.swagger-section .swagger-ui-wrap .markdown pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ background-color: #fcf6db;
+ border: 1px solid #e5e0c6;
+ padding: 10px;
+ margin: 0 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap .markdown pre code {
+ line-height: 1.6em;
+}
+.swagger-section .swagger-ui-wrap div.gist {
+ margin: 20px 0 25px 0 !important;
+}
+.swagger-section .swagger-ui-wrap ul#resources {
+ font-family: "Droid Sans", sans-serif;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource {
+ border-bottom: 1px solid #dddddd;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading h2 a,
+.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading h2 a {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading ul.options li a,
+.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading ul.options li a {
+ color: #555555;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource:last-child {
+ border-bottom: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading {
+ border: 1px solid transparent;
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options {
+ overflow: hidden;
+ padding: 0;
+ display: block;
+ clear: none;
+ float: right;
+ margin: 14px 10px 0 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li {
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 2px 10px;
+ border-right: 1px solid #dddddd;
+ color: #666666;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a {
+ color: #aaaaaa;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover {
+ text-decoration: underline;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:active,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a.active {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.last {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 {
+ color: #999999;
+ padding-left: 0;
+ display: block;
+ clear: none;
+ float: left;
+ font-family: "Droid Sans", sans-serif;
+ font-weight: bold;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a {
+ color: #999999;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+ margin: 0 0 10px;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 {
+ display: block;
+ clear: none;
+ float: left;
+ width: auto;
+ margin: 0;
+ padding: 0;
+ line-height: 1.1em;
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path {
+ padding-left: 10px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a {
+ color: black;
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a:hover {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ text-decoration: none;
+ color: white;
+ display: inline-block;
+ width: 50px;
+ font-size: 0.7em;
+ text-align: center;
+ padding: 7px 0 4px;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ -o-border-radius: 2px;
+ -ms-border-radius: 2px;
+ -khtml-border-radius: 2px;
+ border-radius: 2px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span {
+ margin: 0;
+ padding: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options {
+ overflow: hidden;
+ padding: 0;
+ display: block;
+ clear: none;
+ float: right;
+ margin: 6px 10px 0 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li {
+ float: left;
+ clear: none;
+ margin: 0;
+ padding: 2px 10px;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
+ text-decoration: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
+ color: black;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content {
+ border-top: none;
+ padding: 10px;
+ -moz-border-radius-bottomleft: 6px;
+ -webkit-border-bottom-left-radius: 6px;
+ -o-border-bottom-left-radius: 6px;
+ -ms-border-bottom-left-radius: 6px;
+ -khtml-border-bottom-left-radius: 6px;
+ border-bottom-left-radius: 6px;
+ -moz-border-radius-bottomright: 6px;
+ -webkit-border-bottom-right-radius: 6px;
+ -o-border-bottom-right-radius: 6px;
+ -ms-border-bottom-right-radius: 6px;
+ -khtml-border-bottom-right-radius: 6px;
+ border-bottom-right-radius: 6px;
+ margin: 0 0 20px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content h4 {
+ font-size: 1.1em;
+ margin: 0;
+ padding: 15px 0 5px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header {
+ float: none;
+ clear: both;
+ overflow: hidden;
+ display: block;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header a {
+ padding: 4px 0 0 10px;
+ display: inline-block;
+ font-size: 0.9em;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header input.submit {
+ display: block;
+ clear: none;
+ float: left;
+ padding: 6px 8px;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber {
+ background-image: url('../images/throbber.gif');
+ width: 128px;
+ height: 16px;
+ display: block;
+ clear: none;
+ float: right;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content form input[type='text'].error {
+ outline: 2px solid black;
+ outline-color: #cc0000;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.response div.block pre {
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
+ padding: 10px;
+ font-size: 0.9em;
+ max-height: 400px;
+ overflow-y: auto;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading {
+ background-color: #f9f2e9;
+ border: 1px solid #f0e0ca;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading h3 span.http_method a {
+ background-color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #f0e0ca;
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li a {
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content {
+ background-color: #faf5ee;
+ border: 1px solid #f0e0ca;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content h4 {
+ color: #c5862b;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content div.sandbox_header a {
+ color: #dcb67f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading {
+ background-color: #fcffcd;
+ border: 1px solid black;
+ border-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ background-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #ffd20f;
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li a {
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content {
+ background-color: #fcffcd;
+ border: 1px solid black;
+ border-color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content h4 {
+ color: #ffd20f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content div.sandbox_header a {
+ color: #6fc992;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading {
+ background-color: #f5e8e8;
+ border: 1px solid #e8c6c7;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading h3 span.http_method a {
+ text-transform: uppercase;
+ background-color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #e8c6c7;
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li a {
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content {
+ background-color: #f7eded;
+ border: 1px solid #e8c6c7;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content h4 {
+ color: #a41e22;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content div.sandbox_header a {
+ color: #c8787a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading {
+ background-color: #e7f6ec;
+ border: 1px solid #c3e8d1;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading h3 span.http_method a {
+ background-color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3e8d1;
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li a {
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content {
+ background-color: #ebf7f0;
+ border: 1px solid #c3e8d1;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content h4 {
+ color: #10a54a;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content div.sandbox_header a {
+ color: #6fc992;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading {
+ background-color: #FCE9E3;
+ border: 1px solid #F5D5C3;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 span.http_method a {
+ background-color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #f0cecb;
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li a {
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content {
+ background-color: #faf0ef;
+ border: 1px solid #f0cecb;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content h4 {
+ color: #D38042;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content div.sandbox_header a {
+ color: #dcb67f;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading {
+ background-color: #e7f0f7;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading h3 span.http_method a {
+ background-color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3d9ec;
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li a {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content h4 {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content div.sandbox_header a {
+ color: #6fa5d2;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading {
+ background-color: #e7f0f7;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading h3 span.http_method a {
+ background-color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li {
+ border-right: 1px solid #dddddd;
+ border-right-color: #c3d9ec;
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li a {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content h4 {
+ color: #0f6ab4;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content div.sandbox_header a {
+ color: #6fa5d2;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content {
+ border-top: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li:last-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li.last,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li.last {
+ padding-right: 0;
+ border-right: none;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:hover,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:active,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a.active {
+ text-decoration: underline;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations:first-child,
+.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations.first {
+ padding-left: 0;
+}
+.swagger-section .swagger-ui-wrap p#colophon {
+ margin: 0 15px 40px 15px;
+ padding: 10px 0;
+ font-size: 0.8em;
+ border-top: 1px solid #dddddd;
+ font-family: "Droid Sans", sans-serif;
+ color: #999999;
+ font-style: italic;
+}
+.swagger-section .swagger-ui-wrap p#colophon a {
+ text-decoration: none;
+ color: #547f00;
+}
+.swagger-section .swagger-ui-wrap h3 {
+ color: black;
+ font-size: 1.1em;
+ padding: 10px 0 10px 0;
+}
+.swagger-section .swagger-ui-wrap .markdown ol,
+.swagger-section .swagger-ui-wrap .markdown ul {
+ font-family: "Droid Sans", sans-serif;
+ margin: 5px 0 10px;
+ padding: 0 0 0 18px;
+ list-style-type: disc;
+}
+.swagger-section .swagger-ui-wrap form.form_box {
+ background-color: #ebf3f9;
+ border: 1px solid #c3d9ec;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap form.form_box label {
+ color: #0f6ab4 !important;
+}
+.swagger-section .swagger-ui-wrap form.form_box input[type=submit] {
+ display: block;
+ padding: 10px;
+}
+.swagger-section .swagger-ui-wrap form.form_box p.weak {
+ font-size: 0.8em;
+}
+.swagger-section .swagger-ui-wrap form.form_box p {
+ font-size: 0.9em;
+ padding: 0 0 15px;
+ color: #7e7b6d;
+}
+.swagger-section .swagger-ui-wrap form.form_box p a {
+ color: #646257;
+}
+.swagger-section .swagger-ui-wrap form.form_box p strong {
+ color: black;
+}
+.swagger-section .title {
+ font-style: bold;
+}
+.swagger-section .secondary_form {
+ display: none;
+}
+.swagger-section .main_image {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+}
+.swagger-section .oauth_body {
+ margin-left: 100px;
+ margin-right: 100px;
+}
+.swagger-section .oauth_submit {
+ text-align: center;
+}
+.swagger-section .api-popup-dialog {
+ z-index: 10000;
+ position: absolute;
+ width: 500px;
+ background: #FFF;
+ padding: 20px;
+ border: 1px solid #ccc;
+ border-radius: 5px;
+ display: none;
+ font-size: 13px;
+ color: #777;
+}
+.swagger-section .api-popup-dialog .api-popup-title {
+ font-size: 24px;
+ padding: 10px 0;
+}
+.swagger-section .api-popup-dialog .api-popup-title {
+ font-size: 24px;
+ padding: 10px 0;
+}
+.swagger-section .api-popup-dialog p.error-msg {
+ padding-left: 5px;
+ padding-bottom: 5px;
+}
+.swagger-section .api-popup-dialog button.api-popup-authbtn {
+ height: 30px;
+}
+.swagger-section .api-popup-dialog button.api-popup-cancel {
+ height: 30px;
+}
+.swagger-section .api-popup-scopes {
+ padding: 10px 20px;
+}
+.swagger-section .api-popup-scopes li {
+ padding: 5px 0;
+ line-height: 20px;
+}
+.swagger-section .api-popup-scopes .api-scope-desc {
+ padding-left: 20px;
+ font-style: italic;
+}
+.swagger-section .api-popup-scopes li input {
+ position: relative;
+ top: 2px;
+}
+.swagger-section .api-popup-actions {
+ padding-top: 10px;
+}
+.swagger-section .access {
+ float: right;
+}
+.swagger-section .auth {
+ float: right;
+}
+.swagger-section #api_information_panel {
+ position: absolute;
+ background: #FFF;
+ border: 1px solid #ccc;
+ border-radius: 5px;
+ display: none;
+ font-size: 13px;
+ max-width: 300px;
+ line-height: 30px;
+ color: black;
+ padding: 5px;
+}
+.swagger-section #api_information_panel p .api-msg-enabled {
+ color: green;
+}
+.swagger-section #api_information_panel p .api-msg-disabled {
+ color: red;
+}
+.swagger-section .api-ic {
+ height: 18px;
+ vertical-align: middle;
+ display: inline-block;
+ background: url(../images/explorer_icons.png) no-repeat;
+}
+.swagger-section .ic-info {
+ background-position: 0 0;
+ width: 18px;
+ margin-top: -7px;
+ margin-left: 4px;
+}
+.swagger-section .ic-warning {
+ background-position: -60px 0;
+ width: 18px;
+ margin-top: -7px;
+ margin-left: 4px;
+}
+.swagger-section .ic-error {
+ background-position: -30px 0;
+ width: 18px;
+ margin-top: -7px;
+ margin-left: 4px;
+}
+.swagger-section .ic-off {
+ background-position: -90px 0;
+ width: 58px;
+ margin-top: -4px;
+ cursor: pointer;
+}
+.swagger-section .ic-on {
+ background-position: -160px 0;
+ width: 58px;
+ margin-top: -4px;
+ cursor: pointer;
+}
+.swagger-section #header {
+ background-color: #89bf04;
+ padding: 14px;
+}
+.swagger-section #header a#logo {
+ font-size: 1.5em;
+ font-weight: bold;
+ text-decoration: none;
+ background: transparent url(../images/logo_small.png) no-repeat left center;
+ padding: 20px 0 20px 40px;
+ color: white;
+}
+.swagger-section #header form#api_selector {
+ display: block;
+ clear: none;
+ float: right;
+}
+.swagger-section #header form#api_selector .input {
+ display: block;
+ clear: none;
+ float: left;
+ margin: 0 10px 0 0;
+}
+.swagger-section #header form#api_selector .input input#input_apiKey {
+ width: 200px;
+}
+.swagger-section #header form#api_selector .input input#input_baseUrl {
+ width: 400px;
+}
+.swagger-section #header form#api_selector .input a#explore {
+ display: block;
+ text-decoration: none;
+ font-weight: bold;
+ padding: 6px 8px;
+ font-size: 0.9em;
+ color: white;
+ background-color: #547f00;
+ -moz-border-radius: 4px;
+ -webkit-border-radius: 4px;
+ -o-border-radius: 4px;
+ -ms-border-radius: 4px;
+ -khtml-border-radius: 4px;
+ border-radius: 4px;
+}
+.swagger-section #header form#api_selector .input a#explore:hover {
+ background-color: #547f00;
+}
+.swagger-section #header form#api_selector .input input {
+ font-size: 0.9em;
+ padding: 3px;
+ margin: 0;
+}
+.swagger-section #content_message {
+ margin: 10px 15px;
+ font-style: italic;
+ color: #999999;
+}
+.swagger-section #message-bar {
+ min-height: 30px;
+ text-align: center;
+ padding-top: 10px;
+}
diff --git a/catalog-be/src/main/resources/swagger/css/typography.css b/catalog-be/src/main/resources/swagger/css/typography.css
new file mode 100644
index 0000000000..27c3751ac2
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/css/typography.css
@@ -0,0 +1,26 @@
+/* droid-sans-regular - latin */
+@font-face {
+ font-family: 'Droid Sans';
+ font-style: normal;
+ font-weight: 400;
+ src: url('../fonts/droid-sans-v6-latin-regular.eot'); /* IE9 Compat Modes */
+ src: local('Droid Sans'), local('DroidSans'),
+ url('../fonts/droid-sans-v6-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
+ url('../fonts/droid-sans-v6-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
+ url('../fonts/droid-sans-v6-latin-regular.woff') format('woff'), /* Modern Browsers */
+ url('../fonts/droid-sans-v6-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
+ url('../fonts/droid-sans-v6-latin-regular.svg#DroidSans') format('svg'); /* Legacy iOS */
+}
+/* droid-sans-700 - latin */
+@font-face {
+ font-family: 'Droid Sans';
+ font-style: normal;
+ font-weight: 700;
+ src: url('../fonts/droid-sans-v6-latin-700.eot'); /* IE9 Compat Modes */
+ src: local('Droid Sans Bold'), local('DroidSans-Bold'),
+ url('../fonts/droid-sans-v6-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
+ url('../fonts/droid-sans-v6-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
+ url('../fonts/droid-sans-v6-latin-700.woff') format('woff'), /* Modern Browsers */
+ url('../fonts/droid-sans-v6-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
+ url('../fonts/droid-sans-v6-latin-700.svg#DroidSans') format('svg'); /* Legacy iOS */
+}
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.eot b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.eot
new file mode 100644
index 0000000000..d8524983ad
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.eot
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.svg b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.svg
new file mode 100644
index 0000000000..a54bbbbf25
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.svg
@@ -0,0 +1,411 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg">
+<defs >
+<font id="DroidSans" horiz-adv-x="1123" ><font-face
+ font-family="Droid Sans"
+ units-per-em="2048"
+ panose-1="2 11 8 6 3 8 4 2 2 4"
+ ascent="1907"
+ descent="-492"
+ alphabetic="0" />
+<glyph unicode=" " glyph-name="space" horiz-adv-x="532" />
+<glyph unicode="!" glyph-name="exclam" horiz-adv-x="586" d="M416 485H172L121 1462H467L416 485ZM117 143Q117 190 130 222T168 275T224 304T293 313Q328 313 359 304T415 275T453 223T467 143Q467 98 453 66T415 13T360 -17T293 -27Q256 -27 224 -18T168 13T131
+66T117 143Z" />
+<glyph unicode="&quot;" glyph-name="quotedbl" horiz-adv-x="967" d="M412 1462L371 934H174L133 1462H412ZM834 1462L793 934H596L555 1462H834Z" />
+<glyph unicode="#" glyph-name="numbersign" horiz-adv-x="1323" d="M999 844L952 612H1210V406H913L836 0H616L694 406H500L424 0H209L283 406H45V612H322L369 844H117V1053H406L483 1460H702L625 1053H823L901 1460H1116L1038 1053H1278V844H999ZM539 612H735L782
+844H586L539 612Z" />
+<glyph unicode="$" glyph-name="dollar" horiz-adv-x="1128" d="M1061 457Q1061 382 1035 318T956 206T825 127T645 86V-119H508V82Q442 84 386 90T281 107T188 133T100 168V432Q142 411 191 392T294 358T401 331T508 317V635Q500 638 491 642Q483 645 475 648T461
+653Q370 688 302 726T189 811T121 915T98 1044Q98 1119 126 1180T208 1287T337 1361T508 1399V1556H645V1405Q732 1400 823 1380T1014 1317L913 1083Q848 1109 778 1129T645 1155V862L684 848Q779 813 850 776T968 693T1038 590T1061 457ZM760 451Q760 475 754
+493T733 526T698 553T645 580V328Q704 337 732 367T760 451ZM399 1051Q399 1004 425 973T508 920V1153Q454 1147 427 1123T399 1051Z" />
+<glyph unicode="%" glyph-name="percent" horiz-adv-x="1804" d="M315 1024Q315 897 337 835T410 772Q459 772 482 834T506 1024Q506 1274 410 1274Q360 1274 338 1213T315 1024ZM758 1026Q758 918 738 832T674 687T565 597T408 565Q323 565 259 596T151 687T85
+832T63 1026Q63 1134 83 1219T145 1362T253 1452T408 1483Q494 1483 559 1452T669 1363T735 1219T758 1026ZM1425 1462L614 0H375L1186 1462H1425ZM1298 440Q1298 313 1320 251T1393 188Q1442 188 1465 250T1489 440Q1489 690 1393 690Q1343 690 1321 629T1298
+440ZM1741 442Q1741 334 1721 249T1657 104T1548 14T1391 -18Q1306 -18 1242 13T1135 104T1069 248T1047 442Q1047 550 1067 635T1129 778T1236 868T1391 899Q1477 899 1542 868T1652 779T1718 635T1741 442Z" />
+<glyph unicode="&amp;" glyph-name="ampersand" horiz-adv-x="1479" d="M1475 0H1098L1001 100Q921 45 825 13T612 -20Q492 -20 395 10T228 94T120 225T82 395Q82 472 100 532T153 642T235 731T344 807Q306 853 280 895T237 979T214 1062T207 1149Q207 1227 237
+1288T322 1393T452 1460T618 1483Q704 1483 776 1462T901 1401T984 1301T1014 1165Q1014 1096 992 1039T931 932T842 842T731 766L991 498Q1026 564 1052 637T1098 784H1415Q1400 727 1380 664T1332 538T1270 411T1192 291L1475 0ZM403 424Q403 380 419 345T463
+286T530 249T614 236Q674 236 725 251T819 295L510 625Q459 583 431 535T403 424ZM731 1124Q731 1155 721 1176T695 1212T658 1232T616 1239Q594 1239 572 1233T531 1214T501 1178T489 1122Q489 1070 512 1024T575 932Q652 976 691 1020T731 1124Z" />
+<glyph unicode="&apos;" glyph-name="quotesingle" horiz-adv-x="545" d="M412 1462L371 934H174L133 1462H412Z" />
+<glyph unicode="(" glyph-name="parenleft" horiz-adv-x="694" d="M82 561Q82 686 100 807T155 1043T248 1263T383 1462H633Q492 1269 420 1038T348 563Q348 444 366 326T420 95T509 -124T631 -324H383Q305 -234 249 -131T155 84T100 317T82 561Z" />
+<glyph unicode=")" glyph-name="parenright" horiz-adv-x="694" d="M612 561Q612 437 594 317T539 85T446 -131T311 -324H63Q132 -230 185 -124T274 95T328 326T346 563Q346 807 274 1038T61 1462H311Q389 1369 445 1264T539 1044T594 808T612 561Z" />
+<glyph unicode="*" glyph-name="asterisk" horiz-adv-x="1116" d="M688 1556L647 1188L1020 1292L1053 1040L713 1016L936 719L709 598L553 911L416 600L180 719L401 1016L63 1042L102 1292L467 1188L426 1556H688Z" />
+<glyph unicode="+" glyph-name="plus" horiz-adv-x="1128" d="M455 612H88V831H455V1200H674V831H1040V612H674V248H455V612Z" />
+<glyph unicode="," glyph-name="comma" horiz-adv-x="594" d="M459 215Q445 161 426 100T383 -23T334 -146T283 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H444L459 215Z" />
+<glyph unicode="-" glyph-name="hyphen" horiz-adv-x="659" d="M61 424V674H598V424H61Z" />
+<glyph unicode="." glyph-name="period" horiz-adv-x="584" d="M117 143Q117 190 130 222T168 275T224 304T293 313Q328 313 359 304T415 275T453 223T467 143Q467 98 453 66T415 13T360 -17T293 -27Q256 -27 224 -18T168 13T131 66T117 143Z" />
+<glyph unicode="/" glyph-name="slash" horiz-adv-x="846" d="M836 1462L291 0H14L559 1462H836Z" />
+<glyph unicode="0" glyph-name="zero" horiz-adv-x="1128" d="M1065 731Q1065 554 1038 415T950 179T794 31T563 -20Q436 -20 342 31T186 179T94 415T63 731Q63 908 90 1048T178 1285T333 1433T563 1485Q689 1485 783 1434T940 1286T1034 1049T1065 731ZM371 731Q371
+481 414 355T563 229Q667 229 712 354T758 731Q758 982 713 1108T563 1235Q510 1235 474 1203T414 1108T381 951T371 731Z" />
+<glyph unicode="1" glyph-name="one" horiz-adv-x="1128" d="M817 0H508V846Q508 872 508 908T510 984T513 1064T516 1137Q511 1131 499 1119T472 1093T441 1063T410 1036L242 901L92 1087L563 1462H817V0Z" />
+<glyph unicode="2" glyph-name="two" horiz-adv-x="1128" d="M1063 0H82V215L426 586Q491 656 544 715T635 830T694 944T715 1069Q715 1143 671 1184T551 1225Q472 1225 399 1186T246 1075L78 1274Q123 1315 172 1352T280 1419T410 1465T569 1483Q674 1483 757
+1454T900 1372T990 1242T1022 1071Q1022 985 992 907T910 753T790 603T643 451L467 274V260H1063V0Z" />
+<glyph unicode="3" glyph-name="three" horiz-adv-x="1128" d="M1006 1135Q1006 1059 982 999T915 893T815 817T690 770V764Q867 742 958 657T1049 426Q1049 330 1015 249T909 107T729 14T473 -20Q355 -20 251 -1T57 59V322Q102 298 152 280T252 250T350 231T442
+225Q528 225 585 241T676 286T724 355T739 444Q739 489 721 525T661 587T552 627T387 641H283V858H385Q477 858 538 874T635 919T687 986T702 1067Q702 1145 654 1189T500 1233Q452 1233 411 1224T334 1200T269 1168T215 1133L59 1339Q101 1370 150 1396T258 1441T383
+1472T526 1483Q634 1483 722 1460T874 1392T971 1283T1006 1135Z" />
+<glyph unicode="4" glyph-name="four" horiz-adv-x="1128" d="M1085 303H909V0H608V303H4V518L625 1462H909V543H1085V303ZM608 543V791Q608 804 608 828T610 884T612 948T615 1011T618 1063T621 1096H612Q594 1054 572 1007T520 913L276 543H608Z" />
+<glyph unicode="5" glyph-name="five" horiz-adv-x="1128" d="M598 934Q692 934 773 905T914 820T1008 681T1042 489Q1042 370 1005 276T896 116T718 15T473 -20Q418 -20 364 -15T261 -1T167 24T86 59V326Q121 306 167 289T262 259T362 239T457 231Q591 231 661
+286T731 463Q731 571 663 627T451 684Q425 684 396 681T338 673T283 663T238 651L115 717L170 1462H942V1200H438L414 913Q446 920 488 927T598 934Z" />
+<glyph unicode="6" glyph-name="six" horiz-adv-x="1128" d="M76 621Q76 726 87 830T128 1029T208 1207T336 1349T522 1444T776 1479Q797 1479 822 1478T872 1476T922 1471T965 1464V1217Q927 1226 885 1231T799 1237Q664 1237 577 1204T439 1110T367 966T340
+780H352Q372 816 400 847T467 901T552 937T659 950Q754 950 830 919T958 829T1039 684T1067 487Q1067 368 1034 274T938 115T788 15T590 -20Q482 -20 388 18T225 136T116 335T76 621ZM584 227Q625 227 658 242T716 289T754 369T768 483Q768 590 724 651T588 713Q542
+713 504 695T439 648T398 583T383 510Q383 459 395 409T433 318T496 252T584 227Z" />
+<glyph unicode="7" glyph-name="seven" horiz-adv-x="1128" d="M207 0L727 1200H55V1460H1063V1266L530 0H207Z" />
+<glyph unicode="8" glyph-name="eight" horiz-adv-x="1128" d="M565 1481Q656 1481 737 1459T879 1393T976 1283T1012 1128Q1012 1062 992 1009T937 912T854 834T750 772Q808 741 863 703T962 618T1031 511T1057 379Q1057 288 1021 214T920 88T765 8T565 -20Q447
+-20 355 7T200 84T105 207T72 371Q72 446 94 506T154 614T243 699T352 764Q303 795 260 831T186 912T136 1011T117 1130Q117 1217 153 1282T252 1392T395 1459T565 1481ZM358 389Q358 349 371 316T409 258T473 221T561 207Q666 207 718 256T770 387Q770 429 753
+462T708 524T645 577T575 623L553 637Q509 615 473 590T412 534T372 467T358 389ZM563 1255Q530 1255 502 1245T453 1216T420 1169T408 1106Q408 1064 420 1034T454 980T504 938T565 901Q596 917 624 936T673 979T708 1035T721 1106Q721 1141 709 1169T676 1216T626
+1245T563 1255Z" />
+<glyph unicode="9" glyph-name="nine" horiz-adv-x="1128" d="M1055 838Q1055 733 1044 629T1003 429T923 252T795 109T609 15T354 -20Q333 -20 308 -19T258 -17T208 -13T166 -6V242Q203 232 245 227T332 221Q467 221 554 254T692 348T764 493T791 678H778Q758
+642 730 611T664 557T578 521T471 508Q376 508 300 539T172 629T91 774T63 971Q63 1090 96 1184T192 1343T342 1444T541 1479Q649 1479 743 1441T906 1323T1015 1123T1055 838ZM547 1231Q506 1231 472 1216T414 1170T376 1090T362 975Q362 869 407 807T543 745Q589
+745 627 763T692 810T733 875T748 948Q748 999 736 1049T698 1140T635 1206T547 1231Z" />
+<glyph unicode=":" glyph-name="colon" horiz-adv-x="584" d="M117 143Q117 190 130 222T168 275T224 304T293 313Q328 313 359 304T415 275T453 223T467 143Q467 98 453 66T415 13T360 -17T293 -27Q256 -27 224 -18T168 13T131 66T117 143ZM117 969Q117 1016
+130 1048T168 1101T224 1130T293 1139Q328 1139 359 1130T415 1101T453 1049T467 969Q467 924 453 892T415 839T360 809T293 799Q256 799 224 808T168 838T131 891T117 969Z" />
+<glyph unicode=";" glyph-name="semicolon" horiz-adv-x="594" d="M444 238L459 215Q445 161 426 100T383 -23T334 -146T283 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H444ZM117 969Q117 1016 130 1048T168 1101T224 1130T293 1139Q328 1139 359 1130T415
+1101T453 1049T467 969Q467 924 453 892T415 839T360 809T293 799Q256 799 224 808T168 838T131 891T117 969Z" />
+<glyph unicode="&lt;" glyph-name="less" horiz-adv-x="1128" d="M1040 203L88 641V784L1040 1280V1040L397 723L1040 442V203Z" />
+<glyph unicode="=" glyph-name="equal" horiz-adv-x="1128" d="M88 807V1024H1040V807H88ZM88 418V637H1040V418H88Z" />
+<glyph unicode="&gt;" glyph-name="greater" horiz-adv-x="1128" d="M88 442L731 723L88 1040V1280L1040 784V641L88 203V442Z" />
+<glyph unicode="?" glyph-name="question" horiz-adv-x="940" d="M264 485V559Q264 610 274 651T306 730T362 803T444 877Q486 910 515 936T562 987T588 1041T596 1106Q596 1163 558 1200T440 1237Q371 1237 292 1208T127 1137L25 1358Q68 1383 118 1405T223 1445T334
+1473T444 1483Q546 1483 628 1459T767 1387T854 1273T885 1120Q885 1057 871 1008T830 916T761 834T664 750Q622 717 596 693T554 646T534 601T528 545V485H264ZM231 143Q231 190 244 222T282 275T338 304T408 313Q443 313 474 304T530 275T568 223T582 143Q582
+98 568 66T530 13T475 -17T408 -27Q371 -27 339 -18T282 13T245 66T231 143Z" />
+<glyph unicode="@" glyph-name="at" horiz-adv-x="1774" d="M1673 752Q1673 657 1651 564T1582 398T1467 279T1303 233Q1265 233 1232 242T1170 269T1122 310T1090 362H1075Q1056 337 1031 314T975 272T907 244T825 233Q742 233 678 261T569 342T502 468T479 631Q479
+734 510 820T599 968T740 1065T926 1100Q971 1100 1019 1095T1111 1082T1195 1064T1262 1044L1241 625Q1239 603 1239 582T1239 555Q1239 513 1245 486T1262 444T1286 422T1315 416Q1350 416 1376 443T1419 516T1445 623T1454 754Q1454 882 1416 982T1311 1151T1150
+1256T948 1292Q795 1292 679 1241T484 1099T365 882T324 608Q324 470 359 364T463 185T633 75T866 37Q922 37 981 44T1098 63T1213 92T1321 129V-63Q1227 -105 1113 -129T868 -154Q687 -154 545 -103T304 46T154 283T102 602Q102 726 129 839T207 1050T331 1227T499
+1363T706 1450T948 1481Q1106 1481 1239 1431T1468 1286T1619 1056T1673 752ZM711 627Q711 515 749 466T850 416Q892 416 922 435T972 490T1002 575T1016 686L1028 907Q1008 912 981 915T926 918Q867 918 826 893T760 827T723 734T711 627Z" />
+<glyph unicode="A" glyph-name="A" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489 608H846Z" />
+<glyph unicode="B" glyph-name="B" horiz-adv-x="1315" d="M184 1462H612Q750 1462 854 1443T1028 1380T1133 1266T1169 1092Q1169 1030 1154 976T1110 881T1040 813T944 776V766Q999 754 1046 732T1129 670T1185 570T1206 424Q1206 324 1171 246T1071 113T912
+29T700 0H184V1462ZM494 883H655Q713 883 752 893T815 925T849 977T860 1051Q860 1135 808 1171T641 1208H494V883ZM494 637V256H676Q737 256 778 270T845 310T882 373T893 455Q893 496 882 529T845 587T775 624T668 637H494Z" />
+<glyph unicode="C" glyph-name="C" horiz-adv-x="1305" d="M805 1225Q716 1225 648 1191T533 1092T462 935T438 727Q438 610 459 519T525 366T639 271T805 238Q894 238 983 258T1178 315V55Q1130 35 1083 21T987 -2T887 -15T776 -20Q607 -20 483 34T278 186T158
+422T119 729Q119 895 164 1033T296 1272T511 1427T805 1483Q914 1483 1023 1456T1233 1380L1133 1128Q1051 1167 968 1196T805 1225Z" />
+<glyph unicode="D" glyph-name="D" horiz-adv-x="1434" d="M1315 745Q1315 560 1265 421T1119 188T885 47T569 0H184V1462H612Q773 1462 902 1416T1124 1280T1265 1055T1315 745ZM1001 737Q1001 859 977 947T906 1094T792 1180T637 1208H494V256H608Q804 256 902
+376T1001 737Z" />
+<glyph unicode="E" glyph-name="E" horiz-adv-x="1147" d="M1026 0H184V1462H1026V1208H494V887H989V633H494V256H1026V0Z" />
+<glyph unicode="F" glyph-name="F" horiz-adv-x="1124" d="M489 0H184V1462H1022V1208H489V831H985V578H489V0Z" />
+<glyph unicode="G" glyph-name="G" horiz-adv-x="1483" d="M739 821H1319V63Q1261 44 1202 29T1080 3T947 -14T799 -20Q635 -20 509 28T296 172T164 408T119 733Q119 905 169 1044T316 1280T556 1430T883 1483Q1000 1483 1112 1458T1317 1393L1214 1145Q1146 1179
+1061 1202T881 1225Q779 1225 698 1190T558 1089T469 932T438 727Q438 619 459 530T527 375T645 274T819 238Q885 238 930 244T1016 258V563H739V821Z" />
+<glyph unicode="H" glyph-name="H" horiz-adv-x="1485" d="M1300 0H991V631H494V0H184V1462H494V889H991V1462H1300V0Z" />
+<glyph unicode="I" glyph-name="I" horiz-adv-x="797" d="M731 0H66V176L244 258V1204L66 1286V1462H731V1286L553 1204V258L731 176V0Z" />
+<glyph unicode="J" glyph-name="J" horiz-adv-x="678" d="M-2 -430Q-67 -430 -116 -424T-199 -408V-150Q-162 -158 -122 -164T-33 -170Q13 -170 52 -160T121 -126T167 -60T184 43V1462H494V53Q494 -73 458 -164T356 -314T199 -402T-2 -430Z" />
+<glyph unicode="K" glyph-name="K" horiz-adv-x="1298" d="M1298 0H946L610 608L494 522V0H184V1462H494V758L616 965L950 1462H1294L827 803L1298 0Z" />
+<glyph unicode="L" glyph-name="L" horiz-adv-x="1096" d="M184 0V1462H494V256H1026V0H184Z" />
+<glyph unicode="M" glyph-name="M" horiz-adv-x="1870" d="M772 0L451 1147H442Q448 1055 452 969Q454 932 455 893T458 816T460 743T461 680V0H184V1462H606L922 344H928L1264 1462H1686V0H1397V692Q1397 718 1397 751T1399 821T1401 896T1404 970Q1408 1054
+1411 1145H1403L1057 0H772Z" />
+<glyph unicode="N" glyph-name="N" horiz-adv-x="1604" d="M1419 0H1026L451 1106H442Q448 1029 452 953Q456 888 458 817T461 688V0H184V1462H575L1149 367H1155Q1152 443 1148 517Q1147 549 1146 582T1143 649T1142 714T1141 770V1462H1419V0Z" />
+<glyph unicode="O" glyph-name="O" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430 733ZM438
+733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733Z" />
+<glyph unicode="P" glyph-name="P" horiz-adv-x="1225" d="M494 774H555Q686 774 752 826T819 995Q819 1104 760 1156T573 1208H494V774ZM1133 1006Q1133 910 1104 822T1009 667T834 560T565 520H494V0H184V1462H590Q731 1462 833 1431T1002 1341T1101 1198T1133 1006Z" />
+<glyph unicode="Q" glyph-name="Q" horiz-adv-x="1548" d="M1430 733Q1430 614 1411 510T1352 319T1253 166T1112 55L1473 -348H1075L807 -18Q800 -18 794 -19Q789 -20 784 -20T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483
+1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430 733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733Z"
+/>
+<glyph unicode="R" glyph-name="R" horiz-adv-x="1290" d="M494 813H578Q707 813 763 864T819 1016Q819 1120 759 1164T573 1208H494V813ZM494 561V0H184V1462H584Q865 1462 999 1354T1133 1024Q1133 949 1113 888T1060 780T983 697T891 637Q1002 459 1090 319Q1128
+259 1163 202T1227 100T1273 28L1290 0H946L629 561H494Z" />
+<glyph unicode="S" glyph-name="S" horiz-adv-x="1073" d="M985 406Q985 308 952 230T854 96T696 10T481 -20Q375 -20 277 2T94 68V356Q142 333 191 312T290 273T391 246T492 236Q543 236 579 247T638 279T671 328T682 391Q682 432 665 463T616 522T540 576T440
+631Q394 655 337 689T230 773T145 895T111 1067Q111 1165 143 1242T236 1373T381 1455T573 1483Q626 1483 676 1476T776 1456T876 1424T979 1380L879 1139Q834 1160 795 1176T719 1203T647 1219T575 1225Q497 1225 456 1184T414 1073Q414 1036 426 1008T466 954T537
+903T643 844Q718 804 781 763T889 671T960 556T985 406Z" />
+<glyph unicode="T" glyph-name="T" horiz-adv-x="1124" d="M717 0H408V1204H41V1462H1083V1204H717V0Z" />
+<glyph unicode="U" glyph-name="U" horiz-adv-x="1466" d="M1292 1462V516Q1292 402 1258 304T1153 134T976 21T727 -20Q592 -20 489 18T316 128T210 298T174 520V1462H483V543Q483 462 499 405T546 311T625 257T735 240Q866 240 924 316T983 545V1462H1292Z" />
+<glyph unicode="V" glyph-name="V" horiz-adv-x="1249" d="M936 1462H1249L793 0H455L0 1462H313L561 582Q566 565 574 525T592 437T611 341T625 260Q630 293 639 341T658 436T677 524T692 582L936 1462Z" />
+<glyph unicode="W" glyph-name="W" horiz-adv-x="1898" d="M1546 0H1194L1014 721Q1010 736 1005 763T992 824T978 895T965 967T955 1031T948 1079Q946 1061 942 1032T931 968T919 896T906 825T893 763T883 719L705 0H352L0 1462H305L471 664Q474 648 479 618T492
+549T506 469T521 387T534 313T543 256Q546 278 551 312T563 384T576 464T590 540T601 603T610 643L813 1462H1085L1288 643Q1291 631 1296 604T1308 541T1322 464T1335 385T1347 312T1356 256Q1359 278 1364 312T1377 387T1391 469T1406 549T1418 617T1427 664L1593
+1462H1898L1546 0Z" />
+<glyph unicode="X" glyph-name="X" horiz-adv-x="1284" d="M1284 0H930L631 553L332 0H0L444 754L31 1462H373L647 936L915 1462H1249L831 737L1284 0Z" />
+<glyph unicode="Y" glyph-name="Y" horiz-adv-x="1196" d="M598 860L862 1462H1196L752 569V0H444V559L0 1462H336L598 860Z" />
+<glyph unicode="Z" glyph-name="Z" horiz-adv-x="1104" d="M1055 0H49V201L668 1206H68V1462H1036V1262L418 256H1055V0Z" />
+<glyph unicode="[" glyph-name="bracketleft" horiz-adv-x="678" d="M627 -324H143V1462H627V1251H403V-113H627V-324Z" />
+<glyph unicode="\" glyph-name="backslash" horiz-adv-x="846" d="M289 1462L834 0H557L12 1462H289Z" />
+<glyph unicode="]" glyph-name="bracketright" horiz-adv-x="678" d="M51 -113H274V1251H51V1462H535V-324H51V-113Z" />
+<glyph unicode="^" glyph-name="asciicircum" horiz-adv-x="1090" d="M8 520L446 1470H590L1085 520H846L524 1163Q455 1002 384 839T244 520H8Z" />
+<glyph unicode="_" glyph-name="underscore" horiz-adv-x="842" d="M846 -324H-4V-184H846V-324Z" />
+<glyph unicode="`" glyph-name="grave" horiz-adv-x="1182" d="M645 1241Q611 1269 564 1310T470 1396T386 1480T332 1548V1569H674Q690 1535 711 1495T756 1414T803 1335T848 1268V1241H645Z" />
+<glyph unicode="a" glyph-name="a" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289 838L190 1040Q274
+1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518Z" />
+<glyph unicode="b" glyph-name="b" horiz-adv-x="1245" d="M756 1139Q842 1139 913 1102T1035 992T1114 811T1143 561Q1143 417 1115 309T1034 127T909 17T748 -20Q692 -20 649 -8T571 24T512 69T465 123H444L393 0H160V1556H465V1194Q465 1161 463 1123T459 1051Q456
+1012 453 973H465Q486 1008 513 1038T575 1090T656 1126T756 1139ZM653 895Q602 895 567 877T509 821T477 728T465 596V563Q465 482 474 419T506 314T564 249T655 227Q746 227 788 313T831 565Q831 730 789 812T653 895Z" />
+<glyph unicode="c" glyph-name="c" horiz-adv-x="1022" d="M625 -20Q505 -20 409 13T244 115T139 293T102 553Q102 720 139 832T245 1013T410 1110T625 1139Q711 1139 796 1118T956 1059L868 827Q802 856 741 874T625 893Q514 893 464 809T414 555Q414 387 464
+307T621 227Q708 227 779 249T924 307V53Q887 35 852 21T782 -2T708 -15T625 -20Z" />
+<glyph unicode="d" glyph-name="d" horiz-adv-x="1245" d="M489 -20Q403 -20 332 17T210 126T131 307T102 557Q102 701 130 809T211 991T337 1102T498 1139Q552 1139 597 1127T678 1092T742 1040T793 975H803Q797 1014 792 1054Q787 1088 784 1126T780 1198V1556H1085V0H852L793
+145H780Q759 111 732 81T670 28T590 -7T489 -20ZM600 223Q654 223 692 241T753 297T788 391T801 522V555Q801 636 791 699T758 804T696 869T598 891Q502 891 457 805T412 553Q412 388 457 306T600 223Z" />
+<glyph unicode="e" glyph-name="e" horiz-adv-x="1190" d="M612 922Q531 922 478 865T416 686H805Q804 737 792 780T756 854T696 904T612 922ZM651 -20Q531 -20 430 15T256 120T143 298T102 551Q102 698 139 808T242 991T402 1102T610 1139Q721 1139 810 1106T962
+1007T1058 848T1092 631V483H410Q412 419 430 368T482 281T563 226T672 207Q723 207 768 212T857 229T942 256T1028 295V59Q988 38 948 24T862 -1T765 -15T651 -20Z" />
+<glyph unicode="f" glyph-name="f" horiz-adv-x="793" d="M741 889H514V0H209V889H41V1036L209 1118V1200Q209 1307 235 1377T309 1490T425 1549T578 1567Q670 1567 733 1553T840 1520L768 1296Q737 1307 703 1316T623 1325Q563 1325 539 1287T514 1188V1118H741V889Z" />
+<glyph unicode="g" glyph-name="g" horiz-adv-x="1130" d="M1085 1116V950L922 899Q942 865 950 829T958 750Q958 665 931 595T851 474T718 397T532 369Q509 369 482 371T442 377Q422 360 411 342T399 297Q399 276 412 264T446 244T495 234T553 231H727Q808 231
+872 213T980 156T1049 60T1073 -80Q1073 -175 1035 -251T922 -381T734 -463T475 -492Q361 -492 276 -471T134 -409T49 -311T20 -182Q20 -121 41 -76T97 1T176 53T268 84Q247 93 227 109T190 146T163 192T152 246Q152 278 161 304T189 352T234 395T295 436Q207 474
+156 558T104 756Q104 846 132 917T214 1037T348 1113T532 1139Q552 1139 577 1137T626 1131T672 1123T705 1116H1085ZM285 -158Q285 -183 295 -206T330 -248T393 -276T489 -287Q645 -287 724 -243T803 -125Q803 -62 754 -41T602 -20H461Q434 -20 403 -26T346 -49T303
+-91T285 -158ZM395 752Q395 661 429 611T532 561Q604 561 636 611T668 752Q668 842 637 895T532 948Q395 948 395 752Z" />
+<glyph unicode="h" glyph-name="h" horiz-adv-x="1284" d="M1130 0H825V653Q825 774 788 834T672 895Q613 895 573 871T509 800T475 684T465 526V0H160V1556H465V1239Q465 1197 463 1151T458 1065Q454 1019 451 975H467Q516 1062 592 1100T764 1139Q847 1139 914
+1116T1030 1042T1104 915T1130 729V0Z" />
+<glyph unicode="i" glyph-name="i" horiz-adv-x="625" d="M147 1407Q147 1450 160 1478T195 1524T248 1549T313 1556Q347 1556 377 1549T429 1525T465 1479T479 1407Q479 1365 466 1336T430 1290T377 1265T313 1257Q279 1257 249 1264T196 1289T160 1336T147 1407ZM465
+0H160V1118H465V0Z" />
+<glyph unicode="j" glyph-name="j" horiz-adv-x="625" d="M102 -492Q54 -492 3 -485T-82 -467V-227Q-51 -237 -24 -241T37 -246Q62 -246 84 -239T123 -212T150 -160T160 -76V1118H465V-121Q465 -198 446 -265T383 -383T270 -463T102 -492ZM147 1407Q147 1450 160
+1478T195 1524T248 1549T313 1556Q347 1556 377 1549T429 1525T465 1479T479 1407Q479 1365 466 1336T430 1290T377 1265T313 1257Q279 1257 249 1264T196 1289T160 1336T147 1407Z" />
+<glyph unicode="k" glyph-name="k" horiz-adv-x="1208" d="M453 608L565 778L838 1118H1182L778 633L1208 0H856L584 430L465 348V0H160V1556H465V862L449 608H453Z" />
+<glyph unicode="l" glyph-name="l" horiz-adv-x="625" d="M465 0H160V1556H465V0Z" />
+<glyph unicode="m" glyph-name="m" horiz-adv-x="1929" d="M1120 0H815V653Q815 774 779 834T666 895Q608 895 570 871T508 800T475 684T465 526V0H160V1118H393L434 975H451Q475 1018 508 1049T582 1100T667 1129T758 1139Q873 1139 953 1100T1077 975H1102Q1126
+1018 1160 1049T1235 1100T1321 1129T1413 1139Q1593 1139 1684 1042T1776 729V0H1470V653Q1470 774 1434 834T1321 895Q1212 895 1166 809T1120 561V0Z" />
+<glyph unicode="n" glyph-name="n" horiz-adv-x="1284" d="M1130 0H825V653Q825 774 789 834T672 895Q612 895 572 871T509 800T475 684T465 526V0H160V1118H393L434 975H451Q475 1018 509 1049T585 1100T672 1129T766 1139Q848 1139 915 1116T1030 1042T1104
+915T1130 729V0Z" />
+<glyph unicode="o" glyph-name="o" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246 131T140 313T102
+561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561Z" />
+<glyph unicode="p" glyph-name="p" horiz-adv-x="1245" d="M748 -20Q693 -20 650 -8T572 24T512 69T465 123H449Q453 88 457 57Q460 31 462 4T465 -39V-492H160V1118H408L451 973H465Q486 1007 513 1037T575 1089T656 1125T756 1139Q843 1139 914 1102T1036 992T1115
+811T1143 561Q1143 418 1114 310T1033 128T908 17T748 -20ZM653 895Q602 895 567 877T509 821T477 728T465 596V563Q465 482 474 419T506 314T564 249T655 227Q746 227 788 313T831 565Q831 730 789 812T653 895Z" />
+<glyph unicode="q" glyph-name="q" horiz-adv-x="1245" d="M602 219Q657 219 694 237T755 293T789 386T801 518V555Q801 636 792 699T759 804T697 869T600 891Q504 891 459 805T414 553Q414 385 459 302T602 219ZM489 -20Q402 -20 331 17T209 126T130 307T102
+557Q102 700 130 808T211 990T337 1101T498 1139Q554 1139 599 1127T680 1092T745 1040T795 975H803L827 1118H1085V-492H780V-23Q780 -4 782 24T787 80Q790 112 793 145H780Q760 111 733 81T671 28T590 -7T489 -20Z" />
+<glyph unicode="r" glyph-name="r" horiz-adv-x="889" d="M743 1139Q755 1139 769 1139T797 1137T822 1134T840 1130V844Q832 846 818 848T789 851T758 853T733 854Q674 854 625 839T540 791T485 703T465 569V0H160V1118H391L436 950H451Q475 993 503 1028T565
+1087T643 1125T743 1139Z" />
+<glyph unicode="s" glyph-name="s" horiz-adv-x="985" d="M905 332Q905 244 873 178T782 68T639 2T451 -20Q396 -20 349 -17T260 -5T179 15T100 45V297Q142 276 188 259T281 230T370 210T451 203Q492 203 521 210T568 231T595 263T604 303Q604 324 598 340T568
+375T501 417T381 475Q308 508 255 540T167 613T115 704T98 827Q98 905 128 963T213 1061T345 1119T518 1139Q618 1139 708 1116T893 1047L801 831Q725 867 656 890T518 913Q456 913 429 891T401 831Q401 811 408 796T436 764T495 728T594 680Q665 649 722 619T820
+549T883 458T905 332Z" />
+<glyph unicode="t" glyph-name="t" horiz-adv-x="848" d="M614 223Q659 223 699 233T782 258V31Q739 9 676 -5T537 -20Q464 -20 401 -3T292 56T220 170T193 350V889H47V1018L215 1120L303 1356H498V1118H770V889H498V350Q498 285 530 254T614 223Z" />
+<glyph unicode="u" glyph-name="u" horiz-adv-x="1284" d="M891 0L850 143H834Q809 100 775 70T699 19T612 -10T518 -20Q436 -20 369 3T254 77T180 204T154 389V1118H459V465Q459 344 495 284T612 223Q672 223 712 247T775 318T809 434T819 592V1118H1124V0H891Z" />
+<glyph unicode="v" glyph-name="v" horiz-adv-x="1104" d="M395 0L0 1118H319L504 481Q521 424 533 363T549 252H555Q558 305 570 364T600 481L784 1118H1104L709 0H395Z" />
+<glyph unicode="w" glyph-name="w" horiz-adv-x="1651" d="M1014 0L928 391Q924 408 918 439T903 510T887 594T869 683Q849 786 825 905H819Q796 786 777 682Q769 638 761 593T744 509T730 437T719 387L629 0H301L0 1118H303L416 623Q425 584 434 530T452 420T468
+315T479 236H485Q486 255 489 285T498 351T508 422T519 491T529 547T537 582L659 1118H995L1112 582Q1117 560 1125 514T1141 416T1156 314T1163 236H1169Q1172 261 1179 310T1196 415T1215 528T1235 623L1352 1118H1651L1346 0H1014Z" />
+<glyph unicode="x" glyph-name="x" horiz-adv-x="1122" d="M389 571L29 1118H375L561 782L750 1118H1096L731 571L1112 0H766L561 362L356 0H10L389 571Z" />
+<glyph unicode="y" glyph-name="y" horiz-adv-x="1104" d="M0 1118H334L514 489Q530 437 537 378T547 272H553Q555 295 558 323T567 380T578 437T592 489L768 1118H1104L662 -143Q600 -320 493 -406T225 -492Q173 -492 135 -487T70 -475V-233Q91 -238 123 -242T190
+-246Q238 -246 272 -233T330 -197T372 -140T403 -66L422 -10L0 1118Z" />
+<glyph unicode="z" glyph-name="z" horiz-adv-x="936" d="M877 0H55V180L512 885H86V1118H858V920L416 233H877V0Z" />
+<glyph unicode="{" glyph-name="braceleft" horiz-adv-x="745" d="M287 367T222 408T31 449V688Q93 688 141 697T223 728T272 784T287 866V1184Q287 1258 306 1310T374 1396T509 1446T725 1462V1237Q685 1236 653 1230T598 1209T563 1166T551 1096V797Q545 610
+317 575V563Q432 546 493 491T551 342V43Q551 0 563 -27T597 -69T652 -91T725 -98V-324Q594 -324 509 -308T375 -259T306 -172T287 -45V270Q287 367 222 408Z" />
+<glyph unicode="|" glyph-name="bar" horiz-adv-x="1128" d="M455 1550H674V-465H455V1550Z" />
+<glyph unicode="}" glyph-name="braceright" horiz-adv-x="745" d="M469 -45Q469 -119 450 -172T382 -258T247 -308T31 -324V-98Q71 -97 103 -91T157 -70T192 -27T205 43V342Q202 436 263 491T438 563V575Q211 610 205 797V1096Q205 1139 193 1166T158 1208T103
+1230T31 1237V1462Q162 1462 247 1446T381 1397T450 1311T469 1184V866Q468 818 484 784T533 729T614 698T725 688V449Q600 449 535 408T469 270V-45Z" />
+<glyph unicode="~" glyph-name="asciitilde" horiz-adv-x="1128" d="M528 616Q491 632 463 643T411 660T366 669T322 672Q293 672 262 663T201 637T143 598T88 551V782Q139 836 202 863T344 891Q374 891 399 889T453 879T517 860T600 827Q638 811 666 801T719
+784T764 775T807 772Q836 772 867 781T928 807T986 845T1040 893V662Q939 553 784 553Q754 553 729 555T675 564T611 583T528 616Z" />
+<glyph unicode="&#xa0;" glyph-name="nbspace" horiz-adv-x="532" />
+<glyph unicode="&#xa1;" glyph-name="exclamdown" horiz-adv-x="586" d="M168 606H412L463 -369H117L168 606ZM467 948Q467 901 454 869T416 816T360 787T291 778Q256 778 225 787T169 816T131 868T117 948Q117 993 131 1025T169 1078T224 1108T291 1118Q328 1118
+360 1109T416 1079T453 1026T467 948Z" />
+<glyph unicode="&#xa2;" glyph-name="cent" horiz-adv-x="1128" d="M543 -20V186Q451 199 377 236T251 340T171 506T143 743Q143 884 171 985T251 1155T378 1260T543 1311V1483H721V1319Q759 1318 797 1313T870 1299T937 1281T993 1260L907 1034Q886 1044 860
+1053T805 1070T750 1082T698 1087Q632 1087 586 1067T511 1006T468 901T455 750Q455 579 512 500T698 420Q774 420 844 438T965 481V242Q914 213 852 198T721 180V-20H543Z" />
+<glyph unicode="&#xa3;" glyph-name="sterling" horiz-adv-x="1128" d="M680 1483Q790 1483 879 1459T1049 1401L956 1171Q885 1200 827 1217T705 1235Q638 1235 601 1197T563 1063V870H897V651H563V508Q563 453 550 413T514 343T466 294T412 260H1090V0H82V248Q124
+266 157 287T214 337T250 407T262 506V651H84V870H262V1065Q262 1178 293 1257T380 1387T512 1460T680 1483Z" />
+<glyph unicode="&#xa4;" glyph-name="currency" horiz-adv-x="1128" d="M168 723Q168 777 182 826T221 920L92 1047L240 1194L367 1067Q410 1092 461 1106T563 1120Q617 1120 665 1107T760 1065L887 1194L1036 1051L907 922Q932 880 946 829T961 723Q961 667 947
+618T907 524L1032 399L887 254L760 379Q716 356 667 342T563 328Q507 328 458 340T365 379L240 256L94 401L221 526Q168 617 168 723ZM375 723Q375 684 390 650T430 590T490 550T563 535Q603 535 638 549T699 589T741 649T756 723Q756 763 741 797T700 857T638
+898T563 913Q524 913 490 898T431 858T390 798T375 723Z" />
+<glyph unicode="&#xa5;" glyph-name="yen" horiz-adv-x="1128" d="M565 860L809 1462H1122L760 715H954V537H709V399H954V221H709V0H422V221H174V399H422V537H174V715H365L8 1462H324L565 860Z" />
+<glyph unicode="&#xa6;" glyph-name="brokenbar" horiz-adv-x="1128" d="M455 1550H674V735H455V1550ZM455 350H674V-465H455V350Z" />
+<glyph unicode="&#xa7;" glyph-name="section" horiz-adv-x="995" d="M121 805Q121 849 131 886T160 955T203 1012T254 1055Q191 1095 156 1154T121 1288Q121 1353 150 1406T232 1498T360 1556T526 1577Q628 1577 716 1554T889 1493L807 1303Q739 1335 669 1360T520
+1386Q439 1386 402 1363T365 1292Q365 1267 377 1246T415 1206T481 1167T578 1124Q649 1096 707 1062T807 987T872 895T895 782Q895 682 861 621T770 522Q832 482 863 430T895 303Q895 229 864 170T776 68T638 3T455 -20Q345 -20 261 0T106 59V266Q145 246 190
+229T281 198T371 176T455 168Q511 168 548 177T607 202T639 239T649 285Q649 310 642 329T612 368T549 408T442 457Q366 489 306 521T205 593T143 685T121 805ZM344 827Q344 764 400 716T575 616L590 610Q605 621 619 635T644 668T661 708T668 756Q668 788 658
+815T621 867T550 917T434 967Q416 960 400 947T372 915T352 875T344 827Z" />
+<glyph unicode="&#xa8;" glyph-name="dieresis" horiz-adv-x="1182" d="M248 1405Q248 1440 259 1465T288 1507T332 1532T387 1540Q416 1540 441 1532T486 1508T516 1466T528 1405Q528 1371 517 1346T486 1305T442 1280T387 1272Q358 1272 333 1280T289 1304T259
+1346T248 1405ZM651 1405Q651 1440 662 1465T692 1507T737 1532T793 1540Q821 1540 846 1532T891 1508T922 1466T934 1405Q934 1371 923 1346T892 1305T847 1280T793 1272Q733 1272 692 1305T651 1405Z" />
+<glyph unicode="&#xa9;" glyph-name="copyright" horiz-adv-x="1704" d="M895 1010Q798 1010 745 936T692 731Q692 596 740 524T895 451Q952 451 1018 466T1141 510V319Q1084 292 1025 277T889 262Q782 262 702 296T569 392T488 540T461 733Q461 836 487 921T565
+1068T697 1164T881 1198Q964 1198 1041 1176T1186 1120L1112 952Q999 1010 895 1010ZM100 731Q100 835 127 931T202 1110T320 1263T472 1380T652 1456T852 1483Q956 1483 1052 1456T1231 1381T1384 1263T1501 1111T1577 931T1604 731Q1604 627 1577 531T1502 352T1384
+200T1232 82T1052 7T852 -20Q748 -20 652 6T473 82T320 199T203 351T127 531T100 731ZM242 731Q242 604 290 493T420 300T614 169T852 121Q979 121 1090 169T1283 299T1414 493T1462 731Q1462 858 1414 969T1284 1162T1090 1293T852 1341Q725 1341 614 1293T421
+1163T290 969T242 731Z" />
+<glyph unicode="&#xaa;" glyph-name="ordfeminine" horiz-adv-x="743" d="M520 764L489 874Q449 816 393 784T268 752Q218 752 178 765T108 806T63 876T47 975Q47 1035 68 1076T130 1144T230 1184T365 1202L455 1206Q455 1269 426 1296T342 1323Q302 1323 253
+1306T152 1262L86 1397Q148 1429 222 1454T387 1479Q455 1479 505 1460T589 1405T638 1319T655 1206V764H520ZM373 1081Q335 1078 312 1068T275 1044T257 1012T252 977Q252 939 271 921T317 903Q349 903 374 914T418 944T445 991T455 1051V1087L373 1081Z" />
+<glyph unicode="&#xab;" glyph-name="guillemotleft" horiz-adv-x="1198" d="M82 573L391 1028L610 909L393 561L610 213L391 94L82 547V573ZM588 573L897 1028L1116 909L899 561L1116 213L897 94L588 547V573Z" />
+<glyph unicode="&#xac;" glyph-name="logicalnot" horiz-adv-x="1128" d="M1040 248H821V612H88V831H1040V248Z" />
+<glyph unicode="&#xad;" glyph-name="uni00AD" horiz-adv-x="659" d="M61 424V674H598V424H61Z" />
+<glyph unicode="&#xae;" glyph-name="registered" horiz-adv-x="1704" d="M1157 905Q1157 811 1119 756T1014 672L1251 272H997L819 610H772V272H543V1188H807Q989 1188 1073 1118T1157 905ZM772 778H803Q869 778 897 806T926 901Q926 936 919 959T896 995T857
+1014T801 1020H772V778ZM100 731Q100 835 127 931T202 1110T320 1263T472 1380T652 1456T852 1483Q956 1483 1052 1456T1231 1381T1384 1263T1501 1111T1577 931T1604 731Q1604 627 1577 531T1502 352T1384 200T1232 82T1052 7T852 -20Q748 -20 652 6T473 82T320
+199T203 351T127 531T100 731ZM242 731Q242 604 290 493T420 300T614 169T852 121Q979 121 1090 169T1283 299T1414 493T1462 731Q1462 858 1414 969T1284 1162T1090 1293T852 1341Q725 1341 614 1293T421 1163T290 969T242 731Z" />
+<glyph unicode="&#xaf;" glyph-name="overscore" horiz-adv-x="1024" d="M1030 1556H-6V1757H1030V1556Z" />
+<glyph unicode="&#xb0;" glyph-name="degree" horiz-adv-x="877" d="M92 1137Q92 1208 119 1271T193 1381T303 1455T438 1483Q510 1483 573 1456T683 1381T757 1271T784 1137Q784 1065 757 1002T684 893T574 820T438 793Q366 793 303 819T193 892T119 1002T92
+1137ZM283 1137Q283 1106 295 1078T328 1029T377 996T438 983Q470 983 498 995T548 1029T581 1078T594 1137Q594 1169 582 1197T548 1247T499 1281T438 1294Q406 1294 378 1282T328 1248T295 1198T283 1137Z" />
+<glyph unicode="&#xb1;" glyph-name="plusminus" horiz-adv-x="1128" d="M455 674H88V893H455V1262H674V893H1040V674H674V309H455V674ZM88 0V219H1040V0H88Z" />
+<glyph unicode="&#xb2;" glyph-name="twosuperior" horiz-adv-x="776" d="M702 586H55V754L279 973Q325 1018 355 1051T404 1111T430 1161T438 1212Q438 1250 414 1270T350 1290Q310 1290 267 1270T170 1202L47 1354Q112 1411 193 1447T383 1483Q449 1483 503
+1467T596 1419T656 1341T678 1233Q678 1187 666 1147T626 1065T557 980T455 881L350 786H702V586Z" />
+<glyph unicode="&#xb3;" glyph-name="threesuperior" horiz-adv-x="776" d="M666 1249Q666 1180 626 1130T496 1051V1038Q547 1028 584 1007T645 959T682 898T694 829Q694 708 606 639T332 569Q256 569 190 586T59 639V829Q125 789 191 764T330 739Q404 739 438
+766T473 846Q473 867 465 886T438 919T387 943T307 952H195V1112H287Q339 1112 371 1121T421 1145T445 1180T451 1221Q451 1259 426 1284T350 1309Q303 1309 261 1290T162 1231L61 1372Q123 1419 198 1450T377 1481Q439 1481 492 1465T583 1418T644 1345T666 1249Z"
+/>
+<glyph unicode="&#xb4;" glyph-name="acute" horiz-adv-x="1182" d="M332 1241V1268Q353 1297 377 1335T424 1413T469 1494T506 1569H848V1548Q837 1530 816 1506T768 1453T710 1396T648 1338T587 1285T535 1241H332Z" />
+<glyph unicode="&#xb5;" glyph-name="mu" horiz-adv-x="1290" d="M465 465Q465 344 502 284T621 223Q679 223 718 247T781 318T815 434T825 592V1118H1130V0H897L854 150H842Q807 65 755 23T627 -20Q573 -20 528 3T455 70Q457 28 460 -15Q462 -52 463 -94T465
+-172V-492H160V1118H465V465Z" />
+<glyph unicode="&#xb6;" glyph-name="paragraph" horiz-adv-x="1341" d="M1167 -260H1006V1356H840V-260H678V559Q617 541 532 541Q437 541 360 566T228 651T143 806T113 1042Q113 1189 145 1287T237 1446T380 1531T563 1556H1167V-260Z" />
+<glyph unicode="&#xb7;" glyph-name="middot" horiz-adv-x="584" d="M117 723Q117 770 130 802T168 855T224 884T293 893Q328 893 359 884T415 855T453 803T467 723Q467 678 453 646T415 593T360 563T293 553Q256 553 224 562T168 592T131 645T117 723Z" />
+<glyph unicode="&#xb8;" glyph-name="cedilla" horiz-adv-x="420" d="M418 -250Q418 -307 403 -352T351 -428T256 -475T109 -492Q64 -492 28 -486T-37 -471V-303Q-22 -307 -4 -310T34 -317T72 -322T106 -324Q135 -324 156 -311T178 -262Q178 -225 141 -197T12
+-154L90 0H283L256 -61Q287 -71 316 -88T367 -128T404 -182T418 -250Z" />
+<glyph unicode="&#xb9;" glyph-name="onesuperior" horiz-adv-x="776" d="M584 586H346V1032Q346 1052 346 1082T348 1144T351 1201T354 1239Q348 1231 339 1221T319 1199T298 1178T279 1161L201 1100L92 1227L393 1462H584V586Z" />
+<glyph unicode="&#xba;" glyph-name="ordmasculine" horiz-adv-x="754" d="M696 1116Q696 1029 674 962T609 848T508 777T375 752Q306 752 248 776T147 847T81 961T57 1116Q57 1203 79 1270T143 1384T244 1455T379 1479Q447 1479 504 1455T605 1385T672 1271T696
+1116ZM260 1116Q260 1016 287 966T377 915Q437 915 464 965T492 1116Q492 1216 465 1265T377 1315Q315 1315 288 1266T260 1116Z" />
+<glyph unicode="&#xbb;" glyph-name="guillemotright" horiz-adv-x="1198" d="M1118 547L809 94L590 213L807 561L590 909L809 1028L1118 573V547ZM612 547L303 94L84 213L301 561L84 909L303 1028L612 573V547Z" />
+<glyph unicode="&#xbc;" glyph-name="onequarter" horiz-adv-x="1804" d="M1370 1462L559 0H320L1131 1462H1370ZM794 586H556V1032Q556 1052 556 1082T558 1144T561 1201T564 1239Q558 1231 549 1221T529 1199T508 1178T489 1161L411 1100L302 1227L603 1462H794V586ZM1682
+152H1557V1H1319V152H936V306L1321 883H1557V320H1682V152ZM1319 320V484Q1319 526 1320 572T1325 668Q1320 655 1311 634T1290 590T1268 546T1248 511L1121 320H1319Z" />
+<glyph unicode="&#xbd;" glyph-name="onehalf" horiz-adv-x="1804" d="M1370 1462L559 0H320L1131 1462H1370ZM794 586H556V1032Q556 1052 556 1082T558 1144T561 1201T564 1239Q558 1231 549 1221T529 1199T508 1178T489 1161L411 1100L302 1227L603 1462H794V586ZM1716
+1H1069V169L1293 388Q1339 433 1369 466T1418 526T1444 576T1452 627Q1452 665 1428 685T1364 705Q1324 705 1281 685T1184 617L1061 769Q1126 826 1207 862T1397 898Q1463 898 1517 882T1610 834T1670 756T1692 648Q1692 602 1680 562T1640 480T1571 395T1469
+296L1364 201H1716V1Z" />
+<glyph unicode="&#xbe;" glyph-name="threequarters" horiz-adv-x="1804" d="M1441 1462L630 0H391L1202 1462H1441ZM1712 152H1587V1H1349V152H966V306L1351 883H1587V320H1712V152ZM1349 320V484Q1349 526 1350 572T1355 668Q1350 655 1341 634T1320 590T1298
+546T1278 511L1151 320H1349ZM697 1249Q697 1180 657 1130T527 1051V1038Q578 1028 615 1007T676 959T713 898T725 829Q725 708 637 639T363 569Q287 569 221 586T90 639V829Q156 789 222 764T361 739Q435 739 469 766T504 846Q504 867 496 886T469 919T418 943T338
+952H226V1112H318Q370 1112 402 1121T452 1145T476 1180T482 1221Q482 1259 457 1284T381 1309Q334 1309 292 1290T193 1231L92 1372Q154 1419 229 1450T408 1481Q470 1481 523 1465T614 1418T675 1345T697 1249Z" />
+<glyph unicode="&#xbf;" glyph-name="questiondown" horiz-adv-x="940" d="M686 606V532Q686 481 676 440T644 361T588 288T506 215Q464 182 435 156T388 105T362 51T354 -14Q354 -71 393 -108T510 -145Q579 -145 659 -116T823 -45L926 -266Q883 -292 832 -314T727
+-354T616 -381T506 -391Q404 -391 323 -367T184 -296T97 -182T66 -29Q66 34 79 83T121 175T190 258T287 342Q328 375 354 399T396 446T416 492T422 547V606H686ZM719 948Q719 901 706 869T668 816T612 787T543 778Q508 778 477 787T421 816T383 868T369 948Q369
+993 383 1025T421 1078T476 1108T543 1118Q580 1118 612 1109T668 1079T705 1026T719 948Z" />
+<glyph unicode="&#xc0;" glyph-name="Agrave" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489
+608H846ZM632 1579Q598 1607 551 1648T457 1734T373 1818T319 1886V1907H661Q677 1873 698 1833T743 1752T790 1673T835 1606V1579H632Z" />
+<glyph unicode="&#xc1;" glyph-name="Aacute" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489
+608H846ZM494 1579V1606Q515 1635 539 1673T586 1751T631 1832T668 1907H1010V1886Q999 1868 978 1844T930 1791T872 1734T810 1676T749 1623T697 1579H494Z" />
+<glyph unicode="&#xc2;" glyph-name="Acircumflex" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582
+928L489 608H846ZM879 1579Q828 1613 773 1656T666 1755Q612 1699 560 1656T457 1579H254V1606Q280 1635 311 1673T375 1751T438 1832T490 1907H846Q867 1873 897 1833T959 1752T1024 1673T1082 1606V1579H879Z" />
+<glyph unicode="&#xc3;" glyph-name="Atilde" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489
+608H846ZM504 1684Q473 1684 455 1658T424 1577H275Q281 1657 301 1715T353 1811T430 1867T527 1886Q568 1886 607 1870T684 1835T760 1799T834 1782Q865 1782 883 1808T914 1888H1063Q1057 1809 1037 1751T983 1655T907 1598T811 1579Q771 1579 731 1595T653 1631T578
+1667T504 1684Z" />
+<glyph unicode="&#xc4;" glyph-name="Adieresis" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489
+608H846ZM324 1743Q324 1778 335 1803T364 1845T408 1870T463 1878Q492 1878 517 1870T562 1846T592 1804T604 1743Q604 1709 593 1684T562 1643T518 1618T463 1610Q434 1610 409 1618T365 1642T335 1684T324 1743ZM727 1743Q727 1778 738 1803T768 1845T813 1870T869
+1878Q897 1878 922 1870T967 1846T998 1804T1010 1743Q1010 1709 999 1684T968 1643T923 1618T869 1610Q809 1610 768 1643T727 1743Z" />
+<glyph unicode="&#xc5;" glyph-name="Aring" horiz-adv-x="1331" d="M1018 0L918 348H414L313 0H0L475 1468H854L1331 0H1018ZM846 608L752 928Q746 946 734 987T709 1077T683 1177T666 1262Q662 1240 656 1210T641 1147T623 1079T606 1015T592 962T582 928L489
+608H846ZM918 1567Q918 1511 899 1467T845 1391T764 1344T664 1327Q609 1327 563 1343T485 1390T434 1465T416 1565Q416 1620 434 1664T484 1738T563 1785T664 1802Q717 1802 763 1786T843 1739T898 1665T918 1567ZM760 1565Q760 1610 733 1635T664 1661Q622 1661
+595 1636T568 1565Q568 1520 592 1494T664 1468Q706 1468 733 1494T760 1565Z" />
+<glyph unicode="&#xc6;" glyph-name="AE" horiz-adv-x="1888" d="M1767 0H926V348H465L315 0H0L655 1462H1767V1208H1235V887H1731V633H1235V256H1767V0ZM578 608H926V1198H829L578 608Z" />
+<glyph unicode="&#xc7;" glyph-name="Ccedilla" horiz-adv-x="1305" d="M805 1225Q716 1225 648 1191T533 1092T462 935T438 727Q438 610 459 519T525 366T639 271T805 238Q894 238 983 258T1178 315V55Q1130 35 1083 21T987 -2T887 -15T776 -20Q607 -20 483 34T278
+186T158 422T119 729Q119 895 164 1033T296 1272T511 1427T805 1483Q914 1483 1023 1456T1233 1380L1133 1128Q1051 1167 968 1196T805 1225ZM926 -250Q926 -307 911 -352T859 -428T764 -475T617 -492Q572 -492 536 -486T471 -471V-303Q486 -307 504 -310T542 -317T580
+-322T614 -324Q643 -324 664 -311T686 -262Q686 -225 649 -197T520 -154L598 0H791L764 -61Q795 -71 824 -88T875 -128T912 -182T926 -250Z" />
+<glyph unicode="&#xc8;" glyph-name="Egrave" horiz-adv-x="1147" d="M1026 0H184V1462H1026V1208H494V887H989V633H494V256H1026V0ZM572 1579Q538 1607 491 1648T397 1734T313 1818T259 1886V1907H601Q617 1873 638 1833T683 1752T730 1673T775 1606V1579H572Z" />
+<glyph unicode="&#xc9;" glyph-name="Eacute" horiz-adv-x="1147" d="M1026 0H184V1462H1026V1208H494V887H989V633H494V256H1026V0ZM424 1579V1606Q445 1635 469 1673T516 1751T561 1832T598 1907H940V1886Q929 1868 908 1844T860 1791T802 1734T740 1676T679
+1623T627 1579H424Z" />
+<glyph unicode="&#xca;" glyph-name="Ecircumflex" horiz-adv-x="1147" d="M1026 0H184V1462H1026V1208H494V887H989V633H494V256H1026V0ZM832 1579Q781 1613 726 1656T619 1755Q565 1699 513 1656T410 1579H207V1606Q233 1635 264 1673T328 1751T391 1832T443
+1907H799Q820 1873 850 1833T912 1752T977 1673T1035 1606V1579H832Z" />
+<glyph unicode="&#xcb;" glyph-name="Edieresis" horiz-adv-x="1147" d="M1026 0H184V1462H1026V1208H494V887H989V633H494V256H1026V0ZM273 1743Q273 1778 284 1803T313 1845T357 1870T412 1878Q441 1878 466 1870T511 1846T541 1804T553 1743Q553 1709 542 1684T511
+1643T467 1618T412 1610Q383 1610 358 1618T314 1642T284 1684T273 1743ZM676 1743Q676 1778 687 1803T717 1845T762 1870T818 1878Q846 1878 871 1870T916 1846T947 1804T959 1743Q959 1709 948 1684T917 1643T872 1618T818 1610Q758 1610 717 1643T676 1743Z"
+/>
+<glyph unicode="&#xcc;" glyph-name="Igrave" horiz-adv-x="797" d="M731 0H66V176L244 258V1204L66 1286V1462H731V1286L553 1204V258L731 176V0ZM355 1579Q321 1607 274 1648T180 1734T96 1818T42 1886V1907H384Q400 1873 421 1833T466 1752T513 1673T558 1606V1579H355Z"
+/>
+<glyph unicode="&#xcd;" glyph-name="Iacute" horiz-adv-x="797" d="M731 0H66V176L244 258V1204L66 1286V1462H731V1286L553 1204V258L731 176V0ZM237 1579V1606Q258 1635 282 1673T329 1751T374 1832T411 1907H753V1886Q742 1868 721 1844T673 1791T615 1734T553
+1676T492 1623T440 1579H237Z" />
+<glyph unicode="&#xce;" glyph-name="Icircumflex" horiz-adv-x="797" d="M731 0H66V176L244 258V1204L66 1286V1462H731V1286L553 1204V258L731 176V0ZM609 1579Q558 1613 503 1656T396 1755Q342 1699 290 1656T187 1579H-16V1606Q10 1635 41 1673T105 1751T168
+1832T220 1907H576Q597 1873 627 1833T689 1752T754 1673T812 1606V1579H609Z" />
+<glyph unicode="&#xcf;" glyph-name="Idieresis" horiz-adv-x="797" d="M731 0H66V176L244 258V1204L66 1286V1462H731V1286L553 1204V258L731 176V0ZM54 1743Q54 1778 65 1803T94 1845T138 1870T193 1878Q222 1878 247 1870T292 1846T322 1804T334 1743Q334 1709
+323 1684T292 1643T248 1618T193 1610Q164 1610 139 1618T95 1642T65 1684T54 1743ZM457 1743Q457 1778 468 1803T498 1845T543 1870T599 1878Q627 1878 652 1870T697 1846T728 1804T740 1743Q740 1709 729 1684T698 1643T653 1618T599 1610Q539 1610 498 1643T457
+1743Z" />
+<glyph unicode="&#xd0;" glyph-name="Eth" horiz-adv-x="1434" d="M47 850H184V1462H612Q773 1462 902 1416T1124 1280T1265 1055T1315 745Q1315 560 1265 421T1119 188T885 47T569 0H184V596H47V850ZM1001 737Q1001 859 977 947T906 1094T792 1180T637 1208H494V850H731V596H494V256H608Q804
+256 902 376T1001 737Z" />
+<glyph unicode="&#xd1;" glyph-name="Ntilde" horiz-adv-x="1604" d="M1419 0H1026L451 1106H442Q448 1029 452 953Q456 888 458 817T461 688V0H184V1462H575L1149 367H1155Q1152 443 1148 517Q1147 549 1146 582T1143 649T1142 714T1141 770V1462H1419V0ZM623
+1684Q592 1684 574 1658T543 1577H394Q400 1657 420 1715T472 1811T549 1867T646 1886Q687 1886 726 1870T803 1835T879 1799T953 1782Q984 1782 1002 1808T1033 1888H1182Q1176 1809 1156 1751T1102 1655T1026 1598T930 1579Q890 1579 850 1595T772 1631T697 1667T623
+1684Z" />
+<glyph unicode="&#xd2;" glyph-name="Ograve" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430
+733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM729 1579Q695 1607 648 1648T554 1734T470 1818T416 1886V1907H758Q774
+1873 795 1833T840 1752T887 1673T932 1606V1579H729Z" />
+<glyph unicode="&#xd3;" glyph-name="Oacute" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430
+733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM590 1579V1606Q611 1635 635 1673T682 1751T727 1832T764 1907H1106V1886Q1095
+1868 1074 1844T1026 1791T968 1734T906 1676T845 1623T793 1579H590Z" />
+<glyph unicode="&#xd4;" glyph-name="Ocircumflex" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390
+1043T1430 733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM975 1579Q924 1613 869 1656T762 1755Q708 1699
+656 1656T553 1579H350V1606Q376 1635 407 1673T471 1751T534 1832T586 1907H942Q963 1873 993 1833T1055 1752T1120 1673T1178 1606V1579H975Z" />
+<glyph unicode="&#xd5;" glyph-name="Otilde" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430
+733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM612 1684Q581 1684 563 1658T532 1577H383Q389 1657 409 1715T461
+1811T538 1867T635 1886Q676 1886 715 1870T792 1835T868 1799T942 1782Q973 1782 991 1808T1022 1888H1171Q1165 1809 1145 1751T1091 1655T1015 1598T919 1579Q879 1579 839 1595T761 1631T686 1667T612 1684Z" />
+<glyph unicode="&#xd6;" glyph-name="Odieresis" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q606 -20 483 34T279 187T159 425T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q944 1485 1067 1432T1270 1280T1390 1043T1430
+733ZM438 733Q438 618 458 527T519 372T624 274T774 240Q863 240 926 274T1030 371T1090 526T1110 733Q1110 848 1091 939T1031 1095T927 1193T776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM428 1743Q428 1778 439 1803T468 1845T512 1870T567 1878Q596
+1878 621 1870T666 1846T696 1804T708 1743Q708 1709 697 1684T666 1643T622 1618T567 1610Q538 1610 513 1618T469 1642T439 1684T428 1743ZM831 1743Q831 1778 842 1803T872 1845T917 1870T973 1878Q1001 1878 1026 1870T1071 1846T1102 1804T1114 1743Q1114
+1709 1103 1684T1072 1643T1027 1618T973 1610Q913 1610 872 1643T831 1743Z" />
+<glyph unicode="&#xd7;" glyph-name="multiply" horiz-adv-x="1128" d="M408 723L109 1024L260 1178L561 879L866 1178L1020 1028L715 723L1016 420L866 268L561 569L260 270L111 422L408 723Z" />
+<glyph unicode="&#xd8;" glyph-name="Oslash" horiz-adv-x="1548" d="M1430 733Q1430 564 1391 425T1270 187T1066 34T774 -20Q595 -20 467 41L395 -76L227 18L309 152Q212 252 166 400T119 735Q119 905 158 1043T279 1280T483 1431T776 1485Q867 1485 944 1469T1087
+1421L1157 1532L1323 1436L1243 1307Q1337 1208 1383 1063T1430 733ZM438 733Q438 553 485 438L942 1184Q873 1227 776 1227Q689 1227 625 1193T520 1095T458 940T438 733ZM1110 733Q1110 904 1067 1020L612 279Q646 260 686 250T774 240Q863 240 926 274T1030
+371T1090 526T1110 733Z" />
+<glyph unicode="&#xd9;" glyph-name="Ugrave" horiz-adv-x="1466" d="M1292 1462V516Q1292 402 1258 304T1153 134T976 21T727 -20Q592 -20 489 18T316 128T210 298T174 520V1462H483V543Q483 462 499 405T546 311T625 257T735 240Q866 240 924 316T983 545V1462H1292ZM706
+1579Q672 1607 625 1648T531 1734T447 1818T393 1886V1907H735Q751 1873 772 1833T817 1752T864 1673T909 1606V1579H706Z" />
+<glyph unicode="&#xda;" glyph-name="Uacute" horiz-adv-x="1466" d="M1292 1462V516Q1292 402 1258 304T1153 134T976 21T727 -20Q592 -20 489 18T316 128T210 298T174 520V1462H483V543Q483 462 499 405T546 311T625 257T735 240Q866 240 924 316T983 545V1462H1292ZM570
+1579V1606Q591 1635 615 1673T662 1751T707 1832T744 1907H1086V1886Q1075 1868 1054 1844T1006 1791T948 1734T886 1676T825 1623T773 1579H570Z" />
+<glyph unicode="&#xdb;" glyph-name="Ucircumflex" horiz-adv-x="1466" d="M1292 1462V516Q1292 402 1258 304T1153 134T976 21T727 -20Q592 -20 489 18T316 128T210 298T174 520V1462H483V543Q483 462 499 405T546 311T625 257T735 240Q866 240 924 316T983 545V1462H1292ZM942
+1579Q891 1613 836 1656T729 1755Q675 1699 623 1656T520 1579H317V1606Q343 1635 374 1673T438 1751T501 1832T553 1907H909Q930 1873 960 1833T1022 1752T1087 1673T1145 1606V1579H942Z" />
+<glyph unicode="&#xdc;" glyph-name="Udieresis" horiz-adv-x="1466" d="M1292 1462V516Q1292 402 1258 304T1153 134T976 21T727 -20Q592 -20 489 18T316 128T210 298T174 520V1462H483V543Q483 462 499 405T546 311T625 257T735 240Q866 240 924 316T983 545V1462H1292ZM393
+1743Q393 1778 404 1803T433 1845T477 1870T532 1878Q561 1878 586 1870T631 1846T661 1804T673 1743Q673 1709 662 1684T631 1643T587 1618T532 1610Q503 1610 478 1618T434 1642T404 1684T393 1743ZM796 1743Q796 1778 807 1803T837 1845T882 1870T938 1878Q966
+1878 991 1870T1036 1846T1067 1804T1079 1743Q1079 1709 1068 1684T1037 1643T992 1618T938 1610Q878 1610 837 1643T796 1743Z" />
+<glyph unicode="&#xdd;" glyph-name="Yacute" horiz-adv-x="1196" d="M598 860L862 1462H1196L752 569V0H444V559L0 1462H336L598 860ZM422 1579V1606Q443 1635 467 1673T514 1751T559 1832T596 1907H938V1886Q927 1868 906 1844T858 1791T800 1734T738 1676T677
+1623T625 1579H422Z" />
+<glyph unicode="&#xde;" glyph-name="Thorn" horiz-adv-x="1225" d="M1133 770Q1133 676 1108 590T1024 438T870 333T633 293H494V0H184V1462H494V1233H655Q779 1233 869 1200T1017 1107T1104 961T1133 770ZM494 543H578Q699 543 759 595T819 770Q819 878 766
+929T598 981H494V543Z" />
+<glyph unicode="&#xdf;" glyph-name="germandbls" horiz-adv-x="1395" d="M1188 1241Q1188 1177 1167 1129T1114 1042T1045 975T976 922T923 877T901 834Q901 814 913 797T952 760T1020 715T1118 651Q1167 620 1205 588T1269 517T1309 432T1323 326Q1323 154 1206
+67T862 -20Q764 -20 692 -6T559 43V285Q583 269 617 254T690 226T768 207T842 199Q922 199 966 229T1010 322Q1010 349 1003 370T976 412T918 457T821 516Q758 552 716 584T647 647T609 713T598 788Q598 841 618 880T670 950T737 1007T805 1059T856 1117T877 1188Q877
+1251 827 1290T680 1329Q572 1329 519 1281T465 1128V0H160V1139Q160 1248 197 1328T302 1462T467 1541T680 1567Q795 1567 889 1546T1049 1483T1152 1380T1188 1241Z" />
+<glyph unicode="&#xe0;" glyph-name="agrave" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289 838L190
+1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM808 1241Q774 1269 727 1310T633 1396T549 1480T495 1548V1569H837Q853
+1535 874 1495T919 1414T966 1335T1011 1268V1241H808Z" />
+<glyph unicode="&#xe1;" glyph-name="aacute" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289 838L190
+1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM441 1241V1268Q462 1297 486 1335T533 1413T578 1494T615
+1569H957V1548Q946 1530 925 1506T877 1453T819 1396T757 1338T696 1285T644 1241H441Z" />
+<glyph unicode="&#xe2;" glyph-name="acircumflex" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289
+838L190 1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM801 1496Q750 1530 695 1573T588 1672Q534 1616
+482 1573T379 1496H176V1523Q202 1552 233 1590T297 1668T360 1749T412 1824H768Q789 1790 819 1750T881 1669T946 1590T1004 1523V1496H801Z" />
+<glyph unicode="&#xe3;" glyph-name="atilde" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289 838L190
+1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM681 1346Q650 1346 632 1320T601 1239H452Q458 1319 478
+1377T530 1473T607 1529T704 1548Q745 1548 784 1532T861 1497T937 1461T1011 1444Q1042 1444 1060 1470T1091 1550H1240Q1234 1471 1214 1413T1160 1317T1084 1260T988 1241Q948 1241 908 1257T830 1293T755 1329T681 1346Z" />
+<glyph unicode="&#xe4;" glyph-name="adieresis" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289
+838L190 1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM254 1405Q254 1440 265 1465T294 1507T338 1532T393
+1540Q422 1540 447 1532T492 1508T522 1466T534 1405Q534 1371 523 1346T492 1305T448 1280T393 1272Q364 1272 339 1280T295 1304T265 1346T254 1405ZM657 1405Q657 1440 668 1465T698 1507T743 1532T799 1540Q827 1540 852 1532T897 1508T928 1466T940 1405Q940
+1371 929 1346T898 1305T853 1280T799 1272Q739 1272 698 1305T657 1405Z" />
+<glyph unicode="&#xe5;" glyph-name="aring" horiz-adv-x="1176" d="M809 0L750 152H741Q708 107 675 75T603 21T516 -10T403 -20Q335 -20 277 1T177 66T110 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427 894T289 838L190
+1040Q274 1087 376 1114T590 1141Q799 1141 910 1043T1022 745V0H809ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM842 1479Q842 1423 823 1379T769 1303T688 1256T588 1239Q533
+1239 487 1255T409 1302T358 1377T340 1477Q340 1532 358 1576T408 1650T487 1697T588 1714Q641 1714 687 1698T767 1651T822 1577T842 1479ZM684 1477Q684 1522 657 1547T588 1573Q546 1573 519 1548T492 1477Q492 1432 516 1406T588 1380Q630 1380 657 1406T684
+1477Z" />
+<glyph unicode="&#xe6;" glyph-name="ae" horiz-adv-x="1806" d="M1268 -20Q1137 -20 1030 30T854 186Q811 132 769 94T678 30T568 -8T424 -20Q356 -20 295 1T187 66T113 176T86 334Q86 512 200 596T541 690L719 696V780Q719 849 679 882T567 915Q495 915 427
+894T289 838L190 1040Q274 1087 376 1114T590 1141Q804 1141 913 1010Q1039 1139 1227 1139Q1338 1139 1427 1106T1579 1007T1674 848T1708 631V483H1026Q1028 419 1046 368T1098 281T1179 226T1288 207Q1382 207 1469 228T1645 295V59Q1605 38 1565 24T1479 -1T1382
+-15T1268 -20ZM719 518L618 514Q557 512 515 498T448 461T411 405T399 332Q399 262 433 233T522 203Q564 203 600 217T662 260T704 330T719 426V518ZM1229 922Q1147 922 1094 865T1032 686H1421Q1420 737 1408 780T1373 854T1313 904T1229 922Z" />
+<glyph unicode="&#xe7;" glyph-name="ccedilla" horiz-adv-x="1022" d="M625 -20Q505 -20 409 13T244 115T139 293T102 553Q102 720 139 832T245 1013T410 1110T625 1139Q711 1139 796 1118T956 1059L868 827Q802 856 741 874T625 893Q514 893 464 809T414 555Q414
+387 464 307T621 227Q708 227 779 249T924 307V53Q887 35 852 21T782 -2T708 -15T625 -20ZM778 -250Q778 -307 763 -352T711 -428T616 -475T469 -492Q424 -492 388 -486T323 -471V-303Q338 -307 356 -310T394 -317T432 -322T466 -324Q495 -324 516 -311T538 -262Q538
+-225 501 -197T372 -154L450 0H643L616 -61Q647 -71 676 -88T727 -128T764 -182T778 -250Z" />
+<glyph unicode="&#xe8;" glyph-name="egrave" horiz-adv-x="1190" d="M612 922Q531 922 478 865T416 686H805Q804 737 792 780T756 854T696 904T612 922ZM651 -20Q531 -20 430 15T256 120T143 298T102 551Q102 698 139 808T242 991T402 1102T610 1139Q721 1139
+810 1106T962 1007T1058 848T1092 631V483H410Q412 419 430 368T482 281T563 226T672 207Q723 207 768 212T857 229T942 256T1028 295V59Q988 38 948 24T862 -1T765 -15T651 -20ZM834 1241Q800 1269 753 1310T659 1396T575 1480T521 1548V1569H863Q879 1535 900
+1495T945 1414T992 1335T1037 1268V1241H834Z" />
+<glyph unicode="&#xe9;" glyph-name="eacute" horiz-adv-x="1190" d="M612 922Q531 922 478 865T416 686H805Q804 737 792 780T756 854T696 904T612 922ZM651 -20Q531 -20 430 15T256 120T143 298T102 551Q102 698 139 808T242 991T402 1102T610 1139Q721 1139
+810 1106T962 1007T1058 848T1092 631V483H410Q412 419 430 368T482 281T563 226T672 207Q723 207 768 212T857 229T942 256T1028 295V59Q988 38 948 24T862 -1T765 -15T651 -20ZM447 1241V1268Q468 1297 492 1335T539 1413T584 1494T621 1569H963V1548Q952 1530
+931 1506T883 1453T825 1396T763 1338T702 1285T650 1241H447Z" />
+<glyph unicode="&#xea;" glyph-name="ecircumflex" horiz-adv-x="1190" d="M612 922Q531 922 478 865T416 686H805Q804 737 792 780T756 854T696 904T612 922ZM651 -20Q531 -20 430 15T256 120T143 298T102 551Q102 698 139 808T242 991T402 1102T610 1139Q721
+1139 810 1106T962 1007T1058 848T1092 631V483H410Q412 419 430 368T482 281T563 226T672 207Q723 207 768 212T857 229T942 256T1028 295V59Q988 38 948 24T862 -1T765 -15T651 -20ZM819 1241Q768 1275 713 1318T606 1417Q552 1361 500 1318T397 1241H194V1268Q220
+1297 251 1335T315 1413T378 1494T430 1569H786Q807 1535 837 1495T899 1414T964 1335T1022 1268V1241H819Z" />
+<glyph unicode="&#xeb;" glyph-name="edieresis" horiz-adv-x="1190" d="M612 922Q531 922 478 865T416 686H805Q804 737 792 780T756 854T696 904T612 922ZM651 -20Q531 -20 430 15T256 120T143 298T102 551Q102 698 139 808T242 991T402 1102T610 1139Q721 1139
+810 1106T962 1007T1058 848T1092 631V483H410Q412 419 430 368T482 281T563 226T672 207Q723 207 768 212T857 229T942 256T1028 295V59Q988 38 948 24T862 -1T765 -15T651 -20ZM266 1405Q266 1440 277 1465T306 1507T350 1532T405 1540Q434 1540 459 1532T504
+1508T534 1466T546 1405Q546 1371 535 1346T504 1305T460 1280T405 1272Q376 1272 351 1280T307 1304T277 1346T266 1405ZM669 1405Q669 1440 680 1465T710 1507T755 1532T811 1540Q839 1540 864 1532T909 1508T940 1466T952 1405Q952 1371 941 1346T910 1305T865
+1280T811 1272Q751 1272 710 1305T669 1405Z" />
+<glyph unicode="&#xec;" glyph-name="igrave" horiz-adv-x="625" d="M465 0H160V1118H465V0ZM269 1241Q235 1269 188 1310T94 1396T10 1480T-44 1548V1569H298Q314 1535 335 1495T380 1414T427 1335T472 1268V1241H269Z" />
+<glyph unicode="&#xed;" glyph-name="iacute" horiz-adv-x="625" d="M465 0H160V1118H465V0ZM145 1241V1268Q166 1297 190 1335T237 1413T282 1494T319 1569H661V1548Q650 1530 629 1506T581 1453T523 1396T461 1338T400 1285T348 1241H145Z" />
+<glyph unicode="&#xee;" glyph-name="icircumflex" horiz-adv-x="625" d="M465 0H160V1118H465V0ZM521 1241Q470 1275 415 1318T308 1417Q254 1361 202 1318T99 1241H-104V1268Q-78 1297 -47 1335T17 1413T80 1494T132 1569H488Q509 1535 539 1495T601 1414T666
+1335T724 1268V1241H521Z" />
+<glyph unicode="&#xef;" glyph-name="idieresis" horiz-adv-x="625" d="M465 0H160V1118H465V0ZM-32 1405Q-32 1440 -21 1465T8 1507T52 1532T107 1540Q136 1540 161 1532T206 1508T236 1466T248 1405Q248 1371 237 1346T206 1305T162 1280T107 1272Q78 1272 53
+1280T9 1304T-21 1346T-32 1405ZM371 1405Q371 1440 382 1465T412 1507T457 1532T513 1540Q541 1540 566 1532T611 1508T642 1466T654 1405Q654 1371 643 1346T612 1305T567 1280T513 1272Q453 1272 412 1305T371 1405Z" />
+<glyph unicode="&#xf0;" glyph-name="eth" horiz-adv-x="1182" d="M457 1309Q423 1330 384 1354T303 1401L399 1571Q472 1537 536 1503T657 1430L883 1569L983 1415L809 1309Q881 1240 935 1162T1024 993T1078 798T1096 573Q1096 431 1060 321T957 135T795 20T582
+-20Q471 -20 378 14T218 113T112 272T74 489Q74 611 106 705T197 863T337 961T516 995Q612 995 680 964T780 883L801 885Q773 973 723 1050T606 1184L375 1040L274 1196L457 1309ZM784 532Q784 579 773 622T737 698T675 750T586 770Q478 770 432 700T385 487Q385
+424 396 372T432 283T495 226T586 205Q692 205 738 286T784 532Z" />
+<glyph unicode="&#xf1;" glyph-name="ntilde" horiz-adv-x="1284" d="M1130 0H825V653Q825 774 789 834T672 895Q612 895 572 871T509 800T475 684T465 526V0H160V1118H393L434 975H451Q475 1018 509 1049T585 1100T672 1129T766 1139Q848 1139 915 1116T1030
+1042T1104 915T1130 729V0ZM477 1346Q446 1346 428 1320T397 1239H248Q254 1319 274 1377T326 1473T403 1529T500 1548Q541 1548 580 1532T657 1497T733 1461T807 1444Q838 1444 856 1470T887 1550H1036Q1030 1471 1010 1413T956 1317T880 1260T784 1241Q744 1241
+704 1257T626 1293T551 1329T477 1346Z" />
+<glyph unicode="&#xf2;" glyph-name="ograve" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246
+131T140 313T102 561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561ZM841 1241Q807 1269 760 1310T666 1396T582 1480T528 1548V1569H870Q886 1535 907 1495T952 1414T999 1335T1044 1268V1241H841Z" />
+<glyph unicode="&#xf3;" glyph-name="oacute" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246
+131T140 313T102 561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561ZM434 1241V1268Q455 1297 479 1335T526 1413T571 1494T608 1569H950V1548Q939 1530 918 1506T870 1453T812 1396T750 1338T689 1285T637 1241H434Z"
+/>
+<glyph unicode="&#xf4;" glyph-name="ocircumflex" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246
+131T140 313T102 561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561ZM821 1241Q770 1275 715 1318T608 1417Q554 1361 502 1318T399 1241H196V1268Q222 1297 253 1335T317 1413T380 1494T432 1569H788Q809 1535 839
+1495T901 1414T966 1335T1024 1268V1241H821Z" />
+<glyph unicode="&#xf5;" glyph-name="otilde" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246
+131T140 313T102 561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561ZM444 1346Q413 1346 395 1320T364 1239H215Q221 1319 241 1377T293 1473T370 1529T467 1548Q508 1548 547 1532T624 1497T700 1461T774 1444Q805
+1444 823 1470T854 1550H1003Q997 1471 977 1413T923 1317T847 1260T751 1241Q711 1241 671 1257T593 1293T518 1329T444 1346Z" />
+<glyph unicode="&#xf6;" glyph-name="odieresis" horiz-adv-x="1227" d="M414 561Q414 394 461 310T614 225Q719 225 766 310T813 561Q813 728 766 810T612 893Q507 893 461 811T414 561ZM1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q499 -20 406 18T246
+131T140 313T102 561Q102 700 137 808T239 989T401 1101T616 1139Q727 1139 820 1101T980 990T1086 808T1124 561ZM266 1405Q266 1440 277 1465T306 1507T350 1532T405 1540Q434 1540 459 1532T504 1508T534 1466T546 1405Q546 1371 535 1346T504 1305T460 1280T405
+1272Q376 1272 351 1280T307 1304T277 1346T266 1405ZM669 1405Q669 1440 680 1465T710 1507T755 1532T811 1540Q839 1540 864 1532T909 1508T940 1466T952 1405Q952 1371 941 1346T910 1305T865 1280T811 1272Q751 1272 710 1305T669 1405Z" />
+<glyph unicode="&#xf7;" glyph-name="divide" horiz-adv-x="1128" d="M88 612V831H1040V612H88ZM424 373Q424 415 435 444T465 490T509 516T563 524Q591 524 616 516T660 491T690 444T702 373Q702 333 691 304T660 257T616 230T563 221Q535 221 510 229T465 256T435
+304T424 373ZM424 1071Q424 1113 435 1142T465 1189T509 1215T563 1223Q591 1223 616 1215T660 1189T690 1142T702 1071Q702 1031 691 1003T660 956T616 929T563 920Q535 920 510 928T465 955T435 1002T424 1071Z" />
+<glyph unicode="&#xf8;" glyph-name="oslash" horiz-adv-x="1227" d="M1124 561Q1124 421 1089 313T987 131T825 19T610 -20Q553 -20 501 -10T401 18L344 -76L182 14L250 125Q181 199 142 308T102 561Q102 700 137 808T239 989T401 1101T616 1139Q678 1139 735
+1126T844 1090L893 1169L1053 1073L991 975Q1054 903 1089 799T1124 561ZM414 561Q414 475 426 410L709 868Q669 893 612 893Q507 893 461 811T414 561ZM813 561Q813 625 807 674L539 240Q556 232 574 229T614 225Q719 225 766 310T813 561Z" />
+<glyph unicode="&#xf9;" glyph-name="ugrave" horiz-adv-x="1284" d="M891 0L850 143H834Q809 100 775 70T699 19T612 -10T518 -20Q436 -20 369 3T254 77T180 204T154 389V1118H459V465Q459 344 495 284T612 223Q672 223 712 247T775 318T809 434T819 592V1118H1124V0H891ZM839
+1241Q805 1269 758 1310T664 1396T580 1480T526 1548V1569H868Q884 1535 905 1495T950 1414T997 1335T1042 1268V1241H839Z" />
+<glyph unicode="&#xfa;" glyph-name="uacute" horiz-adv-x="1284" d="M891 0L850 143H834Q809 100 775 70T699 19T612 -10T518 -20Q436 -20 369 3T254 77T180 204T154 389V1118H459V465Q459 344 495 284T612 223Q672 223 712 247T775 318T809 434T819 592V1118H1124V0H891ZM461
+1241V1268Q482 1297 506 1335T553 1413T598 1494T635 1569H977V1548Q966 1530 945 1506T897 1453T839 1396T777 1338T716 1285T664 1241H461Z" />
+<glyph unicode="&#xfb;" glyph-name="ucircumflex" horiz-adv-x="1284" d="M891 0L850 143H834Q809 100 775 70T699 19T612 -10T518 -20Q436 -20 369 3T254 77T180 204T154 389V1118H459V465Q459 344 495 284T612 223Q672 223 712 247T775 318T809 434T819 592V1118H1124V0H891ZM842
+1241Q791 1275 736 1318T629 1417Q575 1361 523 1318T420 1241H217V1268Q243 1297 274 1335T338 1413T401 1494T453 1569H809Q830 1535 860 1495T922 1414T987 1335T1045 1268V1241H842Z" />
+<glyph unicode="&#xfc;" glyph-name="udieresis" horiz-adv-x="1284" d="M891 0L850 143H834Q809 100 775 70T699 19T612 -10T518 -20Q436 -20 369 3T254 77T180 204T154 389V1118H459V465Q459 344 495 284T612 223Q672 223 712 247T775 318T809 434T819 592V1118H1124V0H891ZM295
+1405Q295 1440 306 1465T335 1507T379 1532T434 1540Q463 1540 488 1532T533 1508T563 1466T575 1405Q575 1371 564 1346T533 1305T489 1280T434 1272Q405 1272 380 1280T336 1304T306 1346T295 1405ZM698 1405Q698 1440 709 1465T739 1507T784 1532T840 1540Q868
+1540 893 1532T938 1508T969 1466T981 1405Q981 1371 970 1346T939 1305T894 1280T840 1272Q780 1272 739 1305T698 1405Z" />
+<glyph unicode="&#xfd;" glyph-name="yacute" horiz-adv-x="1104" d="M0 1118H334L514 489Q530 437 537 378T547 272H553Q555 295 558 323T567 380T578 437T592 489L768 1118H1104L662 -143Q600 -320 493 -406T225 -492Q173 -492 135 -487T70 -475V-233Q91 -238
+123 -242T190 -246Q238 -246 272 -233T330 -197T372 -140T403 -66L422 -10L0 1118ZM393 1241V1268Q414 1297 438 1335T485 1413T530 1494T567 1569H909V1548Q898 1530 877 1506T829 1453T771 1396T709 1338T648 1285T596 1241H393Z" />
+<glyph unicode="&#xfe;" glyph-name="thorn" horiz-adv-x="1245" d="M465 973Q485 1008 512 1038T576 1090T656 1126T756 1139Q842 1139 913 1102T1035 992T1114 811T1143 561Q1143 418 1115 310T1036 128T914 17T756 -20Q701 -20 656 -10T576 20T513 64T465 117H451Q454
+85 458 55Q461 29 463 3T465 -39V-492H160V1556H465V1165Q465 1141 463 1108T458 1045Q454 1010 451 973H465ZM653 895Q602 895 567 877T509 821T477 728T465 596V563Q465 482 474 419T506 314T564 249T655 227Q746 227 788 313T831 565Q831 730 789 812T653 895Z"
+/>
+<glyph unicode="&#xff;" glyph-name="ydieresis" horiz-adv-x="1104" d="M0 1118H334L514 489Q530 437 537 378T547 272H553Q555 295 558 323T567 380T578 437T592 489L768 1118H1104L662 -143Q600 -320 493 -406T225 -492Q173 -492 135 -487T70 -475V-233Q91
+-238 123 -242T190 -246Q238 -246 272 -233T330 -197T372 -140T403 -66L422 -10L0 1118ZM466 1405Q466 1440 477 1465T506 1507T550 1532T605 1540Q634 1540 659 1532T704 1508T734 1466T746 1405Q746 1371 735 1346T704 1305T660 1280T605 1272Q576 1272 551 1280T507
+1304T477 1346T466 1405ZM869 1405Q869 1440 880 1465T910 1507T955 1532T1011 1540Q1039 1540 1064 1532T1109 1508T1140 1466T1152 1405Q1152 1371 1141 1346T1110 1305T1065 1280T1011 1272Q951 1272 910 1305T869 1405Z" />
+<glyph unicode="&#x2013;" glyph-name="endash" horiz-adv-x="1024" d="M82 436V666H942V436H82Z" />
+<glyph unicode="&#x2014;" glyph-name="emdash" horiz-adv-x="2048" d="M82 436V666H1966V436H82Z" />
+<glyph unicode="&#x2018;" glyph-name="quoteleft" horiz-adv-x="440" d="M37 961L23 983Q37 1037 56 1098T99 1221T148 1344T199 1462H418Q403 1401 389 1335T361 1204T336 1076T317 961H37Z" />
+<glyph unicode="&#x2019;" glyph-name="quoteright" horiz-adv-x="440" d="M403 1462L418 1440Q404 1385 385 1325T342 1202T293 1078T242 961H23Q37 1021 51 1087T79 1219T104 1347T123 1462H403Z" />
+<glyph unicode="&#x201a;" glyph-name="quotesinglbase" horiz-adv-x="594" d="M459 215Q445 161 426 100T383 -23T334 -146T283 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H444L459 215Z" />
+<glyph unicode="&#x201c;" glyph-name="quotedblleft" horiz-adv-x="907" d="M489 983Q503 1037 523 1098T566 1221T615 1344T666 1462H885Q870 1401 856 1335T828 1204T803 1076T784 961H504L489 983ZM23 983Q37 1037 56 1098T99 1221T148 1344T199 1462H418Q403
+1401 389 1335T361 1204T336 1076T317 961H37L23 983Z" />
+<glyph unicode="&#x201d;" glyph-name="quotedblright" horiz-adv-x="907" d="M418 1440Q404 1385 385 1325T342 1202T293 1078T242 961H23Q37 1021 51 1087T79 1219T104 1347T123 1462H403L418 1440ZM885 1440Q871 1385 852 1325T809 1202T760 1078T709 961H489Q504
+1021 518 1087T546 1219T571 1347T590 1462H870L885 1440Z" />
+<glyph unicode="&#x201e;" glyph-name="quotedblbase" horiz-adv-x="1061" d="M459 215Q445 161 426 100T383 -23T334 -146T283 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H444L459 215ZM926 215Q912 161 893 100T850 -23T801 -146T750 -264H530Q545 -203
+559 -137T587 -6T612 122T631 238H911L926 215Z" />
+<glyph unicode="&#x2022;" glyph-name="bullet" horiz-adv-x="770" d="M98 748Q98 834 120 894T180 992T271 1047T385 1065Q444 1065 496 1048T588 992T649 894T672 748Q672 663 650 603T588 505T497 448T385 430Q324 430 272 448T181 504T120 603T98 748Z" />
+<glyph unicode="&#x2039;" glyph-name="guilsinglleft" horiz-adv-x="692" d="M82 573L391 1028L610 909L393 561L610 213L391 94L82 547V573Z" />
+<glyph unicode="&#x203a;" glyph-name="guilsinglright" horiz-adv-x="692" d="M610 547L301 94L82 213L299 561L82 909L301 1028L610 573V547Z" />
+</font>
+</defs>
+</svg>
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.ttf b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.ttf
new file mode 100644
index 0000000000..15896c441f
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.ttf
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff
new file mode 100644
index 0000000000..67e3e25f83
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff2 b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff2
new file mode 100644
index 0000000000..1e726a7cfc
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-700.woff2
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.eot b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.eot
new file mode 100644
index 0000000000..ac2698e85a
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.eot
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.svg b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.svg
new file mode 100644
index 0000000000..d9f2a214f9
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.svg
@@ -0,0 +1,403 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg">
+<defs >
+<font id="DroidSans" horiz-adv-x="1062" ><font-face
+ font-family="Droid Sans"
+ units-per-em="2048"
+ panose-1="2 11 6 6 3 8 4 2 2 4"
+ ascent="1907"
+ descent="-492"
+ alphabetic="0" />
+<glyph unicode=" " glyph-name="space" horiz-adv-x="532" />
+<glyph unicode="!" glyph-name="exclam" horiz-adv-x="551" d="M336 414H215L164 1462H387L336 414ZM147 111Q147 149 157 175T184 218T224 242T274 250Q300 250 323 243T364 219T391 176T401 111Q401 74 391 48T364 4T324 -21T274 -29Q247 -29 224 -21T184 4T157
+47T147 111Z" />
+<glyph unicode="&quot;" glyph-name="quotedbl" horiz-adv-x="823" d="M330 1462L289 934H174L133 1462H330ZM690 1462L649 934H535L494 1462H690Z" />
+<glyph unicode="#" glyph-name="numbersign" horiz-adv-x="1323" d="M983 893L920 565H1200V428H893L811 0H664L748 428H457L375 0H231L309 428H51V565H336L401 893H127V1030H426L508 1462H655L573 1030H866L950 1462H1094L1010 1030H1272V893H983ZM483 565H774L838
+893H547L483 565Z" />
+<glyph unicode="$" glyph-name="dollar" horiz-adv-x="1128" d="M985 446Q985 376 960 319T889 220T776 151T625 111V-119H487V102Q437 102 386 106T287 120T197 142T123 172V344Q156 328 199 312T291 282T389 261T487 252V686Q398 716 333 749T224 824T160 922T139
+1051Q139 1118 163 1173T233 1270T343 1338T487 1374V1554H625V1378Q725 1373 809 1352T961 1300L895 1155Q839 1180 769 1200T625 1227V805Q713 774 780 741T893 667T962 572T985 446ZM809 446Q809 479 799 506T768 556T711 598T625 635V262Q718 276 763 325T809
+446ZM315 1049Q315 1013 323 985T352 933T405 890T487 854V1223Q398 1207 357 1163T315 1049Z" />
+<glyph unicode="%" glyph-name="percent" horiz-adv-x="1690" d="M250 1026Q250 861 285 779T401 696Q557 696 557 1026Q557 1354 401 1354Q321 1354 286 1273T250 1026ZM705 1026Q705 918 687 832T632 687T538 597T401 565Q328 565 272 596T178 687T121 832T102
+1026Q102 1134 119 1219T173 1362T266 1452T401 1483Q476 1483 532 1452T627 1363T685 1219T705 1026ZM1133 440Q1133 275 1168 193T1284 111Q1440 111 1440 440Q1440 768 1284 768Q1204 768 1169 687T1133 440ZM1587 440Q1587 332 1570 247T1515 102T1421 12T1284
+-20Q1210 -20 1154 11T1061 102T1004 246T985 440Q985 548 1002 633T1056 776T1149 866T1284 897Q1359 897 1415 866T1510 777T1567 633T1587 440ZM1331 1462L520 0H362L1174 1462H1331Z" />
+<glyph unicode="&amp;" glyph-name="ampersand" horiz-adv-x="1438" d="M422 1165Q422 1131 430 1099T454 1034T497 968T559 897Q618 932 661 963T732 1026T774 1093T788 1169Q788 1205 776 1235T740 1288T683 1322T608 1335Q522 1335 472 1291T422 1165ZM557
+141Q615 141 664 152T755 184T833 231T901 289L514 696Q462 663 422 632T355 564T313 486T299 387Q299 333 316 288T367 210T448 159T557 141ZM109 381Q109 459 129 520T187 631T281 724T408 809Q377 845 347 883T295 965T258 1058T244 1165Q244 1240 269 1299T341
+1400T457 1463T614 1485Q697 1485 762 1464T873 1401T943 1300T967 1165Q967 1101 942 1047T875 946T779 860T664 784L1016 412Q1043 441 1064 471T1103 535T1133 608T1157 694H1341Q1326 628 1306 573T1259 468T1200 377T1128 293L1405 0H1180L1012 172Q963 127
+915 92T813 32T697 -6T557 -20Q452 -20 369 6T228 84T140 210T109 381Z" />
+<glyph unicode="&apos;" glyph-name="quotesingle" horiz-adv-x="463" d="M330 1462L289 934H174L133 1462H330Z" />
+<glyph unicode="(" glyph-name="parenleft" horiz-adv-x="616" d="M82 561Q82 686 100 807T155 1043T248 1263T383 1462H555Q415 1269 343 1038T270 563Q270 444 288 326T342 95T431 -124T553 -324H383Q305 -234 249 -131T155 84T100 317T82 561Z" />
+<glyph unicode=")" glyph-name="parenright" horiz-adv-x="616" d="M535 561Q535 437 517 317T462 85T368 -131T233 -324H63Q132 -230 185 -124T274 95T328 326T346 563Q346 807 274 1038T61 1462H233Q311 1369 367 1264T461 1044T517 808T535 561Z" />
+<glyph unicode="*" glyph-name="asterisk" horiz-adv-x="1128" d="M664 1556L621 1163L1018 1274L1044 1081L666 1053L911 727L733 631L557 989L399 631L215 727L457 1053L82 1081L111 1274L502 1163L459 1556H664Z" />
+<glyph unicode="+" glyph-name="plus" horiz-adv-x="1128" d="M489 647H102V797H489V1186H639V797H1026V647H639V262H489V647Z" />
+<glyph unicode="," glyph-name="comma" horiz-adv-x="512" d="M362 238L377 215Q363 161 344 100T301 -23T252 -146T201 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H362Z" />
+<glyph unicode="-" glyph-name="hyphen" horiz-adv-x="659" d="M82 465V633H578V465H82Z" />
+<glyph unicode="." glyph-name="period" horiz-adv-x="549" d="M147 111Q147 149 157 175T184 218T224 242T274 250Q300 250 323 243T364 219T391 176T401 111Q401 74 391 48T364 4T324 -21T274 -29Q247 -29 224 -21T184 4T157 47T147 111Z" />
+<glyph unicode="/" glyph-name="slash" horiz-adv-x="764" d="M743 1462L199 0H20L565 1462H743Z" />
+<glyph unicode="0" glyph-name="zero" horiz-adv-x="1128" d="M1032 733Q1032 556 1007 416T925 179T779 31T563 -20Q445 -20 358 31T213 179T127 416T98 733Q98 910 123 1050T204 1286T348 1434T563 1485Q682 1485 770 1435T916 1288T1003 1051T1032 733ZM283
+733Q283 583 298 471T346 285T432 173T563 135Q640 135 694 172T782 283T832 469T848 733Q848 883 833 995T783 1181T694 1292T563 1329Q486 1329 433 1292T346 1181T298 995T283 733Z" />
+<glyph unicode="1" glyph-name="one" horiz-adv-x="1128" d="M711 0H535V913Q535 956 535 1005T537 1102T540 1195T543 1274Q526 1256 513 1243T487 1218T458 1193T422 1161L274 1040L178 1163L561 1462H711V0Z" />
+<glyph unicode="2" glyph-name="two" horiz-adv-x="1128" d="M1008 0H96V156L446 537Q521 618 580 685T680 816T744 944T766 1085Q766 1144 749 1189T701 1265T626 1313T530 1329Q435 1329 359 1291T213 1192L111 1311Q151 1347 197 1378T296 1433T408 1469T532
+1483Q628 1483 705 1456T837 1379T920 1256T950 1092Q950 1007 924 930T851 779T740 629T600 473L319 174V166H1008V0Z" />
+<glyph unicode="3" glyph-name="three" horiz-adv-x="1128" d="M961 1120Q961 1047 938 987T874 883T774 811T645 770V764Q822 742 914 652T1006 416Q1006 320 974 240T875 102T708 12T469 -20Q360 -20 264 -3T82 59V229Q169 183 270 158T465 133Q557 133 624
+153T734 210T798 301T819 422Q819 490 793 538T717 618T598 665T438 680H305V831H438Q519 831 582 851T687 908T752 996T774 1108Q774 1160 756 1201T705 1270T626 1314T524 1329Q417 1329 336 1296T180 1208L88 1333Q126 1364 172 1391T274 1438T391 1471T524
+1483Q632 1483 713 1456T850 1381T933 1266T961 1120Z" />
+<glyph unicode="4" glyph-name="four" horiz-adv-x="1128" d="M1087 328H874V0H698V328H23V487L686 1470H874V494H1087V328ZM698 494V850Q698 906 699 967T703 1087T707 1197T711 1282H702Q695 1262 685 1238T662 1189T636 1141T612 1102L201 494H698Z" />
+<glyph unicode="5" glyph-name="five" horiz-adv-x="1128" d="M545 897Q644 897 729 870T878 788T978 654T1014 469Q1014 355 980 264T879 110T714 14T487 -20Q436 -20 387 -15T292 -1T205 24T131 59V231Q164 208 208 190T302 160T400 142T492 135Q571 135 633
+153T738 211T804 309T827 449Q827 592 739 667T483 743Q456 743 425 741T362 734T302 726T252 717L162 774L217 1462H907V1296H375L336 877Q368 883 420 890T545 897Z" />
+<glyph unicode="6" glyph-name="six" horiz-adv-x="1128" d="M113 625Q113 730 123 834T160 1033T233 1211T350 1353T520 1448T752 1483Q771 1483 794 1482T840 1479T885 1473T924 1464V1309Q889 1321 845 1327T758 1333Q668 1333 600 1312T481 1251T398 1158T343
+1039T312 899T299 745H311Q331 781 359 812T426 866T511 902T618 915Q713 915 790 886T921 799T1004 660T1034 471Q1034 357 1003 266T914 112T774 14T590 -20Q490 -20 403 19T251 138T150 339T113 625ZM588 133Q648 133 697 153T783 215T838 320T858 471Q858 541
+842 596T792 691T710 751T594 772Q527 772 472 749T377 688T317 602T295 506Q295 439 313 373T368 253T460 167T588 133Z" />
+<glyph unicode="7" glyph-name="seven" horiz-adv-x="1128" d="M281 0L844 1296H90V1462H1030V1317L475 0H281Z" />
+<glyph unicode="8" glyph-name="eight" horiz-adv-x="1128" d="M565 1485Q649 1485 723 1463T854 1397T944 1287T977 1133Q977 1066 957 1012T902 915T819 837T715 774Q773 743 828 705T927 620T997 513T1024 381Q1024 289 991 215T897 88T752 8T565 -20Q455 -20
+370 7T226 84T137 208T106 373Q106 448 128 508T189 616T279 701T389 766Q340 797 297 833T223 915T173 1014T154 1135Q154 1222 187 1287T278 1397T409 1463T565 1485ZM285 371Q285 318 301 274T351 198T437 149T561 131Q631 131 684 148T774 198T828 277T846
+379Q846 431 827 473T771 551T683 619T569 682L539 696Q413 636 349 559T285 371ZM563 1333Q457 1333 395 1280T332 1126Q332 1069 349 1028T398 955T472 898T567 848Q615 870 657 896T731 955T781 1030T799 1126Q799 1227 736 1280T563 1333Z" />
+<glyph unicode="9" glyph-name="nine" horiz-adv-x="1128" d="M1028 838Q1028 733 1018 629T981 429T908 252T791 109T621 15T389 -20Q370 -20 347 -19T301 -16T256 -10T217 -2V154Q252 141 296 135T383 129Q518 129 605 176T743 303T815 491T842 717H829Q809
+681 781 650T715 596T629 560T522 547Q427 547 350 576T219 663T136 802T106 991Q106 1105 137 1196T226 1351T366 1449T551 1483Q652 1483 739 1444T890 1325T991 1124T1028 838ZM553 1329Q493 1329 444 1309T358 1247T303 1142T283 991Q283 921 299 866T349 771T431
+711T547 690Q615 690 670 713T764 774T824 860T846 956Q846 1023 828 1089T773 1209T681 1296T553 1329Z" />
+<glyph unicode=":" glyph-name="colon" horiz-adv-x="549" d="M147 111Q147 149 157 175T184 218T224 242T274 250Q300 250 323 243T364 219T391 176T401 111Q401 74 391 48T364 4T324 -21T274 -29Q247 -29 224 -21T184 4T157 47T147 111ZM147 987Q147 1026 157
+1052T184 1095T224 1119T274 1126Q300 1126 323 1119T364 1096T391 1053T401 987Q401 950 391 924T364 881T324 856T274 848Q247 848 224 856T184 881T157 924T147 987Z" />
+<glyph unicode=";" glyph-name="semicolon" horiz-adv-x="549" d="M362 238L377 215Q363 161 344 100T301 -23T252 -146T201 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H362ZM147 987Q147 1026 157 1052T184 1095T224 1119T274 1126Q300 1126 323 1119T364
+1096T391 1053T401 987Q401 950 391 924T364 881T324 856T274 848Q247 848 224 856T184 881T157 924T147 987Z" />
+<glyph unicode="&lt;" glyph-name="less" horiz-adv-x="1128" d="M1026 238L102 662V764L1026 1245V1085L291 721L1026 399V238Z" />
+<glyph unicode="=" glyph-name="equal" horiz-adv-x="1128" d="M102 852V1001H1026V852H102ZM102 442V592H1026V442H102Z" />
+<glyph unicode="&gt;" glyph-name="greater" horiz-adv-x="1128" d="M102 399L838 721L102 1085V1245L1026 764V662L102 238V399Z" />
+<glyph unicode="?" glyph-name="question" horiz-adv-x="872" d="M281 414V451Q281 508 288 554T315 640T368 718T451 799Q499 840 533 873T588 941T620 1015T631 1108Q631 1156 616 1195T573 1263T502 1307T403 1323Q320 1323 245 1297T100 1237L37 1382Q118
+1424 212 1453T403 1483Q496 1483 570 1458T697 1384T777 1267T805 1110Q805 1043 792 991T751 893T684 806T590 717Q538 672 505 639T453 574T427 509T420 432V414H281ZM233 111Q233 149 243 175T270 218T310 242T360 250Q386 250 409 243T450 219T477 176T487
+111Q487 74 477 48T450 4T410 -21T360 -29Q333 -29 310 -21T270 4T243 47T233 111Z" />
+<glyph unicode="@" glyph-name="at" horiz-adv-x="1774" d="M1665 731Q1665 669 1656 607T1628 488T1581 383T1514 298T1428 242T1321 221Q1276 221 1240 236T1177 276T1135 333T1112 401H1108Q1090 364 1063 331T1001 274T921 235T823 221Q746 221 687 249T586
+327T524 449T502 606Q502 707 531 791T616 936T751 1031T928 1065Q973 1065 1018 1061T1104 1050T1179 1035T1237 1018L1214 602Q1213 580 1213 567T1212 545T1212 533T1212 526Q1212 473 1222 439T1250 385T1288 358T1333 350Q1379 350 1414 380T1472 463T1508
+585T1520 733Q1520 875 1477 985T1358 1172T1178 1287T950 1327Q781 1327 652 1272T436 1117T303 881T258 582Q258 431 297 314T413 117T603 -4T864 -45Q925 -45 984 -38T1099 -19T1205 8T1298 41V-100Q1212 -138 1104 -160T866 -182Q687 -182 547 -131T309 17T160
+255T109 575Q109 763 168 925T336 1207T601 1394T950 1462Q1106 1462 1237 1412T1463 1267T1612 1037T1665 731ZM662 602Q662 469 712 410T848 350Q903 350 942 372T1006 436T1044 535T1061 662L1075 915Q1047 923 1009 929T928 936Q854 936 804 907T722 831T676
+724T662 602Z" />
+<glyph unicode="A" glyph-name="A" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836Z" />
+<glyph unicode="B" glyph-name="B" horiz-adv-x="1272" d="M199 1462H598Q726 1462 823 1443T986 1380T1085 1266T1118 1092Q1118 1030 1099 976T1042 881T951 813T827 776V766Q896 754 956 732T1062 670T1133 570T1159 424Q1159 324 1127 246T1033 113T883 29T684
+0H199V1462ZM385 842H629Q713 842 770 857T862 901T912 975T928 1079Q928 1199 851 1251T608 1303H385V842ZM385 686V158H651Q739 158 798 178T894 234T947 320T963 432Q963 488 947 535T893 615T793 667T639 686H385Z" />
+<glyph unicode="C" glyph-name="C" horiz-adv-x="1235" d="M793 1319Q686 1319 599 1279T451 1162T356 977T322 731Q322 590 351 481T440 296T587 182T793 143Q882 143 962 160T1120 201V39Q1081 24 1042 13T961 -6T870 -16T762 -20Q598 -20 478 34T280 187T163
+425T125 733Q125 899 168 1037T296 1274T506 1428T793 1483Q901 1483 999 1461T1176 1397L1098 1241Q1035 1273 961 1296T793 1319Z" />
+<glyph unicode="D" glyph-name="D" horiz-adv-x="1401" d="M1276 745Q1276 560 1228 421T1089 188T866 47T565 0H199V1462H606Q759 1462 883 1416T1094 1280T1228 1055T1276 745ZM1079 739Q1079 885 1046 991T950 1167T795 1269T586 1303H385V160H547Q811 160
+945 306T1079 739Z" />
+<glyph unicode="E" glyph-name="E" horiz-adv-x="1081" d="M958 0H199V1462H958V1298H385V846H920V684H385V164H958V0Z" />
+<glyph unicode="F" glyph-name="F" horiz-adv-x="1006" d="M385 0H199V1462H958V1298H385V782H920V618H385V0Z" />
+<glyph unicode="G" glyph-name="G" horiz-adv-x="1413" d="M782 772H1266V55Q1211 37 1155 23T1040 0T916 -15T776 -20Q619 -20 498 32T294 182T168 419T125 733Q125 905 172 1044T311 1280T535 1430T840 1483Q951 1483 1053 1461T1243 1397L1171 1235Q1135 1252
+1094 1267T1008 1293T918 1312T825 1319Q703 1319 609 1279T452 1162T355 977T322 731Q322 601 349 493T437 307T592 186T821 143Q865 143 901 145T969 152T1027 161T1081 172V608H782V772Z" />
+<glyph unicode="H" glyph-name="H" horiz-adv-x="1436" d="M1237 0H1051V682H385V0H199V1462H385V846H1051V1462H1237V0Z" />
+<glyph unicode="I" glyph-name="I" horiz-adv-x="694" d="M612 0H82V102L254 143V1319L82 1360V1462H612V1360L440 1319V143L612 102V0Z" />
+<glyph unicode="J" glyph-name="J" horiz-adv-x="555" d="M-29 -389Q-80 -389 -118 -383T-184 -365V-205Q-150 -214 -111 -219T-27 -225Q10 -225 47 -216T115 -181T165 -112T184 0V1462H371V20Q371 -85 342 -162T260 -289T134 -364T-29 -389Z" />
+<glyph unicode="K" glyph-name="K" horiz-adv-x="1186" d="M1186 0H975L524 698L385 584V0H199V1462H385V731L506 899L958 1462H1167L647 825L1186 0Z" />
+<glyph unicode="L" glyph-name="L" horiz-adv-x="1006" d="M199 0V1462H385V166H958V0H199Z" />
+<glyph unicode="M" glyph-name="M" horiz-adv-x="1782" d="M803 0L360 1280H352Q358 1206 362 1133Q366 1070 368 1001T371 874V0H199V1462H475L887 270H893L1307 1462H1583V0H1397V887Q1397 939 1399 1006T1404 1134Q1408 1205 1411 1278H1403L956 0H803Z" />
+<glyph unicode="N" glyph-name="N" horiz-adv-x="1493" d="M1294 0H1079L360 1210H352Q358 1133 362 1057Q366 992 368 921T371 793V0H199V1462H412L1128 258H1135Q1132 334 1128 408Q1127 440 1126 473T1123 540T1121 605T1120 662V1462H1294V0Z" />
+<glyph unicode="O" glyph-name="O" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393 733ZM322
+733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733Z" />
+<glyph unicode="P" glyph-name="P" horiz-adv-x="1180" d="M1075 1034Q1075 943 1048 859T957 711T791 608T535 569H385V0H199V1462H561Q695 1462 792 1434T952 1351T1045 1216T1075 1034ZM385 727H514Q607 727 676 743T791 794T860 886T883 1024Q883 1166 801
+1234T545 1303H385V727Z" />
+<glyph unicode="Q" glyph-name="Q" horiz-adv-x="1518" d="M1393 733Q1393 602 1369 489T1297 286T1178 129T1014 25Q1057 -69 1125 -140T1284 -272L1163 -414Q1060 -341 974 -242T836 -16Q819 -18 799 -19T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125
+905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393 733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428
+1165T348 980T322 733Z" />
+<glyph unicode="R" glyph-name="R" horiz-adv-x="1208" d="M385 604V0H199V1462H555Q821 1462 948 1359T1075 1047Q1075 960 1051 895T986 784T893 706T786 655L1184 0H965L614 604H385ZM385 762H549Q639 762 702 779T805 831T864 917T883 1038Q883 1110 863 1160T801
+1242T696 1288T545 1303H385V762Z" />
+<glyph unicode="S" glyph-name="S" horiz-adv-x="1063" d="M969 391Q969 294 935 218T836 88T680 8T473 -20Q362 -20 266 -3T104 49V227Q138 211 181 196T273 168T372 149T473 141Q633 141 709 201T786 373Q786 427 772 467T721 540T623 605T469 674Q380 709 315
+750T207 844T144 962T123 1112Q123 1200 155 1269T245 1385T383 1458T561 1483Q680 1483 775 1461T944 1403L877 1247Q812 1276 730 1297T559 1319Q437 1319 370 1263T303 1110Q303 1053 318 1012T368 937T460 874T602 811Q693 775 761 737T876 651T945 540T969
+391Z" />
+<glyph unicode="T" glyph-name="T" horiz-adv-x="1063" d="M625 0H438V1298H20V1462H1042V1298H625V0Z" />
+<glyph unicode="U" glyph-name="U" horiz-adv-x="1430" d="M1245 1464V516Q1245 402 1212 304T1113 134T946 21T709 -20Q581 -20 483 18T319 128T218 298T184 520V1462H371V510Q371 335 457 239T719 143Q808 143 872 170T977 246T1038 363T1059 512V1464H1245Z" />
+<glyph unicode="V" glyph-name="V" horiz-adv-x="1163" d="M965 1462H1163L674 0H487L0 1462H197L492 535Q521 444 542 360T580 201Q595 275 618 359T672 541L965 1462Z" />
+<glyph unicode="W" glyph-name="W" horiz-adv-x="1810" d="M809 1462H1006L1235 606Q1250 550 1264 494T1291 386T1313 286T1329 201Q1333 239 1339 284T1353 378T1370 479T1391 580L1591 1462H1790L1423 0H1235L981 938Q967 989 954 1043T930 1144Q918 1199 907
+1251Q896 1200 885 1145Q875 1098 863 1042T836 932L594 0H406L20 1462H217L440 573Q452 527 462 478T480 379T496 285T508 201Q513 238 520 287T538 390T559 499T584 604L809 1462Z" />
+<glyph unicode="X" glyph-name="X" horiz-adv-x="1120" d="M1120 0H909L555 635L188 0H0L453 764L31 1462H229L561 903L895 1462H1085L664 770L1120 0Z" />
+<glyph unicode="Y" glyph-name="Y" horiz-adv-x="1079" d="M539 723L879 1462H1079L633 569V0H446V559L0 1462H203L539 723Z" />
+<glyph unicode="Z" glyph-name="Z" horiz-adv-x="1104" d="M1022 0H82V145L793 1296H102V1462H1001V1317L291 166H1022V0Z" />
+<glyph unicode="[" glyph-name="bracketleft" horiz-adv-x="621" d="M569 -324H164V1462H569V1313H346V-174H569V-324Z" />
+<glyph unicode="\" glyph-name="backslash" horiz-adv-x="764" d="M201 1462L745 0H567L23 1462H201Z" />
+<glyph unicode="]" glyph-name="bracketright" horiz-adv-x="621" d="M51 -174H274V1313H51V1462H457V-324H51V-174Z" />
+<glyph unicode="^" glyph-name="asciicircum" horiz-adv-x="1090" d="M41 549L500 1473H602L1049 549H888L551 1284L202 549H41Z" />
+<glyph unicode="_" glyph-name="underscore" horiz-adv-x="842" d="M846 -324H-4V-184H846V-324Z" />
+<glyph unicode="`" glyph-name="grave" horiz-adv-x="1182" d="M786 1241H666Q631 1269 590 1310T511 1396T441 1480T393 1548V1569H612Q628 1535 649 1495T694 1414T741 1335T786 1268V1241Z" />
+<glyph unicode="a" glyph-name="a" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967 374 943T236
+885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127Z" />
+<glyph unicode="b" glyph-name="b" horiz-adv-x="1200" d="M670 1118Q764 1118 841 1082T972 975T1057 797T1087 551Q1087 410 1057 304T973 125T841 17T670 -20Q611 -20 563 -7T477 27T409 78T356 139H344L307 0H174V1556H356V1180Q356 1145 355 1106T352 1032Q350
+992 348 954H356Q379 989 408 1019T475 1071T562 1105T670 1118ZM635 967Q555 967 502 942T416 864T370 734T356 551Q356 450 369 372T415 240T502 159T637 131Q772 131 835 240T899 553Q899 761 836 864T635 967Z" />
+<glyph unicode="c" glyph-name="c" horiz-adv-x="948" d="M594 -20Q493 -20 405 11T252 111T150 286T113 543Q113 700 151 809T255 987T411 1087T602 1118Q680 1118 754 1101T879 1059L825 905Q802 915 774 924T716 941T657 953T602 958Q445 958 373 858T301 545Q301
+334 373 237T594 139Q675 139 740 157T860 201V39Q806 10 745 -5T594 -20Z" />
+<glyph unicode="d" glyph-name="d" horiz-adv-x="1200" d="M852 147H844Q822 113 793 83T725 29T638 -7T530 -20Q437 -20 360 16T228 123T143 301T113 547Q113 688 143 794T228 973T360 1081T530 1118Q589 1118 637 1105T723 1070T792 1019T844 958H856Q853 992
+850 1023Q848 1049 846 1076T844 1120V1556H1026V0H879L852 147ZM565 131Q641 131 693 154T778 224T826 341T844 506V547Q844 648 831 726T785 858T698 939T563 967Q428 967 365 858T301 545Q301 336 364 234T565 131Z" />
+<glyph unicode="e" glyph-name="e" horiz-adv-x="1096" d="M608 -20Q498 -20 407 17T251 125T149 301T113 541Q113 677 146 784T239 965T382 1079T567 1118Q666 1118 745 1083T879 983T963 828T993 627V514H301Q306 321 382 230T610 139Q661 139 704 144T788 158T867
+182T944 215V53Q904 34 866 20T787 -3T703 -16T608 -20ZM563 967Q449 967 383 889T305 662H797Q797 730 784 786T742 883T669 945T563 967Z" />
+<glyph unicode="f" glyph-name="f" horiz-adv-x="674" d="M651 961H406V0H223V961H29V1036L223 1104V1200Q223 1307 245 1377T310 1490T415 1549T555 1567Q614 1567 663 1556T752 1530L705 1389Q674 1400 638 1408T561 1417Q521 1417 492 1408T444 1374T416 1309T406
+1202V1098H651V961Z" />
+<glyph unicode="g" glyph-name="g" horiz-adv-x="1061" d="M1020 1098V985L823 958Q851 923 870 869T889 745Q889 669 866 605T795 493T677 420T514 393Q492 393 470 393T434 397Q417 387 401 375T371 346T349 310T340 266Q340 239 352 223T384 197T433 185T492
+182H668Q761 182 825 159T929 95T988 1T1006 -115Q1006 -203 974 -273T874 -391T705 -466T463 -492Q356 -492 276 -471T143 -410T64 -314T37 -186Q37 -126 56 -81T109 -2T185 52T276 84Q234 103 207 144T180 238Q180 299 212 343T313 430Q270 448 235 479T175 551T137
+640T123 739Q123 828 148 898T222 1017T344 1092T514 1118Q551 1118 590 1113T657 1098H1020ZM209 -180Q209 -217 222 -249T264 -304T342 -340T463 -354Q649 -354 741 -297T834 -131Q834 -85 822 -56T783 -11T710 12T600 18H424Q389 18 351 10T282 -20T230 -80T209
+-180ZM301 745Q301 630 355 574T508 518Q608 518 659 573T711 748Q711 871 659 929T506 987Q407 987 354 927T301 745Z" />
+<glyph unicode="h" glyph-name="h" horiz-adv-x="1206" d="M860 0V707Q860 837 808 902T643 967Q562 967 507 941T419 864T371 739T356 569V0H174V1556H356V1094L348 950H358Q383 993 417 1024T493 1077T580 1108T674 1118Q857 1118 949 1023T1042 717V0H860Z" />
+<glyph unicode="i" glyph-name="i" horiz-adv-x="530" d="M356 0H174V1098H356V0ZM160 1395Q160 1455 190 1482T266 1509Q288 1509 307 1503T341 1482T364 1447T373 1395Q373 1337 342 1309T266 1280Q221 1280 191 1308T160 1395Z" />
+<glyph unicode="j" glyph-name="j" horiz-adv-x="530" d="M66 -492Q18 -492 -13 -485T-68 -467V-319Q-42 -329 -15 -334T47 -340Q74 -340 97 -333T137 -306T164 -254T174 -170V1098H356V-158Q356 -235 339 -296T286 -401T196 -468T66 -492ZM160 1395Q160 1455
+190 1482T266 1509Q288 1509 307 1503T341 1482T364 1447T373 1395Q373 1337 342 1309T266 1280Q221 1280 191 1308T160 1395Z" />
+<glyph unicode="k" glyph-name="k" horiz-adv-x="1016" d="M342 567L477 737L770 1098H981L580 623L1008 0H799L463 504L354 422V0H174V1556H354V842L338 567H342Z" />
+<glyph unicode="l" glyph-name="l" horiz-adv-x="530" d="M356 0H174V1556H356V0Z" />
+<glyph unicode="m" glyph-name="m" horiz-adv-x="1835" d="M1489 0V707Q1489 837 1439 902T1284 967Q1211 967 1160 944T1077 875T1029 762T1014 606V0H831V707Q831 837 782 902T627 967Q550 967 498 941T415 864T370 739T356 569V0H174V1098H322L348 950H358Q382
+993 415 1024T487 1077T571 1108T662 1118Q782 1118 861 1074T979 936H987Q1013 983 1049 1017T1129 1073T1221 1107T1319 1118Q1494 1118 1582 1023T1671 717V0H1489Z" />
+<glyph unicode="n" glyph-name="n" horiz-adv-x="1206" d="M860 0V707Q860 837 808 902T643 967Q562 967 507 941T419 864T371 739T356 569V0H174V1098H322L348 950H358Q383 993 417 1024T493 1077T580 1108T674 1118Q857 1118 949 1023T1042 717V0H860Z" />
+<glyph unicode="o" glyph-name="o" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069 551ZM301 551Q301
+342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551Z" />
+<glyph unicode="p" glyph-name="p" horiz-adv-x="1200" d="M670 -20Q611 -20 563 -7T477 27T409 78T356 139H344Q347 105 350 74Q352 48 354 21T356 -23V-492H174V1098H322L348 950H356Q379 985 408 1015T475 1068T562 1104T670 1118Q764 1118 841 1082T972 975T1057
+797T1087 551Q1087 410 1057 304T973 125T841 17T670 -20ZM635 967Q559 967 507 944T422 874T374 757T356 592V551Q356 450 369 372T415 240T502 159T637 131Q772 131 835 240T899 553Q899 761 836 864T635 967Z" />
+<glyph unicode="q" glyph-name="q" horiz-adv-x="1200" d="M565 131Q641 131 693 154T778 224T826 341T844 506V547Q844 648 831 726T785 858T698 939T563 967Q428 967 365 858T301 545Q301 336 364 234T565 131ZM530 -20Q437 -20 360 16T228 123T143 301T113
+547Q113 688 143 794T228 973T360 1081T530 1118Q589 1118 637 1105T723 1069T791 1016T844 950H852L879 1098H1026V-492H844V-23Q844 -4 846 25T850 81Q853 113 856 147H844Q822 113 793 83T725 29T638 -7T530 -20Z" />
+<glyph unicode="r" glyph-name="r" horiz-adv-x="817" d="M649 1118Q678 1118 714 1116T776 1108L752 940Q724 945 695 948T639 952Q576 952 524 927T435 854T377 740T356 592V0H174V1098H322L344 897H352Q377 940 405 980T469 1050T549 1099T649 1118Z" />
+<glyph unicode="s" glyph-name="s" horiz-adv-x="924" d="M831 301Q831 221 802 161T719 61T587 0T414 -20Q305 -20 227 -3T90 49V215Q121 199 159 184T239 156T325 137T414 129Q479 129 524 140T598 171T640 221T653 287Q653 318 643 343T607 392T534 442T416
+498Q344 529 287 559T189 626T128 711T106 827Q106 897 133 951T211 1043T331 1099T487 1118Q584 1118 664 1097T817 1042L754 895Q689 924 621 945T481 967Q379 967 330 934T281 838Q281 803 292 777T332 728T407 682T524 629Q596 599 652 569T749 502T810 416T831
+301Z" />
+<glyph unicode="t" glyph-name="t" horiz-adv-x="694" d="M506 129Q524 129 546 131T590 136T628 143T655 150V12Q642 6 622 0T578 -10T528 -17T477 -20Q415 -20 362 -4T271 51T210 156T188 324V961H33V1042L188 1120L266 1350H371V1098H647V961H371V324Q371 227
+402 178T506 129Z" />
+<glyph unicode="u" glyph-name="u" horiz-adv-x="1206" d="M885 0L858 147H848Q823 104 789 73T713 21T626 -10T532 -20Q441 -20 372 3T257 75T188 200T164 381V1098H346V391Q346 261 399 196T563 131Q644 131 699 157T787 233T835 358T850 528V1098H1032V0H885Z" />
+<glyph unicode="v" glyph-name="v" horiz-adv-x="981" d="M375 0L0 1098H188L387 487Q398 454 413 402T443 296T470 194T487 121H494Q499 146 511 194T538 296T568 402T594 487L793 1098H981L606 0H375Z" />
+<glyph unicode="w" glyph-name="w" horiz-adv-x="1528" d="M1008 0L840 616Q836 634 830 656T818 704T806 755T793 806Q779 864 764 926H758Q744 863 731 805Q720 755 708 702T684 612L512 0H301L20 1098H211L342 514Q352 469 362 417T381 313T397 216T408 141H414Q419
+167 427 210T446 302T468 398T489 479L668 1098H864L1036 479Q1045 445 1056 399T1079 306T1099 214T1112 141H1118Q1121 167 1127 210T1143 306T1162 412T1184 514L1321 1098H1507L1223 0H1008Z" />
+<glyph unicode="x" glyph-name="x" horiz-adv-x="1024" d="M408 563L55 1098H262L512 688L762 1098H969L614 563L987 0H780L512 436L242 0H35L408 563Z" />
+<glyph unicode="y" glyph-name="y" horiz-adv-x="1001" d="M10 1098H199L414 485Q428 445 442 401T469 313T491 228T504 152H510Q515 177 526 220T550 311T578 407T604 487L803 1098H991L557 -143Q529 -224 497 -288T421 -398T320 -467T182 -492Q130 -492 92 -487T27
+-475V-330Q48 -335 80 -338T147 -342Q195 -342 230 -331T291 -297T335 -243T369 -170L426 -10L10 1098Z" />
+<glyph unicode="z" glyph-name="z" horiz-adv-x="903" d="M821 0H82V125L618 961H115V1098H803V952L279 137H821V0Z" />
+<glyph unicode="{" glyph-name="braceleft" horiz-adv-x="725" d="M500 -16Q500 -64 512 -94T546 -142T601 -166T674 -174V-324Q597 -323 532 -307T419 -255T344 -164T317 -31V303Q317 406 252 449T61 492V647Q186 647 251 690T317 836V1169Q317 1247 344 1302T418
+1392T531 1444T674 1462V1313Q634 1312 602 1306T547 1282T512 1234T500 1155V823Q500 718 441 657T266 575V563Q381 543 440 482T500 315V-16Z" />
+<glyph unicode="|" glyph-name="bar" horiz-adv-x="1128" d="M489 1556H639V-492H489V1556Z" />
+<glyph unicode="}" glyph-name="braceright" horiz-adv-x="725" d="M225 315Q225 421 284 482T459 563V575Q344 595 285 656T225 823V1155Q225 1203 213 1233T179 1281T124 1305T51 1313V1462Q128 1461 193 1445T306 1393T381 1302T408 1169V836Q408 784 424 748T473
+690T554 657T664 647V492Q539 492 474 449T408 303V-31Q408 -109 381 -164T307 -254T194 -306T51 -324V-174Q91 -173 123 -167T178 -143T213 -95T225 -16V315Z" />
+<glyph unicode="~" glyph-name="asciitilde" horiz-adv-x="1128" d="M530 651Q493 667 466 678T416 695T373 704T330 707Q302 707 272 698T213 672T155 633T102 586V748Q202 856 350 856Q379 856 404 854T456 845T517 826T598 793Q635 777 662 766T713 749T757
+740T799 737Q827 737 857 746T916 772T974 811T1026 858V696Q927 588 778 588Q749 588 724 590T672 599T611 618T530 651Z" />
+<glyph unicode="&#xa0;" glyph-name="nbspace" horiz-adv-x="532" />
+<glyph unicode="&#xa1;" glyph-name="exclamdown" horiz-adv-x="551" d="M213 676H334L385 -373H162L213 676ZM401 979Q401 941 392 915T365 872T324 848T274 840Q248 840 225 847T185 871T157 914T147 979Q147 1016 157 1042T184 1085T225 1110T274 1118Q301
+1118 324 1110T364 1085T391 1042T401 979Z" />
+<glyph unicode="&#xa2;" glyph-name="cent" horiz-adv-x="1128" d="M886 212T831 197T700 180V-20H563V186Q476 199 407 236T289 340T214 506T188 743Q188 884 214 985T289 1155T407 1260T563 1311V1483H700V1319Q772 1316 840 1300T954 1260L901 1106Q878 1116
+850 1125T792 1142T733 1154T678 1159Q521 1159 449 1058T377 745Q377 535 449 438T670 340Q751 340 816 358T936 401V240Q886 212 831 197Z" />
+<glyph unicode="&#xa3;" glyph-name="sterling" horiz-adv-x="1128" d="M666 1481Q772 1481 859 1459T1012 1401L946 1257Q890 1286 820 1307T674 1329Q626 1329 585 1316T514 1273T468 1196T451 1083V788H827V651H451V440Q451 378 440 334T409 257T364 204T311
+166H1059V0H68V154Q112 165 148 185T211 240T253 322T268 438V651H70V788H268V1112Q268 1199 297 1267T379 1383T505 1456T666 1481Z" />
+<glyph unicode="&#xa4;" glyph-name="currency" horiz-adv-x="1128" d="M186 723Q186 782 203 835T252 936L123 1065L221 1163L348 1034Q395 1066 449 1084T563 1102Q623 1102 676 1084T776 1034L905 1163L1004 1067L874 938Q905 892 923 838T942 723Q942 663
+925 608T874 508L1001 381L905 285L776 412Q730 381 677 364T563 346Q503 346 448 364T348 414L221 287L125 383L252 510Q221 555 204 609T186 723ZM324 723Q324 673 342 630T393 554T469 502T563 483Q614 483 658 502T736 553T788 629T807 723Q807 774 788 818T736
+896T659 948T563 967Q513 967 470 948T394 896T343 819T324 723Z" />
+<glyph unicode="&#xa5;" glyph-name="yen" horiz-adv-x="1128" d="M563 723L909 1462H1100L715 694H954V557H653V399H954V262H653V0H475V262H174V399H475V557H174V694H408L29 1462H221L563 723Z" />
+<glyph unicode="&#xa6;" glyph-name="brokenbar" horiz-adv-x="1128" d="M489 1556H639V776H489V1556ZM489 289H639V-492H489V289Z" />
+<glyph unicode="&#xa7;" glyph-name="section" horiz-adv-x="995" d="M137 809Q137 860 150 901T185 975T237 1029T297 1067Q222 1105 180 1162T137 1303Q137 1364 164 1413T242 1496T362 1548T518 1567Q615 1567 693 1547T844 1495L788 1356Q723 1384 653 1403T512
+1423Q413 1423 362 1394T311 1307Q311 1280 323 1257T363 1212T439 1167T557 1114Q629 1086 685 1054T781 982T841 895T862 784Q862 732 850 690T818 613T771 555T717 514Q786 476 824 422T862 289Q862 218 833 163T749 69T618 10T444 -10Q336 -10 258 6T121 55V213Q152
+198 190 183T270 157T356 138T444 131Q513 131 559 143T633 174T672 219T684 272Q684 301 676 323T642 368T569 415T446 471Q373 502 316 533T218 603T158 692T137 809ZM291 831Q291 794 305 763T350 702T432 646T555 588L590 573Q610 586 630 604T667 645T694
+696T705 758Q705 796 692 828T647 889T560 947T424 1006Q399 998 376 983T333 945T303 893T291 831Z" />
+<glyph unicode="&#xa8;" glyph-name="dieresis" horiz-adv-x="1182" d="M307 1395Q307 1449 335 1473T403 1497Q442 1497 471 1473T500 1395Q500 1342 471 1317T403 1292Q363 1292 335 1317T307 1395ZM682 1395Q682 1449 710 1473T778 1497Q797 1497 814 1491T845
+1473T866 1441T874 1395Q874 1342 845 1317T778 1292Q738 1292 710 1317T682 1395Z" />
+<glyph unicode="&#xa9;" glyph-name="copyright" horiz-adv-x="1704" d="M891 1053Q830 1053 783 1031T704 968T656 866T639 731Q639 653 653 593T698 492T776 430T891 408Q914 408 941 411T996 421T1053 435T1106 453V322Q1082 311 1058 302T1007 286T950 276T885
+272Q783 272 707 305T581 399T505 545T479 733Q479 834 506 917T585 1061T714 1154T891 1188Q954 1188 1020 1172T1145 1126L1083 999Q1031 1025 983 1039T891 1053ZM100 731Q100 835 127 931T202 1110T320 1263T472 1380T652 1456T852 1483Q956 1483 1052 1456T1231
+1381T1384 1263T1501 1111T1577 931T1604 731Q1604 627 1577 531T1502 352T1384 200T1232 82T1052 7T852 -20Q748 -20 652 6T473 82T320 199T203 351T127 531T100 731ZM209 731Q209 598 259 481T397 277T602 139T852 88Q985 88 1102 138T1306 276T1444 481T1495
+731Q1495 864 1445 981T1307 1185T1102 1323T852 1374Q719 1374 602 1324T398 1186T260 981T209 731Z" />
+<glyph unicode="&#xaa;" glyph-name="ordfeminine" horiz-adv-x="678" d="M487 797L459 879Q441 857 422 840T379 810T327 791T264 784Q221 784 185 797T123 835T83 899T68 989Q68 1091 138 1145T352 1204L451 1208V1239Q451 1311 421 1339T334 1368Q286 1368
+241 1354T154 1317L106 1417Q157 1443 215 1461T334 1479Q459 1479 518 1426T578 1251V797H487ZM377 1110Q326 1107 292 1098T238 1074T208 1038T199 987Q199 936 224 914T291 891Q325 891 354 901T404 934T438 988T451 1065V1114L377 1110Z" />
+<glyph unicode="&#xab;" glyph-name="guillemotleft" horiz-adv-x="997" d="M82 553L391 967L508 889L270 541L508 193L391 115L82 526V553ZM489 553L799 967L915 889L678 541L915 193L799 115L489 526V553Z" />
+<glyph unicode="&#xac;" glyph-name="logicalnot" horiz-adv-x="1128" d="M1026 797V262H877V647H102V797H1026Z" />
+<glyph unicode="&#xad;" glyph-name="uni00AD" horiz-adv-x="659" d="M82 465V633H578V465H82Z" />
+<glyph unicode="&#xae;" glyph-name="registered" horiz-adv-x="1704" d="M743 768H815Q906 768 945 804T985 909Q985 983 944 1012T813 1042H743V768ZM1145 913Q1145 865 1132 828T1096 762T1045 713T985 680Q1052 570 1105 483Q1128 446 1149 411T1186 347T1213
+302L1223 285H1044L838 637H743V285H586V1178H819Q987 1178 1066 1113T1145 913ZM100 731Q100 835 127 931T202 1110T320 1263T472 1380T652 1456T852 1483Q956 1483 1052 1456T1231 1381T1384 1263T1501 1111T1577 931T1604 731Q1604 627 1577 531T1502 352T1384
+200T1232 82T1052 7T852 -20Q748 -20 652 6T473 82T320 199T203 351T127 531T100 731ZM209 731Q209 598 259 481T397 277T602 139T852 88Q985 88 1102 138T1306 276T1444 481T1495 731Q1495 864 1445 981T1307 1185T1102 1323T852 1374Q719 1374 602 1324T398 1186T260
+981T209 731Z" />
+<glyph unicode="&#xaf;" glyph-name="overscore" horiz-adv-x="1024" d="M1030 1556H-6V1696H1030V1556Z" />
+<glyph unicode="&#xb0;" glyph-name="degree" horiz-adv-x="877" d="M123 1167Q123 1232 148 1289T215 1390T315 1458T438 1483Q503 1483 560 1458T661 1390T729 1290T754 1167Q754 1102 729 1045T661 946T561 879T438 854Q373 854 316 878T216 945T148 1045T123
+1167ZM246 1167Q246 1128 261 1094T302 1033T363 992T438 977Q478 977 513 992T574 1033T616 1093T631 1167Q631 1207 616 1242T575 1304T513 1346T438 1362Q398 1362 363 1347T302 1305T261 1243T246 1167Z" />
+<glyph unicode="&#xb1;" glyph-name="plusminus" horiz-adv-x="1128" d="M489 647H102V797H489V1186H639V797H1026V647H639V262H489V647ZM102 0V150H1026V0H102Z" />
+<glyph unicode="&#xb2;" glyph-name="twosuperior" horiz-adv-x="678" d="M621 586H49V698L258 926Q315 988 351 1030T407 1106T434 1169T442 1233Q442 1298 409 1330T322 1362Q271 1362 225 1337T133 1274L55 1368Q109 1416 175 1448T324 1481Q384 1481 432 1465T515
+1417T567 1340T586 1237Q586 1187 572 1144T530 1059T464 971T373 870L225 713H621V586Z" />
+<glyph unicode="&#xb3;" glyph-name="threesuperior" horiz-adv-x="678" d="M590 1255Q590 1177 550 1124T440 1047Q528 1024 572 971T616 840Q616 780 596 730T535 645T430 589T281 569Q211 569 150 581T31 625V758Q94 724 160 705T279 686Q377 686 421 727T465
+842Q465 916 412 949T262 983H164V1096H262Q354 1096 396 1135T438 1239Q438 1271 428 1294T401 1333T360 1355T309 1362Q250 1362 202 1342T102 1284L33 1380Q62 1403 92 1421T157 1453T229 1473T311 1481Q380 1481 432 1464T520 1417T572 1346T590 1255Z" />
+<glyph unicode="&#xb4;" glyph-name="acute" horiz-adv-x="1182" d="M393 1268Q415 1297 438 1335T485 1413T530 1494T567 1569H786V1548Q770 1521 739 1481T669 1396T590 1311T514 1241H393V1268Z" />
+<glyph unicode="&#xb5;" glyph-name="mu" horiz-adv-x="1217" d="M356 391Q356 261 409 196T573 131Q655 131 710 157T798 233T846 358T860 528V1098H1042V0H895L868 147H858Q810 64 738 22T563 -20Q491 -20 438 3T350 68Q351 30 353 -10Q355 -45 355 -87T356
+-172V-492H174V1098H356V391Z" />
+<glyph unicode="&#xb6;" glyph-name="paragraph" horiz-adv-x="1341" d="M1126 -260H1006V1397H799V-260H678V559Q617 541 532 541Q437 541 360 566T228 651T143 806T113 1042Q113 1189 145 1287T237 1446T380 1531T563 1556H1126V-260Z" />
+<glyph unicode="&#xb7;" glyph-name="middot" horiz-adv-x="549" d="M147 723Q147 761 157 787T184 830T224 854T274 862Q300 862 323 855T364 831T391 788T401 723Q401 686 391 660T364 617T324 592T274 584Q247 584 224 592T184 617T157 660T147 723Z" />
+<glyph unicode="&#xb8;" glyph-name="cedilla" horiz-adv-x="420" d="M408 -287Q408 -384 338 -438T117 -492Q95 -492 73 -489T35 -483V-375Q50 -378 74 -379T115 -381Q186 -381 226 -360T266 -289Q266 -265 253 -248T217 -217T163 -195T94 -176L184 0H305L248
+-115Q282 -123 311 -136T361 -169T395 -219T408 -287Z" />
+<glyph unicode="&#xb9;" glyph-name="onesuperior" horiz-adv-x="678" d="M307 1462H442V586H297V1102Q297 1127 297 1157T299 1217T302 1275T305 1325Q291 1308 272 1288T231 1251L137 1178L63 1274L307 1462Z" />
+<glyph unicode="&#xba;" glyph-name="ordmasculine" horiz-adv-x="717" d="M651 1133Q651 1050 631 985T572 876T479 808T356 784Q293 784 240 807T148 875T88 985T66 1133Q66 1216 86 1280T145 1389T237 1456T360 1479Q422 1479 475 1456T568 1389T629 1281T651
+1133ZM197 1133Q197 1014 234 954T358 893Q443 893 480 953T518 1133Q518 1253 481 1310T358 1368Q272 1368 235 1311T197 1133Z" />
+<glyph unicode="&#xbb;" glyph-name="guillemotright" horiz-adv-x="997" d="M918 526L608 115L492 193L729 541L492 889L608 967L918 553V526ZM510 526L201 115L84 193L322 541L84 889L201 967L510 553V526Z" />
+<glyph unicode="&#xbc;" glyph-name="onequarter" horiz-adv-x="1509" d="M307 1462H442V586H297V1102Q297 1127 297 1157T299 1217T302 1275T305 1325Q291 1308 272 1288T231 1251L137 1178L63 1274L307 1462ZM1202 1462L391 0H234L1045 1462H1202ZM1419 193H1294V1H1151V193H776V304L1153
+883H1294V320H1419V193ZM1151 320V515Q1151 557 1152 606T1157 705Q1152 694 1142 676T1121 636T1098 595T1077 560L922 320H1151Z" />
+<glyph unicode="&#xbd;" glyph-name="onehalf" horiz-adv-x="1509" d="M544 1462H679V586H534V1102Q534 1127 534 1157T536 1217T539 1275T542 1325Q528 1308 509 1288T468 1251L374 1178L300 1274L544 1462ZM1181 1462L370 0H213L1024 1462H1181ZM1440 1H868V113L1077
+341Q1134 403 1170 445T1226 521T1253 584T1261 648Q1261 713 1228 745T1141 777Q1090 777 1044 752T952 689L874 783Q928 831 994 863T1143 896Q1203 896 1251 880T1334 832T1386 755T1405 652Q1405 602 1391 559T1349 474T1283 386T1192 285L1044 128H1440V1Z"
+/>
+<glyph unicode="&#xbe;" glyph-name="threequarters" horiz-adv-x="1509" d="M590 1255Q590 1177 550 1124T440 1047Q528 1024 572 971T616 840Q616 780 596 730T535 645T430 589T281 569Q211 569 150 581T31 625V758Q94 724 160 705T279 686Q377 686 421 727T465
+842Q465 916 412 949T262 983H164V1096H262Q354 1096 396 1135T438 1239Q438 1271 428 1294T401 1333T360 1355T309 1362Q250 1362 202 1342T102 1284L33 1380Q62 1403 92 1421T157 1453T229 1473T311 1481Q380 1481 432 1464T520 1417T572 1346T590 1255ZM1296
+1462L485 0H328L1139 1462H1296ZM1486 193H1361V1H1218V193H843V304L1220 883H1361V320H1486V193ZM1218 320V515Q1218 557 1219 606T1224 705Q1219 694 1209 676T1188 636T1165 595T1144 560L989 320H1218Z" />
+<glyph unicode="&#xbf;" glyph-name="questiondown" horiz-adv-x="872" d="M592 676V639Q592 581 584 536T557 450T505 371T422 291Q374 250 340 217T285 149T253 75T242 -18Q242 -66 257 -105T300 -173T371 -217T469 -233Q553 -233 628 -208T772 -147L836 -293Q754
+-335 660 -364T469 -393Q376 -393 302 -368T176 -294T96 -177T68 -20Q68 48 81 100T121 197T188 284T283 373Q335 418 368 451T420 516T446 580T453 657V676H592ZM639 979Q639 941 630 915T603 872T562 848T512 840Q486 840 463 847T423 871T395 914T385 979Q385
+1016 395 1042T422 1085T463 1110T512 1118Q539 1118 562 1110T602 1085T629 1042T639 979Z" />
+<glyph unicode="&#xc0;" glyph-name="Agrave" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM719
+1579H599Q564 1607 523 1648T444 1734T374 1818T326 1886V1907H545Q561 1873 582 1833T627 1752T674 1673T719 1606V1579Z" />
+<glyph unicode="&#xc1;" glyph-name="Aacute" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM534
+1606Q556 1635 579 1673T626 1751T671 1832T708 1907H927V1886Q911 1859 880 1819T810 1734T731 1649T655 1579H534V1606Z" />
+<glyph unicode="&#xc2;" glyph-name="Acircumflex" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM953
+1579H832Q781 1613 727 1661T621 1765Q567 1710 514 1662T410 1579H289V1606Q315 1635 349 1673T416 1751T479 1832T525 1907H717Q733 1873 762 1833T825 1752T893 1673T953 1606V1579Z" />
+<glyph unicode="&#xc3;" glyph-name="Atilde" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM772
+1581Q732 1581 693 1598T615 1637T542 1676T475 1694Q430 1694 406 1668T368 1579H264Q269 1639 285 1688T328 1771T392 1824T475 1843Q517 1843 557 1826T636 1787T708 1749T772 1731Q817 1731 840 1757T878 1845H983Q978 1785 962 1737T919 1654T855 1600T772
+1581Z" />
+<glyph unicode="&#xc4;" glyph-name="Adieresis" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM340
+1733Q340 1787 368 1811T436 1835Q475 1835 504 1811T533 1733Q533 1680 504 1655T436 1630Q396 1630 368 1655T340 1733ZM715 1733Q715 1787 743 1811T811 1835Q830 1835 847 1829T878 1811T899 1779T907 1733Q907 1680 878 1655T811 1630Q771 1630 743 1655T715
+1733Z" />
+<glyph unicode="&#xc5;" glyph-name="Aring" horiz-adv-x="1245" d="M1055 0L895 453H350L188 0H0L537 1468H707L1245 0H1055ZM836 618L688 1042Q682 1060 674 1086T656 1142T638 1204T621 1268Q614 1237 605 1204T587 1141T570 1085T555 1042L410 618H836ZM848
+1583Q848 1532 831 1492T783 1423T710 1381T619 1366Q569 1366 528 1380T458 1423T412 1490T396 1581Q396 1632 412 1671T457 1739T528 1781T619 1796Q667 1796 709 1782T782 1740T830 1673T848 1583ZM731 1581Q731 1634 700 1664T619 1694Q569 1694 538 1664T506
+1581Q506 1528 534 1498T619 1468Q668 1468 699 1498T731 1581Z" />
+<glyph unicode="&#xc6;" glyph-name="AE" horiz-adv-x="1745" d="M1622 0H862V453H387L184 0H-2L653 1462H1622V1298H1049V846H1583V684H1049V164H1622V0ZM459 618H862V1298H754L459 618Z" />
+<glyph unicode="&#xc7;" glyph-name="Ccedilla" horiz-adv-x="1235" d="M793 1319Q686 1319 599 1279T451 1162T356 977T322 731Q322 590 351 481T440 296T587 182T793 143Q882 143 962 160T1120 201V39Q1081 24 1042 13T961 -6T870 -16T762 -20Q598 -20 478 34T280
+187T163 425T125 733Q125 899 168 1037T296 1274T506 1428T793 1483Q901 1483 999 1461T1176 1397L1098 1241Q1035 1273 961 1296T793 1319ZM916 -287Q916 -384 846 -438T625 -492Q603 -492 581 -489T543 -483V-375Q558 -378 582 -379T623 -381Q694 -381 734 -360T774
+-289Q774 -265 761 -248T725 -217T671 -195T602 -176L692 0H813L756 -115Q790 -123 819 -136T869 -169T903 -219T916 -287Z" />
+<glyph unicode="&#xc8;" glyph-name="Egrave" horiz-adv-x="1081" d="M958 0H199V1462H958V1298H385V846H920V684H385V164H958V0ZM713 1579H593Q558 1607 517 1648T438 1734T368 1818T320 1886V1907H539Q555 1873 576 1833T621 1752T668 1673T713 1606V1579Z" />
+<glyph unicode="&#xc9;" glyph-name="Eacute" horiz-adv-x="1081" d="M958 0H199V1462H958V1298H385V846H920V684H385V164H958V0ZM456 1606Q478 1635 501 1673T548 1751T593 1832T630 1907H849V1886Q833 1859 802 1819T732 1734T653 1649T577 1579H456V1606Z" />
+<glyph unicode="&#xca;" glyph-name="Ecircumflex" horiz-adv-x="1081" d="M958 0H199V1462H958V1298H385V846H920V684H385V164H958V0ZM907 1579H786Q735 1613 681 1661T575 1765Q521 1710 468 1662T364 1579H243V1606Q269 1635 303 1673T370 1751T433 1832T479
+1907H671Q687 1873 716 1833T779 1752T847 1673T907 1606V1579Z" />
+<glyph unicode="&#xcb;" glyph-name="Edieresis" horiz-adv-x="1081" d="M958 0H199V1462H958V1298H385V846H920V684H385V164H958V0ZM296 1733Q296 1787 324 1811T392 1835Q431 1835 460 1811T489 1733Q489 1680 460 1655T392 1630Q352 1630 324 1655T296 1733ZM671
+1733Q671 1787 699 1811T767 1835Q786 1835 803 1829T834 1811T855 1779T863 1733Q863 1680 834 1655T767 1630Q727 1630 699 1655T671 1733Z" />
+<glyph unicode="&#xcc;" glyph-name="Igrave" horiz-adv-x="694" d="M612 0H82V102L254 143V1319L82 1360V1462H612V1360L440 1319V143L612 102V0ZM455 1579H335Q300 1607 259 1648T180 1734T110 1818T62 1886V1907H281Q297 1873 318 1833T363 1752T410 1673T455
+1606V1579Z" />
+<glyph unicode="&#xcd;" glyph-name="Iacute" horiz-adv-x="694" d="M612 0H82V102L254 143V1319L82 1360V1462H612V1360L440 1319V143L612 102V0ZM257 1606Q279 1635 302 1673T349 1751T394 1832T431 1907H650V1886Q634 1859 603 1819T533 1734T454 1649T378
+1579H257V1606Z" />
+<glyph unicode="&#xce;" glyph-name="Icircumflex" horiz-adv-x="694" d="M612 0H82V102L254 143V1319L82 1360V1462H612V1360L440 1319V143L612 102V0ZM681 1579H560Q509 1613 455 1661T349 1765Q295 1710 242 1662T138 1579H17V1606Q43 1635 77 1673T144 1751T207
+1832T253 1907H445Q461 1873 490 1833T553 1752T621 1673T681 1606V1579Z" />
+<glyph unicode="&#xcf;" glyph-name="Idieresis" horiz-adv-x="694" d="M612 0H82V102L254 143V1319L82 1360V1462H612V1360L440 1319V143L612 102V0ZM64 1733Q64 1787 92 1811T160 1835Q199 1835 228 1811T257 1733Q257 1680 228 1655T160 1630Q120 1630 92 1655T64
+1733ZM439 1733Q439 1787 467 1811T535 1835Q554 1835 571 1829T602 1811T623 1779T631 1733Q631 1680 602 1655T535 1630Q495 1630 467 1655T439 1733Z" />
+<glyph unicode="&#xd0;" glyph-name="Eth" horiz-adv-x="1401" d="M47 805H199V1462H606Q759 1462 883 1416T1094 1280T1228 1055T1276 745Q1276 560 1228 421T1089 188T866 47T565 0H199V643H47V805ZM1079 739Q1079 885 1046 991T950 1167T795 1269T586 1303H385V805H721V643H385V160H547Q811
+160 945 306T1079 739Z" />
+<glyph unicode="&#xd1;" glyph-name="Ntilde" horiz-adv-x="1493" d="M1294 0H1079L360 1210H352Q358 1133 362 1057Q366 992 368 921T371 793V0H199V1462H412L1128 258H1135Q1132 334 1128 408Q1127 440 1126 473T1123 540T1121 605T1120 662V1462H1294V0ZM905
+1581Q865 1581 826 1598T748 1637T675 1676T608 1694Q563 1694 539 1668T501 1579H397Q402 1639 418 1688T461 1771T525 1824T608 1843Q650 1843 690 1826T769 1787T841 1749T905 1731Q950 1731 973 1757T1011 1845H1116Q1111 1785 1095 1737T1052 1654T988 1600T905
+1581Z" />
+<glyph unicode="&#xd2;" glyph-name="Ograve" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393
+733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM870 1579H750Q715 1607 674 1648T595 1734T525 1818T477 1886V1907H696Q712
+1873 733 1833T778 1752T825 1673T870 1606V1579Z" />
+<glyph unicode="&#xd3;" glyph-name="Oacute" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393
+733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM651 1606Q673 1635 696 1673T743 1751T788 1832T825 1907H1044V1886Q1028
+1859 997 1819T927 1734T848 1649T772 1579H651V1606Z" />
+<glyph unicode="&#xd4;" glyph-name="Ocircumflex" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352
+1043T1393 733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM1096 1579H975Q924 1613 870 1661T764 1765Q710
+1710 657 1662T553 1579H432V1606Q458 1635 492 1673T559 1751T622 1832T668 1907H860Q876 1873 905 1833T968 1752T1036 1673T1096 1606V1579Z" />
+<glyph unicode="&#xd5;" glyph-name="Otilde" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393
+733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM891 1581Q851 1581 812 1598T734 1637T661 1676T594 1694Q549
+1694 525 1668T487 1579H383Q388 1639 404 1688T447 1771T511 1824T594 1843Q636 1843 676 1826T755 1787T827 1749T891 1731Q936 1731 959 1757T997 1845H1102Q1097 1785 1081 1737T1038 1654T974 1600T891 1581Z" />
+<glyph unicode="&#xd6;" glyph-name="Odieresis" horiz-adv-x="1520" d="M1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q597 -20 478 34T280 187T163 425T125 735Q125 905 163 1043T280 1280T479 1431T762 1485Q917 1485 1034 1432T1232 1280T1352 1043T1393
+733ZM322 733Q322 596 348 487T427 301T563 184T760 143Q874 143 956 183T1092 300T1171 486T1196 733Q1196 871 1171 980T1093 1164T958 1280T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM477 1733Q477 1787 505 1811T573 1835Q612 1835 641 1811T670
+1733Q670 1680 641 1655T573 1630Q533 1630 505 1655T477 1733ZM852 1733Q852 1787 880 1811T948 1835Q967 1835 984 1829T1015 1811T1036 1779T1044 1733Q1044 1680 1015 1655T948 1630Q908 1630 880 1655T852 1733Z" />
+<glyph unicode="&#xd7;" glyph-name="multiply" horiz-adv-x="1128" d="M459 723L141 1042L246 1147L563 829L885 1147L989 1044L668 723L987 403L885 301L563 618L246 303L143 406L459 723Z" />
+<glyph unicode="&#xd8;" glyph-name="Oslash" horiz-adv-x="1520" d="M1300 1454L1208 1305Q1299 1206 1346 1061T1393 733Q1393 564 1353 425T1232 187T1034 34T760 -20Q571 -20 438 51L360 -76L223 2L313 147Q216 247 171 396T125 735Q125 905 163 1043T280
+1280T479 1431T762 1485Q856 1485 936 1464T1083 1405L1163 1532L1300 1454ZM322 733Q322 602 345 498T416 315L995 1260Q947 1289 890 1305T762 1321Q648 1321 565 1281T428 1165T348 980T322 733ZM1196 733Q1196 990 1108 1141L530 201Q577 173 634 158T760 143Q874
+143 956 183T1092 300T1171 486T1196 733Z" />
+<glyph unicode="&#xd9;" glyph-name="Ugrave" horiz-adv-x="1430" d="M1245 1464V516Q1245 402 1212 304T1113 134T946 21T709 -20Q581 -20 483 18T319 128T218 298T184 520V1462H371V510Q371 335 457 239T719 143Q808 143 872 170T977 246T1038 363T1059 512V1464H1245ZM847
+1579H727Q692 1607 651 1648T572 1734T502 1818T454 1886V1907H673Q689 1873 710 1833T755 1752T802 1673T847 1606V1579Z" />
+<glyph unicode="&#xda;" glyph-name="Uacute" horiz-adv-x="1430" d="M1245 1464V516Q1245 402 1212 304T1113 134T946 21T709 -20Q581 -20 483 18T319 128T218 298T184 520V1462H371V510Q371 335 457 239T719 143Q808 143 872 170T977 246T1038 363T1059 512V1464H1245ZM590
+1606Q612 1635 635 1673T682 1751T727 1832T764 1907H983V1886Q967 1859 936 1819T866 1734T787 1649T711 1579H590V1606Z" />
+<glyph unicode="&#xdb;" glyph-name="Ucircumflex" horiz-adv-x="1430" d="M1245 1464V516Q1245 402 1212 304T1113 134T946 21T709 -20Q581 -20 483 18T319 128T218 298T184 520V1462H371V510Q371 335 457 239T719 143Q808 143 872 170T977 246T1038 363T1059
+512V1464H1245ZM1043 1579H922Q871 1613 817 1661T711 1765Q657 1710 604 1662T500 1579H379V1606Q405 1635 439 1673T506 1751T569 1832T615 1907H807Q823 1873 852 1833T915 1752T983 1673T1043 1606V1579Z" />
+<glyph unicode="&#xdc;" glyph-name="Udieresis" horiz-adv-x="1430" d="M1245 1464V516Q1245 402 1212 304T1113 134T946 21T709 -20Q581 -20 483 18T319 128T218 298T184 520V1462H371V510Q371 335 457 239T719 143Q808 143 872 170T977 246T1038 363T1059 512V1464H1245ZM432
+1733Q432 1787 460 1811T528 1835Q567 1835 596 1811T625 1733Q625 1680 596 1655T528 1630Q488 1630 460 1655T432 1733ZM807 1733Q807 1787 835 1811T903 1835Q922 1835 939 1829T970 1811T991 1779T999 1733Q999 1680 970 1655T903 1630Q863 1630 835 1655T807
+1733Z" />
+<glyph unicode="&#xdd;" glyph-name="Yacute" horiz-adv-x="1079" d="M539 723L879 1462H1079L633 569V0H446V559L0 1462H203L539 723ZM442 1606Q464 1635 487 1673T534 1751T579 1832T616 1907H835V1886Q819 1859 788 1819T718 1734T639 1649T563 1579H442V1606Z" />
+<glyph unicode="&#xde;" glyph-name="Thorn" horiz-adv-x="1180" d="M1075 782Q1075 691 1048 607T957 459T791 356T535 317H385V0H199V1462H385V1210H561Q695 1210 792 1182T952 1099T1045 964T1075 782ZM385 475H514Q607 475 676 491T791 542T860 634T883 772Q883
+915 801 983T545 1051H385V475Z" />
+<glyph unicode="&#xdf;" glyph-name="germandbls" horiz-adv-x="1233" d="M1010 1260Q1010 1203 989 1159T936 1078T867 1011T798 954T745 899T723 842Q723 821 730 805T756 769T811 725T903 662Q959 625 1003 589T1077 512T1124 423T1141 313Q1141 226 1113 163T1035
+60T914 0T758 -20Q661 -20 592 -3T469 49V215Q495 199 527 184T596 156T670 137T745 129Q801 129 841 141T908 176T946 231T958 303Q958 339 950 368T920 426T862 483T770 547Q707 587 665 621T596 688T558 757T547 834Q547 888 567 927T619 998T686 1057T753 1113T804
+1175T825 1253Q825 1295 809 1326T762 1377T691 1407T598 1417Q549 1417 505 1408T428 1374T376 1309T356 1202V0H174V1200Q174 1304 205 1374T293 1487T428 1548T598 1567Q690 1567 766 1548T896 1491T980 1395T1010 1260Z" />
+<glyph unicode="&#xe0;" glyph-name="agrave" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967
+374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM934 1241H814Q779
+1269 738 1310T659 1396T589 1480T541 1548V1569H760Q776 1535 797 1495T842 1414T889 1335T934 1268V1241Z" />
+<glyph unicode="&#xe1;" glyph-name="aacute" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967
+374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM446 1268Q468 1297
+491 1335T538 1413T583 1494T620 1569H839V1548Q823 1521 792 1481T722 1396T643 1311T567 1241H446V1268Z" />
+<glyph unicode="&#xe2;" glyph-name="acircumflex" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445
+967 374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM1148 1241H1027Q976
+1275 922 1323T816 1427Q762 1372 709 1324T605 1241H484V1268Q510 1297 544 1335T611 1413T674 1494T720 1569H912Q928 1535 957 1495T1020 1414T1088 1335T1148 1268V1241Z" />
+<glyph unicode="&#xe3;" glyph-name="atilde" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967
+374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM955 1243Q915 1243
+876 1260T798 1299T725 1338T658 1356Q613 1356 589 1330T551 1241H447Q452 1301 468 1350T511 1433T575 1486T658 1505Q700 1505 740 1488T819 1449T891 1411T955 1393Q1000 1393 1023 1419T1061 1507H1166Q1161 1447 1145 1399T1102 1316T1038 1262T955 1243Z"
+/>
+<glyph unicode="&#xe4;" glyph-name="adieresis" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445
+967 374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM529 1395Q529
+1449 557 1473T625 1497Q664 1497 693 1473T722 1395Q722 1342 693 1317T625 1292Q585 1292 557 1317T529 1395ZM904 1395Q904 1449 932 1473T1000 1497Q1019 1497 1036 1491T1067 1473T1088 1441T1096 1395Q1096 1342 1067 1317T1000 1292Q960 1292 932 1317T904
+1395Z" />
+<glyph unicode="&#xe5;" glyph-name="aring" horiz-adv-x="1087" d="M793 0L756 152H748Q715 107 682 75T610 21T523 -10T412 -20Q343 -20 285 -1T185 59T118 161T94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967
+374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q630 1118 704 1098T827 1033T900 919T924 752V0H793ZM459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305Q283 213 331 170T459 127ZM1039 1458Q1039
+1407 1022 1367T974 1298T901 1256T810 1241Q760 1241 719 1255T649 1298T603 1365T587 1456Q587 1507 603 1546T648 1614T719 1656T810 1671Q858 1671 900 1657T973 1615T1021 1548T1039 1458ZM922 1456Q922 1509 891 1539T810 1569Q760 1569 729 1539T697 1456Q697
+1403 725 1373T810 1343Q859 1343 890 1373T922 1456Z" />
+<glyph unicode="&#xe6;" glyph-name="ae" horiz-adv-x="1706" d="M94 307Q94 471 209 559T561 655L745 662V731Q745 798 731 843T689 915T621 955T528 967Q445 967 374 943T236 885L172 1022Q246 1062 337 1090T528 1118Q659 1118 742 1076T868 940Q919 1025 1002
+1071T1188 1118Q1285 1118 1362 1083T1493 983T1575 828T1604 627V514H932Q937 321 1010 230T1231 139Q1280 139 1322 144T1404 158T1480 182T1554 215V53Q1515 34 1478 20T1401 -3T1319 -16T1227 -20Q1089 -20 988 37T825 209Q791 155 753 113T668 41T562 -4T430
+-20Q359 -20 298 -1T191 59T120 161T94 307ZM283 305Q283 213 331 170T459 127Q520 127 572 146T662 203T721 300T743 438V537L600 530Q510 526 449 510T352 466T299 397T283 305ZM1184 967Q1074 967 1011 889T936 662H1407Q1407 730 1394 786T1354 883T1284 945T1184
+967Z" />
+<glyph unicode="&#xe7;" glyph-name="ccedilla" horiz-adv-x="948" d="M594 -20Q493 -20 405 11T252 111T150 286T113 543Q113 700 151 809T255 987T411 1087T602 1118Q680 1118 754 1101T879 1059L825 905Q802 915 774 924T716 941T657 953T602 958Q445 958 373
+858T301 545Q301 334 373 237T594 139Q675 139 740 157T860 201V39Q806 10 745 -5T594 -20ZM730 -287Q730 -384 660 -438T439 -492Q417 -492 395 -489T357 -483V-375Q372 -378 396 -379T437 -381Q508 -381 548 -360T588 -289Q588 -265 575 -248T539 -217T485 -195T416
+-176L506 0H627L570 -115Q604 -123 633 -136T683 -169T717 -219T730 -287Z" />
+<glyph unicode="&#xe8;" glyph-name="egrave" horiz-adv-x="1096" d="M608 -20Q498 -20 407 17T251 125T149 301T113 541Q113 677 146 784T239 965T382 1079T567 1118Q666 1118 745 1083T879 983T963 828T993 627V514H301Q306 321 382 230T610 139Q661 139 704
+144T788 158T867 182T944 215V53Q904 34 866 20T787 -3T703 -16T608 -20ZM563 967Q449 967 383 889T305 662H797Q797 730 784 786T742 883T669 945T563 967ZM934 1241H814Q779 1269 738 1310T659 1396T589 1480T541 1548V1569H760Q776 1535 797 1495T842 1414T889
+1335T934 1268V1241Z" />
+<glyph unicode="&#xe9;" glyph-name="eacute" horiz-adv-x="1096" d="M608 -20Q498 -20 407 17T251 125T149 301T113 541Q113 677 146 784T239 965T382 1079T567 1118Q666 1118 745 1083T879 983T963 828T993 627V514H301Q306 321 382 230T610 139Q661 139 704
+144T788 158T867 182T944 215V53Q904 34 866 20T787 -3T703 -16T608 -20ZM563 967Q449 967 383 889T305 662H797Q797 730 784 786T742 883T669 945T563 967ZM475 1268Q497 1297 520 1335T567 1413T612 1494T649 1569H868V1548Q852 1521 821 1481T751 1396T672 1311T596
+1241H475V1268Z" />
+<glyph unicode="&#xea;" glyph-name="ecircumflex" horiz-adv-x="1096" d="M608 -20Q498 -20 407 17T251 125T149 301T113 541Q113 677 146 784T239 965T382 1079T567 1118Q666 1118 745 1083T879 983T963 828T993 627V514H301Q306 321 382 230T610 139Q661 139
+704 144T788 158T867 182T944 215V53Q904 34 866 20T787 -3T703 -16T608 -20ZM563 967Q449 967 383 889T305 662H797Q797 730 784 786T742 883T669 945T563 967ZM1144 1241H1023Q972 1275 918 1323T812 1427Q758 1372 705 1324T601 1241H480V1268Q506 1297 540
+1335T607 1413T670 1494T716 1569H908Q924 1535 953 1495T1016 1414T1084 1335T1144 1268V1241Z" />
+<glyph unicode="&#xeb;" glyph-name="edieresis" horiz-adv-x="1096" d="M608 -20Q498 -20 407 17T251 125T149 301T113 541Q113 677 146 784T239 965T382 1079T567 1118Q666 1118 745 1083T879 983T963 828T993 627V514H301Q306 321 382 230T610 139Q661 139
+704 144T788 158T867 182T944 215V53Q904 34 866 20T787 -3T703 -16T608 -20ZM563 967Q449 967 383 889T305 662H797Q797 730 784 786T742 883T669 945T563 967ZM525 1395Q525 1449 553 1473T621 1497Q660 1497 689 1473T718 1395Q718 1342 689 1317T621 1292Q581
+1292 553 1317T525 1395ZM900 1395Q900 1449 928 1473T996 1497Q1015 1497 1032 1491T1063 1473T1084 1441T1092 1395Q1092 1342 1063 1317T996 1292Q956 1292 928 1317T900 1395Z" />
+<glyph unicode="&#xec;" glyph-name="igrave" horiz-adv-x="530" d="M356 0H174V1098H356V0ZM359 1241H239Q204 1269 163 1310T84 1396T14 1480T-34 1548V1569H185Q201 1535 222 1495T267 1414T314 1335T359 1268V1241Z" />
+<glyph unicode="&#xed;" glyph-name="iacute" horiz-adv-x="530" d="M356 0H174V1098H356V0ZM185 1268Q207 1297 230 1335T277 1413T322 1494T359 1569H578V1548Q562 1521 531 1481T461 1396T382 1311T306 1241H185V1268Z" />
+<glyph unicode="&#xee;" glyph-name="icircumflex" horiz-adv-x="530" d="M356 0H174V1098H356V0ZM597 1241H476Q425 1275 371 1323T265 1427Q211 1372 158 1324T54 1241H-67V1268Q-41 1297 -7 1335T60 1413T123 1494T169 1569H361Q377 1535 406 1495T469 1414T537
+1335T597 1268V1241Z" />
+<glyph unicode="&#xef;" glyph-name="idieresis" horiz-adv-x="530" d="M356 0H174V1098H356V0ZM-18 1395Q-18 1449 10 1473T78 1497Q117 1497 146 1473T175 1395Q175 1342 146 1317T78 1292Q38 1292 10 1317T-18 1395ZM357 1395Q357 1449 385 1473T453 1497Q472
+1497 489 1491T520 1473T541 1441T549 1395Q549 1342 520 1317T453 1292Q413 1292 385 1317T357 1395Z" />
+<glyph unicode="&#xf0;" glyph-name="eth" horiz-adv-x="1182" d="M1069 573Q1069 431 1036 321T940 135T788 20T588 -20Q484 -20 397 13T246 109T147 265T111 477Q111 596 142 688T233 843T376 938T565 971Q667 971 744 942T864 852L872 856Q841 974 781 1070T631
+1247L375 1094L301 1208L518 1339Q478 1367 436 1394T346 1448L416 1571Q481 1539 542 1503T662 1423L889 1561L963 1448L768 1331Q835 1266 890 1188T985 1017T1047 813T1069 573ZM881 526Q881 582 864 635T812 730T722 796T592 821Q515 821 461 798T371 731T320
+622T303 471Q303 395 319 333T371 225T461 156T592 131Q746 131 813 230T881 526Z" />
+<glyph unicode="&#xf1;" glyph-name="ntilde" horiz-adv-x="1206" d="M860 0V707Q860 837 808 902T643 967Q562 967 507 941T419 864T371 739T356 569V0H174V1098H322L348 950H358Q383 993 417 1024T493 1077T580 1108T674 1118Q857 1118 949 1023T1042 717V0H860ZM1015
+1243Q975 1243 936 1260T858 1299T785 1338T718 1356Q673 1356 649 1330T611 1241H507Q512 1301 528 1350T571 1433T635 1486T718 1505Q760 1505 800 1488T879 1449T951 1411T1015 1393Q1060 1393 1083 1419T1121 1507H1226Q1221 1447 1205 1399T1162 1316T1098
+1262T1015 1243Z" />
+<glyph unicode="&#xf2;" glyph-name="ograve" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069 551ZM301
+551Q301 342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551ZM1002 1241H882Q847 1269 806 1310T727 1396T657 1480T609 1548V1569H828Q844 1535 865 1495T910 1414T957 1335T1002 1268V1241Z" />
+<glyph unicode="&#xf3;" glyph-name="oacute" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069 551ZM301
+551Q301 342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551ZM473 1268Q495 1297 518 1335T565 1413T610 1494T647 1569H866V1548Q850 1521 819 1481T749 1396T670 1311T594 1241H473V1268Z" />
+<glyph unicode="&#xf4;" glyph-name="ocircumflex" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069
+551ZM301 551Q301 342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551ZM1173 1241H1052Q1001 1275 947 1323T841 1427Q787 1372 734 1324T630 1241H509V1268Q535 1297 569 1335T636 1413T699 1494T745 1569H937Q953
+1535 982 1495T1045 1414T1113 1335T1173 1268V1241Z" />
+<glyph unicode="&#xf5;" glyph-name="otilde" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069 551ZM301
+551Q301 342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551ZM992 1243Q952 1243 913 1260T835 1299T762 1338T695 1356Q650 1356 626 1330T588 1241H484Q489 1301 505 1350T548 1433T612 1486T695 1505Q737 1505 777
+1488T856 1449T928 1411T992 1393Q1037 1393 1060 1419T1098 1507H1203Q1198 1447 1182 1399T1139 1316T1075 1262T992 1243Z" />
+<glyph unicode="&#xf6;" glyph-name="odieresis" horiz-adv-x="1182" d="M1069 551Q1069 414 1036 308T940 129T788 18T588 -20Q485 -20 398 18T248 128T149 307T113 551Q113 687 146 792T242 970T393 1080T594 1118Q697 1118 784 1081T934 971T1033 793T1069
+551ZM301 551Q301 342 369 237T592 131Q746 131 813 236T881 551Q881 760 813 863T590 967Q436 967 369 864T301 551ZM556 1395Q556 1449 584 1473T652 1497Q691 1497 720 1473T749 1395Q749 1342 720 1317T652 1292Q612 1292 584 1317T556 1395ZM931 1395Q931
+1449 959 1473T1027 1497Q1046 1497 1063 1491T1094 1473T1115 1441T1123 1395Q1123 1342 1094 1317T1027 1292Q987 1292 959 1317T931 1395Z" />
+<glyph unicode="&#xf7;" glyph-name="divide" horiz-adv-x="1128" d="M102 647V797H1026V647H102ZM449 373Q449 408 458 431T482 470T518 491T563 498Q586 498 607 492T644 470T669 432T678 373Q678 340 669 317T644 278T607 255T563 248Q539 248 519 255T483
+277T458 316T449 373ZM449 1071Q449 1106 458 1129T482 1168T518 1189T563 1196Q586 1196 607 1190T644 1168T669 1130T678 1071Q678 1038 669 1015T644 976T607 953T563 946Q539 946 519 953T483 975T458 1014T449 1071Z" />
+<glyph unicode="&#xf8;" glyph-name="oslash" horiz-adv-x="1182" d="M1071 551Q1071 414 1038 308T942 129T790 18T590 -20Q465 -20 367 33L299 -76L168 -2L248 129Q185 201 150 307T115 551Q115 687 148 792T244 970T395 1080T596 1118Q659 1118 715 1104T821
+1061L889 1169L1020 1096L940 967Q1002 894 1036 790T1071 551ZM303 551Q303 467 312 402T344 285L741 932Q712 949 675 958T592 967Q438 967 371 864T303 551ZM883 551Q883 710 844 809L446 164Q477 147 513 139T594 131Q748 131 815 236T883 551Z" />
+<glyph unicode="&#xf9;" glyph-name="ugrave" horiz-adv-x="1206" d="M885 0L858 147H848Q823 104 789 73T713 21T626 -10T532 -20Q441 -20 372 3T257 75T188 200T164 381V1098H346V391Q346 261 399 196T563 131Q644 131 699 157T787 233T835 358T850 528V1098H1032V0H885ZM949
+1241H829Q794 1269 753 1310T674 1396T604 1480T556 1548V1569H775Q791 1535 812 1495T857 1414T904 1335T949 1268V1241Z" />
+<glyph unicode="&#xfa;" glyph-name="uacute" horiz-adv-x="1206" d="M885 0L858 147H848Q823 104 789 73T713 21T626 -10T532 -20Q441 -20 372 3T257 75T188 200T164 381V1098H346V391Q346 261 399 196T563 131Q644 131 699 157T787 233T835 358T850 528V1098H1032V0H885ZM489
+1268Q511 1297 534 1335T581 1413T626 1494T663 1569H882V1548Q866 1521 835 1481T765 1396T686 1311T610 1241H489V1268Z" />
+<glyph unicode="&#xfb;" glyph-name="ucircumflex" horiz-adv-x="1206" d="M885 0L858 147H848Q823 104 789 73T713 21T626 -10T532 -20Q441 -20 372 3T257 75T188 200T164 381V1098H346V391Q346 261 399 196T563 131Q644 131 699 157T787 233T835 358T850 528V1098H1032V0H885ZM930
+1241H809Q758 1275 704 1323T598 1427Q544 1372 491 1324T387 1241H266V1268Q292 1297 326 1335T393 1413T456 1494T502 1569H694Q710 1535 739 1495T802 1414T870 1335T930 1268V1241Z" />
+<glyph unicode="&#xfc;" glyph-name="udieresis" horiz-adv-x="1206" d="M885 0L858 147H848Q823 104 789 73T713 21T626 -10T532 -20Q441 -20 372 3T257 75T188 200T164 381V1098H346V391Q346 261 399 196T563 131Q644 131 699 157T787 233T835 358T850 528V1098H1032V0H885ZM309
+1395Q309 1449 337 1473T405 1497Q444 1497 473 1473T502 1395Q502 1342 473 1317T405 1292Q365 1292 337 1317T309 1395ZM684 1395Q684 1449 712 1473T780 1497Q799 1497 816 1491T847 1473T868 1441T876 1395Q876 1342 847 1317T780 1292Q740 1292 712 1317T684
+1395Z" />
+<glyph unicode="&#xfd;" glyph-name="yacute" horiz-adv-x="1001" d="M10 1098H199L414 485Q428 445 442 401T469 313T491 228T504 152H510Q515 177 526 220T550 311T578 407T604 487L803 1098H991L557 -143Q529 -224 497 -288T421 -398T320 -467T182 -492Q130
+-492 92 -487T27 -475V-330Q48 -335 80 -338T147 -342Q195 -342 230 -331T291 -297T335 -243T369 -170L426 -10L10 1098ZM407 1268Q429 1297 452 1335T499 1413T544 1494T581 1569H800V1548Q784 1521 753 1481T683 1396T604 1311T528 1241H407V1268Z" />
+<glyph unicode="&#xfe;" glyph-name="thorn" horiz-adv-x="1200" d="M356 950Q379 985 408 1015T475 1068T562 1104T670 1118Q764 1118 841 1082T972 975T1057 797T1087 551Q1087 410 1057 304T973 125T841 17T670 -20Q611 -20 563 -7T477 27T409 78T356 139H344Q347
+105 350 74Q352 48 354 21T356 -23V-492H174V1556H356V1098L348 950H356ZM635 967Q559 967 507 944T422 874T374 757T356 592V551Q356 450 369 372T415 240T502 159T637 131Q772 131 835 240T899 553Q899 761 836 864T635 967Z" />
+<glyph unicode="&#xff;" glyph-name="ydieresis" horiz-adv-x="1001" d="M10 1098H199L414 485Q428 445 442 401T469 313T491 228T504 152H510Q515 177 526 220T550 311T578 407T604 487L803 1098H991L557 -143Q529 -224 497 -288T421 -398T320 -467T182 -492Q130
+-492 92 -487T27 -475V-330Q48 -335 80 -338T147 -342Q195 -342 230 -331T291 -297T335 -243T369 -170L426 -10L10 1098ZM484 1395Q484 1449 512 1473T580 1497Q619 1497 648 1473T677 1395Q677 1342 648 1317T580 1292Q540 1292 512 1317T484 1395ZM859 1395Q859
+1449 887 1473T955 1497Q974 1497 991 1491T1022 1473T1043 1441T1051 1395Q1051 1342 1022 1317T955 1292Q915 1292 887 1317T859 1395Z" />
+<glyph unicode="&#x2013;" glyph-name="endash" horiz-adv-x="1024" d="M82 465V633H942V465H82Z" />
+<glyph unicode="&#x2014;" glyph-name="emdash" horiz-adv-x="2048" d="M82 465V633H1966V465H82Z" />
+<glyph unicode="&#x2018;" glyph-name="quoteleft" horiz-adv-x="358" d="M37 961L23 983Q37 1037 56 1098T99 1221T148 1344T199 1462H336Q321 1401 307 1335T279 1204T255 1076T236 961H37Z" />
+<glyph unicode="&#x2019;" glyph-name="quoteright" horiz-adv-x="358" d="M322 1462L336 1440Q322 1385 303 1325T260 1202T211 1078T160 961H23Q37 1021 51 1087T79 1219T104 1347T123 1462H322Z" />
+<glyph unicode="&#x201a;" glyph-name="quotesinglbase" horiz-adv-x="512" d="M362 238L377 215Q363 161 344 100T301 -23T252 -146T201 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H362Z" />
+<glyph unicode="&#x201c;" glyph-name="quotedblleft" horiz-adv-x="743" d="M422 961L408 983Q422 1037 441 1098T484 1221T533 1344T584 1462H721Q706 1401 692 1335T664 1204T640 1076T621 961H422ZM37 961L23 983Q37 1037 56 1098T99 1221T148 1344T199 1462H336Q321
+1401 307 1335T279 1204T255 1076T236 961H37Z" />
+<glyph unicode="&#x201d;" glyph-name="quotedblright" horiz-adv-x="743" d="M322 1462L336 1440Q322 1385 303 1325T260 1202T211 1078T160 961H23Q37 1021 51 1087T79 1219T104 1347T123 1462H322ZM707 1462L721 1440Q707 1385 688 1325T645 1202T596 1078T545
+961H408Q422 1021 436 1087T464 1219T489 1347T508 1462H707Z" />
+<glyph unicode="&#x201e;" glyph-name="quotedblbase" horiz-adv-x="897" d="M362 238L377 215Q363 161 344 100T301 -23T252 -146T201 -264H63Q78 -203 92 -137T120 -6T145 122T164 238H362ZM748 238L762 215Q748 161 729 100T686 -23T637 -146T586 -264H449Q463
+-203 477 -137T505 -6T530 122T549 238H748Z" />
+<glyph unicode="&#x2022;" glyph-name="bullet" horiz-adv-x="770" d="M150 748Q150 819 168 869T217 950T292 996T385 1010Q434 1010 477 996T552 951T602 869T621 748Q621 678 603 628T552 547T477 500T385 485Q335 485 292 500T218 546T168 628T150 748Z" />
+<glyph unicode="&#x2039;" glyph-name="guilsinglleft" horiz-adv-x="590" d="M82 553L391 967L508 889L270 541L508 193L391 115L82 526V553Z" />
+<glyph unicode="&#x203a;" glyph-name="guilsinglright" horiz-adv-x="590" d="M508 526L199 115L82 193L319 541L82 889L199 967L508 553V526Z" />
+</font>
+</defs>
+</svg>
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.ttf b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.ttf
new file mode 100644
index 0000000000..fb8cea662b
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.ttf
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff
new file mode 100644
index 0000000000..abf19899f7
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff2 b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff2
new file mode 100644
index 0000000000..9f93f74c3b
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/fonts/droid-sans-v6-latin-regular.woff2
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/explorer_icons.png b/catalog-be/src/main/resources/swagger/images/explorer_icons.png
new file mode 100644
index 0000000000..ed9d2fffb6
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/explorer_icons.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/favicon-16x16.png b/catalog-be/src/main/resources/swagger/images/favicon-16x16.png
new file mode 100644
index 0000000000..66b1a5bfb9
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/favicon-16x16.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/favicon-32x32.png b/catalog-be/src/main/resources/swagger/images/favicon-32x32.png
new file mode 100644
index 0000000000..32f319f89b
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/favicon-32x32.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/favicon.ico b/catalog-be/src/main/resources/swagger/images/favicon.ico
new file mode 100644
index 0000000000..8b60bcf06a
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/favicon.ico
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/logo_small.png b/catalog-be/src/main/resources/swagger/images/logo_small.png
new file mode 100644
index 0000000000..5496a65579
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/logo_small.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/pet_store_api.png b/catalog-be/src/main/resources/swagger/images/pet_store_api.png
new file mode 100644
index 0000000000..f9f9cd4aeb
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/pet_store_api.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/throbber.gif b/catalog-be/src/main/resources/swagger/images/throbber.gif
new file mode 100644
index 0000000000..0639388924
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/throbber.gif
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/images/wordnik_api.png b/catalog-be/src/main/resources/swagger/images/wordnik_api.png
new file mode 100644
index 0000000000..dca4f1455a
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/images/wordnik_api.png
Binary files differ
diff --git a/catalog-be/src/main/resources/swagger/index.html b/catalog-be/src/main/resources/swagger/index.html
new file mode 100644
index 0000000000..0e9a9e8de3
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/index.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Swagger UI</title>
+ <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
+ <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
+ <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
+ <link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>
+ <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
+ <script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
+ <script src='lib/underscore-min.js' type='text/javascript'></script>
+ <script src='lib/backbone-min.js' type='text/javascript'></script>
+ <script src='swagger-ui.js' type='text/javascript'></script>
+ <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
+ <script src='lib/marked.js' type='text/javascript'></script>
+
+ <script type="text/javascript">
+ $(function () {
+ /* var url = window.location.search.match(/url=([^&]+)/);
+ if (url && url.length > 1) {
+ url = decodeURIComponent(url[1]);
+ } else {
+ url = "http://petstore.swagger.io/v2/swagger.json";
+ } */
+ var hostData= {};
+ var conf = getConfiguration(hostData);
+ var url = "http://" + hostData.beFqdn + "/sdc2/rest/swagger.json";
+ window.swaggerUi = new SwaggerUi({
+ url: url,
+ dom_id: "swagger-ui-container",
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
+ onComplete: function(swaggerApi, swaggerUi){
+ if(typeof initOAuth == "function") {
+ /*
+ initOAuth({
+ clientId: "your-client-id",
+ realm: "your-realms",
+ appName: "your-app-name"
+ });
+ */
+ }
+ $('pre code').each(function(i, e) {
+ hljs.highlightBlock(e)
+ });
+ },
+ onFailure: function(data) {
+ log("Unable to Load SwaggerUI");
+ },
+ docExpansion: "none",
+ sorter : "alpha"
+ });
+
+ function addApiKeyAuthorization() {
+ var key = encodeURIComponent($('#input_apiKey')[0].value);
+ log("key: " + key);
+ if(key && key.trim() != "") {
+ var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
+ window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
+ log("added key " + key);
+ }
+ }
+
+ $('#input_apiKey').change(addApiKeyAuthorization);
+
+ // if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
+ /*
+ var apiKey = "myApiKeyXXXX123456789";
+ $('#input_apiKey').val(apiKey);
+ addApiKeyAuthorization();
+ */
+
+ window.swaggerUi.load();
+
+ function log() {
+ if ('console' in window) {
+ console.log.apply(console, arguments);
+ }
+ }
+
+ function getConfiguration(hostData){
+ $.ajax({
+ url: "/sdc2/rest/configmgr/get",
+ type: "GET",
+ async: false,
+
+ complete: function(data) {
+ if( data.status == 200 ){
+ var jsonConf = JSON.parse(data.responseText);
+ hostData.beFqdn = jsonConf.beFqdn;
+
+ }
+ else{
+ hostData.beFqdn = "localhost:8080";
+ }
+ }
+ });
+ }
+ });
+ </script>
+</head>
+
+<body class="swagger-section">
+<div id='header'>
+ <div class="swagger-ui-wrap">
+ <a id="logo" href="http://swagger.io">swagger</a>
+ <form id='api_selector'>
+ <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
+ <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
+ <div class='input'><a id="explore" href="#">Explore</a></div>
+ </form>
+ </div>
+</div>
+
+<div id="message-bar" class="swagger-ui-wrap">&nbsp;</div>
+<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
+</body>
+</html>
diff --git a/catalog-be/src/main/resources/swagger/lib/backbone-min.js b/catalog-be/src/main/resources/swagger/lib/backbone-min.js
new file mode 100644
index 0000000000..f082fcffca
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/backbone-min.js
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+// Backbone.js 1.1.2
+
+(function(t,e){if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){t.Backbone=e(t,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore");e(t,exports,i)}else{t.Backbone=e(t,{},t._,t.jQuery||t.Zepto||t.ender||t.$)}})(this,function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.push;var o=n.slice;var h=n.splice;e.VERSION="1.1.2";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var u=e.Events={on:function(t,e,i){if(!c(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,r){if(!c(this,"once",t,[e,r])||!e)return this;var s=this;var n=i.once(function(){s.off(t,n);e.apply(this,arguments)});n._callback=e;return this.on(t,n,r)},off:function(t,e,r){var s,n,a,o,h,u,l,f;if(!this._events||!c(this,"off",t,[e,r]))return this;if(!t&&!e&&!r){this._events=void 0;return this}o=t?[t]:i.keys(this._events);for(h=0,u=o.length;h<u;h++){t=o[h];if(a=this._events[t]){this._events[t]=s=[];if(e||r){for(l=0,f=a.length;l<f;l++){n=a[l];if(e&&e!==n.callback&&e!==n.callback._callback||r&&r!==n.context){s.push(n)}}}if(!s.length)delete this._events[t]}}return this},trigger:function(t){if(!this._events)return this;var e=o.call(arguments,1);if(!c(this,"trigger",t,e))return this;var i=this._events[t];var r=this._events.all;if(i)f(i,e);if(r)f(r,arguments);return this},stopListening:function(t,e,r){var s=this._listeningTo;if(!s)return this;var n=!e&&!r;if(!r&&typeof e==="object")r=this;if(t)(s={})[t._listenId]=t;for(var a in s){t=s[a];t.off(e,r,this);if(n||i.isEmpty(t._events))delete this._listeningTo[a]}return this}};var l=/\s+/;var c=function(t,e,i,r){if(!i)return true;if(typeof i==="object"){for(var s in i){t[e].apply(t,[s,i[s]].concat(r))}return false}if(l.test(i)){var n=i.split(l);for(var a=0,o=n.length;a<o;a++){t[e].apply(t,[n[a]].concat(r))}return false}return true};var f=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],o=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,o);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e);return}};var d={listenTo:"on",listenToOnce:"once"};i.each(d,function(t,e){u[e]=function(e,r,s){var n=this._listeningTo||(this._listeningTo={});var a=e._listenId||(e._listenId=i.uniqueId("l"));n[a]=e;if(!s&&typeof r==="object")s=this;e[t](r,s,this);return this}});u.bind=u.on;u.unbind=u.off;i.extend(e,u);var p=e.Model=function(t,e){var r=t||{};e||(e={});this.cid=i.uniqueId("c");this.attributes={};if(e.collection)this.collection=e.collection;if(e.parse)r=this.parse(r,e)||{};r=i.defaults({},r,i.result(this,"defaults"));this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};i.extend(p.prototype,u,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){return i.clone(this.attributes)},sync:function(){return e.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return i.escape(this.get(t))},has:function(t){return this.get(t)!=null},set:function(t,e,r){var s,n,a,o,h,u,l,c;if(t==null)return this;if(typeof t==="object"){n=t;r=e}else{(n={})[t]=e}r||(r={});if(!this._validate(n,r))return false;a=r.unset;h=r.silent;o=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=i.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttribute in n)this.id=n[this.idAttribute];for(s in n){e=n[s];if(!i.isEqual(c[s],e))o.push(s);if(!i.isEqual(l[s],e)){this.changed[s]=e}else{delete this.changed[s]}a?delete c[s]:c[s]=e}if(!h){if(o.length)this._pending=r;for(var f=0,d=o.length;f<d;f++){this.trigger("change:"+o[f],this,c[o[f]],r)}}if(u)return this;if(!h){while(this._pending){r=this._pending;this._pending=false;this.trigger("change",this,r)}}this._pending=false;this._changing=false;return this},unset:function(t,e){return this.set(t,void 0,i.extend({},e,{unset:true}))},clear:function(t){var e={};for(var r in this.attributes)e[r]=void 0;return this.set(e,i.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!i.isEmpty(this.changed);return i.has(this.changed,t)},changedAttributes:function(t){if(!t)return this.hasChanged()?i.clone(this.changed):false;var e,r=false;var s=this._changing?this._previousAttributes:this.attributes;for(var n in t){if(i.isEqual(s[n],e=t[n]))continue;(r||(r={}))[n]=e}return r},previous:function(t){if(t==null||!this._previousAttributes)return null;return this._previousAttributes[t]},previousAttributes:function(){return i.clone(this._previousAttributes)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=this;var r=t.success;t.success=function(i){if(!e.set(e.parse(i,t),t))return false;if(r)r(e,i,t);e.trigger("sync",e,i,t)};q(this,t);return this.sync("read",this,t)},save:function(t,e,r){var s,n,a,o=this.attributes;if(t==null||typeof t==="object"){s=t;r=e}else{(s={})[t]=e}r=i.extend({validate:true},r);if(s&&!r.wait){if(!this.set(s,r))return false}else{if(!this._validate(s,r))return false}if(s&&r.wait){this.attributes=i.extend({},o,s)}if(r.parse===void 0)r.parse=true;var h=this;var u=r.success;r.success=function(t){h.attributes=o;var e=h.parse(t,r);if(r.wait)e=i.extend(s||{},e);if(i.isObject(e)&&!h.set(e,r)){return false}if(u)u(h,t,r);h.trigger("sync",h,t,r)};q(this,r);n=this.isNew()?"create":r.patch?"patch":"update";if(n==="patch")r.attrs=s;a=this.sync(n,this,r);if(s&&r.wait)this.attributes=o;return a},destroy:function(t){t=t?i.clone(t):{};var e=this;var r=t.success;var s=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(i){if(t.wait||e.isNew())s();if(r)r(e,i,t);if(!e.isNew())e.trigger("sync",e,i,t)};if(this.isNew()){t.success();return false}q(this,t);var n=this.sync("delete",this,t);if(!t.wait)s();return n},url:function(){var t=i.result(this,"urlRoot")||i.result(this.collection,"url")||M();if(this.isNew())return t;return t.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(t){return this._validate({},i.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)return true;t=i.extend({},this.attributes,t);var r=this.validationError=this.validate(t,e)||null;if(!r)return true;this.trigger("invalid",this,r,i.extend(e,{validationError:r}));return false}});var v=["keys","values","pairs","invert","pick","omit"];i.each(v,function(t){p.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.attributes);return i[t].apply(i,e)}});var g=e.Collection=function(t,e){e||(e={});if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,i.extend({silent:true},e))};var m={add:true,remove:true,merge:true};var y={add:true,remove:false};i.extend(g.prototype,u,{model:p,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return e.sync.apply(this,arguments)},add:function(t,e){return this.set(t,i.extend({merge:false},e,y))},remove:function(t,e){var r=!i.isArray(t);t=r?[t]:i.clone(t);e||(e={});var s,n,a,o;for(s=0,n=t.length;s<n;s++){o=t[s]=this.get(t[s]);if(!o)continue;delete this._byId[o.id];delete this._byId[o.cid];a=this.indexOf(o);this.models.splice(a,1);this.length--;if(!e.silent){e.index=a;o.trigger("remove",o,this,e)}this._removeReference(o,e)}return r?t[0]:t},set:function(t,e){e=i.defaults({},e,m);if(e.parse)t=this.parse(t,e);var r=!i.isArray(t);t=r?t?[t]:[]:i.clone(t);var s,n,a,o,h,u,l;var c=e.at;var f=this.model;var d=this.comparator&&c==null&&e.sort!==false;var v=i.isString(this.comparator)?this.comparator:null;var g=[],y=[],_={};var b=e.add,w=e.merge,x=e.remove;var E=!d&&b&&x?[]:false;for(s=0,n=t.length;s<n;s++){h=t[s]||{};if(h instanceof p){a=o=h}else{a=h[f.prototype.idAttribute||"id"]}if(u=this.get(a)){if(x)_[u.cid]=true;if(w){h=h===o?o.attributes:h;if(e.parse)h=u.parse(h,e);u.set(h,e);if(d&&!l&&u.hasChanged(v))l=true}t[s]=u}else if(b){o=t[s]=this._prepareModel(h,e);if(!o)continue;g.push(o);this._addReference(o,e)}o=u||o;if(E&&(o.isNew()||!_[o.id]))E.push(o);_[o.id]=true}if(x){for(s=0,n=this.length;s<n;++s){if(!_[(o=this.models[s]).cid])y.push(o)}if(y.length)this.remove(y,e)}if(g.length||E&&E.length){if(d)l=true;this.length+=g.length;if(c!=null){for(s=0,n=g.length;s<n;s++){this.models.splice(c+s,0,g[s])}}else{if(E)this.models.length=0;var k=E||g;for(s=0,n=k.length;s<n;s++){this.models.push(k[s])}}}if(l)this.sort({silent:true});if(!e.silent){for(s=0,n=g.length;s<n;s++){(o=g[s]).trigger("add",o,this,e)}if(l||E&&E.length)this.trigger("sort",this,e)}return r?t[0]:t},reset:function(t,e){e||(e={});for(var r=0,s=this.models.length;r<s;r++){this._removeReference(this.models[r],e)}e.previousModels=this.models;this._reset();t=this.add(t,i.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);return t},push:function(t,e){return this.add(t,i.extend({at:this.length},e))},pop:function(t){var e=this.at(this.length-1);this.remove(e,t);return e},unshift:function(t,e){return this.add(t,i.extend({at:0},e))},shift:function(t){var e=this.at(0);this.remove(e,t);return e},slice:function(){return o.apply(this.models,arguments)},get:function(t){if(t==null)return void 0;return this._byId[t]||this._byId[t.id]||this._byId[t.cid]},at:function(t){return this.models[t]},where:function(t,e){if(i.isEmpty(t))return e?void 0:[];return this[e?"find":"filter"](function(e){for(var i in t){if(t[i]!==e.get(i))return false}return true})},findWhere:function(t){return this.where(t,true)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");t||(t={});if(i.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(i.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);return this},pluck:function(t){return i.invoke(this.models,"get",t)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=t.success;var r=this;t.success=function(i){var s=t.reset?"reset":"set";r[s](i,t);if(e)e(r,i,t);r.trigger("sync",r,i,t)};q(this,t);return this.sync("read",this,t)},create:function(t,e){e=e?i.clone(e):{};if(!(t=this._prepareModel(t,e)))return false;if(!e.wait)this.add(t,e);var r=this;var s=e.success;e.success=function(t,i){if(e.wait)r.add(t,e);if(s)s(t,i,e)};t.save(null,e);return t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(t instanceof p)return t;e=e?i.clone(e):{};e.collection=this;var r=new this.model(t,e);if(!r.validationError)return r;this.trigger("invalid",this,r.validationError,e);return false},_addReference:function(t,e){this._byId[t.cid]=t;if(t.id!=null)this._byId[t.id]=t;if(!t.collection)t.collection=this;t.on("all",this._onModelEvent,this)},_removeReference:function(t,e){if(this===t.collection)delete t.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){delete this._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var _=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];i.each(_,function(t){g.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.models);return i[t].apply(i,e)}});var b=["groupBy","countBy","sortBy","indexBy"];i.each(b,function(t){g.prototype[t]=function(e,r){var s=i.isFunction(e)?e:function(t){return t.get(e)};return i[t](this.models,s,r)}});var w=e.View=function(t){this.cid=i.uniqueId("view");t||(t={});i.extend(this,i.pick(t,E));this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var x=/^(\S+)\s*(.*)$/;var E=["model","collection","el","id","attributes","className","tagName","events"];i.extend(w.prototype,u,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(t,i){if(this.$el)this.undelegateEvents();this.$el=t instanceof e.$?t:e.$(t);this.el=this.$el[0];if(i!==false)this.delegateEvents();return this},delegateEvents:function(t){if(!(t||(t=i.result(this,"events"))))return this;this.undelegateEvents();for(var e in t){var r=t[e];if(!i.isFunction(r))r=this[t[e]];if(!r)continue;var s=e.match(x);var n=s[1],a=s[2];r=i.bind(r,this);n+=".delegateEvents"+this.cid;if(a===""){this.$el.on(n,r)}else{this.$el.on(n,a,r)}}return this},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);return this},_ensureElement:function(){if(!this.el){var t=i.extend({},i.result(this,"attributes"));if(this.id)t.id=i.result(this,"id");if(this.className)t["class"]=i.result(this,"className");var r=e.$("<"+i.result(this,"tagName")+">").attr(t);this.setElement(r,false)}else{this.setElement(i.result(this,"el"),false)}}});e.sync=function(t,r,s){var n=T[t];i.defaults(s||(s={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var a={type:n,dataType:"json"};if(!s.url){a.url=i.result(r,"url")||M()}if(s.data==null&&r&&(t==="create"||t==="update"||t==="patch")){a.contentType="application/json";a.data=JSON.stringify(s.attrs||r.toJSON(s))}if(s.emulateJSON){a.contentType="application/x-www-form-urlencoded";a.data=a.data?{model:a.data}:{}}if(s.emulateHTTP&&(n==="PUT"||n==="DELETE"||n==="PATCH")){a.type="POST";if(s.emulateJSON)a.data._method=n;var o=s.beforeSend;s.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",n);if(o)return o.apply(this,arguments)}}if(a.type!=="GET"&&!s.emulateJSON){a.processData=false}if(a.type==="PATCH"&&k){a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var h=s.xhr=e.ajax(i.extend(a,s));r.trigger("request",r,h,s);return h};var k=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var $=e.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var H=/(\(\?)?:\w+/g;var A=/\*\w+/g;var I=/[\-{}\[\]+?.,\\\^$|#\s]/g;i.extend($.prototype,u,{initialize:function(){},route:function(t,r,s){if(!i.isRegExp(t))t=this._routeToRegExp(t);if(i.isFunction(r)){s=r;r=""}if(!s)s=this[r];var n=this;e.history.route(t,function(i){var a=n._extractParameters(t,i);n.execute(s,a);n.trigger.apply(n,["route:"+r].concat(a));n.trigger("route",r,a);e.history.trigger("route",n,r,a)});return this},execute:function(t,e){if(t)t.apply(this,e)},navigate:function(t,i){e.history.navigate(t,i);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=i.result(this,"routes");var t,e=i.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(I,"\\$&").replace(S,"(?:$1)?").replace(H,function(t,e){return e?t:"([^/?]+)"}).replace(A,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return i.map(r,function(t,e){if(e===r.length-1)return t||null;return t?decodeURIComponent(t):null})}});var N=e.History=function(){this.handlers=[];i.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var R=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/#.*$/;N.started=false;i.extend(N.prototype,u,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=decodeURI(this.location.pathname+this.location.search);var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(R,"")},start:function(t){if(N.started)throw new Error("Backbone.history has already been started");N.started=true;this.options=i.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment();var s=document.documentMode;var n=P.exec(navigator.userAgent.toLowerCase())&&(!s||s<=7);this.root=("/"+this.root+"/").replace(O,"/");if(n&&this._wantsHashChange){var a=e.$('<iframe src="javascript:0" tabindex="-1">');this.iframe=a.hide().appendTo("body")[0].contentWindow;this.navigate(r)}if(this._hasPushState){e.$(window).on("popstate",this.checkUrl)}else if(this._wantsHashChange&&"onhashchange"in window&&!n){e.$(window).on("hashchange",this.checkUrl)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=r;var o=this.location;if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){this.fragment=this.getFragment(null,true);this.location.replace(this.root+"#"+this.fragment);return true}else if(this._hasPushState&&this.atRoot()&&o.hash){this.fragment=this.getHash().replace(R,"");this.history.replaceState({},document.title,this.root+this.fragment)}}if(!this.options.silent)return this.loadUrl()},stop:function(){e.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);if(this._checkUrlInterval)clearInterval(this._checkUrlInterval);N.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)return false;if(this.iframe)this.navigate(e);this.loadUrl()},loadUrl:function(t){t=this.fragment=this.getFragment(t);return i.any(this.handlers,function(e){if(e.route.test(t)){e.callback(t);return true}})},navigate:function(t,e){if(!N.started)return false;if(!e||e===true)e={trigger:!!e};var i=this.root+(t=this.getFragment(t||""));t=t.replace(j,"");if(this.fragment===t)return;this.fragment=t;if(t===""&&i!=="/")i=i.slice(0,-1);if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}else if(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{return this.location.assign(i)}if(e.trigger)return this.loadUrl(t)},_updateHash:function(t,e,i){if(i){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});e.history=new N;var U=function(t,e){var r=this;var s;if(t&&i.has(t,"constructor")){s=t.constructor}else{s=function(){return r.apply(this,arguments)}}i.extend(s,r,e);var n=function(){this.constructor=s};n.prototype=r.prototype;s.prototype=new n;if(t)i.extend(s.prototype,t);s.__super__=r.prototype;return s};p.extend=g.extend=$.extend=w.extend=N.extend=U;var M=function(){throw new Error('A "url" property or function must be specified')};var q=function(t,e){var i=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}};return e});
+
+// From http://stackoverflow.com/a/19431552
+// Compatibility override - Backbone 1.1 got rid of the 'options' binding
+// automatically to views in the constructor - we need to keep that.
+Backbone.View = (function(View) {
+ return View.extend({
+ constructor: function(options) {
+ this.options = options || {};
+ View.apply(this, arguments);
+ }
+ });
+})(Backbone.View);
diff --git a/catalog-be/src/main/resources/swagger/lib/handlebars-2.0.0.js b/catalog-be/src/main/resources/swagger/lib/handlebars-2.0.0.js
new file mode 100644
index 0000000000..0abd7a6149
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/handlebars-2.0.0.js
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/*!
+
+ handlebars v2.0.0
+
+Copyright (C) 2011-2014 by Yehuda Katz
+
+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.
+
+@license
+*/
+!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Handlebars=a.Handlebars||b()}(this,function(){var a=function(){"use strict";function a(a){this.string=a}var b;return a.prototype.toString=function(){return""+this.string},b=a}(),b=function(a){"use strict";function b(a){return i[a]}function c(a){for(var b=1;b<arguments.length;b++)for(var c in arguments[b])Object.prototype.hasOwnProperty.call(arguments[b],c)&&(a[c]=arguments[b][c]);return a}function d(a){return a instanceof h?a.toString():null==a?"":a?(a=""+a,k.test(a)?a.replace(j,b):a):a+""}function e(a){return a||0===a?n(a)&&0===a.length?!0:!1:!0}function f(a,b){return(a?a+".":"")+b}var g={},h=a,i={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},j=/[&<>"'`]/g,k=/[&<>"'`]/;g.extend=c;var l=Object.prototype.toString;g.toString=l;var m=function(a){return"function"==typeof a};m(/x/)&&(m=function(a){return"function"==typeof a&&"[object Function]"===l.call(a)});var m;g.isFunction=m;var n=Array.isArray||function(a){return a&&"object"==typeof a?"[object Array]"===l.call(a):!1};return g.isArray=n,g.escapeExpression=d,g.isEmpty=e,g.appendContextPath=f,g}(a),c=function(){"use strict";function a(a,b){var d;b&&b.firstLine&&(d=b.firstLine,a+=" - "+d+":"+b.firstColumn);for(var e=Error.prototype.constructor.call(this,a),f=0;f<c.length;f++)this[c[f]]=e[c[f]];d&&(this.lineNumber=d,this.column=b.firstColumn)}var b,c=["description","fileName","lineNumber","message","name","number","stack"];return a.prototype=new Error,b=a}(),d=function(a,b){"use strict";function c(a,b){this.helpers=a||{},this.partials=b||{},d(this)}function d(a){a.registerHelper("helperMissing",function(){if(1===arguments.length)return void 0;throw new g("Missing helper: '"+arguments[arguments.length-1].name+"'")}),a.registerHelper("blockHelperMissing",function(b,c){var d=c.inverse,e=c.fn;if(b===!0)return e(this);if(b===!1||null==b)return d(this);if(k(b))return b.length>0?(c.ids&&(c.ids=[c.name]),a.helpers.each(b,c)):d(this);if(c.data&&c.ids){var g=q(c.data);g.contextPath=f.appendContextPath(c.data.contextPath,c.name),c={data:g}}return e(b,c)}),a.registerHelper("each",function(a,b){if(!b)throw new g("Must pass iterator to #each");var c,d,e=b.fn,h=b.inverse,i=0,j="";if(b.data&&b.ids&&(d=f.appendContextPath(b.data.contextPath,b.ids[0])+"."),l(a)&&(a=a.call(this)),b.data&&(c=q(b.data)),a&&"object"==typeof a)if(k(a))for(var m=a.length;m>i;i++)c&&(c.index=i,c.first=0===i,c.last=i===a.length-1,d&&(c.contextPath=d+i)),j+=e(a[i],{data:c});else for(var n in a)a.hasOwnProperty(n)&&(c&&(c.key=n,c.index=i,c.first=0===i,d&&(c.contextPath=d+n)),j+=e(a[n],{data:c}),i++);return 0===i&&(j=h(this)),j}),a.registerHelper("if",function(a,b){return l(a)&&(a=a.call(this)),!b.hash.includeZero&&!a||f.isEmpty(a)?b.inverse(this):b.fn(this)}),a.registerHelper("unless",function(b,c){return a.helpers["if"].call(this,b,{fn:c.inverse,inverse:c.fn,hash:c.hash})}),a.registerHelper("with",function(a,b){l(a)&&(a=a.call(this));var c=b.fn;if(f.isEmpty(a))return b.inverse(this);if(b.data&&b.ids){var d=q(b.data);d.contextPath=f.appendContextPath(b.data.contextPath,b.ids[0]),b={data:d}}return c(a,b)}),a.registerHelper("log",function(b,c){var d=c.data&&null!=c.data.level?parseInt(c.data.level,10):1;a.log(d,b)}),a.registerHelper("lookup",function(a,b){return a&&a[b]})}var e={},f=a,g=b,h="2.0.0";e.VERSION=h;var i=6;e.COMPILER_REVISION=i;var j={1:"<= 1.0.rc.2",2:"== 1.0.0-rc.3",3:"== 1.0.0-rc.4",4:"== 1.x.x",5:"== 2.0.0-alpha.x",6:">= 2.0.0-beta.1"};e.REVISION_CHANGES=j;var k=f.isArray,l=f.isFunction,m=f.toString,n="[object Object]";e.HandlebarsEnvironment=c,c.prototype={constructor:c,logger:o,log:p,registerHelper:function(a,b){if(m.call(a)===n){if(b)throw new g("Arg not supported with multiple helpers");f.extend(this.helpers,a)}else this.helpers[a]=b},unregisterHelper:function(a){delete this.helpers[a]},registerPartial:function(a,b){m.call(a)===n?f.extend(this.partials,a):this.partials[a]=b},unregisterPartial:function(a){delete this.partials[a]}};var o={methodMap:{0:"debug",1:"info",2:"warn",3:"error"},DEBUG:0,INFO:1,WARN:2,ERROR:3,level:3,log:function(a,b){if(o.level<=a){var c=o.methodMap[a];"undefined"!=typeof console&&console[c]&&console[c].call(console,b)}}};e.logger=o;var p=o.log;e.log=p;var q=function(a){var b=f.extend({},a);return b._parent=a,b};return e.createFrame=q,e}(b,c),e=function(a,b,c){"use strict";function d(a){var b=a&&a[0]||1,c=m;if(b!==c){if(c>b){var d=n[c],e=n[b];throw new l("Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version ("+d+") or downgrade your runtime to an older version ("+e+").")}throw new l("Template was precompiled with a newer version of Handlebars than the current runtime. Please update your runtime to a newer version ("+a[1]+").")}}function e(a,b){if(!b)throw new l("No environment passed to template");if(!a||!a.main)throw new l("Unknown template object: "+typeof a);b.VM.checkRevision(a.compiler);var c=function(c,d,e,f,g,h,i,j,m){g&&(f=k.extend({},f,g));var n=b.VM.invokePartial.call(this,c,e,f,h,i,j,m);if(null==n&&b.compile){var o={helpers:h,partials:i,data:j,depths:m};i[e]=b.compile(c,{data:void 0!==j,compat:a.compat},b),n=i[e](f,o)}if(null!=n){if(d){for(var p=n.split("\n"),q=0,r=p.length;r>q&&(p[q]||q+1!==r);q++)p[q]=d+p[q];n=p.join("\n")}return n}throw new l("The partial "+e+" could not be compiled when running in runtime-only mode")},d={lookup:function(a,b){for(var c=a.length,d=0;c>d;d++)if(a[d]&&null!=a[d][b])return a[d][b]},lambda:function(a,b){return"function"==typeof a?a.call(b):a},escapeExpression:k.escapeExpression,invokePartial:c,fn:function(b){return a[b]},programs:[],program:function(a,b,c){var d=this.programs[a],e=this.fn(a);return b||c?d=f(this,a,e,b,c):d||(d=this.programs[a]=f(this,a,e)),d},data:function(a,b){for(;a&&b--;)a=a._parent;return a},merge:function(a,b){var c=a||b;return a&&b&&a!==b&&(c=k.extend({},b,a)),c},noop:b.VM.noop,compilerInfo:a.compiler},e=function(b,c){c=c||{};var f=c.data;e._setup(c),!c.partial&&a.useData&&(f=i(b,f));var g;return a.useDepths&&(g=c.depths?[b].concat(c.depths):[b]),a.main.call(d,b,d.helpers,d.partials,f,g)};return e.isTop=!0,e._setup=function(c){c.partial?(d.helpers=c.helpers,d.partials=c.partials):(d.helpers=d.merge(c.helpers,b.helpers),a.usePartial&&(d.partials=d.merge(c.partials,b.partials)))},e._child=function(b,c,e){if(a.useDepths&&!e)throw new l("must pass parent depths");return f(d,b,a[b],c,e)},e}function f(a,b,c,d,e){var f=function(b,f){return f=f||{},c.call(a,b,a.helpers,a.partials,f.data||d,e&&[b].concat(e))};return f.program=b,f.depth=e?e.length:0,f}function g(a,b,c,d,e,f,g){var h={partial:!0,helpers:d,partials:e,data:f,depths:g};if(void 0===a)throw new l("The partial "+b+" could not be found");return a instanceof Function?a(c,h):void 0}function h(){return""}function i(a,b){return b&&"root"in b||(b=b?o(b):{},b.root=a),b}var j={},k=a,l=b,m=c.COMPILER_REVISION,n=c.REVISION_CHANGES,o=c.createFrame;return j.checkRevision=d,j.template=e,j.program=f,j.invokePartial=g,j.noop=h,j}(b,c,d),f=function(a,b,c,d,e){"use strict";var f,g=a,h=b,i=c,j=d,k=e,l=function(){var a=new g.HandlebarsEnvironment;return j.extend(a,g),a.SafeString=h,a.Exception=i,a.Utils=j,a.escapeExpression=j.escapeExpression,a.VM=k,a.template=function(b){return k.template(b,a)},a},m=l();return m.create=l,m["default"]=m,f=m}(d,a,c,b,e),g=function(a){"use strict";function b(a){a=a||{},this.firstLine=a.first_line,this.firstColumn=a.first_column,this.lastColumn=a.last_column,this.lastLine=a.last_line}var c,d=a,e={ProgramNode:function(a,c,d){b.call(this,d),this.type="program",this.statements=a,this.strip=c},MustacheNode:function(a,c,d,f,g){if(b.call(this,g),this.type="mustache",this.strip=f,null!=d&&d.charAt){var h=d.charAt(3)||d.charAt(2);this.escaped="{"!==h&&"&"!==h}else this.escaped=!!d;this.sexpr=a instanceof e.SexprNode?a:new e.SexprNode(a,c),this.id=this.sexpr.id,this.params=this.sexpr.params,this.hash=this.sexpr.hash,this.eligibleHelper=this.sexpr.eligibleHelper,this.isHelper=this.sexpr.isHelper},SexprNode:function(a,c,d){b.call(this,d),this.type="sexpr",this.hash=c;var e=this.id=a[0],f=this.params=a.slice(1);this.isHelper=!(!f.length&&!c),this.eligibleHelper=this.isHelper||e.isSimple},PartialNode:function(a,c,d,e,f){b.call(this,f),this.type="partial",this.partialName=a,this.context=c,this.hash=d,this.strip=e,this.strip.inlineStandalone=!0},BlockNode:function(a,c,d,e,f){b.call(this,f),this.type="block",this.mustache=a,this.program=c,this.inverse=d,this.strip=e,d&&!c&&(this.isInverse=!0)},RawBlockNode:function(a,c,f,g){if(b.call(this,g),a.sexpr.id.original!==f)throw new d(a.sexpr.id.original+" doesn't match "+f,this);c=new e.ContentNode(c,g),this.type="block",this.mustache=a,this.program=new e.ProgramNode([c],{},g)},ContentNode:function(a,c){b.call(this,c),this.type="content",this.original=this.string=a},HashNode:function(a,c){b.call(this,c),this.type="hash",this.pairs=a},IdNode:function(a,c){b.call(this,c),this.type="ID";for(var e="",f=[],g=0,h="",i=0,j=a.length;j>i;i++){var k=a[i].part;if(e+=(a[i].separator||"")+k,".."===k||"."===k||"this"===k){if(f.length>0)throw new d("Invalid path: "+e,this);".."===k?(g++,h+="../"):this.isScoped=!0}else f.push(k)}this.original=e,this.parts=f,this.string=f.join("."),this.depth=g,this.idName=h+this.string,this.isSimple=1===a.length&&!this.isScoped&&0===g,this.stringModeValue=this.string},PartialNameNode:function(a,c){b.call(this,c),this.type="PARTIAL_NAME",this.name=a.original},DataNode:function(a,c){b.call(this,c),this.type="DATA",this.id=a,this.stringModeValue=a.stringModeValue,this.idName="@"+a.stringModeValue},StringNode:function(a,c){b.call(this,c),this.type="STRING",this.original=this.string=this.stringModeValue=a},NumberNode:function(a,c){b.call(this,c),this.type="NUMBER",this.original=this.number=a,this.stringModeValue=Number(a)},BooleanNode:function(a,c){b.call(this,c),this.type="BOOLEAN",this.bool=a,this.stringModeValue="true"===a},CommentNode:function(a,c){b.call(this,c),this.type="comment",this.comment=a,this.strip={inlineStandalone:!0}}};return c=e}(c),h=function(){"use strict";var a,b=function(){function a(){this.yy={}}var b={trace:function(){},yy:{},symbols_:{error:2,root:3,program:4,EOF:5,program_repetition0:6,statement:7,mustache:8,block:9,rawBlock:10,partial:11,CONTENT:12,COMMENT:13,openRawBlock:14,END_RAW_BLOCK:15,OPEN_RAW_BLOCK:16,sexpr:17,CLOSE_RAW_BLOCK:18,openBlock:19,block_option0:20,closeBlock:21,openInverse:22,block_option1:23,OPEN_BLOCK:24,CLOSE:25,OPEN_INVERSE:26,inverseAndProgram:27,INVERSE:28,OPEN_ENDBLOCK:29,path:30,OPEN:31,OPEN_UNESCAPED:32,CLOSE_UNESCAPED:33,OPEN_PARTIAL:34,partialName:35,param:36,partial_option0:37,partial_option1:38,sexpr_repetition0:39,sexpr_option0:40,dataName:41,STRING:42,NUMBER:43,BOOLEAN:44,OPEN_SEXPR:45,CLOSE_SEXPR:46,hash:47,hash_repetition_plus0:48,hashSegment:49,ID:50,EQUALS:51,DATA:52,pathSegments:53,SEP:54,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",12:"CONTENT",13:"COMMENT",15:"END_RAW_BLOCK",16:"OPEN_RAW_BLOCK",18:"CLOSE_RAW_BLOCK",24:"OPEN_BLOCK",25:"CLOSE",26:"OPEN_INVERSE",28:"INVERSE",29:"OPEN_ENDBLOCK",31:"OPEN",32:"OPEN_UNESCAPED",33:"CLOSE_UNESCAPED",34:"OPEN_PARTIAL",42:"STRING",43:"NUMBER",44:"BOOLEAN",45:"OPEN_SEXPR",46:"CLOSE_SEXPR",50:"ID",51:"EQUALS",52:"DATA",54:"SEP"},productions_:[0,[3,2],[4,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[10,3],[14,3],[9,4],[9,4],[19,3],[22,3],[27,2],[21,3],[8,3],[8,3],[11,5],[11,4],[17,3],[17,1],[36,1],[36,1],[36,1],[36,1],[36,1],[36,3],[47,1],[49,3],[35,1],[35,1],[35,1],[41,2],[30,1],[53,3],[53,1],[6,0],[6,2],[20,0],[20,1],[23,0],[23,1],[37,0],[37,1],[38,0],[38,1],[39,0],[39,2],[40,0],[40,1],[48,1],[48,2]],performAction:function(a,b,c,d,e,f){var g=f.length-1;switch(e){case 1:return d.prepareProgram(f[g-1].statements,!0),f[g-1];case 2:this.$=new d.ProgramNode(d.prepareProgram(f[g]),{},this._$);break;case 3:this.$=f[g];break;case 4:this.$=f[g];break;case 5:this.$=f[g];break;case 6:this.$=f[g];break;case 7:this.$=new d.ContentNode(f[g],this._$);break;case 8:this.$=new d.CommentNode(f[g],this._$);break;case 9:this.$=new d.RawBlockNode(f[g-2],f[g-1],f[g],this._$);break;case 10:this.$=new d.MustacheNode(f[g-1],null,"","",this._$);break;case 11:this.$=d.prepareBlock(f[g-3],f[g-2],f[g-1],f[g],!1,this._$);break;case 12:this.$=d.prepareBlock(f[g-3],f[g-2],f[g-1],f[g],!0,this._$);break;case 13:this.$=new d.MustacheNode(f[g-1],null,f[g-2],d.stripFlags(f[g-2],f[g]),this._$);break;case 14:this.$=new d.MustacheNode(f[g-1],null,f[g-2],d.stripFlags(f[g-2],f[g]),this._$);break;case 15:this.$={strip:d.stripFlags(f[g-1],f[g-1]),program:f[g]};break;case 16:this.$={path:f[g-1],strip:d.stripFlags(f[g-2],f[g])};break;case 17:this.$=new d.MustacheNode(f[g-1],null,f[g-2],d.stripFlags(f[g-2],f[g]),this._$);break;case 18:this.$=new d.MustacheNode(f[g-1],null,f[g-2],d.stripFlags(f[g-2],f[g]),this._$);break;case 19:this.$=new d.PartialNode(f[g-3],f[g-2],f[g-1],d.stripFlags(f[g-4],f[g]),this._$);break;case 20:this.$=new d.PartialNode(f[g-2],void 0,f[g-1],d.stripFlags(f[g-3],f[g]),this._$);break;case 21:this.$=new d.SexprNode([f[g-2]].concat(f[g-1]),f[g],this._$);break;case 22:this.$=new d.SexprNode([f[g]],null,this._$);break;case 23:this.$=f[g];break;case 24:this.$=new d.StringNode(f[g],this._$);break;case 25:this.$=new d.NumberNode(f[g],this._$);break;case 26:this.$=new d.BooleanNode(f[g],this._$);break;case 27:this.$=f[g];break;case 28:f[g-1].isHelper=!0,this.$=f[g-1];break;case 29:this.$=new d.HashNode(f[g],this._$);break;case 30:this.$=[f[g-2],f[g]];break;case 31:this.$=new d.PartialNameNode(f[g],this._$);break;case 32:this.$=new d.PartialNameNode(new d.StringNode(f[g],this._$),this._$);break;case 33:this.$=new d.PartialNameNode(new d.NumberNode(f[g],this._$));break;case 34:this.$=new d.DataNode(f[g],this._$);break;case 35:this.$=new d.IdNode(f[g],this._$);break;case 36:f[g-2].push({part:f[g],separator:f[g-1]}),this.$=f[g-2];break;case 37:this.$=[{part:f[g]}];break;case 38:this.$=[];break;case 39:f[g-1].push(f[g]);break;case 48:this.$=[];break;case 49:f[g-1].push(f[g]);break;case 52:this.$=[f[g]];break;case 53:f[g-1].push(f[g])}},table:[{3:1,4:2,5:[2,38],6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],31:[2,38],32:[2,38],34:[2,38]},{1:[3]},{5:[1,4]},{5:[2,2],7:5,8:6,9:7,10:8,11:9,12:[1,10],13:[1,11],14:16,16:[1,20],19:14,22:15,24:[1,18],26:[1,19],28:[2,2],29:[2,2],31:[1,12],32:[1,13],34:[1,17]},{1:[2,1]},{5:[2,39],12:[2,39],13:[2,39],16:[2,39],24:[2,39],26:[2,39],28:[2,39],29:[2,39],31:[2,39],32:[2,39],34:[2,39]},{5:[2,3],12:[2,3],13:[2,3],16:[2,3],24:[2,3],26:[2,3],28:[2,3],29:[2,3],31:[2,3],32:[2,3],34:[2,3]},{5:[2,4],12:[2,4],13:[2,4],16:[2,4],24:[2,4],26:[2,4],28:[2,4],29:[2,4],31:[2,4],32:[2,4],34:[2,4]},{5:[2,5],12:[2,5],13:[2,5],16:[2,5],24:[2,5],26:[2,5],28:[2,5],29:[2,5],31:[2,5],32:[2,5],34:[2,5]},{5:[2,6],12:[2,6],13:[2,6],16:[2,6],24:[2,6],26:[2,6],28:[2,6],29:[2,6],31:[2,6],32:[2,6],34:[2,6]},{5:[2,7],12:[2,7],13:[2,7],16:[2,7],24:[2,7],26:[2,7],28:[2,7],29:[2,7],31:[2,7],32:[2,7],34:[2,7]},{5:[2,8],12:[2,8],13:[2,8],16:[2,8],24:[2,8],26:[2,8],28:[2,8],29:[2,8],31:[2,8],32:[2,8],34:[2,8]},{17:21,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:27,30:22,41:23,50:[1,26],52:[1,25],53:24},{4:28,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],28:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{4:29,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],28:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{12:[1,30]},{30:32,35:31,42:[1,33],43:[1,34],50:[1,26],53:24},{17:35,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:36,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:37,30:22,41:23,50:[1,26],52:[1,25],53:24},{25:[1,38]},{18:[2,48],25:[2,48],33:[2,48],39:39,42:[2,48],43:[2,48],44:[2,48],45:[2,48],46:[2,48],50:[2,48],52:[2,48]},{18:[2,22],25:[2,22],33:[2,22],46:[2,22]},{18:[2,35],25:[2,35],33:[2,35],42:[2,35],43:[2,35],44:[2,35],45:[2,35],46:[2,35],50:[2,35],52:[2,35],54:[1,40]},{30:41,50:[1,26],53:24},{18:[2,37],25:[2,37],33:[2,37],42:[2,37],43:[2,37],44:[2,37],45:[2,37],46:[2,37],50:[2,37],52:[2,37],54:[2,37]},{33:[1,42]},{20:43,27:44,28:[1,45],29:[2,40]},{23:46,27:47,28:[1,45],29:[2,42]},{15:[1,48]},{25:[2,46],30:51,36:49,38:50,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],47:57,48:58,49:60,50:[1,59],52:[1,25],53:24},{25:[2,31],42:[2,31],43:[2,31],44:[2,31],45:[2,31],50:[2,31],52:[2,31]},{25:[2,32],42:[2,32],43:[2,32],44:[2,32],45:[2,32],50:[2,32],52:[2,32]},{25:[2,33],42:[2,33],43:[2,33],44:[2,33],45:[2,33],50:[2,33],52:[2,33]},{25:[1,61]},{25:[1,62]},{18:[1,63]},{5:[2,17],12:[2,17],13:[2,17],16:[2,17],24:[2,17],26:[2,17],28:[2,17],29:[2,17],31:[2,17],32:[2,17],34:[2,17]},{18:[2,50],25:[2,50],30:51,33:[2,50],36:65,40:64,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],46:[2,50],47:66,48:58,49:60,50:[1,59],52:[1,25],53:24},{50:[1,67]},{18:[2,34],25:[2,34],33:[2,34],42:[2,34],43:[2,34],44:[2,34],45:[2,34],46:[2,34],50:[2,34],52:[2,34]},{5:[2,18],12:[2,18],13:[2,18],16:[2,18],24:[2,18],26:[2,18],28:[2,18],29:[2,18],31:[2,18],32:[2,18],34:[2,18]},{21:68,29:[1,69]},{29:[2,41]},{4:70,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{21:71,29:[1,69]},{29:[2,43]},{5:[2,9],12:[2,9],13:[2,9],16:[2,9],24:[2,9],26:[2,9],28:[2,9],29:[2,9],31:[2,9],32:[2,9],34:[2,9]},{25:[2,44],37:72,47:73,48:58,49:60,50:[1,74]},{25:[1,75]},{18:[2,23],25:[2,23],33:[2,23],42:[2,23],43:[2,23],44:[2,23],45:[2,23],46:[2,23],50:[2,23],52:[2,23]},{18:[2,24],25:[2,24],33:[2,24],42:[2,24],43:[2,24],44:[2,24],45:[2,24],46:[2,24],50:[2,24],52:[2,24]},{18:[2,25],25:[2,25],33:[2,25],42:[2,25],43:[2,25],44:[2,25],45:[2,25],46:[2,25],50:[2,25],52:[2,25]},{18:[2,26],25:[2,26],33:[2,26],42:[2,26],43:[2,26],44:[2,26],45:[2,26],46:[2,26],50:[2,26],52:[2,26]},{18:[2,27],25:[2,27],33:[2,27],42:[2,27],43:[2,27],44:[2,27],45:[2,27],46:[2,27],50:[2,27],52:[2,27]},{17:76,30:22,41:23,50:[1,26],52:[1,25],53:24},{25:[2,47]},{18:[2,29],25:[2,29],33:[2,29],46:[2,29],49:77,50:[1,74]},{18:[2,37],25:[2,37],33:[2,37],42:[2,37],43:[2,37],44:[2,37],45:[2,37],46:[2,37],50:[2,37],51:[1,78],52:[2,37],54:[2,37]},{18:[2,52],25:[2,52],33:[2,52],46:[2,52],50:[2,52]},{12:[2,13],13:[2,13],16:[2,13],24:[2,13],26:[2,13],28:[2,13],29:[2,13],31:[2,13],32:[2,13],34:[2,13]},{12:[2,14],13:[2,14],16:[2,14],24:[2,14],26:[2,14],28:[2,14],29:[2,14],31:[2,14],32:[2,14],34:[2,14]},{12:[2,10]},{18:[2,21],25:[2,21],33:[2,21],46:[2,21]},{18:[2,49],25:[2,49],33:[2,49],42:[2,49],43:[2,49],44:[2,49],45:[2,49],46:[2,49],50:[2,49],52:[2,49]},{18:[2,51],25:[2,51],33:[2,51],46:[2,51]},{18:[2,36],25:[2,36],33:[2,36],42:[2,36],43:[2,36],44:[2,36],45:[2,36],46:[2,36],50:[2,36],52:[2,36],54:[2,36]},{5:[2,11],12:[2,11],13:[2,11],16:[2,11],24:[2,11],26:[2,11],28:[2,11],29:[2,11],31:[2,11],32:[2,11],34:[2,11]},{30:79,50:[1,26],53:24},{29:[2,15]},{5:[2,12],12:[2,12],13:[2,12],16:[2,12],24:[2,12],26:[2,12],28:[2,12],29:[2,12],31:[2,12],32:[2,12],34:[2,12]},{25:[1,80]},{25:[2,45]},{51:[1,78]},{5:[2,20],12:[2,20],13:[2,20],16:[2,20],24:[2,20],26:[2,20],28:[2,20],29:[2,20],31:[2,20],32:[2,20],34:[2,20]},{46:[1,81]},{18:[2,53],25:[2,53],33:[2,53],46:[2,53],50:[2,53]},{30:51,36:82,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],50:[1,26],52:[1,25],53:24},{25:[1,83]},{5:[2,19],12:[2,19],13:[2,19],16:[2,19],24:[2,19],26:[2,19],28:[2,19],29:[2,19],31:[2,19],32:[2,19],34:[2,19]},{18:[2,28],25:[2,28],33:[2,28],42:[2,28],43:[2,28],44:[2,28],45:[2,28],46:[2,28],50:[2,28],52:[2,28]},{18:[2,30],25:[2,30],33:[2,30],46:[2,30],50:[2,30]},{5:[2,16],12:[2,16],13:[2,16],16:[2,16],24:[2,16],26:[2,16],28:[2,16],29:[2,16],31:[2,16],32:[2,16],34:[2,16]}],defaultActions:{4:[2,1],44:[2,41],47:[2,43],57:[2,47],63:[2,10],70:[2,15],73:[2,45]},parseError:function(a){throw new Error(a)},parse:function(a){function b(){var a;return a=c.lexer.lex()||1,"number"!=typeof a&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,"undefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var l=this.lexer.yylloc;f.push(l);var m=this.lexer.options&&this.lexer.options.ranges;"function"==typeof this.yy.parseError&&(this.parseError=this.yy.parseError);for(var n,o,p,q,r,s,t,u,v,w={};;){if(p=d[d.length-1],this.defaultActions[p]?q=this.defaultActions[p]:((null===n||"undefined"==typeof n)&&(n=b()),q=g[p]&&g[p][n]),"undefined"==typeof q||!q.length||!q[0]){var x="";if(!k){v=[];for(s in g[p])this.terminals_[s]&&s>2&&v.push("'"+this.terminals_[s]+"'");x=this.lexer.showPosition?"Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+v.join(", ")+", got '"+(this.terminals_[n]||n)+"'":"Parse error on line "+(i+1)+": Unexpected "+(1==n?"end of input":"'"+(this.terminals_[n]||n)+"'"),this.parseError(x,{text:this.lexer.match,token:this.terminals_[n]||n,line:this.lexer.yylineno,loc:l,expected:v})}}if(q[0]instanceof Array&&q.length>1)throw new Error("Parse Error: multiple actions possible at state: "+p+", token: "+n);switch(q[0]){case 1:d.push(n),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(q[1]),n=null,o?(n=o,o=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,l=this.lexer.yylloc,k>0&&k--);break;case 2:if(t=this.productions_[q[1]][1],w.$=e[e.length-t],w._$={first_line:f[f.length-(t||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(t||1)].first_column,last_column:f[f.length-1].last_column},m&&(w._$.range=[f[f.length-(t||1)].range[0],f[f.length-1].range[1]]),r=this.performAction.call(w,h,j,i,this.yy,q[1],e,f),"undefined"!=typeof r)return r;t&&(d=d.slice(0,-1*t*2),e=e.slice(0,-1*t),f=f.slice(0,-1*t)),d.push(this.productions_[q[1]][0]),e.push(w.$),f.push(w._$),u=g[d[d.length-2]][d[d.length-1]],d.push(u);break;case 3:return!0}}return!0}},c=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b-1),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this},more:function(){return this._more=!0,this},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d,e;this._more||(this.yytext="",this.match="");for(var f=this._currentRules(),g=0;g<f.length&&(c=this._input.match(this.rules[f[g]]),!c||b&&!(c[0].length>b[0].length)||(b=c,d=g,this.options.flex));g++);return b?(e=b[0].match(/(?:\r\n?|\n).*/g),e&&(this.yylineno+=e.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:e?e[e.length-1].length-e[e.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+b[0].length},this.yytext+=b[0],this.match+=b[0],this.matches=b,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._input=this._input.slice(b[0].length),this.matched+=b[0],a=this.performAction.call(this,this.yy,this,f[d],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),a?a:void 0):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return"undefined"!=typeof a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(a){this.begin(a)}};return a.options={},a.performAction=function(a,b,c,d){function e(a,c){return b.yytext=b.yytext.substr(a,b.yyleng-c)}switch(c){case 0:if("\\\\"===b.yytext.slice(-2)?(e(0,1),this.begin("mu")):"\\"===b.yytext.slice(-1)?(e(0,1),this.begin("emu")):this.begin("mu"),b.yytext)return 12;break;case 1:return 12;case 2:return this.popState(),12;case 3:return b.yytext=b.yytext.substr(5,b.yyleng-9),this.popState(),15;case 4:return 12;case 5:return e(0,4),this.popState(),13;case 6:return 45;case 7:return 46;case 8:return 16;case 9:return this.popState(),this.begin("raw"),18;case 10:return 34;case 11:return 24;case 12:return 29;case 13:return this.popState(),28;case 14:return this.popState(),28;case 15:return 26;case 16:return 26;case 17:return 32;case 18:return 31;case 19:this.popState(),this.begin("com");break;case 20:return e(3,5),this.popState(),13;case 21:return 31;case 22:return 51;case 23:return 50;case 24:return 50;case 25:return 54;case 26:break;case 27:return this.popState(),33;case 28:return this.popState(),25;case 29:return b.yytext=e(1,2).replace(/\\"/g,'"'),42;case 30:return b.yytext=e(1,2).replace(/\\'/g,"'"),42;case 31:return 52;case 32:return 44;case 33:return 44;case 34:return 43;case 35:return 50;case 36:return b.yytext=e(1,2),50;case 37:return"INVALID";case 38:return 5}},a.rules=[/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/,/^(?:[^\x00]*?(?=(\{\{\{\{\/)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\()/,/^(?:\))/,/^(?:\{\{\{\{)/,/^(?:\}\}\}\})/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^\s*(~)?\}\})/,/^(?:\{\{(~)?\s*else\s*(~)?\}\})/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{(~)?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/,/^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)]))))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/],a.conditions={mu:{rules:[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],inclusive:!1},emu:{rules:[2],inclusive:!1},com:{rules:[5],inclusive:!1},raw:{rules:[3,4],inclusive:!1},INITIAL:{rules:[0,1,38],inclusive:!0}},a}();return b.lexer=c,a.prototype=b,b.Parser=a,new a}();return a=b}(),i=function(a){"use strict";function b(a,b){return{left:"~"===a.charAt(2),right:"~"===b.charAt(b.length-3)}}function c(a,b,c,d,i,k){if(a.sexpr.id.original!==d.path.original)throw new j(a.sexpr.id.original+" doesn't match "+d.path.original,a);var l=c&&c.program,m={left:a.strip.left,right:d.strip.right,openStandalone:f(b.statements),closeStandalone:e((l||b).statements)};if(a.strip.right&&g(b.statements,null,!0),l){var n=c.strip;n.left&&h(b.statements,null,!0),n.right&&g(l.statements,null,!0),d.strip.left&&h(l.statements,null,!0),e(b.statements)&&f(l.statements)&&(h(b.statements),g(l.statements))}else d.strip.left&&h(b.statements,null,!0);return i?new this.BlockNode(a,l,b,m,k):new this.BlockNode(a,b,l,m,k)}function d(a,b){for(var c=0,d=a.length;d>c;c++){var i=a[c],j=i.strip;if(j){var k=e(a,c,b,"partial"===i.type),l=f(a,c,b),m=j.openStandalone&&k,n=j.closeStandalone&&l,o=j.inlineStandalone&&k&&l;j.right&&g(a,c,!0),j.left&&h(a,c,!0),o&&(g(a,c),h(a,c)&&"partial"===i.type&&(i.indent=/([ \t]+$)/.exec(a[c-1].original)?RegExp.$1:"")),m&&(g((i.program||i.inverse).statements),h(a,c)),n&&(g(a,c),h((i.inverse||i.program).statements))}}return a}function e(a,b,c){void 0===b&&(b=a.length);var d=a[b-1],e=a[b-2];return d?"content"===d.type?(e||!c?/\r?\n\s*?$/:/(^|\r?\n)\s*?$/).test(d.original):void 0:c}function f(a,b,c){void 0===b&&(b=-1);var d=a[b+1],e=a[b+2];return d?"content"===d.type?(e||!c?/^\s*?\r?\n/:/^\s*?(\r?\n|$)/).test(d.original):void 0:c}function g(a,b,c){var d=a[null==b?0:b+1];if(d&&"content"===d.type&&(c||!d.rightStripped)){var e=d.string;d.string=d.string.replace(c?/^\s+/:/^[ \t]*\r?\n?/,""),d.rightStripped=d.string!==e}}function h(a,b,c){var d=a[null==b?a.length-1:b-1];if(d&&"content"===d.type&&(c||!d.leftStripped)){var e=d.string;return d.string=d.string.replace(c?/\s+$/:/[ \t]+$/,""),d.leftStripped=d.string!==e,d.leftStripped}}var i={},j=a;return i.stripFlags=b,i.prepareBlock=c,i.prepareProgram=d,i}(c),j=function(a,b,c,d){"use strict";function e(a){return a.constructor===h.ProgramNode?a:(g.yy=k,g.parse(a))}var f={},g=a,h=b,i=c,j=d.extend;f.parser=g;var k={};return j(k,i,h),f.parse=e,f}(h,g,i,b),k=function(a,b){"use strict";function c(){}function d(a,b,c){if(null==a||"string"!=typeof a&&a.constructor!==c.AST.ProgramNode)throw new h("You must pass a string or Handlebars AST to Handlebars.precompile. You passed "+a);b=b||{},"data"in b||(b.data=!0),b.compat&&(b.useDepths=!0);var d=c.parse(a),e=(new c.Compiler).compile(d,b);return(new c.JavaScriptCompiler).compile(e,b)}function e(a,b,c){function d(){var d=c.parse(a),e=(new c.Compiler).compile(d,b),f=(new c.JavaScriptCompiler).compile(e,b,void 0,!0);return c.template(f)}if(null==a||"string"!=typeof a&&a.constructor!==c.AST.ProgramNode)throw new h("You must pass a string or Handlebars AST to Handlebars.compile. You passed "+a);b=b||{},"data"in b||(b.data=!0),b.compat&&(b.useDepths=!0);var e,f=function(a,b){return e||(e=d()),e.call(this,a,b)};return f._setup=function(a){return e||(e=d()),e._setup(a)},f._child=function(a,b,c){return e||(e=d()),e._child(a,b,c)},f}function f(a,b){if(a===b)return!0;if(i(a)&&i(b)&&a.length===b.length){for(var c=0;c<a.length;c++)if(!f(a[c],b[c]))return!1;return!0}}var g={},h=a,i=b.isArray,j=[].slice;return g.Compiler=c,c.prototype={compiler:c,equals:function(a){var b=this.opcodes.length;if(a.opcodes.length!==b)return!1;for(var c=0;b>c;c++){var d=this.opcodes[c],e=a.opcodes[c];if(d.opcode!==e.opcode||!f(d.args,e.args))return!1}for(b=this.children.length,c=0;b>c;c++)if(!this.children[c].equals(a.children[c]))return!1;return!0},guid:0,compile:function(a,b){this.opcodes=[],this.children=[],this.depths={list:[]},this.options=b,this.stringParams=b.stringParams,this.trackIds=b.trackIds;var c=this.options.knownHelpers;if(this.options.knownHelpers={helperMissing:!0,blockHelperMissing:!0,each:!0,"if":!0,unless:!0,"with":!0,log:!0,lookup:!0},c)for(var d in c)this.options.knownHelpers[d]=c[d];return this.accept(a)},accept:function(a){return this[a.type](a)},program:function(a){for(var b=a.statements,c=0,d=b.length;d>c;c++)this.accept(b[c]);return this.isSimple=1===d,this.depths.list=this.depths.list.sort(function(a,b){return a-b}),this},compileProgram:function(a){var b,c=(new this.compiler).compile(a,this.options),d=this.guid++;
+this.usePartial=this.usePartial||c.usePartial,this.children[d]=c;for(var e=0,f=c.depths.list.length;f>e;e++)b=c.depths.list[e],2>b||this.addDepth(b-1);return d},block:function(a){var b=a.mustache,c=a.program,d=a.inverse;c&&(c=this.compileProgram(c)),d&&(d=this.compileProgram(d));var e=b.sexpr,f=this.classifySexpr(e);"helper"===f?this.helperSexpr(e,c,d):"simple"===f?(this.simpleSexpr(e),this.opcode("pushProgram",c),this.opcode("pushProgram",d),this.opcode("emptyHash"),this.opcode("blockValue",e.id.original)):(this.ambiguousSexpr(e,c,d),this.opcode("pushProgram",c),this.opcode("pushProgram",d),this.opcode("emptyHash"),this.opcode("ambiguousBlockValue")),this.opcode("append")},hash:function(a){var b,c,d=a.pairs;for(this.opcode("pushHash"),b=0,c=d.length;c>b;b++)this.pushParam(d[b][1]);for(;b--;)this.opcode("assignToHash",d[b][0]);this.opcode("popHash")},partial:function(a){var b=a.partialName;this.usePartial=!0,a.hash?this.accept(a.hash):this.opcode("push","undefined"),a.context?this.accept(a.context):(this.opcode("getContext",0),this.opcode("pushContext")),this.opcode("invokePartial",b.name,a.indent||""),this.opcode("append")},content:function(a){a.string&&this.opcode("appendContent",a.string)},mustache:function(a){this.sexpr(a.sexpr),a.escaped&&!this.options.noEscape?this.opcode("appendEscaped"):this.opcode("append")},ambiguousSexpr:function(a,b,c){var d=a.id,e=d.parts[0],f=null!=b||null!=c;this.opcode("getContext",d.depth),this.opcode("pushProgram",b),this.opcode("pushProgram",c),this.ID(d),this.opcode("invokeAmbiguous",e,f)},simpleSexpr:function(a){var b=a.id;"DATA"===b.type?this.DATA(b):b.parts.length?this.ID(b):(this.addDepth(b.depth),this.opcode("getContext",b.depth),this.opcode("pushContext")),this.opcode("resolvePossibleLambda")},helperSexpr:function(a,b,c){var d=this.setupFullMustacheParams(a,b,c),e=a.id,f=e.parts[0];if(this.options.knownHelpers[f])this.opcode("invokeKnownHelper",d.length,f);else{if(this.options.knownHelpersOnly)throw new h("You specified knownHelpersOnly, but used the unknown helper "+f,a);e.falsy=!0,this.ID(e),this.opcode("invokeHelper",d.length,e.original,e.isSimple)}},sexpr:function(a){var b=this.classifySexpr(a);"simple"===b?this.simpleSexpr(a):"helper"===b?this.helperSexpr(a):this.ambiguousSexpr(a)},ID:function(a){this.addDepth(a.depth),this.opcode("getContext",a.depth);var b=a.parts[0];b?this.opcode("lookupOnContext",a.parts,a.falsy,a.isScoped):this.opcode("pushContext")},DATA:function(a){this.options.data=!0,this.opcode("lookupData",a.id.depth,a.id.parts)},STRING:function(a){this.opcode("pushString",a.string)},NUMBER:function(a){this.opcode("pushLiteral",a.number)},BOOLEAN:function(a){this.opcode("pushLiteral",a.bool)},comment:function(){},opcode:function(a){this.opcodes.push({opcode:a,args:j.call(arguments,1)})},addDepth:function(a){0!==a&&(this.depths[a]||(this.depths[a]=!0,this.depths.list.push(a)))},classifySexpr:function(a){var b=a.isHelper,c=a.eligibleHelper,d=this.options;if(c&&!b){var e=a.id.parts[0];d.knownHelpers[e]?b=!0:d.knownHelpersOnly&&(c=!1)}return b?"helper":c?"ambiguous":"simple"},pushParams:function(a){for(var b=0,c=a.length;c>b;b++)this.pushParam(a[b])},pushParam:function(a){this.stringParams?(a.depth&&this.addDepth(a.depth),this.opcode("getContext",a.depth||0),this.opcode("pushStringParam",a.stringModeValue,a.type),"sexpr"===a.type&&this.sexpr(a)):(this.trackIds&&this.opcode("pushId",a.type,a.idName||a.stringModeValue),this.accept(a))},setupFullMustacheParams:function(a,b,c){var d=a.params;return this.pushParams(d),this.opcode("pushProgram",b),this.opcode("pushProgram",c),a.hash?this.hash(a.hash):this.opcode("emptyHash"),d}},g.precompile=d,g.compile=e,g}(c,b),l=function(a,b){"use strict";function c(a){this.value=a}function d(){}var e,f=a.COMPILER_REVISION,g=a.REVISION_CHANGES,h=b;d.prototype={nameLookup:function(a,b){return d.isValidJavaScriptVariableName(b)?a+"."+b:a+"['"+b+"']"},depthedLookup:function(a){return this.aliases.lookup="this.lookup",'lookup(depths, "'+a+'")'},compilerInfo:function(){var a=f,b=g[a];return[a,b]},appendToBuffer:function(a){return this.environment.isSimple?"return "+a+";":{appendToBuffer:!0,content:a,toString:function(){return"buffer += "+a+";"}}},initializeBuffer:function(){return this.quotedString("")},namespace:"Handlebars",compile:function(a,b,c,d){this.environment=a,this.options=b,this.stringParams=this.options.stringParams,this.trackIds=this.options.trackIds,this.precompile=!d,this.name=this.environment.name,this.isChild=!!c,this.context=c||{programs:[],environments:[]},this.preamble(),this.stackSlot=0,this.stackVars=[],this.aliases={},this.registers={list:[]},this.hashes=[],this.compileStack=[],this.inlineStack=[],this.compileChildren(a,b),this.useDepths=this.useDepths||a.depths.list.length||this.options.compat;var e,f,g,i=a.opcodes;for(f=0,g=i.length;g>f;f++)e=i[f],this[e.opcode].apply(this,e.args);if(this.pushSource(""),this.stackSlot||this.inlineStack.length||this.compileStack.length)throw new h("Compile completed with content left on stack");var j=this.createFunctionContext(d);if(this.isChild)return j;var k={compiler:this.compilerInfo(),main:j},l=this.context.programs;for(f=0,g=l.length;g>f;f++)l[f]&&(k[f]=l[f]);return this.environment.usePartial&&(k.usePartial=!0),this.options.data&&(k.useData=!0),this.useDepths&&(k.useDepths=!0),this.options.compat&&(k.compat=!0),d||(k.compiler=JSON.stringify(k.compiler),k=this.objectLiteral(k)),k},preamble:function(){this.lastContext=0,this.source=[]},createFunctionContext:function(a){var b="",c=this.stackVars.concat(this.registers.list);c.length>0&&(b+=", "+c.join(", "));for(var d in this.aliases)this.aliases.hasOwnProperty(d)&&(b+=", "+d+"="+this.aliases[d]);var e=["depth0","helpers","partials","data"];this.useDepths&&e.push("depths");var f=this.mergeSource(b);return a?(e.push(f),Function.apply(this,e)):"function("+e.join(",")+") {\n "+f+"}"},mergeSource:function(a){for(var b,c,d="",e=!this.forceBuffer,f=0,g=this.source.length;g>f;f++){var h=this.source[f];h.appendToBuffer?b=b?b+"\n + "+h.content:h.content:(b&&(d?d+="buffer += "+b+";\n ":(c=!0,d=b+";\n "),b=void 0),d+=h+"\n ",this.environment.isSimple||(e=!1))}return e?(b||!d)&&(d+="return "+(b||'""')+";\n"):(a+=", buffer = "+(c?"":this.initializeBuffer()),d+=b?"return buffer + "+b+";\n":"return buffer;\n"),a&&(d="var "+a.substring(2)+(c?"":";\n ")+d),d},blockValue:function(a){this.aliases.blockHelperMissing="helpers.blockHelperMissing";var b=[this.contextName(0)];this.setupParams(a,0,b);var c=this.popStack();b.splice(1,0,c),this.push("blockHelperMissing.call("+b.join(", ")+")")},ambiguousBlockValue:function(){this.aliases.blockHelperMissing="helpers.blockHelperMissing";var a=[this.contextName(0)];this.setupParams("",0,a,!0),this.flushInline();var b=this.topStack();a.splice(1,0,b),this.pushSource("if (!"+this.lastHelper+") { "+b+" = blockHelperMissing.call("+a.join(", ")+"); }")},appendContent:function(a){this.pendingContent&&(a=this.pendingContent+a),this.pendingContent=a},append:function(){this.flushInline();var a=this.popStack();this.pushSource("if ("+a+" != null) { "+this.appendToBuffer(a)+" }"),this.environment.isSimple&&this.pushSource("else { "+this.appendToBuffer("''")+" }")},appendEscaped:function(){this.aliases.escapeExpression="this.escapeExpression",this.pushSource(this.appendToBuffer("escapeExpression("+this.popStack()+")"))},getContext:function(a){this.lastContext=a},pushContext:function(){this.pushStackLiteral(this.contextName(this.lastContext))},lookupOnContext:function(a,b,c){var d=0,e=a.length;for(c||!this.options.compat||this.lastContext?this.pushContext():this.push(this.depthedLookup(a[d++]));e>d;d++)this.replaceStack(function(c){var e=this.nameLookup(c,a[d],"context");return b?" && "+e:" != null ? "+e+" : "+c})},lookupData:function(a,b){a?this.pushStackLiteral("this.data(data, "+a+")"):this.pushStackLiteral("data");for(var c=b.length,d=0;c>d;d++)this.replaceStack(function(a){return" && "+this.nameLookup(a,b[d],"data")})},resolvePossibleLambda:function(){this.aliases.lambda="this.lambda",this.push("lambda("+this.popStack()+", "+this.contextName(0)+")")},pushStringParam:function(a,b){this.pushContext(),this.pushString(b),"sexpr"!==b&&("string"==typeof a?this.pushString(a):this.pushStackLiteral(a))},emptyHash:function(){this.pushStackLiteral("{}"),this.trackIds&&this.push("{}"),this.stringParams&&(this.push("{}"),this.push("{}"))},pushHash:function(){this.hash&&this.hashes.push(this.hash),this.hash={values:[],types:[],contexts:[],ids:[]}},popHash:function(){var a=this.hash;this.hash=this.hashes.pop(),this.trackIds&&this.push("{"+a.ids.join(",")+"}"),this.stringParams&&(this.push("{"+a.contexts.join(",")+"}"),this.push("{"+a.types.join(",")+"}")),this.push("{\n "+a.values.join(",\n ")+"\n }")},pushString:function(a){this.pushStackLiteral(this.quotedString(a))},push:function(a){return this.inlineStack.push(a),a},pushLiteral:function(a){this.pushStackLiteral(a)},pushProgram:function(a){null!=a?this.pushStackLiteral(this.programExpression(a)):this.pushStackLiteral(null)},invokeHelper:function(a,b,c){this.aliases.helperMissing="helpers.helperMissing";var d=this.popStack(),e=this.setupHelper(a,b),f=(c?e.name+" || ":"")+d+" || helperMissing";this.push("(("+f+").call("+e.callParams+"))")},invokeKnownHelper:function(a,b){var c=this.setupHelper(a,b);this.push(c.name+".call("+c.callParams+")")},invokeAmbiguous:function(a,b){this.aliases.functionType='"function"',this.aliases.helperMissing="helpers.helperMissing",this.useRegister("helper");var c=this.popStack();this.emptyHash();var d=this.setupHelper(0,a,b),e=this.lastHelper=this.nameLookup("helpers",a,"helper");this.push("((helper = (helper = "+e+" || "+c+") != null ? helper : helperMissing"+(d.paramsInit?"),("+d.paramsInit:"")+"),(typeof helper === functionType ? helper.call("+d.callParams+") : helper))")},invokePartial:function(a,b){var c=[this.nameLookup("partials",a,"partial"),"'"+b+"'","'"+a+"'",this.popStack(),this.popStack(),"helpers","partials"];this.options.data?c.push("data"):this.options.compat&&c.push("undefined"),this.options.compat&&c.push("depths"),this.push("this.invokePartial("+c.join(", ")+")")},assignToHash:function(a){var b,c,d,e=this.popStack();this.trackIds&&(d=this.popStack()),this.stringParams&&(c=this.popStack(),b=this.popStack());var f=this.hash;b&&f.contexts.push("'"+a+"': "+b),c&&f.types.push("'"+a+"': "+c),d&&f.ids.push("'"+a+"': "+d),f.values.push("'"+a+"': ("+e+")")},pushId:function(a,b){"ID"===a||"DATA"===a?this.pushString(b):"sexpr"===a?this.pushStackLiteral("true"):this.pushStackLiteral("null")},compiler:d,compileChildren:function(a,b){for(var c,d,e=a.children,f=0,g=e.length;g>f;f++){c=e[f],d=new this.compiler;var h=this.matchExistingProgram(c);null==h?(this.context.programs.push(""),h=this.context.programs.length,c.index=h,c.name="program"+h,this.context.programs[h]=d.compile(c,b,this.context,!this.precompile),this.context.environments[h]=c,this.useDepths=this.useDepths||d.useDepths):(c.index=h,c.name="program"+h)}},matchExistingProgram:function(a){for(var b=0,c=this.context.environments.length;c>b;b++){var d=this.context.environments[b];if(d&&d.equals(a))return b}},programExpression:function(a){var b=this.environment.children[a],c=(b.depths.list,this.useDepths),d=[b.index,"data"];return c&&d.push("depths"),"this.program("+d.join(", ")+")"},useRegister:function(a){this.registers[a]||(this.registers[a]=!0,this.registers.list.push(a))},pushStackLiteral:function(a){return this.push(new c(a))},pushSource:function(a){this.pendingContent&&(this.source.push(this.appendToBuffer(this.quotedString(this.pendingContent))),this.pendingContent=void 0),a&&this.source.push(a)},pushStack:function(a){this.flushInline();var b=this.incrStack();return this.pushSource(b+" = "+a+";"),this.compileStack.push(b),b},replaceStack:function(a){{var b,d,e,f="";this.isInline()}if(!this.isInline())throw new h("replaceStack on non-inline");var g=this.popStack(!0);if(g instanceof c)f=b=g.value,e=!0;else{d=!this.stackSlot;var i=d?this.incrStack():this.topStackName();f="("+this.push(i)+" = "+g+")",b=this.topStack()}var j=a.call(this,b);e||this.popStack(),d&&this.stackSlot--,this.push("("+f+j+")")},incrStack:function(){return this.stackSlot++,this.stackSlot>this.stackVars.length&&this.stackVars.push("stack"+this.stackSlot),this.topStackName()},topStackName:function(){return"stack"+this.stackSlot},flushInline:function(){var a=this.inlineStack;if(a.length){this.inlineStack=[];for(var b=0,d=a.length;d>b;b++){var e=a[b];e instanceof c?this.compileStack.push(e):this.pushStack(e)}}},isInline:function(){return this.inlineStack.length},popStack:function(a){var b=this.isInline(),d=(b?this.inlineStack:this.compileStack).pop();if(!a&&d instanceof c)return d.value;if(!b){if(!this.stackSlot)throw new h("Invalid stack pop");this.stackSlot--}return d},topStack:function(){var a=this.isInline()?this.inlineStack:this.compileStack,b=a[a.length-1];return b instanceof c?b.value:b},contextName:function(a){return this.useDepths&&a?"depths["+a+"]":"depth"+a},quotedString:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")+'"'},objectLiteral:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(this.quotedString(c)+":"+a[c]);return"{"+b.join(",")+"}"},setupHelper:function(a,b,c){var d=[],e=this.setupParams(b,a,d,c),f=this.nameLookup("helpers",b,"helper");return{params:d,paramsInit:e,name:f,callParams:[this.contextName(0)].concat(d).join(", ")}},setupOptions:function(a,b,c){var d,e,f,g={},h=[],i=[],j=[];g.name=this.quotedString(a),g.hash=this.popStack(),this.trackIds&&(g.hashIds=this.popStack()),this.stringParams&&(g.hashTypes=this.popStack(),g.hashContexts=this.popStack()),e=this.popStack(),f=this.popStack(),(f||e)&&(f||(f="this.noop"),e||(e="this.noop"),g.fn=f,g.inverse=e);for(var k=b;k--;)d=this.popStack(),c[k]=d,this.trackIds&&(j[k]=this.popStack()),this.stringParams&&(i[k]=this.popStack(),h[k]=this.popStack());return this.trackIds&&(g.ids="["+j.join(",")+"]"),this.stringParams&&(g.types="["+i.join(",")+"]",g.contexts="["+h.join(",")+"]"),this.options.data&&(g.data="data"),g},setupParams:function(a,b,c,d){var e=this.objectLiteral(this.setupOptions(a,b,c));return d?(this.useRegister("options"),c.push("options"),"options="+e):(c.push(e),"")}};for(var i="break else new var case finally return void catch for switch while continue function this with default if throw delete in try do instanceof typeof abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public let yield".split(" "),j=d.RESERVED_WORDS={},k=0,l=i.length;l>k;k++)j[i[k]]=!0;return d.isValidJavaScriptVariableName=function(a){return!d.RESERVED_WORDS[a]&&/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(a)},e=d}(d,c),m=function(a,b,c,d,e){"use strict";var f,g=a,h=b,i=c.parser,j=c.parse,k=d.Compiler,l=d.compile,m=d.precompile,n=e,o=g.create,p=function(){var a=o();return a.compile=function(b,c){return l(b,c,a)},a.precompile=function(b,c){return m(b,c,a)},a.AST=h,a.Compiler=k,a.JavaScriptCompiler=n,a.Parser=i,a.parse=j,a};return g=p(),g.create=p,g["default"]=g,f=g}(f,g,j,k,l);return m});
diff --git a/catalog-be/src/main/resources/swagger/lib/highlight.7.3.pack.js b/catalog-be/src/main/resources/swagger/lib/highlight.7.3.pack.js
new file mode 100644
index 0000000000..a61ad222c2
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/highlight.7.3.pack.js
@@ -0,0 +1,21 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR 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 hljs=new function(){function l(o){return o.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;")}function b(p){for(var o=p.firstChild;o;o=o.nextSibling){if(o.nodeName=="CODE"){return o}if(!(o.nodeType==3&&o.nodeValue.match(/\s+/))){break}}}function h(p,o){return Array.prototype.map.call(p.childNodes,function(q){if(q.nodeType==3){return o?q.nodeValue.replace(/\n/g,""):q.nodeValue}if(q.nodeName=="BR"){return"\n"}return h(q,o)}).join("")}function a(q){var p=(q.className+" "+q.parentNode.className).split(/\s+/);p=p.map(function(r){return r.replace(/^language-/,"")});for(var o=0;o<p.length;o++){if(e[p[o]]||p[o]=="no-highlight"){return p[o]}}}function c(q){var o=[];(function p(r,s){for(var t=r.firstChild;t;t=t.nextSibling){if(t.nodeType==3){s+=t.nodeValue.length}else{if(t.nodeName=="BR"){s+=1}else{if(t.nodeType==1){o.push({event:"start",offset:s,node:t});s=p(t,s);o.push({event:"stop",offset:s,node:t})}}}}return s})(q,0);return o}function j(x,v,w){var p=0;var y="";var r=[];function t(){if(x.length&&v.length){if(x[0].offset!=v[0].offset){return(x[0].offset<v[0].offset)?x:v}else{return v[0].event=="start"?x:v}}else{return x.length?x:v}}function s(A){function z(B){return" "+B.nodeName+'="'+l(B.value)+'"'}return"<"+A.nodeName+Array.prototype.map.call(A.attributes,z).join("")+">"}while(x.length||v.length){var u=t().splice(0,1)[0];y+=l(w.substr(p,u.offset-p));p=u.offset;if(u.event=="start"){y+=s(u.node);r.push(u.node)}else{if(u.event=="stop"){var o,q=r.length;do{q--;o=r[q];y+=("</"+o.nodeName.toLowerCase()+">")}while(o!=u.node);r.splice(q,1);while(q<r.length){y+=s(r[q]);q++}}}}return y+l(w.substr(p))}function f(q){function o(s,r){return RegExp(s,"m"+(q.cI?"i":"")+(r?"g":""))}function p(y,w){if(y.compiled){return}y.compiled=true;var s=[];if(y.k){var r={};function z(A,t){t.split(" ").forEach(function(B){var C=B.split("|");r[C[0]]=[A,C[1]?Number(C[1]):1];s.push(C[0])})}y.lR=o(y.l||hljs.IR,true);if(typeof y.k=="string"){z("keyword",y.k)}else{for(var x in y.k){if(!y.k.hasOwnProperty(x)){continue}z(x,y.k[x])}}y.k=r}if(w){if(y.bWK){y.b="\\b("+s.join("|")+")\\s"}y.bR=o(y.b?y.b:"\\B|\\b");if(!y.e&&!y.eW){y.e="\\B|\\b"}if(y.e){y.eR=o(y.e)}y.tE=y.e||"";if(y.eW&&w.tE){y.tE+=(y.e?"|":"")+w.tE}}if(y.i){y.iR=o(y.i)}if(y.r===undefined){y.r=1}if(!y.c){y.c=[]}for(var v=0;v<y.c.length;v++){if(y.c[v]=="self"){y.c[v]=y}p(y.c[v],y)}if(y.starts){p(y.starts,w)}var u=[];for(var v=0;v<y.c.length;v++){u.push(y.c[v].b)}if(y.tE){u.push(y.tE)}if(y.i){u.push(y.i)}y.t=u.length?o(u.join("|"),true):{exec:function(t){return null}}}p(q)}function d(D,E){function o(r,M){for(var L=0;L<M.c.length;L++){var K=M.c[L].bR.exec(r);if(K&&K.index==0){return M.c[L]}}}function s(K,r){if(K.e&&K.eR.test(r)){return K}if(K.eW){return s(K.parent,r)}}function t(r,K){return K.i&&K.iR.test(r)}function y(L,r){var K=F.cI?r[0].toLowerCase():r[0];return L.k.hasOwnProperty(K)&&L.k[K]}function G(){var K=l(w);if(!A.k){return K}var r="";var N=0;A.lR.lastIndex=0;var L=A.lR.exec(K);while(L){r+=K.substr(N,L.index-N);var M=y(A,L);if(M){v+=M[1];r+='<span class="'+M[0]+'">'+L[0]+"</span>"}else{r+=L[0]}N=A.lR.lastIndex;L=A.lR.exec(K)}return r+K.substr(N)}function z(){if(A.sL&&!e[A.sL]){return l(w)}var r=A.sL?d(A.sL,w):g(w);if(A.r>0){v+=r.keyword_count;B+=r.r}return'<span class="'+r.language+'">'+r.value+"</span>"}function J(){return A.sL!==undefined?z():G()}function I(L,r){var K=L.cN?'<span class="'+L.cN+'">':"";if(L.rB){x+=K;w=""}else{if(L.eB){x+=l(r)+K;w=""}else{x+=K;w=r}}A=Object.create(L,{parent:{value:A}});B+=L.r}function C(K,r){w+=K;if(r===undefined){x+=J();return 0}var L=o(r,A);if(L){x+=J();I(L,r);return L.rB?0:r.length}var M=s(A,r);if(M){if(!(M.rE||M.eE)){w+=r}x+=J();do{if(A.cN){x+="</span>"}A=A.parent}while(A!=M.parent);if(M.eE){x+=l(r)}w="";if(M.starts){I(M.starts,"")}return M.rE?0:r.length}if(t(r,A)){throw"Illegal"}w+=r;return r.length||1}var F=e[D];f(F);var A=F;var w="";var B=0;var v=0;var x="";try{var u,q,p=0;while(true){A.t.lastIndex=p;u=A.t.exec(E);if(!u){break}q=C(E.substr(p,u.index-p),u[0]);p=u.index+q}C(E.substr(p));return{r:B,keyword_count:v,value:x,language:D}}catch(H){if(H=="Illegal"){return{r:0,keyword_count:0,value:l(E)}}else{throw H}}}function g(s){var o={keyword_count:0,r:0,value:l(s)};var q=o;for(var p in e){if(!e.hasOwnProperty(p)){continue}var r=d(p,s);r.language=p;if(r.keyword_count+r.r>q.keyword_count+q.r){q=r}if(r.keyword_count+r.r>o.keyword_count+o.r){q=o;o=r}}if(q.language){o.second_best=q}return o}function i(q,p,o){if(p){q=q.replace(/^((<[^>]+>|\t)+)/gm,function(r,v,u,t){return v.replace(/\t/g,p)})}if(o){q=q.replace(/\n/g,"<br>")}return q}function m(r,u,p){var v=h(r,p);var t=a(r);if(t=="no-highlight"){return}var w=t?d(t,v):g(v);t=w.language;var o=c(r);if(o.length){var q=document.createElement("pre");q.innerHTML=w.value;w.value=j(o,c(q),v)}w.value=i(w.value,u,p);var s=r.className;if(!s.match("(\\s|^)(language-)?"+t+"(\\s|$)")){s=s?(s+" "+t):t}r.innerHTML=w.value;r.className=s;r.result={language:t,kw:w.keyword_count,re:w.r};if(w.second_best){r.second_best={language:w.second_best.language,kw:w.second_best.keyword_count,re:w.second_best.r}}}function n(){if(n.called){return}n.called=true;Array.prototype.map.call(document.getElementsByTagName("pre"),b).filter(Boolean).forEach(function(o){m(o,hljs.tabReplace)})}function k(){window.addEventListener("DOMContentLoaded",n,false);window.addEventListener("load",n,false)}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=m;this.initHighlighting=n;this.initHighlightingOnLoad=k;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\[\\s\\S]",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE],r:0};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE],r:0};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.inherit=function(q,r){var o={};for(var p in q){o[p]=q[p]}if(r){for(var p in r){o[p]=r[p]}}return o}}();hljs.LANGUAGES.xml=function(a){var c="[A-Za-z0-9\\._:-]+";var b={eW:true,c:[{cN:"attribute",b:c,r:0},{b:'="',rB:true,e:'"',c:[{cN:"value",b:'"',eW:true}]},{b:"='",rB:true,e:"'",c:[{cN:"value",b:"'",eW:true}]},{b:"=",c:[{cN:"value",b:"[^\\s/>]+"}]}]};return{cI:true,c:[{cN:"pi",b:"<\\?",e:"\\?>",r:10},{cN:"doctype",b:"<!DOCTYPE",e:">",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"<!--",e:"-->",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"<style(?=\\s|>|$)",e:">",k:{title:"style"},c:[b],starts:{e:"</style>",rE:true,sL:"css"}},{cN:"tag",b:"<script(?=\\s|>|$)",e:">",k:{title:"script"},c:[b],starts:{e:"<\/script>",rE:true,sL:"javascript"}},{b:"<%",e:"%>",sL:"vbscript"},{cN:"tag",b:"</?",e:"/?>",c:[{cN:"title",b:"[^ />]+"},b]}]}}(hljs);hljs.LANGUAGES.json=function(a){var e={literal:"true false null"};var d=[a.QSM,a.CNM];var c={cN:"value",e:",",eW:true,eE:true,c:d,k:e};var b={b:"{",e:"}",c:[{cN:"attribute",b:'\\s*"',e:'"\\s*:\\s*',eB:true,eE:true,c:[a.BE],i:"\\n",starts:c}],i:"\\S"};var f={b:"\\[",e:"\\]",c:[a.inherit(c,{cN:null})],i:"\\S"};d.splice(d.length,0,b,f);return{c:d,k:e,i:"\\S"}}(hljs);
diff --git a/catalog-be/src/main/resources/swagger/lib/jquery-1.8.0.min.js b/catalog-be/src/main/resources/swagger/lib/jquery-1.8.0.min.js
new file mode 100644
index 0000000000..2ebc792d3a
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/jquery-1.8.0.min.js
@@ -0,0 +1,22 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/*! jQuery v@1.8.0 jquery.com | jquery.org/license */
+(function(a,b){function G(a){var b=F[a]={};return p.each(a.split(s),function(a,c){b[c]=!0}),b}function J(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(I,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:+d+""===d?+d:H.test(d)?p.parseJSON(d):d}catch(f){}p.data(a,c,d)}else d=b}return d}function K(a){var b;for(b in a){if(b==="data"&&p.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function ba(){return!1}function bb(){return!0}function bh(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function bi(a,b){do a=a[b];while(a&&a.nodeType!==1);return a}function bj(a,b,c){b=b||0;if(p.isFunction(b))return p.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return p.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=p.grep(a,function(a){return a.nodeType===1});if(be.test(b))return p.filter(b,d,!c);b=p.filter(b,d)}return p.grep(a,function(a,d){return p.inArray(a,b)>=0===c})}function bk(a){var b=bl.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function bC(a,b){return a.getElementsByTagName(b)[0]||a.appendChild(a.ownerDocument.createElement(b))}function bD(a,b){if(b.nodeType!==1||!p.hasData(a))return;var c,d,e,f=p._data(a),g=p._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;d<e;d++)p.event.add(b,c,h[c][d])}g.data&&(g.data=p.extend({},g.data))}function bE(a,b){var c;if(b.nodeType!==1)return;b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase(),c==="object"?(b.parentNode&&(b.outerHTML=a.outerHTML),p.support.html5Clone&&a.innerHTML&&!p.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):c==="input"&&bv.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):c==="option"?b.selected=a.defaultSelected:c==="input"||c==="textarea"?b.defaultValue=a.defaultValue:c==="script"&&b.text!==a.text&&(b.text=a.text),b.removeAttribute(p.expando)}function bF(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bG(a){bv.test(a.type)&&(a.defaultChecked=a.checked)}function bX(a,b){if(b in a)return b;var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=bV.length;while(e--){b=bV[e]+c;if(b in a)return b}return d}function bY(a,b){return a=b||a,p.css(a,"display")==="none"||!p.contains(a.ownerDocument,a)}function bZ(a,b){var c,d,e=[],f=0,g=a.length;for(;f<g;f++){c=a[f];if(!c.style)continue;e[f]=p._data(c,"olddisplay"),b?(!e[f]&&c.style.display==="none"&&(c.style.display=""),c.style.display===""&&bY(c)&&(e[f]=p._data(c,"olddisplay",cb(c.nodeName)))):(d=bH(c,"display"),!e[f]&&d!=="none"&&p._data(c,"olddisplay",d))}for(f=0;f<g;f++){c=a[f];if(!c.style)continue;if(!b||c.style.display==="none"||c.style.display==="")c.style.display=b?e[f]||"":"none"}return a}function b$(a,b,c){var d=bO.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function b_(a,b,c,d){var e=c===(d?"border":"content")?4:b==="width"?1:0,f=0;for(;e<4;e+=2)c==="margin"&&(f+=p.css(a,c+bU[e],!0)),d?(c==="content"&&(f-=parseFloat(bH(a,"padding"+bU[e]))||0),c!=="margin"&&(f-=parseFloat(bH(a,"border"+bU[e]+"Width"))||0)):(f+=parseFloat(bH(a,"padding"+bU[e]))||0,c!=="padding"&&(f+=parseFloat(bH(a,"border"+bU[e]+"Width"))||0));return f}function ca(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=!0,f=p.support.boxSizing&&p.css(a,"boxSizing")==="border-box";if(d<=0){d=bH(a,b);if(d<0||d==null)d=a.style[b];if(bP.test(d))return d;e=f&&(p.support.boxSizingReliable||d===a.style[b]),d=parseFloat(d)||0}return d+b_(a,b,c||(f?"border":"content"),e)+"px"}function cb(a){if(bR[a])return bR[a];var b=p("<"+a+">").appendTo(e.body),c=b.css("display");b.remove();if(c==="none"||c===""){bI=e.body.appendChild(bI||p.extend(e.createElement("iframe"),{frameBorder:0,width:0,height:0}));if(!bJ||!bI.createElement)bJ=(bI.contentWindow||bI.contentDocument).document,bJ.write("<!doctype html><html><body>"),bJ.close();b=bJ.body.appendChild(bJ.createElement(a)),c=bH(b,"display"),e.body.removeChild(bI)}return bR[a]=c,c}function ch(a,b,c,d){var e;if(p.isArray(b))p.each(b,function(b,e){c||cd.test(a)?d(a,e):ch(a+"["+(typeof e=="object"?b:"")+"]",e,c,d)});else if(!c&&p.type(b)==="object")for(e in b)ch(a+"["+e+"]",b[e],c,d);else d(a,b)}function cy(a){return function(b,c){typeof b!="string"&&(c=b,b="*");var d,e,f,g=b.toLowerCase().split(s),h=0,i=g.length;if(p.isFunction(c))for(;h<i;h++)d=g[h],f=/^\+/.test(d),f&&(d=d.substr(1)||"*"),e=a[d]=a[d]||[],e[f?"unshift":"push"](c)}}function cz(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h,i=a[f],j=0,k=i?i.length:0,l=a===cu;for(;j<k&&(l||!h);j++)h=i[j](c,d,e),typeof h=="string"&&(!l||g[h]?h=b:(c.dataTypes.unshift(h),h=cz(a,c,d,e,h,g)));return(l||!h)&&!g["*"]&&(h=cz(a,c,d,e,"*",g)),h}function cA(a,c){var d,e,f=p.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((f[d]?a:e||(e={}))[d]=c[d]);e&&p.extend(!0,a,e)}function cB(a,c,d){var e,f,g,h,i=a.contents,j=a.dataTypes,k=a.responseFields;for(f in k)f in d&&(c[k[f]]=d[f]);while(j[0]==="*")j.shift(),e===b&&(e=a.mimeType||c.getResponseHeader("content-type"));if(e)for(f in i)if(i[f]&&i[f].test(e)){j.unshift(f);break}if(j[0]in d)g=j[0];else{for(f in d){if(!j[0]||a.converters[f+" "+j[0]]){g=f;break}h||(h=f)}g=g||h}if(g)return g!==j[0]&&j.unshift(g),d[g]}function cC(a,b){var c,d,e,f,g=a.dataTypes.slice(),h=g[0],i={},j=0;a.dataFilter&&(b=a.dataFilter(b,a.dataType));if(g[1])for(c in a.converters)i[c.toLowerCase()]=a.converters[c];for(;e=g[++j];)if(e!=="*"){if(h!=="*"&&h!==e){c=i[h+" "+e]||i["* "+e];if(!c)for(d in i){f=d.split(" ");if(f[1]===e){c=i[h+" "+f[0]]||i["* "+f[0]];if(c){c===!0?c=i[d]:i[d]!==!0&&(e=f[0],g.splice(j--,0,e));break}}}if(c!==!0)if(c&&a["throws"])b=c(b);else try{b=c(b)}catch(k){return{state:"parsererror",error:c?k:"No conversion from "+h+" to "+e}}}h=e}return{state:"success",data:b}}function cK(){try{return new a.XMLHttpRequest}catch(b){}}function cL(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function cT(){return setTimeout(function(){cM=b},0),cM=p.now()}function cU(a,b){p.each(b,function(b,c){var d=(cS[b]||[]).concat(cS["*"]),e=0,f=d.length;for(;e<f;e++)if(d[e].call(a,b,c))return})}function cV(a,b,c){var d,e=0,f=0,g=cR.length,h=p.Deferred().always(function(){delete i.elem}),i=function(){var b=cM||cT(),c=Math.max(0,j.startTime+j.duration-b),d=1-(c/j.duration||0),e=0,f=j.tweens.length;for(;e<f;e++)j.tweens[e].run(d);return h.notifyWith(a,[j,d,c]),d<1&&f?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:p.extend({},b),opts:p.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:cM||cT(),duration:c.duration,tweens:[],createTween:function(b,c,d){var e=p.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(e),e},stop:function(b){var c=0,d=b?j.tweens.length:0;for(;c<d;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;cW(k,j.opts.specialEasing);for(;e<g;e++){d=cR[e].call(j,a,k,j.opts);if(d)return d}return cU(j,k),p.isFunction(j.opts.start)&&j.opts.start.call(a,j),p.fx.timer(p.extend(i,{anim:j,queue:j.opts.queue,elem:a})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}function cW(a,b){var c,d,e,f,g;for(c in a){d=p.camelCase(c),e=b[d],f=a[c],p.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=p.cssHooks[d];if(g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}}function cX(a,b,c){var d,e,f,g,h,i,j,k,l=this,m=a.style,n={},o=[],q=a.nodeType&&bY(a);c.queue||(j=p._queueHooks(a,"fx"),j.unqueued==null&&(j.unqueued=0,k=j.empty.fire,j.empty.fire=function(){j.unqueued||k()}),j.unqueued++,l.always(function(){l.always(function(){j.unqueued--,p.queue(a,"fx").length||j.empty.fire()})})),a.nodeType===1&&("height"in b||"width"in b)&&(c.overflow=[m.overflow,m.overflowX,m.overflowY],p.css(a,"display")==="inline"&&p.css(a,"float")==="none"&&(!p.support.inlineBlockNeedsLayout||cb(a.nodeName)==="inline"?m.display="inline-block":m.zoom=1)),c.overflow&&(m.overflow="hidden",p.support.shrinkWrapBlocks||l.done(function(){m.overflow=c.overflow[0],m.overflowX=c.overflow[1],m.overflowY=c.overflow[2]}));for(d in b){f=b[d];if(cO.exec(f)){delete b[d];if(f===(q?"hide":"show"))continue;o.push(d)}}g=o.length;if(g){h=p._data(a,"fxshow")||p._data(a,"fxshow",{}),q?p(a).show():l.done(function(){p(a).hide()}),l.done(function(){var b;p.removeData(a,"fxshow",!0);for(b in n)p.style(a,b,n[b])});for(d=0;d<g;d++)e=o[d],i=l.createTween(e,q?h[e]:0),n[e]=h[e]||p.style(a,e),e in h||(h[e]=i.start,q&&(i.end=i.start,i.start=e==="width"||e==="height"?1:0))}}function cY(a,b,c,d,e){return new cY.prototype.init(a,b,c,d,e)}function cZ(a,b){var c,d={height:a},e=0;for(;e<4;e+=2-b)c=bU[e],d["margin"+c]=d["padding"+c]=a;return b&&(d.opacity=d.width=a),d}function c_(a){return p.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}var c,d,e=a.document,f=a.location,g=a.navigator,h=a.jQuery,i=a.$,j=Array.prototype.push,k=Array.prototype.slice,l=Array.prototype.indexOf,m=Object.prototype.toString,n=Object.prototype.hasOwnProperty,o=String.prototype.trim,p=function(a,b){return new p.fn.init(a,b,c)},q=/[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,r=/\S/,s=/\s+/,t=r.test(" ")?/^[\s\xA0]+|[\s\xA0]+$/g:/^\s+|\s+$/g,u=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^[\],:{}\s]*$/,x=/(?:^|:|,)(?:\s*\[)+/g,y=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,z=/"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,A=/^-ms-/,B=/-([\da-z])/gi,C=function(a,b){return(b+"").toUpperCase()},D=function(){e.addEventListener?(e.removeEventListener("DOMContentLoaded",D,!1),p.ready()):e.readyState==="complete"&&(e.detachEvent("onreadystatechange",D),p.ready())},E={};p.fn=p.prototype={constructor:p,init:function(a,c,d){var f,g,h,i;if(!a)return this;if(a.nodeType)return this.context=this[0]=a,this.length=1,this;if(typeof a=="string"){a.charAt(0)==="<"&&a.charAt(a.length-1)===">"&&a.length>=3?f=[null,a,null]:f=u.exec(a);if(f&&(f[1]||!c)){if(f[1])return c=c instanceof p?c[0]:c,i=c&&c.nodeType?c.ownerDocument||c:e,a=p.parseHTML(f[1],i,!0),v.test(f[1])&&p.isPlainObject(c)&&this.attr.call(a,c,!0),p.merge(this,a);g=e.getElementById(f[2]);if(g&&g.parentNode){if(g.id!==f[2])return d.find(a);this.length=1,this[0]=g}return this.context=e,this.selector=a,this}return!c||c.jquery?(c||d).find(a):this.constructor(c).find(a)}return p.isFunction(a)?d.ready(a):(a.selector!==b&&(this.selector=a.selector,this.context=a.context),p.makeArray(a,this))},selector:"",jquery:"1.8.0",length:0,size:function(){return this.length},toArray:function(){return k.call(this)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=p.merge(this.constructor(),a);return d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")"),d},each:function(a,b){return p.each(this,a,b)},ready:function(a){return p.ready.promise().done(a),this},eq:function(a){return a=+a,a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(k.apply(this,arguments),"slice",k.call(arguments).join(","))},map:function(a){return this.pushStack(p.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:j,sort:[].sort,splice:[].splice},p.fn.init.prototype=p.fn,p.extend=p.fn.extend=function(){var a,c,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;typeof h=="boolean"&&(k=h,h=arguments[1]||{},i=2),typeof h!="object"&&!p.isFunction(h)&&(h={}),j===i&&(h=this,--i);for(;i<j;i++)if((a=arguments[i])!=null)for(c in a){d=h[c],e=a[c];if(h===e)continue;k&&e&&(p.isPlainObject(e)||(f=p.isArray(e)))?(f?(f=!1,g=d&&p.isArray(d)?d:[]):g=d&&p.isPlainObject(d)?d:{},h[c]=p.extend(k,g,e)):e!==b&&(h[c]=e)}return h},p.extend({noConflict:function(b){return a.$===p&&(a.$=i),b&&a.jQuery===p&&(a.jQuery=h),p},isReady:!1,readyWait:1,holdReady:function(a){a?p.readyWait++:p.ready(!0)},ready:function(a){if(a===!0?--p.readyWait:p.isReady)return;if(!e.body)return setTimeout(p.ready,1);p.isReady=!0;if(a!==!0&&--p.readyWait>0)return;d.resolveWith(e,[p]),p.fn.trigger&&p(e).trigger("ready").off("ready")},isFunction:function(a){return p.type(a)==="function"},isArray:Array.isArray||function(a){return p.type(a)==="array"},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):E[m.call(a)]||"object"},isPlainObject:function(a){if(!a||p.type(a)!=="object"||a.nodeType||p.isWindow(a))return!1;try{if(a.constructor&&!n.call(a,"constructor")&&!n.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||n.call(a,d)},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},error:function(a){throw new Error(a)},parseHTML:function(a,b,c){var d;return!a||typeof a!="string"?null:(typeof b=="boolean"&&(c=b,b=0),b=b||e,(d=v.exec(a))?[b.createElement(d[1])]:(d=p.buildFragment([a],b,c?null:[]),p.merge([],(d.cacheable?p.clone(d.fragment):d.fragment).childNodes)))},parseJSON:function(b){if(!b||typeof b!="string")return null;b=p.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(w.test(b.replace(y,"@").replace(z,"]").replace(x,"")))return(new Function("return "+b))();p.error("Invalid JSON: "+b)},parseXML:function(c){var d,e;if(!c||typeof c!="string")return null;try{a.DOMParser?(e=new DOMParser,d=e.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(f){d=b}return(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&p.error("Invalid XML: "+c),d},noop:function(){},globalEval:function(b){b&&r.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(A,"ms-").replace(B,C)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var e,f=0,g=a.length,h=g===b||p.isFunction(a);if(d){if(h){for(e in a)if(c.apply(a[e],d)===!1)break}else for(;f<g;)if(c.apply(a[f++],d)===!1)break}else if(h){for(e in a)if(c.call(a[e],e,a[e])===!1)break}else for(;f<g;)if(c.call(a[f],f,a[f++])===!1)break;return a},trim:o?function(a){return a==null?"":o.call(a)}:function(a){return a==null?"":a.toString().replace(t,"")},makeArray:function(a,b){var c,d=b||[];return a!=null&&(c=p.type(a),a.length==null||c==="string"||c==="function"||c==="regexp"||p.isWindow(a)?j.call(d,a):p.merge(d,a)),d},inArray:function(a,b,c){var d;if(b){if(l)return l.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=c.length,e=a.length,f=0;if(typeof d=="number")for(;f<d;f++)a[e++]=c[f];else while(c[f]!==b)a[e++]=c[f++];return a.length=e,a},grep:function(a,b,c){var d,e=[],f=0,g=a.length;c=!!c;for(;f<g;f++)d=!!b(a[f],f),c!==d&&e.push(a[f]);return e},map:function(a,c,d){var e,f,g=[],h=0,i=a.length,j=a instanceof p||i!==b&&typeof i=="number"&&(i>0&&a[0]&&a[i-1]||i===0||p.isArray(a));if(j)for(;h<i;h++)e=c(a[h],h,d),e!=null&&(g[g.length]=e);else for(f in a)e=c(a[f],f,d),e!=null&&(g[g.length]=e);return g.concat.apply([],g)},guid:1,proxy:function(a,c){var d,e,f;return typeof c=="string"&&(d=a[c],c=a,a=d),p.isFunction(a)?(e=k.call(arguments,2),f=function(){return a.apply(c,e.concat(k.call(arguments)))},f.guid=a.guid=a.guid||f.guid||p.guid++,f):b},access:function(a,c,d,e,f,g,h){var i,j=d==null,k=0,l=a.length;if(d&&typeof d=="object"){for(k in d)p.access(a,c,k,d[k],1,g,e);f=1}else if(e!==b){i=h===b&&p.isFunction(e),j&&(i?(i=c,c=function(a,b,c){return i.call(p(a),c)}):(c.call(a,e),c=null));if(c)for(;k<l;k++)c(a[k],d,i?e.call(a[k],k,c(a[k],d)):e,h);f=1}return f?a:j?c.call(a):l?c(a[0],d):g},now:function(){return(new Date).getTime()}}),p.ready.promise=function(b){if(!d){d=p.Deferred();if(e.readyState==="complete"||e.readyState!=="loading"&&e.addEventListener)setTimeout(p.ready,1);else if(e.addEventListener)e.addEventListener("DOMContentLoaded",D,!1),a.addEventListener("load",p.ready,!1);else{e.attachEvent("onreadystatechange",D),a.attachEvent("onload",p.ready);var c=!1;try{c=a.frameElement==null&&e.documentElement}catch(f){}c&&c.doScroll&&function g(){if(!p.isReady){try{c.doScroll("left")}catch(a){return setTimeout(g,50)}p.ready()}}()}}return d.promise(b)},p.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){E["[object "+b+"]"]=b.toLowerCase()}),c=p(e);var F={};p.Callbacks=function(a){a=typeof a=="string"?F[a]||G(a):p.extend({},a);var c,d,e,f,g,h,i=[],j=!a.once&&[],k=function(b){c=a.memory&&b,d=!0,h=f||0,f=0,g=i.length,e=!0;for(;i&&h<g;h++)if(i[h].apply(b[0],b[1])===!1&&a.stopOnFalse){c=!1;break}e=!1,i&&(j?j.length&&k(j.shift()):c?i=[]:l.disable())},l={add:function(){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this},remove:function(){return i&&p.each(arguments,function(a,b){var c;while((c=p.inArray(b,i,c))>-1)i.splice(c,1),e&&(c<=g&&g--,c<=h&&h--)}),this},has:function(a){return p.inArray(a,i)>-1},empty:function(){return i=[],this},disable:function(){return i=j=c=b,this},disabled:function(){return!i},lock:function(){return j=b,c||l.disable(),this},locked:function(){return!j},fireWith:function(a,b){return b=b||[],b=[a,b.slice?b.slice():b],i&&(!d||j)&&(e?j.push(b):k(b)),this},fire:function(){return l.fireWith(this,arguments),this},fired:function(){return!!d}};return l},p.extend({Deferred:function(a){var b=[["resolve","done",p.Callbacks("once memory"),"resolved"],["reject","fail",p.Callbacks("once memory"),"rejected"],["notify","progress",p.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()},promise:function(a){return typeof a=="object"?p.extend(a,d):d}},e={};return d.pipe=d.then,p.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[a^1][2].disable,b[2][2].lock),e[f[0]]=g.fire,e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=k.call(arguments),d=c.length,e=d!==1||a&&p.isFunction(a.promise)?d:0,f=e===1?a:p.Deferred(),g=function(a,b,c){return function(d){b[a]=this,c[a]=arguments.length>1?k.call(arguments):d,c===h?f.notifyWith(b,c):--e||f.resolveWith(b,c)}},h,i,j;if(d>1){h=new Array(d),i=new Array(d),j=new Array(d);for(;b<d;b++)c[b]&&p.isFunction(c[b].promise)?c[b].promise().done(g(b,j,c)).fail(f.reject).progress(g(b,i,h)):--e}return e||f.resolveWith(j,c),f.promise()}}),p.support=function(){var b,c,d,f,g,h,i,j,k,l,m,n=e.createElement("div");n.setAttribute("className","t"),n.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",c=n.getElementsByTagName("*"),d=n.getElementsByTagName("a")[0],d.style.cssText="top:1px;float:left;opacity:.5";if(!c||!c.length||!d)return{};f=e.createElement("select"),g=f.appendChild(e.createElement("option")),h=n.getElementsByTagName("input")[0],b={leadingWhitespace:n.firstChild.nodeType===3,tbody:!n.getElementsByTagName("tbody").length,htmlSerialize:!!n.getElementsByTagName("link").length,style:/top/.test(d.getAttribute("style")),hrefNormalized:d.getAttribute("href")==="/a",opacity:/^0.5/.test(d.style.opacity),cssFloat:!!d.style.cssFloat,checkOn:h.value==="on",optSelected:g.selected,getSetAttribute:n.className!=="t",enctype:!!e.createElement("form").enctype,html5Clone:e.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",boxModel:e.compatMode==="CSS1Compat",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},h.checked=!0,b.noCloneChecked=h.cloneNode(!0).checked,f.disabled=!0,b.optDisabled=!g.disabled;try{delete n.test}catch(o){b.deleteExpando=!1}!n.addEventListener&&n.attachEvent&&n.fireEvent&&(n.attachEvent("onclick",m=function(){b.noCloneEvent=!1}),n.cloneNode(!0).fireEvent("onclick"),n.detachEvent("onclick",m)),h=e.createElement("input"),h.value="t",h.setAttribute("type","radio"),b.radioValue=h.value==="t",h.setAttribute("checked","checked"),h.setAttribute("name","t"),n.appendChild(h),i=e.createDocumentFragment(),i.appendChild(n.lastChild),b.checkClone=i.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=h.checked,i.removeChild(h),i.appendChild(n);if(n.attachEvent)for(k in{submit:!0,change:!0,focusin:!0})j="on"+k,l=j in n,l||(n.setAttribute(j,"return;"),l=typeof n[j]=="function"),b[k+"Bubbles"]=l;return p(function(){var c,d,f,g,h="padding:0;margin:0;border:0;display:block;overflow:hidden;",i=e.getElementsByTagName("body")[0];if(!i)return;c=e.createElement("div"),c.style.cssText="visibility:hidden;border:0;width:0;height:0;position:static;top:0;margin-top:1px",i.insertBefore(c,i.firstChild),d=e.createElement("div"),c.appendChild(d),d.innerHTML="<table><tr><td></td><td>t</td></tr></table>",f=d.getElementsByTagName("td"),f[0].style.cssText="padding:0;margin:0;border:0;display:none",l=f[0].offsetHeight===0,f[0].style.display="",f[1].style.display="none",b.reliableHiddenOffsets=l&&f[0].offsetHeight===0,d.innerHTML="",d.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%;",b.boxSizing=d.offsetWidth===4,b.doesNotIncludeMarginInBodyOffset=i.offsetTop!==1,a.getComputedStyle&&(b.pixelPosition=(a.getComputedStyle(d,null)||{}).top!=="1%",b.boxSizingReliable=(a.getComputedStyle(d,null)||{width:"4px"}).width==="4px",g=e.createElement("div"),g.style.cssText=d.style.cssText=h,g.style.marginRight=g.style.width="0",d.style.width="1px",d.appendChild(g),b.reliableMarginRight=!parseFloat((a.getComputedStyle(g,null)||{}).marginRight)),typeof d.style.zoom!="undefined"&&(d.innerHTML="",d.style.cssText=h+"width:1px;padding:1px;display:inline;zoom:1",b.inlineBlockNeedsLayout=d.offsetWidth===3,d.style.display="block",d.style.overflow="visible",d.innerHTML="<div></div>",d.firstChild.style.width="5px",b.shrinkWrapBlocks=d.offsetWidth!==3,c.style.zoom=1),i.removeChild(c),c=d=f=g=null}),i.removeChild(n),c=d=f=g=h=i=n=null,b}();var H=/^(?:\{.*\}|\[.*\])$/,I=/([A-Z])/g;p.extend({cache:{},deletedIds:[],uuid:0,expando:"jQuery"+(p.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){return a=a.nodeType?p.cache[a[p.expando]]:a[p.expando],!!a&&!K(a)},data:function(a,c,d,e){if(!p.acceptData(a))return;var f,g,h=p.expando,i=typeof c=="string",j=a.nodeType,k=j?p.cache:a,l=j?a[h]:a[h]&&h;if((!l||!k[l]||!e&&!k[l].data)&&i&&d===b)return;l||(j?a[h]=l=p.deletedIds.pop()||++p.uuid:l=h),k[l]||(k[l]={},j||(k[l].toJSON=p.noop));if(typeof c=="object"||typeof c=="function")e?k[l]=p.extend(k[l],c):k[l].data=p.extend(k[l].data,c);return f=k[l],e||(f.data||(f.data={}),f=f.data),d!==b&&(f[p.camelCase(c)]=d),i?(g=f[c],g==null&&(g=f[p.camelCase(c)])):g=f,g},removeData:function(a,b,c){if(!p.acceptData(a))return;var d,e,f,g=a.nodeType,h=g?p.cache:a,i=g?a[p.expando]:p.expando;if(!h[i])return;if(b){d=c?h[i]:h[i].data;if(d){p.isArray(b)||(b in d?b=[b]:(b=p.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,f=b.length;e<f;e++)delete d[b[e]];if(!(c?K:p.isEmptyObject)(d))return}}if(!c){delete h[i].data;if(!K(h[i]))return}g?p.cleanData([a],!0):p.support.deleteExpando||h!=h.window?delete h[i]:h[i]=null},_data:function(a,b,c){return p.data(a,b,c,!0)},acceptData:function(a){var b=a.nodeName&&p.noData[a.nodeName.toLowerCase()];return!b||b!==!0&&a.getAttribute("classid")===b}}),p.fn.extend({data:function(a,c){var d,e,f,g,h,i=this[0],j=0,k=null;if(a===b){if(this.length){k=p.data(i);if(i.nodeType===1&&!p._data(i,"parsedAttrs")){f=i.attributes;for(h=f.length;j<h;j++)g=f[j].name,g.indexOf("data-")===0&&(g=p.camelCase(g.substring(5)),J(i,g,k[g]));p._data(i,"parsedAttrs",!0)}}return k}return typeof a=="object"?this.each(function(){p.data(this,a)}):(d=a.split(".",2),d[1]=d[1]?"."+d[1]:"",e=d[1]+"!",p.access(this,function(c){if(c===b)return k=this.triggerHandler("getData"+e,[d[0]]),k===b&&i&&(k=p.data(i,a),k=J(i,a,k)),k===b&&d[1]?this.data(d[0]):k;d[1]=c,this.each(function(){var b=p(this);b.triggerHandler("setData"+e,d),p.data(this,a,c),b.triggerHandler("changeData"+e,d)})},null,c,arguments.length>1,null,!1))},removeData:function(a){return this.each(function(){p.removeData(this,a)})}}),p.extend({queue:function(a,b,c){var d;if(a)return b=(b||"fx")+"queue",d=p._data(a,b),c&&(!d||p.isArray(c)?d=p._data(a,b,p.makeArray(c)):d.push(c)),d||[]},dequeue:function(a,b){b=b||"fx";var c=p.queue(a,b),d=c.shift(),e=p._queueHooks(a,b),f=function(){p.dequeue(a,b)};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),delete e.stop,d.call(a,f,e)),!c.length&&e&&e.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return p._data(a,c)||p._data(a,c,{empty:p.Callbacks("once memory").add(function(){p.removeData(a,b+"queue",!0),p.removeData(a,c,!0)})})}}),p.fn.extend({queue:function(a,c){var d=2;return typeof a!="string"&&(c=a,a="fx",d--),arguments.length<d?p.queue(this[0],a):c===b?this:this.each(function(){var b=p.queue(this,a,c);p._queueHooks(this,a),a==="fx"&&b[0]!=="inprogress"&&p.dequeue(this,a)})},dequeue:function(a){return this.each(function(){p.dequeue(this,a)})},delay:function(a,b){return a=p.fx?p.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){var d,e=1,f=p.Deferred(),g=this,h=this.length,i=function(){--e||f.resolveWith(g,[g])};typeof a!="string"&&(c=a,a=b),a=a||"fx";while(h--)(d=p._data(g[h],a+"queueHooks"))&&d.empty&&(e++,d.empty.add(i));return i(),f.promise(c)}});var L,M,N,O=/[\t\r\n]/g,P=/\r/g,Q=/^(?:button|input)$/i,R=/^(?:button|input|object|select|textarea)$/i,S=/^a(?:rea|)$/i,T=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,U=p.support.getSetAttribute;p.fn.extend({attr:function(a,b){return p.access(this,p.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){p.removeAttr(this,a)})},prop:function(a,b){return p.access(this,p.prop,a,b,arguments.length>1)},removeProp:function(a){return a=p.propFix[a]||a,this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,f,g,h;if(p.isFunction(a))return this.each(function(b){p(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(s);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{f=" "+e.className+" ";for(g=0,h=b.length;g<h;g++)~f.indexOf(" "+b[g]+" ")||(f+=b[g]+" ");e.className=p.trim(f)}}}return this},removeClass:function(a){var c,d,e,f,g,h,i;if(p.isFunction(a))return this.each(function(b){p(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(s);for(h=0,i=this.length;h<i;h++){e=this[h];if(e.nodeType===1&&e.className){d=(" "+e.className+" ").replace(O," ");for(f=0,g=c.length;f<g;f++)while(d.indexOf(" "+c[f]+" ")>-1)d=d.replace(" "+c[f]+" "," ");e.className=a?p.trim(d):""}}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";return p.isFunction(a)?this.each(function(c){p(this).toggleClass(a.call(this,c,this.className,b),b)}):this.each(function(){if(c==="string"){var e,f=0,g=p(this),h=b,i=a.split(s);while(e=i[f++])h=d?h:!g.hasClass(e),g[h?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&p._data(this,"__className__",this.className),this.className=this.className||a===!1?"":p._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(O," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,f=this[0];if(!arguments.length){if(f)return c=p.valHooks[f.type]||p.valHooks[f.nodeName.toLowerCase()],c&&"get"in c&&(d=c.get(f,"value"))!==b?d:(d=f.value,typeof d=="string"?d.replace(P,""):d==null?"":d);return}return e=p.isFunction(a),this.each(function(d){var f,g=p(this);if(this.nodeType!==1)return;e?f=a.call(this,d,g.val()):f=a,f==null?f="":typeof f=="number"?f+="":p.isArray(f)&&(f=p.map(f,function(a){return a==null?"":a+""})),c=p.valHooks[this.type]||p.valHooks[this.nodeName.toLowerCase()];if(!c||!("set"in c)||c.set(this,f,"value")===b)this.value=f})}}),p.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,f=a.selectedIndex,g=[],h=a.options,i=a.type==="select-one";if(f<0)return null;c=i?f:0,d=i?f+1:h.length;for(;c<d;c++){e=h[c];if(e.selected&&(p.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!p.nodeName(e.parentNode,"optgroup"))){b=p(e).val();if(i)return b;g.push(b)}}return i&&!g.length&&h.length?p(h[f]).val():g},set:function(a,b){var c=p.makeArray(b);return p(a).find("option").each(function(){this.selected=p.inArray(p(this).val(),c)>=0}),c.length||(a.selectedIndex=-1),c}}},attrFn:{},attr:function(a,c,d,e){var f,g,h,i=a.nodeType;if(!a||i===3||i===8||i===2)return;if(e&&p.isFunction(p.fn[c]))return p(a)[c](d);if(typeof a.getAttribute=="undefined")return p.prop(a,c,d);h=i!==1||!p.isXMLDoc(a),h&&(c=c.toLowerCase(),g=p.attrHooks[c]||(T.test(c)?M:L));if(d!==b){if(d===null){p.removeAttr(a,c);return}return g&&"set"in g&&h&&(f=g.set(a,d,c))!==b?f:(a.setAttribute(c,""+d),d)}return g&&"get"in g&&h&&(f=g.get(a,c))!==null?f:(f=a.getAttribute(c),f===null?b:f)},removeAttr:function(a,b){var c,d,e,f,g=0;if(b&&a.nodeType===1){d=b.split(s);for(;g<d.length;g++)e=d[g],e&&(c=p.propFix[e]||e,f=T.test(e),f||p.attr(a,e,""),a.removeAttribute(U?e:c),f&&c in a&&(a[c]=!1))}},attrHooks:{type:{set:function(a,b){if(Q.test(a.nodeName)&&a.parentNode)p.error("type property can't be changed");else if(!p.support.radioValue&&b==="radio"&&p.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}},value:{get:function(a,b){return L&&p.nodeName(a,"button")?L.get(a,b):b in a?a.value:null},set:function(a,b,c){if(L&&p.nodeName(a,"button"))return L.set(a,b,c);a.value=b}}},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(a,c,d){var e,f,g,h=a.nodeType;if(!a||h===3||h===8||h===2)return;return g=h!==1||!p.isXMLDoc(a),g&&(c=p.propFix[c]||c,f=p.propHooks[c]),d!==b?f&&"set"in f&&(e=f.set(a,d,c))!==b?e:a[c]=d:f&&"get"in f&&(e=f.get(a,c))!==null?e:a[c]},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):R.test(a.nodeName)||S.test(a.nodeName)&&a.href?0:b}}}}),M={get:function(a,c){var d,e=p.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;return b===!1?p.removeAttr(a,c):(d=p.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase())),c}},U||(N={name:!0,id:!0,coords:!0},L=p.valHooks.button={get:function(a,c){var d;return d=a.getAttributeNode(c),d&&(N[c]?d.value!=="":d.specified)?d.value:b},set:function(a,b,c){var d=a.getAttributeNode(c);return d||(d=e.createAttribute(c),a.setAttributeNode(d)),d.value=b+""}},p.each(["width","height"],function(a,b){p.attrHooks[b]=p.extend(p.attrHooks[b],{set:function(a,c){if(c==="")return a.setAttribute(b,"auto"),c}})}),p.attrHooks.contenteditable={get:L.get,set:function(a,b,c){b===""&&(b="false"),L.set(a,b,c)}}),p.support.hrefNormalized||p.each(["href","src","width","height"],function(a,c){p.attrHooks[c]=p.extend(p.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),p.support.style||(p.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),p.support.optSelected||(p.propHooks.selected=p.extend(p.propHooks.selected,{get:function(a){var b=a.parentNode;return b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex),null}})),p.support.enctype||(p.propFix.enctype="encoding"),p.support.checkOn||p.each(["radio","checkbox"],function(){p.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),p.each(["radio","checkbox"],function(){p.valHooks[this]=p.extend(p.valHooks[this],{set:function(a,b){if(p.isArray(b))return a.checked=p.inArray(p(a).val(),b)>=0}})});var V=/^(?:textarea|input|select)$/i,W=/^([^\.]*|)(?:\.(.+)|)$/,X=/(?:^|\s)hover(\.\S+|)\b/,Y=/^key/,Z=/^(?:mouse|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=function(a){return p.event.special.hover?a:a.replace(X,"mouseenter$1 mouseleave$1")};p.event={add:function(a,c,d,e,f){var g,h,i,j,k,l,m,n,o,q,r;if(a.nodeType===3||a.nodeType===8||!c||!d||!(g=p._data(a)))return;d.handler&&(o=d,d=o.handler,f=o.selector),d.guid||(d.guid=p.guid++),i=g.events,i||(g.events=i={}),h=g.handle,h||(g.handle=h=function(a){return typeof p!="undefined"&&(!a||p.event.triggered!==a.type)?p.event.dispatch.apply(h.elem,arguments):b},h.elem=a),c=p.trim(_(c)).split(" ");for(j=0;j<c.length;j++){k=W.exec(c[j])||[],l=k[1],m=(k[2]||"").split(".").sort(),r=p.event.special[l]||{},l=(f?r.delegateType:r.bindType)||l,r=p.event.special[l]||{},n=p.extend({type:l,origType:k[1],data:e,handler:d,guid:d.guid,selector:f,namespace:m.join(".")},o),q=i[l];if(!q){q=i[l]=[],q.delegateCount=0;if(!r.setup||r.setup.call(a,e,m,h)===!1)a.addEventListener?a.addEventListener(l,h,!1):a.attachEvent&&a.attachEvent("on"+l,h)}r.add&&(r.add.call(a,n),n.handler.guid||(n.handler.guid=d.guid)),f?q.splice(q.delegateCount++,0,n):q.push(n),p.event.global[l]=!0}a=null},global:{},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,q,r=p.hasData(a)&&p._data(a);if(!r||!(m=r.events))return;b=p.trim(_(b||"")).split(" ");for(f=0;f<b.length;f++){g=W.exec(b[f])||[],h=i=g[1],j=g[2];if(!h){for(h in m)p.event.remove(a,h+b[f],c,d,!0);continue}n=p.event.special[h]||{},h=(d?n.delegateType:n.bindType)||h,o=m[h]||[],k=o.length,j=j?new RegExp("(^|\\.)"+j.split(".").sort().join("\\.(?:.*\\.|)")+"(\\.|$)"):null;for(l=0;l<o.length;l++)q=o[l],(e||i===q.origType)&&(!c||c.guid===q.guid)&&(!j||j.test(q.namespace))&&(!d||d===q.selector||d==="**"&&q.selector)&&(o.splice(l--,1),q.selector&&o.delegateCount--,n.remove&&n.remove.call(a,q));o.length===0&&k!==o.length&&((!n.teardown||n.teardown.call(a,j,r.handle)===!1)&&p.removeEvent(a,h,r.handle),delete m[h])}p.isEmptyObject(m)&&(delete r.handle,p.removeData(a,"events",!0))},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,f,g){if(!f||f.nodeType!==3&&f.nodeType!==8){var h,i,j,k,l,m,n,o,q,r,s=c.type||c,t=[];if($.test(s+p.event.triggered))return;s.indexOf("!")>=0&&(s=s.slice(0,-1),i=!0),s.indexOf(".")>=0&&(t=s.split("."),s=t.shift(),t.sort());if((!f||p.event.customEvent[s])&&!p.event.global[s])return;c=typeof c=="object"?c[p.expando]?c:new p.Event(s,c):new p.Event(s),c.type=s,c.isTrigger=!0,c.exclusive=i,c.namespace=t.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+t.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,m=s.indexOf(":")<0?"on"+s:"";if(!f){h=p.cache;for(j in h)h[j].events&&h[j].events[s]&&p.event.trigger(c,d,h[j].handle.elem,!0);return}c.result=b,c.target||(c.target=f),d=d!=null?p.makeArray(d):[],d.unshift(c),n=p.event.special[s]||{};if(n.trigger&&n.trigger.apply(f,d)===!1)return;q=[[f,n.bindType||s]];if(!g&&!n.noBubble&&!p.isWindow(f)){r=n.delegateType||s,k=$.test(r+s)?f:f.parentNode;for(l=f;k;k=k.parentNode)q.push([k,r]),l=k;l===(f.ownerDocument||e)&&q.push([l.defaultView||l.parentWindow||a,r])}for(j=0;j<q.length&&!c.isPropagationStopped();j++)k=q[j][0],c.type=q[j][1],o=(p._data(k,"events")||{})[c.type]&&p._data(k,"handle"),o&&o.apply(k,d),o=m&&k[m],o&&p.acceptData(k)&&o.apply(k,d)===!1&&c.preventDefault();return c.type=s,!g&&!c.isDefaultPrevented()&&(!n._default||n._default.apply(f.ownerDocument,d)===!1)&&(s!=="click"||!p.nodeName(f,"a"))&&p.acceptData(f)&&m&&f[s]&&(s!=="focus"&&s!=="blur"||c.target.offsetWidth!==0)&&!p.isWindow(f)&&(l=f[m],l&&(f[m]=null),p.event.triggered=s,f[s](),p.event.triggered=b,l&&(f[m]=l)),c.result}return},dispatch:function(c){c=p.event.fix(c||a.event);var d,e,f,g,h,i,j,k,l,m,n,o=(p._data(this,"events")||{})[c.type]||[],q=o.delegateCount,r=[].slice.call(arguments),s=!c.exclusive&&!c.namespace,t=p.event.special[c.type]||{},u=[];r[0]=c,c.delegateTarget=this;if(t.preDispatch&&t.preDispatch.call(this,c)===!1)return;if(q&&(!c.button||c.type!=="click")){g=p(this),g.context=this;for(f=c.target;f!=this;f=f.parentNode||this)if(f.disabled!==!0||c.type!=="click"){i={},k=[],g[0]=f;for(d=0;d<q;d++)l=o[d],m=l.selector,i[m]===b&&(i[m]=g.is(m)),i[m]&&k.push(l);k.length&&u.push({elem:f,matches:k})}}o.length>q&&u.push({elem:this,matches:o.slice(q)});for(d=0;d<u.length&&!c.isPropagationStopped();d++){j=u[d],c.currentTarget=j.elem;for(e=0;e<j.matches.length&&!c.isImmediatePropagationStopped();e++){l=j.matches[e];if(s||!c.namespace&&!l.namespace||c.namespace_re&&c.namespace_re.test(l.namespace))c.data=l.data,c.handleObj=l,h=((p.event.special[l.origType]||{}).handle||l.handler).apply(j.elem,r),h!==b&&(c.result=h,h===!1&&(c.preventDefault(),c.stopPropagation()))}}return t.postDispatch&&t.postDispatch.call(this,c),c.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,c){var d,f,g,h=c.button,i=c.fromElement;return a.pageX==null&&c.clientX!=null&&(d=a.target.ownerDocument||e,f=d.documentElement,g=d.body,a.pageX=c.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=c.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?c.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0),a}},fix:function(a){if(a[p.expando])return a;var b,c,d=a,f=p.event.fixHooks[a.type]||{},g=f.props?this.props.concat(f.props):this.props;a=p.Event(d);for(b=g.length;b;)c=g[--b],a[c]=d[c];return a.target||(a.target=d.srcElement||e),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey=!!a.metaKey,f.filter?f.filter(a,d):a},special:{ready:{setup:p.bindReady},load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(a,b,c){p.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=p.extend(new p.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?p.event.trigger(e,null,b):p.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},p.event.handle=p.event.dispatch,p.removeEvent=e.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){var d="on"+b;a.detachEvent&&(typeof a[d]=="undefined"&&(a[d]=null),a.detachEvent(d,c))},p.Event=function(a,b){if(this instanceof p.Event)a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?bb:ba):this.type=a,b&&p.extend(this,b),this.timeStamp=a&&a.timeStamp||p.now(),this[p.expando]=!0;else return new p.Event(a,b)},p.Event.prototype={preventDefault:function(){this.isDefaultPrevented=bb;var a=this.originalEvent;if(!a)return;a.preventDefault?a.preventDefault():a.returnValue=!1},stopPropagation:function(){this.isPropagationStopped=bb;var a=this.originalEvent;if(!a)return;a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=bb,this.stopPropagation()},isDefaultPrevented:ba,isPropagationStopped:ba,isImmediatePropagationStopped:ba},p.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){p.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj,g=f.selector;if(!e||e!==d&&!p.contains(d,e))a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b;return c}}}),p.support.submitBubbles||(p.event.special.submit={setup:function(){if(p.nodeName(this,"form"))return!1;p.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=p.nodeName(c,"input")||p.nodeName(c,"button")?c.form:b;d&&!p._data(d,"_submit_attached")&&(p.event.add(d,"submit._submit",function(a){a._submit_bubble=!0}),p._data(d,"_submit_attached",!0))})},postDispatch:function(a){a._submit_bubble&&(delete a._submit_bubble,this.parentNode&&!a.isTrigger&&p.event.simulate("submit",this.parentNode,a,!0))},teardown:function(){if(p.nodeName(this,"form"))return!1;p.event.remove(this,"._submit")}}),p.support.changeBubbles||(p.event.special.change={setup:function(){if(V.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")p.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),p.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1),p.event.simulate("change",this,a,!0)});return!1}p.event.add(this,"beforeactivate._change",function(a){var b=a.target;V.test(b.nodeName)&&!p._data(b,"_change_attached")&&(p.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&!a.isTrigger&&p.event.simulate("change",this.parentNode,a,!0)}),p._data(b,"_change_attached",!0))})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){return p.event.remove(this,"._change"),V.test(this.nodeName)}}),p.support.focusinBubbles||p.each({focus:"focusin",blur:"focusout"},function(a,b){var c=0,d=function(a){p.event.simulate(b,a.target,p.event.fix(a),!0)};p.event.special[b]={setup:function(){c++===0&&e.addEventListener(a,d,!0)},teardown:function(){--c===0&&e.removeEventListener(a,d,!0)}}}),p.fn.extend({on:function(a,c,d,e,f){var g,h;if(typeof a=="object"){typeof c!="string"&&(d=d||c,c=b);for(h in a)this.on(h,c,d,a[h],f);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=ba;else if(!e)return this;return f===1&&(g=e,e=function(a){return p().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=p.guid++)),this.each(function(){p.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,c,d){var e,f;if(a&&a.preventDefault&&a.handleObj)return e=a.handleObj,p(a.delegateTarget).off(e.namespace?e.origType+"."+e.namespace:e.origType,e.selector,e.handler),this;if(typeof a=="object"){for(f in a)this.off(f,c,a[f]);return this}if(c===!1||typeof c=="function")d=c,c=b;return d===!1&&(d=ba),this.each(function(){p.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){return p(this.context).on(a,this.selector,b,c),this},die:function(a,b){return p(this.context).off(a,this.selector||"**",b),this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a||"**",c)},trigger:function(a,b){return this.each(function(){p.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return p.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||p.guid++,d=0,e=function(c){var e=(p._data(this,"lastToggle"+a.guid)||0)%d;return p._data(this,"lastToggle"+a.guid,e+1),c.preventDefault(),b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),p.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(a,b){p.fn[b]=function(a,c){return c==null&&(c=a,a=null),arguments.length>0?this.on(b,null,a,c):this.trigger(b)},Y.test(b)&&(p.event.fixHooks[b]=p.event.keyHooks),Z.test(b)&&(p.event.fixHooks[b]=p.event.mouseHooks)}),function(a,b){function bd(a,b,c,d){var e=0,f=b.length;for(;e<f;e++)Z(a,b[e],c,d)}function be(a,b,c,d,e,f){var g,h=$.setFilters[b.toLowerCase()];return h||Z.error(b),(a||!(g=e))&&bd(a||"*",d,g=[],e),g.length>0?h(g,c,f):[]}function bf(a,c,d,e,f){var g,h,i,j,k,l,m,n,p=0,q=f.length,s=L.POS,t=new RegExp("^"+s.source+"(?!"+r+")","i"),u=function(){var a=1,c=arguments.length-2;for(;a<c;a++)arguments[a]===b&&(g[a]=b)};for(;p<q;p++){s.exec(""),a=f[p],j=[],i=0,k=e;while(g=s.exec(a)){n=s.lastIndex=g.index+g[0].length;if(n>i){m=a.slice(i,g.index),i=n,l=[c],B.test(m)&&(k&&(l=k),k=e);if(h=H.test(m))m=m.slice(0,-5).replace(B,"$&*");g.length>1&&g[0].replace(t,u),k=be(m,g[1],g[2],l,k,h)}}k?(j=j.concat(k),(m=a.slice(i))&&m!==")"?B.test(m)?bd(m,j,d,e):Z(m,c,d,e?e.concat(k):k):o.apply(d,j)):Z(a,c,d,e)}return q===1?d:Z.uniqueSort(d)}function bg(a,b,c){var d,e,f,g=[],i=0,j=D.exec(a),k=!j.pop()&&!j.pop(),l=k&&a.match(C)||[""],m=$.preFilter,n=$.filter,o=!c&&b!==h;for(;(e=l[i])!=null&&k;i++){g.push(d=[]),o&&(e=" "+e);while(e){k=!1;if(j=B.exec(e))e=e.slice(j[0].length),k=d.push({part:j.pop().replace(A," "),captures:j});for(f in n)(j=L[f].exec(e))&&(!m[f]||(j=m[f](j,b,c)))&&(e=e.slice(j.shift().length),k=d.push({part:f,captures:j}));if(!k)break}}return k||Z.error(a),g}function bh(a,b,e){var f=b.dir,g=m++;return a||(a=function(a){return a===e}),b.first?function(b,c){while(b=b[f])if(b.nodeType===1)return a(b,c)&&b}:function(b,e){var h,i=g+"."+d,j=i+"."+c;while(b=b[f])if(b.nodeType===1){if((h=b[q])===j)return b.sizset;if(typeof h=="string"&&h.indexOf(i)===0){if(b.sizset)return b}else{b[q]=j;if(a(b,e))return b.sizset=!0,b;b.sizset=!1}}}}function bi(a,b){return a?function(c,d){var e=b(c,d);return e&&a(e===!0?c:e,d)}:b}function bj(a,b,c){var d,e,f=0;for(;d=a[f];f++)$.relative[d.part]?e=bh(e,$.relative[d.part],b):(d.captures.push(b,c),e=bi(e,$.filter[d.part].apply(null,d.captures)));return e}function bk(a){return function(b,c){var d,e=0;for(;d=a[e];e++)if(d(b,c))return!0;return!1}}var c,d,e,f,g,h=a.document,i=h.documentElement,j="undefined",k=!1,l=!0,m=0,n=[].slice,o=[].push,q=("sizcache"+Math.random()).replace(".",""),r="[\\x20\\t\\r\\n\\f]",s="(?:\\\\.|[-\\w]|[^\\x00-\\xa0])+",t=s.replace("w","w#"),u="([*^$|!~]?=)",v="\\["+r+"*("+s+")"+r+"*(?:"+u+r+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+t+")|)|)"+r+"*\\]",w=":("+s+")(?:\\((?:(['\"])((?:\\\\.|[^\\\\])*?)\\2|((?:[^,]|\\\\,|(?:,(?=[^\\[]*\\]))|(?:,(?=[^\\(]*\\))))*))\\)|)",x=":(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\)|)(?=[^-]|$)",y=r+"*([\\x20\\t\\r\\n\\f>+~])"+r+"*",z="(?=[^\\x20\\t\\r\\n\\f])(?:\\\\.|"+v+"|"+w.replace(2,7)+"|[^\\\\(),])+",A=new RegExp("^"+r+"+|((?:^|[^\\\\])(?:\\\\.)*)"+r+"+$","g"),B=new RegExp("^"+y),C=new RegExp(z+"?(?="+r+"*,|$)","g"),D=new RegExp("^(?:(?!,)(?:(?:^|,)"+r+"*"+z+")*?|"+r+"*(.*?))(\\)|$)"),E=new RegExp(z.slice(19,-6)+"\\x20\\t\\r\\n\\f>+~])+|"+y,"g"),F=/^(?:#([\w\-]+)|(\w+)|\.([\w\-]+))$/,G=/[\x20\t\r\n\f]*[+~]/,H=/:not\($/,I=/h\d/i,J=/input|select|textarea|button/i,K=/\\(?!\\)/g,L={ID:new RegExp("^#("+s+")"),CLASS:new RegExp("^\\.("+s+")"),NAME:new RegExp("^\\[name=['\"]?("+s+")['\"]?\\]"),TAG:new RegExp("^("+s.replace("[-","[-\\*")+")"),ATTR:new RegExp("^"+v),PSEUDO:new RegExp("^"+w),CHILD:new RegExp("^:(only|nth|last|first)-child(?:\\("+r+"*(even|odd|(([+-]|)(\\d*)n|)"+r+"*(?:([+-]|)"+r+"*(\\d+)|))"+r+"*\\)|)","i"),POS:new RegExp(x,"ig"),needsContext:new RegExp("^"+r+"*[>+~]|"+x,"i")},M={},N=[],O={},P=[],Q=function(a){return a.sizzleFilter=!0,a},R=function(a){return function(b){return b.nodeName.toLowerCase()==="input"&&b.type===a}},S=function(a){return function(b){var c=b.nodeName.toLowerCase();return(c==="input"||c==="button")&&b.type===a}},T=function(a){var b=!1,c=h.createElement("div");try{b=a(c)}catch(d){}return c=null,b},U=T(function(a){a.innerHTML="<select></select>";var b=typeof a.lastChild.getAttribute("multiple");return b!=="boolean"&&b!=="string"}),V=T(function(a){a.id=q+0,a.innerHTML="<a name='"+q+"'></a><div name='"+q+"'></div>",i.insertBefore(a,i.firstChild);var b=h.getElementsByName&&h.getElementsByName(q).length===2+h.getElementsByName(q+0).length;return g=!h.getElementById(q),i.removeChild(a),b}),W=T(function(a){return a.appendChild(h.createComment("")),a.getElementsByTagName("*").length===0}),X=T(function(a){return a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!==j&&a.firstChild.getAttribute("href")==="#"}),Y=T(function(a){return a.innerHTML="<div class='hidden e'></div><div class='hidden'></div>",!a.getElementsByClassName||a.getElementsByClassName("e").length===0?!1:(a.lastChild.className="e",a.getElementsByClassName("e").length!==1)}),Z=function(a,b,c,d){c=c||[],b=b||h;var e,f,g,i,j=b.nodeType;if(j!==1&&j!==9)return[];if(!a||typeof a!="string")return c;g=ba(b);if(!g&&!d)if(e=F.exec(a))if(i=e[1]){if(j===9){f=b.getElementById(i);if(!f||!f.parentNode)return c;if(f.id===i)return c.push(f),c}else if(b.ownerDocument&&(f=b.ownerDocument.getElementById(i))&&bb(b,f)&&f.id===i)return c.push(f),c}else{if(e[2])return o.apply(c,n.call(b.getElementsByTagName(a),0)),c;if((i=e[3])&&Y&&b.getElementsByClassName)return o.apply(c,n.call(b.getElementsByClassName(i),0)),c}return bm(a,b,c,d,g)},$=Z.selectors={cacheLength:50,match:L,order:["ID","TAG"],attrHandle:{},createPseudo:Q,find:{ID:g?function(a,b,c){if(typeof b.getElementById!==j&&!c){var d=b.getElementById(a);return d&&d.parentNode?[d]:[]}}:function(a,c,d){if(typeof c.getElementById!==j&&!d){var e=c.getElementById(a);return e?e.id===a||typeof e.getAttributeNode!==j&&e.getAttributeNode("id").value===a?[e]:b:[]}},TAG:W?function(a,b){if(typeof b.getElementsByTagName!==j)return b.getElementsByTagName(a)}:function(a,b){var c=b.getElementsByTagName(a);if(a==="*"){var d,e=[],f=0;for(;d=c[f];f++)d.nodeType===1&&e.push(d);return e}return c}},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(K,""),a[3]=(a[4]||a[5]||"").replace(K,""),a[2]==="~="&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),a[1]==="nth"?(a[2]||Z.error(a[0]),a[3]=+(a[3]?a[4]+(a[5]||1):2*(a[2]==="even"||a[2]==="odd")),a[4]=+(a[6]+a[7]||a[2]==="odd")):a[2]&&Z.error(a[0]),a},PSEUDO:function(a){var b,c=a[4];return L.CHILD.test(a[0])?null:(c&&(b=D.exec(c))&&b.pop()&&(a[0]=a[0].slice(0,b[0].length-c.length-1),c=b[0].slice(0,-1)),a.splice(2,3,c||a[3]),a)}},filter:{ID:g?function(a){return a=a.replace(K,""),function(b){return b.getAttribute("id")===a}}:function(a){return a=a.replace(K,""),function(b){var c=typeof b.getAttributeNode!==j&&b.getAttributeNode("id");return c&&c.value===a}},TAG:function(a){return a==="*"?function(){return!0}:(a=a.replace(K,"").toLowerCase(),function(b){return b.nodeName&&b.nodeName.toLowerCase()===a})},CLASS:function(a){var b=M[a];return b||(b=M[a]=new RegExp("(^|"+r+")"+a+"("+r+"|$)"),N.push(a),N.length>$.cacheLength&&delete M[N.shift()]),function(a){return b.test(a.className||typeof a.getAttribute!==j&&a.getAttribute("class")||"")}},ATTR:function(a,b,c){return b?function(d){var e=Z.attr(d,a),f=e+"";if(e==null)return b==="!=";switch(b){case"=":return f===c;case"!=":return f!==c;case"^=":return c&&f.indexOf(c)===0;case"*=":return c&&f.indexOf(c)>-1;case"$=":return c&&f.substr(f.length-c.length)===c;case"~=":return(" "+f+" ").indexOf(c)>-1;case"|=":return f===c||f.substr(0,c.length+1)===c+"-"}}:function(b){return Z.attr(b,a)!=null}},CHILD:function(a,b,c,d){if(a==="nth"){var e=m++;return function(a){var b,f,g=0,h=a;if(c===1&&d===0)return!0;b=a.parentNode;if(b&&(b[q]!==e||!a.sizset)){for(h=b.firstChild;h;h=h.nextSibling)if(h.nodeType===1){h.sizset=++g;if(h===a)break}b[q]=e}return f=a.sizset-d,c===0?f===0:f%c===0&&f/c>=0}}return function(b){var c=b;switch(a){case"only":case"first":while(c=c.previousSibling)if(c.nodeType===1)return!1;if(a==="first")return!0;c=b;case"last":while(c=c.nextSibling)if(c.nodeType===1)return!1;return!0}}},PSEUDO:function(a,b,c,d){var e=$.pseudos[a]||$.pseudos[a.toLowerCase()];return e||Z.error("unsupported pseudo: "+a),e.sizzleFilter?e(b,c,d):e}},pseudos:{not:Q(function(a,b,c){var d=bl(a.replace(A,"$1"),b,c);return function(a){return!d(a)}}),enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&!!a.checked||b==="option"&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},parent:function(a){return!$.pseudos.empty(a)},empty:function(a){var b;a=a.firstChild;while(a){if(a.nodeName>"@"||(b=a.nodeType)===3||b===4)return!1;a=a.nextSibling}return!0},contains:Q(function(a){return function(b){return(b.textContent||b.innerText||bc(b)).indexOf(a)>-1}}),has:Q(function(a){return function(b){return Z(a,b).length>0}}),header:function(a){return I.test(a.nodeName)},text:function(a){var b,c;return a.nodeName.toLowerCase()==="input"&&(b=a.type)==="text"&&((c=a.getAttribute("type"))==null||c.toLowerCase()===b)},radio:R("radio"),checkbox:R("checkbox"),file:R("file"),password:R("password"),image:R("image"),submit:S("submit"),reset:S("reset"),button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&a.type==="button"||b==="button"},input:function(a){return J.test(a.nodeName)},focus:function(a){var b=a.ownerDocument;return a===b.activeElement&&(!b.hasFocus||b.hasFocus())&&(!!a.type||!!a.href)},active:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b,c){return c?a.slice(1):[a[0]]},last:function(a,b,c){var d=a.pop();return c?a:[d]},even:function(a,b,c){var d=[],e=c?1:0,f=a.length;for(;e<f;e=e+2)d.push(a[e]);return d},odd:function(a,b,c){var d=[],e=c?0:1,f=a.length;for(;e<f;e=e+2)d.push(a[e]);return d},lt:function(a,b,c){return c?a.slice(+b):a.slice(0,+b)},gt:function(a,b,c){return c?a.slice(0,+b+1):a.slice(+b+1)},eq:function(a,b,c){var d=a.splice(+b,1);return c?a:d}}};$.setFilters.nth=$.setFilters.eq,$.filters=$.pseudos,X||($.attrHandle={href:function(a){return a.getAttribute("href",2)},type:function(a){return a.getAttribute("type")}}),V&&($.order.push("NAME"),$.find.NAME=function(a,b){if(typeof b.getElementsByName!==j)return b.getElementsByName(a)}),Y&&($.order.splice(1,0,"CLASS"),$.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!==j&&!c)return b.getElementsByClassName(a)});try{n.call(i.childNodes,0)[0].nodeType}catch(_){n=function(a){var b,c=[];for(;b=this[a];a++)c.push(b);return c}}var ba=Z.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?b.nodeName!=="HTML":!1},bb=Z.contains=i.compareDocumentPosition?function(a,b){return!!(a.compareDocumentPosition(b)&16)}:i.contains?function(a,b){var c=a.nodeType===9?a.documentElement:a,d=b.parentNode;return a===d||!!(d&&d.nodeType===1&&c.contains&&c.contains(d))}:function(a,b){while(b=b.parentNode)if(b===a)return!0;return!1},bc=Z.getText=function(a){var b,c="",d=0,e=a.nodeType;if(e){if(e===1||e===9||e===11){if(typeof a.textContent=="string")return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=bc(a)}else if(e===3||e===4)return a.nodeValue}else for(;b=a[d];d++)c+=bc(b);return c};Z.attr=function(a,b){var c,d=ba(a);return d||(b=b.toLowerCase()),$.attrHandle[b]?$.attrHandle[b](a):U||d?a.getAttribute(b):(c=a.getAttributeNode(b),c?typeof a[b]=="boolean"?a[b]?b:null:c.specified?c.value:null:null)},Z.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},[0,0].sort(function(){return l=0}),i.compareDocumentPosition?e=function(a,b){return a===b?(k=!0,0):(!a.compareDocumentPosition||!b.compareDocumentPosition?a.compareDocumentPosition:a.compareDocumentPosition(b)&4)?-1:1}:(e=function(a,b){if(a===b)return k=!0,0;if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],g=[],h=a.parentNode,i=b.parentNode,j=h;if(h===i)return f(a,b);if(!h)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)g.unshift(j),j=j.parentNode;c=e.length,d=g.length;for(var l=0;l<c&&l<d;l++)if(e[l]!==g[l])return f(e[l],g[l]);return l===c?f(a,g[l],-1):f(e[l],b,1)},f=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),Z.uniqueSort=function(a){var b,c=1;if(e){k=l,a.sort(e);if(k)for(;b=a[c];c++)b===a[c-1]&&a.splice(c--,1)}return a};var bl=Z.compile=function(a,b,c){var d,e,f,g=O[a];if(g&&g.context===b)return g;e=bg(a,b,c);for(f=0;d=e[f];f++)e[f]=bj(d,b,c);return g=O[a]=bk(e),g.context=b,g.runs=g.dirruns=0,P.push(a),P.length>$.cacheLength&&delete O[P.shift()],g};Z.matches=function(a,b){return Z(a,null,null,b)},Z.matchesSelector=function(a,b){return Z(b,null,null,[a]).length>0};var bm=function(a,b,e,f,g){a=a.replace(A,"$1");var h,i,j,k,l,m,p,q,r,s=a.match(C),t=a.match(E),u=b.nodeType;if(L.POS.test(a))return bf(a,b,e,f,s);if(f)h=n.call(f,0);else if(s&&s.length===1){if(t.length>1&&u===9&&!g&&(s=L.ID.exec(t[0]))){b=$.find.ID(s[1],b,g)[0];if(!b)return e;a=a.slice(t.shift().length)}q=(s=G.exec(t[0]))&&!s.index&&b.parentNode||b,r=t.pop(),m=r.split(":not")[0];for(j=0,k=$.order.length;j<k;j++){p=$.order[j];if(s=L[p].exec(m)){h=$.find[p]((s[1]||"").replace(K,""),q,g);if(h==null)continue;m===r&&(a=a.slice(0,a.length-r.length)+m.replace(L[p],""),a||o.apply(e,n.call(h,0)));break}}}if(a){i=bl(a,b,g),d=i.dirruns++,h==null&&(h=$.find.TAG("*",G.test(a)&&b.parentNode||b));for(j=0;l=h[j];j++)c=i.runs++,i(l,b)&&e.push(l)}return e};h.querySelectorAll&&function(){var a,b=bm,c=/'|\\/g,d=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,e=[],f=[":active"],g=i.matchesSelector||i.mozMatchesSelector||i.webkitMatchesSelector||i.oMatchesSelector||i.msMatchesSelector;T(function(a){a.innerHTML="<select><option selected></option></select>",a.querySelectorAll("[selected]").length||e.push("\\["+r+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),a.querySelectorAll(":checked").length||e.push(":checked")}),T(function(a){a.innerHTML="<p test=''></p>",a.querySelectorAll("[test^='']").length&&e.push("[*^$]="+r+"*(?:\"\"|'')"),a.innerHTML="<input type='hidden'>",a.querySelectorAll(":enabled").length||e.push(":enabled",":disabled")}),e=e.length&&new RegExp(e.join("|")),bm=function(a,d,f,g,h){if(!g&&!h&&(!e||!e.test(a)))if(d.nodeType===9)try{return o.apply(f,n.call(d.querySelectorAll(a),0)),f}catch(i){}else if(d.nodeType===1&&d.nodeName.toLowerCase()!=="object"){var j=d.getAttribute("id"),k=j||q,l=G.test(a)&&d.parentNode||d;j?k=k.replace(c,"\\$&"):d.setAttribute("id",k);try{return o.apply(f,n.call(l.querySelectorAll(a.replace(C,"[id='"+k+"'] $&")),0)),f}catch(i){}finally{j||d.removeAttribute("id")}}return b(a,d,f,g,h)},g&&(T(function(b){a=g.call(b,"div");try{g.call(b,"[test!='']:sizzle"),f.push($.match.PSEUDO)}catch(c){}}),f=new RegExp(f.join("|")),Z.matchesSelector=function(b,c){c=c.replace(d,"='$1']");if(!ba(b)&&!f.test(c)&&(!e||!e.test(c)))try{var h=g.call(b,c);if(h||a||b.document&&b.document.nodeType!==11)return h}catch(i){}return Z(c,null,null,[b]).length>0})}(),Z.attr=p.attr,p.find=Z,p.expr=Z.selectors,p.expr[":"]=p.expr.pseudos,p.unique=Z.uniqueSort,p.text=Z.getText,p.isXMLDoc=Z.isXML,p.contains=Z.contains}(a);var bc=/Until$/,bd=/^(?:parents|prev(?:Until|All))/,be=/^.[^:#\[\.,]*$/,bf=p.expr.match.needsContext,bg={children:!0,contents:!0,next:!0,prev:!0};p.fn.extend({find:function(a){var b,c,d,e,f,g,h=this;if(typeof a!="string")return p(a).filter(function(){for(b=0,c=h.length;b<c;b++)if(p.contains(h[b],this))return!0});g=this.pushStack("","find",a);for(b=0,c=this.length;b<c;b++){d=g.length,p.find(a,this[b],g);if(b>0)for(e=d;e<g.length;e++)for(f=0;f<d;f++)if(g[f]===g[e]){g.splice(e--,1);break}}return g},has:function(a){var b,c=p(a,this),d=c.length;return this.filter(function(){for(b=0;b<d;b++)if(p.contains(this,c[b]))return!0})},not:function(a){return this.pushStack(bj(this,a,!1),"not",a)},filter:function(a){return this.pushStack(bj(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?bf.test(a)?p(a,this.context).index(this[0])>=0:p.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c,d=0,e=this.length,f=[],g=bf.test(a)||typeof a!="string"?p(a,b||this.context):0;for(;d<e;d++){c=this[d];while(c&&c.ownerDocument&&c!==b&&c.nodeType!==11){if(g?g.index(c)>-1:p.find.matchesSelector(c,a)){f.push(c);break}c=c.parentNode}}return f=f.length>1?p.unique(f):f,this.pushStack(f,"closest",a)},index:function(a){return a?typeof a=="string"?p.inArray(this[0],p(a)):p.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.prevAll().length:-1},add:function(a,b){var c=typeof a=="string"?p(a,b):p.makeArray(a&&a.nodeType?[a]:a),d=p.merge(this.get(),c);return this.pushStack(bh(c[0])||bh(d[0])?d:p.unique(d))},addBack:function(a){return this.add(a==null?this.prevObject:this.prevObject.filter(a))}}),p.fn.andSelf=p.fn.addBack,p.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return p.dir(a,"parentNode")},parentsUntil:function(a,b,c){return p.dir(a,"parentNode",c)},next:function(a){return bi(a,"nextSibling")},prev:function(a){return bi(a,"previousSibling")},nextAll:function(a){return p.dir(a,"nextSibling")},prevAll:function(a){return p.dir(a,"previousSibling")},nextUntil:function(a,b,c){return p.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return p.dir(a,"previousSibling",c)},siblings:function(a){return p.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return p.sibling(a.firstChild)},contents:function(a){return p.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:p.merge([],a.childNodes)}},function(a,b){p.fn[a]=function(c,d){var e=p.map(this,b,c);return bc.test(a)||(d=c),d&&typeof d=="string"&&(e=p.filter(d,e)),e=this.length>1&&!bg[a]?p.unique(e):e,this.length>1&&bd.test(a)&&(e=e.reverse()),this.pushStack(e,a,k.call(arguments).join(","))}}),p.extend({filter:function(a,b,c){return c&&(a=":not("+a+")"),b.length===1?p.find.matchesSelector(b[0],a)?[b[0]]:[]:p.find.matches(a,b)},dir:function(a,c,d){var e=[],f=a[c];while(f&&f.nodeType!==9&&(d===b||f.nodeType!==1||!p(f).is(d)))f.nodeType===1&&e.push(f),f=f[c];return e},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var bl="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",bm=/ jQuery\d+="(?:null|\d+)"/g,bn=/^\s+/,bo=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bp=/<([\w:]+)/,bq=/<tbody/i,br=/<|&#?\w+;/,bs=/<(?:script|style|link)/i,bt=/<(?:script|object|embed|option|style)/i,bu=new RegExp("<(?:"+bl+")[\\s/>]","i"),bv=/^(?:checkbox|radio)$/,bw=/checked\s*(?:[^=]|=\s*.checked.)/i,bx=/\/(java|ecma)script/i,by=/^\s*<!(?:\[CDATA\[|\-\-)|[\]\-]{2}>\s*$/g,bz={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bA=bk(e),bB=bA.appendChild(e.createElement("div"));bz.optgroup=bz.option,bz.tbody=bz.tfoot=bz.colgroup=bz.caption=bz.thead,bz.th=bz.td,p.support.htmlSerialize||(bz._default=[1,"X<div>","</div>"]),p.fn.extend({text:function(a){return p.access(this,function(a){return a===b?p.text(this):this.empty().append((this[0]&&this[0].ownerDocument||e).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(p.isFunction(a))return this.each(function(b){p(this).wrapAll(a.call(this,b))});if(this[0]){var b=p(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){return p.isFunction(a)?this.each(function(b){p(this).wrapInner(a.call(this,b))}):this.each(function(){var b=p(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=p.isFunction(a);return this.each(function(c){p(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){p.nodeName(this,"body")||p(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){(this.nodeType===1||this.nodeType===11)&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){(this.nodeType===1||this.nodeType===11)&&this.insertBefore(a,this.firstChild)})},before:function(){if(!bh(this[0]))return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=p.clean(arguments);return this.pushStack(p.merge(a,this),"before",this.selector)}},after:function(){if(!bh(this[0]))return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=p.clean(arguments);return this.pushStack(p.merge(this,a),"after",this.selector)}},remove:function(a,b){var c,d=0;for(;(c=this[d])!=null;d++)if(!a||p.filter(a,[c]).length)!b&&c.nodeType===1&&(p.cleanData(c.getElementsByTagName("*")),p.cleanData([c])),c.parentNode&&c.parentNode.removeChild(c);return this},empty:function(){var a,b=0;for(;(a=this[b])!=null;b++){a.nodeType===1&&p.cleanData(a.getElementsByTagName("*"));while(a.firstChild)a.removeChild(a.firstChild)}return this},clone:function(a,b){return a=a==null?!1:a,b=b==null?a:b,this.map(function(){return p.clone(this,a,b)})},html:function(a){return p.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(bm,""):b;if(typeof a=="string"&&!bs.test(a)&&(p.support.htmlSerialize||!bu.test(a))&&(p.support.leadingWhitespace||!bn.test(a))&&!bz[(bp.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(bo,"<$1></$2>");try{for(;d<e;d++)c=this[d]||{},c.nodeType===1&&(p.cleanData(c.getElementsByTagName("*")),c.innerHTML=a);c=0}catch(f){}}c&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(a){return bh(this[0])?this.length?this.pushStack(p(p.isFunction(a)?a():a),"replaceWith",a):this:p.isFunction(a)?this.each(function(b){var c=p(this),d=c.html();c.replaceWith(a.call(this,b,d))}):(typeof a!="string"&&(a=p(a).detach()),this.each(function(){var b=this.nextSibling,c=this.parentNode;p(this).remove(),b?p(b).before(a):p(c).append(a)}))},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){a=[].concat.apply([],a);var e,f,g,h,i=0,j=a[0],k=[],l=this.length;if(!p.support.checkClone&&l>1&&typeof j=="string"&&bw.test(j))return this.each(function(){p(this).domManip(a,c,d)});if(p.isFunction(j))return this.each(function(e){var f=p(this);a[0]=j.call(this,e,c?f.html():b),f.domManip(a,c,d)});if(this[0]){e=p.buildFragment(a,this,k),g=e.fragment,f=g.firstChild,g.childNodes.length===1&&(g=f);if(f){c=c&&p.nodeName(f,"tr");for(h=e.cacheable||l-1;i<l;i++)d.call(c&&p.nodeName(this[i],"table")?bC(this[i],"tbody"):this[i],i===h?g:p.clone(g,!0,!0))}g=f=null,k.length&&p.each(k,function(a,b){b.src?p.ajax?p.ajax({url:b.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):p.error("no ajax"):p.globalEval((b.text||b.textContent||b.innerHTML||"").replace(by,"")),b.parentNode&&b.parentNode.removeChild(b)})}return this}}),p.buildFragment=function(a,c,d){var f,g,h,i=a[0];return c=c||e,c=(c[0]||c).ownerDocument||c[0]||c,typeof c.createDocumentFragment=="undefined"&&(c=e),a.length===1&&typeof i=="string"&&i.length<512&&c===e&&i.charAt(0)==="<"&&!bt.test(i)&&(p.support.checkClone||!bw.test(i))&&(p.support.html5Clone||!bu.test(i))&&(g=!0,f=p.fragments[i],h=f!==b),f||(f=c.createDocumentFragment(),p.clean(a,c,f,d),g&&(p.fragments[i]=h&&f)),{fragment:f,cacheable:g}},p.fragments={},p.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){p.fn[a]=function(c){var d,e=0,f=[],g=p(c),h=g.length,i=this.length===1&&this[0].parentNode;if((i==null||i&&i.nodeType===11&&i.childNodes.length===1)&&h===1)return g[b](this[0]),this;for(;e<h;e++)d=(e>0?this.clone(!0):this).get(),p(g[e])[b](d),f=f.concat(d);return this.pushStack(f,a,g.selector)}}),p.extend({clone:function(a,b,c){var d,e,f,g;p.support.html5Clone||p.isXMLDoc(a)||!bu.test("<"+a.nodeName+">")?g=a.cloneNode(!0):(bB.innerHTML=a.outerHTML,bB.removeChild(g=bB.firstChild));if((!p.support.noCloneEvent||!p.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!p.isXMLDoc(a)){bE(a,g),d=bF(a),e=bF(g);for(f=0;d[f];++f)e[f]&&bE(d[f],e[f])}if(b){bD(a,g);if(c){d=bF(a),e=bF(g);for(f=0;d[f];++f)bD(d[f],e[f])}}return d=e=null,g},clean:function(a,b,c,d){var f,g,h,i,j,k,l,m,n,o,q,r,s=0,t=[];if(!b||typeof b.createDocumentFragment=="undefined")b=e;for(g=b===e&&bA;(h=a[s])!=null;s++){typeof h=="number"&&(h+="");if(!h)continue;if(typeof h=="string")if(!br.test(h))h=b.createTextNode(h);else{g=g||bk(b),l=l||g.appendChild(b.createElement("div")),h=h.replace(bo,"<$1></$2>"),i=(bp.exec(h)||["",""])[1].toLowerCase(),j=bz[i]||bz._default,k=j[0],l.innerHTML=j[1]+h+j[2];while(k--)l=l.lastChild;if(!p.support.tbody){m=bq.test(h),n=i==="table"&&!m?l.firstChild&&l.firstChild.childNodes:j[1]==="<table>"&&!m?l.childNodes:[];for(f=n.length-1;f>=0;--f)p.nodeName(n[f],"tbody")&&!n[f].childNodes.length&&n[f].parentNode.removeChild(n[f])}!p.support.leadingWhitespace&&bn.test(h)&&l.insertBefore(b.createTextNode(bn.exec(h)[0]),l.firstChild),h=l.childNodes,l=g.lastChild}h.nodeType?t.push(h):t=p.merge(t,h)}l&&(g.removeChild(l),h=l=g=null);if(!p.support.appendChecked)for(s=0;(h=t[s])!=null;s++)p.nodeName(h,"input")?bG(h):typeof h.getElementsByTagName!="undefined"&&p.grep(h.getElementsByTagName("input"),bG);if(c){q=function(a){if(!a.type||bx.test(a.type))return d?d.push(a.parentNode?a.parentNode.removeChild(a):a):c.appendChild(a)};for(s=0;(h=t[s])!=null;s++)if(!p.nodeName(h,"script")||!q(h))c.appendChild(h),typeof h.getElementsByTagName!="undefined"&&(r=p.grep(p.merge([],h.getElementsByTagName("script")),q),t.splice.apply(t,[s+1,0].concat(r)),s+=r.length)}return t},cleanData:function(a,b){var c,d,e,f,g=0,h=p.expando,i=p.cache,j=p.support.deleteExpando,k=p.event.special;for(;(e=a[g])!=null;g++)if(b||p.acceptData(e)){d=e[h],c=d&&i[d];if(c){if(c.events)for(f in c.events)k[f]?p.event.remove(e,f):p.removeEvent(e,f,c.handle);i[d]&&(delete i[d],j?delete e[h]:e.removeAttribute?e.removeAttribute(h):e[h]=null,p.deletedIds.push(d))}}}}),function(){var a,b;p.uaMatch=function(a){a=a.toLowerCase();var b=/(chrome)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},a=p.uaMatch(g.userAgent),b={},a.browser&&(b[a.browser]=!0,b.version=a.version),b.webkit&&(b.safari=!0),p.browser=b,p.sub=function(){function a(b,c){return new a.fn.init(b,c)}p.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function c(c,d){return d&&d instanceof p&&!(d instanceof a)&&(d=a(d)),p.fn.init.call(this,c,d,b)},a.fn.init.prototype=a.fn;var b=a(e);return a}}();var bH,bI,bJ,bK=/alpha\([^)]*\)/i,bL=/opacity=([^)]*)/,bM=/^(top|right|bottom|left)$/,bN=/^margin/,bO=new RegExp("^("+q+")(.*)$","i"),bP=new RegExp("^("+q+")(?!px)[a-z%]+$","i"),bQ=new RegExp("^([-+])=("+q+")","i"),bR={},bS={position:"absolute",visibility:"hidden",display:"block"},bT={letterSpacing:0,fontWeight:400,lineHeight:1},bU=["Top","Right","Bottom","Left"],bV=["Webkit","O","Moz","ms"],bW=p.fn.toggle;p.fn.extend({css:function(a,c){return p.access(this,function(a,c,d){return d!==b?p.style(a,c,d):p.css(a,c)},a,c,arguments.length>1)},show:function(){return bZ(this,!0)},hide:function(){return bZ(this)},toggle:function(a,b){var c=typeof a=="boolean";return p.isFunction(a)&&p.isFunction(b)?bW.apply(this,arguments):this.each(function(){(c?a:bY(this))?p(this).show():p(this).hide()})}}),p.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bH(a,"opacity");return c===""?"1":c}}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":p.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!a||a.nodeType===3||a.nodeType===8||!a.style)return;var f,g,h,i=p.camelCase(c),j=a.style;c=p.cssProps[i]||(p.cssProps[i]=bX(j,i)),h=p.cssHooks[c]||p.cssHooks[i];if(d===b)return h&&"get"in h&&(f=h.get(a,!1,e))!==b?f:j[c];g=typeof d,g==="string"&&(f=bQ.exec(d))&&(d=(f[1]+1)*f[2]+parseFloat(p.css(a,c)),g="number");if(d==null||g==="number"&&isNaN(d))return;g==="number"&&!p.cssNumber[i]&&(d+="px");if(!h||!("set"in h)||(d=h.set(a,d,e))!==b)try{j[c]=d}catch(k){}},css:function(a,c,d,e){var f,g,h,i=p.camelCase(c);return c=p.cssProps[i]||(p.cssProps[i]=bX(a.style,i)),h=p.cssHooks[c]||p.cssHooks[i],h&&"get"in h&&(f=h.get(a,!0,e)),f===b&&(f=bH(a,c)),f==="normal"&&c in bT&&(f=bT[c]),d||e!==b?(g=parseFloat(f),d||p.isNumeric(g)?g||0:f):f},swap:function(a,b,c){var d,e,f={};for(e in b)f[e]=a.style[e],a.style[e]=b[e];d=c.call(a);for(e in b)a.style[e]=f[e];return d}}),a.getComputedStyle?bH=function(a,b){var c,d,e,f,g=getComputedStyle(a,null),h=a.style;return g&&(c=g[b],c===""&&!p.contains(a.ownerDocument.documentElement,a)&&(c=p.style(a,b)),bP.test(c)&&bN.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=c,c=g.width,h.width=d,h.minWidth=e,h.maxWidth=f)),c}:e.documentElement.currentStyle&&(bH=function(a,b){var c,d,e=a.currentStyle&&a.currentStyle[b],f=a.style;return e==null&&f&&f[b]&&(e=f[b]),bP.test(e)&&!bM.test(b)&&(c=f.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":e,e=f.pixelLeft+"px",f.left=c,d&&(a.runtimeStyle.left=d)),e===""?"auto":e}),p.each(["height","width"],function(a,b){p.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0||bH(a,"display")!=="none"?ca(a,b,d):p.swap(a,bS,function(){return ca(a,b,d)})},set:function(a,c,d){return b$(a,c,d?b_(a,b,d,p.support.boxSizing&&p.css(a,"boxSizing")==="border-box"):0)}}}),p.support.opacity||(p.cssHooks.opacity={get:function(a,b){return bL.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=p.isNumeric(b)?"alpha(opacity="+b*100+")":"",f=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&p.trim(f.replace(bK,""))===""&&c.removeAttribute){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bK.test(f)?f.replace(bK,e):f+" "+e}}),p(function(){p.support.reliableMarginRight||(p.cssHooks.marginRight={get:function(a,b){return p.swap(a,{display:"inline-block"},function(){if(b)return bH(a,"marginRight")})}}),!p.support.pixelPosition&&p.fn.position&&p.each(["top","left"],function(a,b){p.cssHooks[b]={get:function(a,c){if(c){var d=bH(a,b);return bP.test(d)?p(a).position()[b]+"px":d}}}})}),p.expr&&p.expr.filters&&(p.expr.filters.hidden=function(a){return a.offsetWidth===0&&a.offsetHeight===0||!p.support.reliableHiddenOffsets&&(a.style&&a.style.display||bH(a,"display"))==="none"},p.expr.filters.visible=function(a){return!p.expr.filters.hidden(a)}),p.each({margin:"",padding:"",border:"Width"},function(a,b){p.cssHooks[a+b]={expand:function(c){var d,e=typeof c=="string"?c.split(" "):[c],f={};for(d=0;d<4;d++)f[a+bU[d]+b]=e[d]||e[d-2]||e[0];return f}},bN.test(a)||(p.cssHooks[a+b].set=b$)});var cc=/%20/g,cd=/\[\]$/,ce=/\r?\n/g,cf=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,cg=/^(?:select|textarea)/i;p.fn.extend({serialize:function(){return p.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?p.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||cg.test(this.nodeName)||cf.test(this.type))}).map(function(a,b){var c=p(this).val();return c==null?null:p.isArray(c)?p.map(c,function(a,c){return{name:b.name,value:a.replace(ce,"\r\n")}}):{name:b.name,value:c.replace(ce,"\r\n")}}).get()}}),p.param=function(a,c){var d,e=[],f=function(a,b){b=p.isFunction(b)?b():b==null?"":b,e[e.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=p.ajaxSettings&&p.ajaxSettings.traditional);if(p.isArray(a)||a.jquery&&!p.isPlainObject(a))p.each(a,function(){f(this.name,this.value)});else for(d in a)ch(d,a[d],c,f);return e.join("&").replace(cc,"+")};var ci,cj,ck=/#.*$/,cl=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,cm=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,cn=/^(?:GET|HEAD)$/,co=/^\/\//,cp=/\?/,cq=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,cr=/([?&])_=[^&]*/,cs=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,ct=p.fn.load,cu={},cv={},cw=["*/"]+["*"];try{ci=f.href}catch(cx){ci=e.createElement("a"),ci.href="",ci=ci.href}cj=cs.exec(ci.toLowerCase())||[],p.fn.load=function(a,c,d){if(typeof a!="string"&&ct)return ct.apply(this,arguments);if(!this.length)return this;var e,f,g,h=this,i=a.indexOf(" ");return i>=0&&(e=a.slice(i,a.length),a=a.slice(0,i)),p.isFunction(c)?(d=c,c=b):typeof c=="object"&&(f="POST"),p.ajax({url:a,type:f,dataType:"html",data:c,complete:function(a,b){d&&h.each(d,g||[a.responseText,b,a])}}).done(function(a){g=arguments,h.html(e?p("<div>").append(a.replace(cq,"")).find(e):a)}),this},p.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){p.fn[b]=function(a){return this.on(b,a)}}),p.each(["get","post"],function(a,c){p[c]=function(a,d,e,f){return p.isFunction(d)&&(f=f||e,e=d,d=b),p.ajax({type:c,url:a,data:d,success:e,dataType:f})}}),p.extend({getScript:function(a,c){return p.get(a,b,c,"script")},getJSON:function(a,b,c){return p.get(a,b,c,"json")},ajaxSetup:function(a,b){return b?cA(a,p.ajaxSettings):(b=a,a=p.ajaxSettings),cA(a,b),a},ajaxSettings:{url:ci,isLocal:cm.test(cj[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":cw},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":p.parseJSON,"text xml":p.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:cy(cu),ajaxTransport:cy(cv),ajax:function(a,c){function y(a,c,f,i){var k,s,t,u,w,y=c;if(v===2)return;v=2,h&&clearTimeout(h),g=b,e=i||"",x.readyState=a>0?4:0,f&&(u=cB(l,x,f));if(a>=200&&a<300||a===304)l.ifModified&&(w=x.getResponseHeader("Last-Modified"),w&&(p.lastModified[d]=w),w=x.getResponseHeader("Etag"),w&&(p.etag[d]=w)),a===304?(y="notmodified",k=!0):(k=cC(l,u),y=k.state,s=k.data,t=k.error,k=!t);else{t=y;if(!y||a)y="error",a<0&&(a=0)}x.status=a,x.statusText=""+(c||y),k?o.resolveWith(m,[s,y,x]):o.rejectWith(m,[x,y,t]),x.statusCode(r),r=b,j&&n.trigger("ajax"+(k?"Success":"Error"),[x,l,k?s:t]),q.fireWith(m,[x,y]),j&&(n.trigger("ajaxComplete",[x,l]),--p.active||p.event.trigger("ajaxStop"))}typeof a=="object"&&(c=a,a=b),c=c||{};var d,e,f,g,h,i,j,k,l=p.ajaxSetup({},c),m=l.context||l,n=m!==l&&(m.nodeType||m instanceof p)?p(m):p.event,o=p.Deferred(),q=p.Callbacks("once memory"),r=l.statusCode||{},t={},u={},v=0,w="canceled",x={readyState:0,setRequestHeader:function(a,b){if(!v){var c=a.toLowerCase();a=u[c]=u[c]||a,t[a]=b}return this},getAllResponseHeaders:function(){return v===2?e:null},getResponseHeader:function(a){var c;if(v===2){if(!f){f={};while(c=cl.exec(e))f[c[1].toLowerCase()]=c[2]}c=f[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){return v||(l.mimeType=a),this},abort:function(a){return a=a||w,g&&g.abort(a),y(0,a),this}};o.promise(x),x.success=x.done,x.error=x.fail,x.complete=q.add,x.statusCode=function(a){if(a){var b;if(v<2)for(b in a)r[b]=[r[b],a[b]];else b=a[x.status],x.always(b)}return this},l.url=((a||l.url)+"").replace(ck,"").replace(co,cj[1]+"//"),l.dataTypes=p.trim(l.dataType||"*").toLowerCase().split(s),l.crossDomain==null&&(i=cs.exec(l.url.toLowerCase()),l.crossDomain=!(!i||i[1]==cj[1]&&i[2]==cj[2]&&(i[3]||(i[1]==="http:"?80:443))==(cj[3]||(cj[1]==="http:"?80:443)))),l.data&&l.processData&&typeof l.data!="string"&&(l.data=p.param(l.data,l.traditional)),cz(cu,l,c,x);if(v===2)return x;j=l.global,l.type=l.type.toUpperCase(),l.hasContent=!cn.test(l.type),j&&p.active++===0&&p.event.trigger("ajaxStart");if(!l.hasContent){l.data&&(l.url+=(cp.test(l.url)?"&":"?")+l.data,delete l.data),d=l.url;if(l.cache===!1){var z=p.now(),A=l.url.replace(cr,"$1_="+z);l.url=A+(A===l.url?(cp.test(l.url)?"&":"?")+"_="+z:"")}}(l.data&&l.hasContent&&l.contentType!==!1||c.contentType)&&x.setRequestHeader("Content-Type",l.contentType),l.ifModified&&(d=d||l.url,p.lastModified[d]&&x.setRequestHeader("If-Modified-Since",p.lastModified[d]),p.etag[d]&&x.setRequestHeader("If-None-Match",p.etag[d])),x.setRequestHeader("Accept",l.dataTypes[0]&&l.accepts[l.dataTypes[0]]?l.accepts[l.dataTypes[0]]+(l.dataTypes[0]!=="*"?", "+cw+"; q=0.01":""):l.accepts["*"]);for(k in l.headers)x.setRequestHeader(k,l.headers[k]);if(!l.beforeSend||l.beforeSend.call(m,x,l)!==!1&&v!==2){w="abort";for(k in{success:1,error:1,complete:1})x[k](l[k]);g=cz(cv,l,c,x);if(!g)y(-1,"No Transport");else{x.readyState=1,j&&n.trigger("ajaxSend",[x,l]),l.async&&l.timeout>0&&(h=setTimeout(function(){x.abort("timeout")},l.timeout));try{v=1,g.send(t,y)}catch(B){if(v<2)y(-1,B);else throw B}}return x}return x.abort()},active:0,lastModified:{},etag:{}});var cD=[],cE=/\?/,cF=/(=)\?(?=&|$)|\?\?/,cG=p.now();p.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=cD.pop()||p.expando+"_"+cG++;return this[a]=!0,a}}),p.ajaxPrefilter("json jsonp",function(c,d,e){var f,g,h,i=c.data,j=c.url,k=c.jsonp!==!1,l=k&&cF.test(j),m=k&&!l&&typeof i=="string"&&!(c.contentType||"").indexOf("application/x-www-form-urlencoded")&&cF.test(i);if(c.dataTypes[0]==="jsonp"||l||m)return f=c.jsonpCallback=p.isFunction(c.jsonpCallback)?c.jsonpCallback():c.jsonpCallback,g=a[f],l?c.url=j.replace(cF,"$1"+f):m?c.data=i.replace(cF,"$1"+f):k&&(c.url+=(cE.test(j)?"&":"?")+c.jsonp+"="+f),c.converters["script json"]=function(){return h||p.error(f+" was not called"),h[0]},c.dataTypes[0]="json",a[f]=function(){h=arguments},e.always(function(){a[f]=g,c[f]&&(c.jsonpCallback=d.jsonpCallback,cD.push(f)),h&&p.isFunction(g)&&g(h[0]),h=g=b}),"script"}),p.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){return p.globalEval(a),a}}}),p.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),p.ajaxTransport("script",function(a){if(a.crossDomain){var c,d=e.head||e.getElementsByTagName("head")[0]||e.documentElement;return{send:function(f,g){c=e.createElement("script"),c.async="async",a.scriptCharset&&(c.charset=a.scriptCharset),c.src=a.url,c.onload=c.onreadystatechange=function(a,e){if(e||!c.readyState||/loaded|complete/.test(c.readyState))c.onload=c.onreadystatechange=null,d&&c.parentNode&&d.removeChild(c),c=b,e||g(200,"success")},d.insertBefore(c,d.firstChild)},abort:function(){c&&c.onload(0,1)}}}});var cH,cI=a.ActiveXObject?function(){for(var a in cH)cH[a](0,1)}:!1,cJ=0;p.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&cK()||cL()}:cK,function(a){p.extend(p.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(p.ajaxSettings.xhr()),p.support.ajax&&p.ajaxTransport(function(c){if(!c.crossDomain||p.support.cors){var d;return{send:function(e,f){var g,h,i=c.xhr();c.username?i.open(c.type,c.url,c.async,c.username,c.password):i.open(c.type,c.url,c.async);if(c.xhrFields)for(h in c.xhrFields)i[h]=c.xhrFields[h];c.mimeType&&i.overrideMimeType&&i.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(h in e)i.setRequestHeader(h,e[h])}catch(j){}i.send(c.hasContent&&c.data||null),d=function(a,e){var h,j,k,l,m;try{if(d&&(e||i.readyState===4)){d=b,g&&(i.onreadystatechange=p.noop,cI&&delete cH[g]);if(e)i.readyState!==4&&i.abort();else{h=i.status,k=i.getAllResponseHeaders(),l={},m=i.responseXML,m&&m.documentElement&&(l.xml=m);try{l.text=i.responseText}catch(a){}try{j=i.statusText}catch(n){j=""}!h&&c.isLocal&&!c.crossDomain?h=l.text?200:404:h===1223&&(h=204)}}}catch(o){e||f(-1,o)}l&&f(h,j,l,k)},c.async?i.readyState===4?setTimeout(d,0):(g=++cJ,cI&&(cH||(cH={},p(a).unload(cI)),cH[g]=d),i.onreadystatechange=d):d()},abort:function(){d&&d(0,1)}}}});var cM,cN,cO=/^(?:toggle|show|hide)$/,cP=new RegExp("^(?:([-+])=|)("+q+")([a-z%]*)$","i"),cQ=/queueHooks$/,cR=[cX],cS={"*":[function(a,b){var c,d,e,f=this.createTween(a,b),g=cP.exec(b),h=f.cur(),i=+h||0,j=1;if(g){c=+g[2],d=g[3]||(p.cssNumber[a]?"":"px");if(d!=="px"&&i){i=p.css(f.elem,a,!0)||c||1;do e=j=j||".5",i=i/j,p.style(f.elem,a,i+d),j=f.cur()/h;while(j!==1&&j!==e)}f.unit=d,f.start=i,f.end=g[1]?i+(g[1]+1)*c:c}return f}]};p.Animation=p.extend(cV,{tweener:function(a,b){p.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");var c,d=0,e=a.length;for(;d<e;d++)c=a[d],cS[c]=cS[c]||[],cS[c].unshift(b)},prefilter:function(a,b){b?cR.unshift(a):cR.push(a)}}),p.Tween=cY,cY.prototype={constructor:cY,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(p.cssNumber[c]?"":"px")},cur:function(){var a=cY.propHooks[this.prop];return a&&a.get?a.get(this):cY.propHooks._default.get(this)},run:function(a){var b,c=cY.propHooks[this.prop];return this.pos=b=p.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration),this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):cY.propHooks._default.set(this),this}},cY.prototype.init.prototype=cY.prototype,cY.propHooks={_default:{get:function(a){var b;return a.elem[a.prop]==null||!!a.elem.style&&a.elem.style[a.prop]!=null?(b=p.css(a.elem,a.prop,!1,""),!b||b==="auto"?0:b):a.elem[a.prop]},set:function(a){p.fx.step[a.prop]?p.fx.step[a.prop](a):a.elem.style&&(a.elem.style[p.cssProps[a.prop]]!=null||p.cssHooks[a.prop])?p.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},cY.propHooks.scrollTop=cY.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},p.each(["toggle","show","hide"],function(a,b){var c=p.fn[b];p.fn[b]=function(d,e,f){return d==null||typeof d=="boolean"||!a&&p.isFunction(d)&&p.isFunction(e)?c.apply(this,arguments):this.animate(cZ(b,!0),d,e,f)}}),p.fn.extend({fadeTo:function(a,b,c,d){return this.filter(bY).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=p.isEmptyObject(a),f=p.speed(b,c,d),g=function(){var b=cV(this,p.extend({},a),f);e&&b.stop(!0)};return e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,c,d){var e=function(a){var b=a.stop;delete a.stop,b(d)};return typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,c=a!=null&&a+"queueHooks",f=p.timers,g=p._data(this);if(c)g[c]&&g[c].stop&&e(g[c]);else for(c in g)g[c]&&g[c].stop&&cQ.test(c)&&e(g[c]);for(c=f.length;c--;)f[c].elem===this&&(a==null||f[c].queue===a)&&(f[c].anim.stop(d),b=!1,f.splice(c,1));(b||!d)&&p.dequeue(this,a)})}}),p.each({slideDown:cZ("show"),slideUp:cZ("hide"),slideToggle:cZ("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){p.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),p.speed=function(a,b,c){var d=a&&typeof a=="object"?p.extend({},a):{complete:c||!c&&b||p.isFunction(a)&&a,duration:a,easing:c&&b||b&&!p.isFunction(b)&&b};d.duration=p.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in p.fx.speeds?p.fx.speeds[d.duration]:p.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";return d.old=d.complete,d.complete=function(){p.isFunction(d.old)&&d.old.call(this),d.queue&&p.dequeue(this,d.queue)},d},p.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},p.timers=[],p.fx=cY.prototype.init,p.fx.tick=function(){var a,b=p.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||p.fx.stop()},p.fx.timer=function(a){a()&&p.timers.push(a)&&!cN&&(cN=setInterval(p.fx.tick,p.fx.interval))},p.fx.interval=13,p.fx.stop=function(){clearInterval(cN),cN=null},p.fx.speeds={slow:600,fast:200,_default:400},p.fx.step={},p.expr&&p.expr.filters&&(p.expr.filters.animated=function(a){return p.grep(p.timers,function(b){return a===b.elem}).length});var c$=/^(?:body|html)$/i;p.fn.offset=function(a){if(arguments.length)return a===b?this:this.each(function(b){p.offset.setOffset(this,a,b)});var c,d,e,f,g,h,i,j,k,l,m=this[0],n=m&&m.ownerDocument;if(!n)return;return(e=n.body)===m?p.offset.bodyOffset(m):(d=n.documentElement,p.contains(d,m)?(c=m.getBoundingClientRect(),f=c_(n),g=d.clientTop||e.clientTop||0,h=d.clientLeft||e.clientLeft||0,i=f.pageYOffset||d.scrollTop,j=f.pageXOffset||d.scrollLeft,k=c.top+i-g,l=c.left+j-h,{top:k,left:l}):{top:0,left:0})},p.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;return p.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(p.css(a,"marginTop"))||0,c+=parseFloat(p.css(a,"marginLeft"))||0),{top:b,left:c}},setOffset:function(a,b,c){var d=p.css(a,"position");d==="static"&&(a.style.position="relative");var e=p(a),f=e.offset(),g=p.css(a,"top"),h=p.css(a,"left"),i=(d==="absolute"||d==="fixed")&&p.inArray("auto",[g,h])>-1,j={},k={},l,m;i?(k=e.position(),l=k.top,m=k.left):(l=parseFloat(g)||0,m=parseFloat(h)||0),p.isFunction(b)&&(b=b.call(a,c,f)),b.top!=null&&(j.top=b.top-f.top+l),b.left!=null&&(j.left=b.left-f.left+m),"using"in b?b.using.call(a,j):e.css(j)}},p.fn.extend({position:function(){if(!this[0])return;var a=this[0],b=this.offsetParent(),c=this.offset(),d=c$.test(b[0].nodeName)?{top:0,left:0}:b.offset();return c.top-=parseFloat(p.css(a,"marginTop"))||0,c.left-=parseFloat(p.css(a,"marginLeft"))||0,d.top+=parseFloat(p.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(p.css(b[0],"borderLeftWidth"))||0,{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||e.body;while(a&&!c$.test(a.nodeName)&&p.css(a,"position")==="static")a=a.offsetParent;return a||e.body})}}),p.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,c){var d=/Y/.test(c);p.fn[a]=function(e){return p.access(this,function(a,e,f){var g=c_(a);if(f===b)return g?c in g?g[c]:g.document.documentElement[e]:a[e];g?g.scrollTo(d?p(g).scrollLeft():f,d?f:p(g).scrollTop()):a[e]=f},a,e,arguments.length,null)}}),p.each({Height:"height",Width:"width"},function(a,c){p.each({padding:"inner"+a,content:c,"":"outer"+a},function(d,e){p.fn[e]=function(e,f){var g=arguments.length&&(d||typeof e!="boolean"),h=d||(e===!0||f===!0?"margin":"border");return p.access(this,function(c,d,e){var f;return p.isWindow(c)?c.document.documentElement["client"+a]:c.nodeType===9?(f=c.documentElement,Math.max(c.body["scroll"+a],f["scroll"+a],c.body["offset"+a],f["offset"+a],f["client"+a])):e===b?p.css(c,d,e,h):p.style(c,d,e,h)},c,g?e:b,g)}})}),a.jQuery=a.$=p,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return p})})(window);
diff --git a/catalog-be/src/main/resources/swagger/lib/jquery.ba-bbq.min.js b/catalog-be/src/main/resources/swagger/lib/jquery.ba-bbq.min.js
new file mode 100644
index 0000000000..0bcdb66da5
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/jquery.ba-bbq.min.js
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/*
+ * jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
+ * http://benalman.com/projects/jquery-bbq-plugin/
+ *
+ * Copyright (c) 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M<N?O[P]||(R[M+1]&&isNaN(R[M+1])?{}:[]):J}}else{if($.isArray(H[P])){H[P].push(J)}else{if(H[P]!==i){H[P]=[H[P],J]}else{H[P]=J}}}}else{if(P){H[P]=F?i:""}}});return H};function z(H,F,G){if(F===i||typeof F==="boolean"){G=F;F=a[H?D:A]()}else{F=E(F)?F.replace(H?w:x,""):F}return l(F,G)}l[A]=B(z,0);l[D]=v=B(z,1);$[y]||($[y]=function(F){return $.extend(C,F)})({a:k,base:k,iframe:t,img:t,input:t,form:"action",link:k,script:t});j=$[y];function s(I,G,H,F){if(!E(H)&&typeof H!=="object"){F=H;H=G;G=i}return this.each(function(){var L=$(this),J=G||j()[(this.nodeName||"").toLowerCase()]||"",K=J&&L.attr(J)||"";L.attr(J,a[I](K,H,F))})}$.fn[A]=B(s,A);$.fn[D]=B(s,D);b.pushState=q=function(I,F){if(E(I)&&/^#/.test(I)&&F===i){F=2}var H=I!==i,G=c(p[g][k],H?I:{},H?F:2);p[g][k]=G+(/#/.test(G)?"":"#")};b.getState=u=function(F,G){return F===i||typeof F==="boolean"?v(F):v(G)[F]};b.removeState=function(F){var G={};if(F!==i){G=u();$.each($.isArray(F)?F:arguments,function(I,H){delete G[H]})}q(G,2)};e[d]=$.extend(e[d],{add:function(F){var H;function G(J){var I=J[D]=c();J.getState=function(K,L){return K===i||typeof K==="boolean"?l(I,K):l(I,L)[K]};H.apply(this,arguments)}if($.isFunction(F)){H=F;return G}else{H=F.handler;F.handler=G}}})})(jQuery,this);
+/*
+ * jQuery hashchange event - v1.2 - 2/11/2010
+ * http://benalman.com/projects/jquery-hashchange-plugin/
+ *
+ * Copyright (c) 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);
diff --git a/catalog-be/src/main/resources/swagger/lib/jquery.slideto.min.js b/catalog-be/src/main/resources/swagger/lib/jquery.slideto.min.js
new file mode 100644
index 0000000000..df80c45ae6
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/jquery.slideto.min.js
@@ -0,0 +1,21 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR 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(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
diff --git a/catalog-be/src/main/resources/swagger/lib/jquery.wiggle.min.js b/catalog-be/src/main/resources/swagger/lib/jquery.wiggle.min.js
new file mode 100644
index 0000000000..0bdb2b2fd3
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/jquery.wiggle.min.js
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/*
+jQuery Wiggle
+Author: WonderGroup, Jordan Thomas
+URL: http://labs.wondergroup.com/demos/mini-ui/index.html
+License: MIT (http://en.wikipedia.org/wiki/MIT_License)
+*/
+jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('<div class="wiggle-wrap"></div>').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
+if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
diff --git a/catalog-be/src/main/resources/swagger/lib/marked.js b/catalog-be/src/main/resources/swagger/lib/marked.js
new file mode 100644
index 0000000000..cfa182fe4d
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/marked.js
@@ -0,0 +1,1292 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * marked - a markdown parser
+ * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
+ * https://github.com/chjj/marked
+ */
+
+;(function() {
+
+/**
+ * Block-Level Grammar
+ */
+
+var block = {
+ newline: /^\n+/,
+ code: /^( {4}[^\n]+\n*)+/,
+ fences: noop,
+ hr: /^( *[-*_]){3,} *(?:\n+|$)/,
+ heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
+ nptable: noop,
+ lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
+ blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
+ list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
+ html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
+ table: noop,
+ paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
+ text: /^[^\n]+/
+};
+
+block.bullet = /(?:[*+-]|\d+\.)/;
+block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
+block.item = replace(block.item, 'gm')
+ (/bull/g, block.bullet)
+ ();
+
+block.list = replace(block.list)
+ (/bull/g, block.bullet)
+ ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
+ ('def', '\\n+(?=' + block.def.source + ')')
+ ();
+
+block.blockquote = replace(block.blockquote)
+ ('def', block.def)
+ ();
+
+block._tag = '(?!(?:'
+ + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
+ + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
+ + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
+
+block.html = replace(block.html)
+ ('comment', /<!--[\s\S]*?-->/)
+ ('closed', /<(tag)[\s\S]+?<\/\1>/)
+ ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
+ (/tag/g, block._tag)
+ ();
+
+block.paragraph = replace(block.paragraph)
+ ('hr', block.hr)
+ ('heading', block.heading)
+ ('lheading', block.lheading)
+ ('blockquote', block.blockquote)
+ ('tag', '<' + block._tag)
+ ('def', block.def)
+ ();
+
+/**
+ * Normal Block Grammar
+ */
+
+block.normal = merge({}, block);
+
+/**
+ * GFM Block Grammar
+ */
+
+block.gfm = merge({}, block.normal, {
+ fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
+ paragraph: /^/
+});
+
+block.gfm.paragraph = replace(block.paragraph)
+ ('(?!', '(?!'
+ + block.gfm.fences.source.replace('\\1', '\\2') + '|'
+ + block.list.source.replace('\\1', '\\3') + '|')
+ ();
+
+/**
+ * GFM + Tables Block Grammar
+ */
+
+block.tables = merge({}, block.gfm, {
+ nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
+ table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
+});
+
+/**
+ * Block Lexer
+ */
+
+function Lexer(options) {
+ this.tokens = [];
+ this.tokens.links = {};
+ this.options = options || marked.defaults;
+ this.rules = block.normal;
+
+ if (this.options.gfm) {
+ if (this.options.tables) {
+ this.rules = block.tables;
+ } else {
+ this.rules = block.gfm;
+ }
+ }
+}
+
+/**
+ * Expose Block Rules
+ */
+
+Lexer.rules = block;
+
+/**
+ * Static Lex Method
+ */
+
+Lexer.lex = function(src, options) {
+ var lexer = new Lexer(options);
+ return lexer.lex(src);
+};
+
+/**
+ * Preprocessing
+ */
+
+Lexer.prototype.lex = function(src) {
+ src = src
+ .replace(/\r\n|\r/g, '\n')
+ .replace(/\t/g, ' ')
+ .replace(/\u00a0/g, ' ')
+ .replace(/\u2424/g, '\n');
+
+ return this.token(src, true);
+};
+
+/**
+ * Lexing
+ */
+
+Lexer.prototype.token = function(src, top, bq) {
+ var src = src.replace(/^ +$/gm, '')
+ , next
+ , loose
+ , cap
+ , bull
+ , b
+ , item
+ , space
+ , i
+ , l;
+
+ while (src) {
+ // newline
+ if (cap = this.rules.newline.exec(src)) {
+ src = src.substring(cap[0].length);
+ if (cap[0].length > 1) {
+ this.tokens.push({
+ type: 'space'
+ });
+ }
+ }
+
+ // code
+ if (cap = this.rules.code.exec(src)) {
+ src = src.substring(cap[0].length);
+ cap = cap[0].replace(/^ {4}/gm, '');
+ this.tokens.push({
+ type: 'code',
+ text: !this.options.pedantic
+ ? cap.replace(/\n+$/, '')
+ : cap
+ });
+ continue;
+ }
+
+ // fences (gfm)
+ if (cap = this.rules.fences.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'code',
+ lang: cap[2],
+ text: cap[3]
+ });
+ continue;
+ }
+
+ // heading
+ if (cap = this.rules.heading.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'heading',
+ depth: cap[1].length,
+ text: cap[2]
+ });
+ continue;
+ }
+
+ // table no leading pipe (gfm)
+ if (top && (cap = this.rules.nptable.exec(src))) {
+ src = src.substring(cap[0].length);
+
+ item = {
+ type: 'table',
+ header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
+ cells: cap[3].replace(/\n$/, '').split('\n')
+ };
+
+ for (i = 0; i < item.align.length; i++) {
+ if (/^ *-+: *$/.test(item.align[i])) {
+ item.align[i] = 'right';
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
+ item.align[i] = 'center';
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
+ item.align[i] = 'left';
+ } else {
+ item.align[i] = null;
+ }
+ }
+
+ for (i = 0; i < item.cells.length; i++) {
+ item.cells[i] = item.cells[i].split(/ *\| */);
+ }
+
+ this.tokens.push(item);
+
+ continue;
+ }
+
+ // lheading
+ if (cap = this.rules.lheading.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'heading',
+ depth: cap[2] === '=' ? 1 : 2,
+ text: cap[1]
+ });
+ continue;
+ }
+
+ // hr
+ if (cap = this.rules.hr.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'hr'
+ });
+ continue;
+ }
+
+ // blockquote
+ if (cap = this.rules.blockquote.exec(src)) {
+ src = src.substring(cap[0].length);
+
+ this.tokens.push({
+ type: 'blockquote_start'
+ });
+
+ cap = cap[0].replace(/^ *> ?/gm, '');
+
+ // Pass `top` to keep the current
+ // "toplevel" state. This is exactly
+ // how markdown.pl works.
+ this.token(cap, top, true);
+
+ this.tokens.push({
+ type: 'blockquote_end'
+ });
+
+ continue;
+ }
+
+ // list
+ if (cap = this.rules.list.exec(src)) {
+ src = src.substring(cap[0].length);
+ bull = cap[2];
+
+ this.tokens.push({
+ type: 'list_start',
+ ordered: bull.length > 1
+ });
+
+ // Get each top-level item.
+ cap = cap[0].match(this.rules.item);
+
+ next = false;
+ l = cap.length;
+ i = 0;
+
+ for (; i < l; i++) {
+ item = cap[i];
+
+ // Remove the list item's bullet
+ // so it is seen as the next token.
+ space = item.length;
+ item = item.replace(/^ *([*+-]|\d+\.) +/, '');
+
+ // Outdent whatever the
+ // list item contains. Hacky.
+ if (~item.indexOf('\n ')) {
+ space -= item.length;
+ item = !this.options.pedantic
+ ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
+ : item.replace(/^ {1,4}/gm, '');
+ }
+
+ // Determine whether the next list item belongs here.
+ // Backpedal if it does not belong in this list.
+ if (this.options.smartLists && i !== l - 1) {
+ b = block.bullet.exec(cap[i + 1])[0];
+ if (bull !== b && !(bull.length > 1 && b.length > 1)) {
+ src = cap.slice(i + 1).join('\n') + src;
+ i = l - 1;
+ }
+ }
+
+ // Determine whether item is loose or not.
+ // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
+ // for discount behavior.
+ loose = next || /\n\n(?!\s*$)/.test(item);
+ if (i !== l - 1) {
+ next = item.charAt(item.length - 1) === '\n';
+ if (!loose) loose = next;
+ }
+
+ this.tokens.push({
+ type: loose
+ ? 'loose_item_start'
+ : 'list_item_start'
+ });
+
+ // Recurse.
+ this.token(item, false, bq);
+
+ this.tokens.push({
+ type: 'list_item_end'
+ });
+ }
+
+ this.tokens.push({
+ type: 'list_end'
+ });
+
+ continue;
+ }
+
+ // html
+ if (cap = this.rules.html.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: this.options.sanitize
+ ? 'paragraph'
+ : 'html',
+ pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
+ text: cap[0]
+ });
+ continue;
+ }
+
+ // def
+ if ((!bq && top) && (cap = this.rules.def.exec(src))) {
+ src = src.substring(cap[0].length);
+ this.tokens.links[cap[1].toLowerCase()] = {
+ href: cap[2],
+ title: cap[3]
+ };
+ continue;
+ }
+
+ // table (gfm)
+ if (top && (cap = this.rules.table.exec(src))) {
+ src = src.substring(cap[0].length);
+
+ item = {
+ type: 'table',
+ header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
+ cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
+ };
+
+ for (i = 0; i < item.align.length; i++) {
+ if (/^ *-+: *$/.test(item.align[i])) {
+ item.align[i] = 'right';
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
+ item.align[i] = 'center';
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
+ item.align[i] = 'left';
+ } else {
+ item.align[i] = null;
+ }
+ }
+
+ for (i = 0; i < item.cells.length; i++) {
+ item.cells[i] = item.cells[i]
+ .replace(/^ *\| *| *\| *$/g, '')
+ .split(/ *\| */);
+ }
+
+ this.tokens.push(item);
+
+ continue;
+ }
+
+ // top-level paragraph
+ if (top && (cap = this.rules.paragraph.exec(src))) {
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'paragraph',
+ text: cap[1].charAt(cap[1].length - 1) === '\n'
+ ? cap[1].slice(0, -1)
+ : cap[1]
+ });
+ continue;
+ }
+
+ // text
+ if (cap = this.rules.text.exec(src)) {
+ // Top-level should never reach here.
+ src = src.substring(cap[0].length);
+ this.tokens.push({
+ type: 'text',
+ text: cap[0]
+ });
+ continue;
+ }
+
+ if (src) {
+ throw new
+ Error('Infinite loop on byte: ' + src.charCodeAt(0));
+ }
+ }
+
+ return this.tokens;
+};
+
+/**
+ * Inline-Level Grammar
+ */
+
+var inline = {
+ escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
+ autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
+ url: noop,
+ tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
+ link: /^!?\[(inside)\]\(href\)/,
+ reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
+ nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
+ strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
+ em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
+ code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
+ br: /^ {2,}\n(?!\s*$)/,
+ del: noop,
+ text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
+};
+
+inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
+inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
+
+inline.link = replace(inline.link)
+ ('inside', inline._inside)
+ ('href', inline._href)
+ ();
+
+inline.reflink = replace(inline.reflink)
+ ('inside', inline._inside)
+ ();
+
+/**
+ * Normal Inline Grammar
+ */
+
+inline.normal = merge({}, inline);
+
+/**
+ * Pedantic Inline Grammar
+ */
+
+inline.pedantic = merge({}, inline.normal, {
+ strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
+ em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
+});
+
+/**
+ * GFM Inline Grammar
+ */
+
+inline.gfm = merge({}, inline.normal, {
+ escape: replace(inline.escape)('])', '~|])')(),
+ url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
+ del: /^~~(?=\S)([\s\S]*?\S)~~/,
+ text: replace(inline.text)
+ (']|', '~]|')
+ ('|', '|https?://|')
+ ()
+});
+
+/**
+ * GFM + Line Breaks Inline Grammar
+ */
+
+inline.breaks = merge({}, inline.gfm, {
+ br: replace(inline.br)('{2,}', '*')(),
+ text: replace(inline.gfm.text)('{2,}', '*')()
+});
+
+/**
+ * Inline Lexer & Compiler
+ */
+
+function InlineLexer(links, options) {
+ this.options = options || marked.defaults;
+ this.links = links;
+ this.rules = inline.normal;
+ this.renderer = this.options.renderer || new Renderer;
+ this.renderer.options = this.options;
+
+ if (!this.links) {
+ throw new
+ Error('Tokens array requires a `links` property.');
+ }
+
+ if (this.options.gfm) {
+ if (this.options.breaks) {
+ this.rules = inline.breaks;
+ } else {
+ this.rules = inline.gfm;
+ }
+ } else if (this.options.pedantic) {
+ this.rules = inline.pedantic;
+ }
+}
+
+/**
+ * Expose Inline Rules
+ */
+
+InlineLexer.rules = inline;
+
+/**
+ * Static Lexing/Compiling Method
+ */
+
+InlineLexer.output = function(src, links, options) {
+ var inline = new InlineLexer(links, options);
+ return inline.output(src);
+};
+
+/**
+ * Lexing/Compiling
+ */
+
+InlineLexer.prototype.output = function(src) {
+ var out = ''
+ , link
+ , text
+ , href
+ , cap;
+
+ while (src) {
+ // escape
+ if (cap = this.rules.escape.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += cap[1];
+ continue;
+ }
+
+ // autolink
+ if (cap = this.rules.autolink.exec(src)) {
+ src = src.substring(cap[0].length);
+ if (cap[2] === '@') {
+ text = cap[1].charAt(6) === ':'
+ ? this.mangle(cap[1].substring(7))
+ : this.mangle(cap[1]);
+ href = this.mangle('mailto:') + text;
+ } else {
+ text = escape(cap[1]);
+ href = text;
+ }
+ out += this.renderer.link(href, null, text);
+ continue;
+ }
+
+ // url (gfm)
+ if (!this.inLink && (cap = this.rules.url.exec(src))) {
+ src = src.substring(cap[0].length);
+ text = escape(cap[1]);
+ href = text;
+ out += this.renderer.link(href, null, text);
+ continue;
+ }
+
+ // tag
+ if (cap = this.rules.tag.exec(src)) {
+ if (!this.inLink && /^<a /i.test(cap[0])) {
+ this.inLink = true;
+ } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
+ this.inLink = false;
+ }
+ src = src.substring(cap[0].length);
+ out += this.options.sanitize
+ ? escape(cap[0])
+ : cap[0];
+ continue;
+ }
+
+ // link
+ if (cap = this.rules.link.exec(src)) {
+ src = src.substring(cap[0].length);
+ this.inLink = true;
+ out += this.outputLink(cap, {
+ href: cap[2],
+ title: cap[3]
+ });
+ this.inLink = false;
+ continue;
+ }
+
+ // reflink, nolink
+ if ((cap = this.rules.reflink.exec(src))
+ || (cap = this.rules.nolink.exec(src))) {
+ src = src.substring(cap[0].length);
+ link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
+ link = this.links[link.toLowerCase()];
+ if (!link || !link.href) {
+ out += cap[0].charAt(0);
+ src = cap[0].substring(1) + src;
+ continue;
+ }
+ this.inLink = true;
+ out += this.outputLink(cap, link);
+ this.inLink = false;
+ continue;
+ }
+
+ // strong
+ if (cap = this.rules.strong.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.strong(this.output(cap[2] || cap[1]));
+ continue;
+ }
+
+ // em
+ if (cap = this.rules.em.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.em(this.output(cap[2] || cap[1]));
+ continue;
+ }
+
+ // code
+ if (cap = this.rules.code.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.codespan(escape(cap[2], true));
+ continue;
+ }
+
+ // br
+ if (cap = this.rules.br.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.br();
+ continue;
+ }
+
+ // del (gfm)
+ if (cap = this.rules.del.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += this.renderer.del(this.output(cap[1]));
+ continue;
+ }
+
+ // text
+ if (cap = this.rules.text.exec(src)) {
+ src = src.substring(cap[0].length);
+ out += escape(this.smartypants(cap[0]));
+ continue;
+ }
+
+ if (src) {
+ throw new
+ Error('Infinite loop on byte: ' + src.charCodeAt(0));
+ }
+ }
+
+ return out;
+};
+
+/**
+ * Compile Link
+ */
+
+InlineLexer.prototype.outputLink = function(cap, link) {
+ var href = escape(link.href)
+ , title = link.title ? escape(link.title) : null;
+
+ return cap[0].charAt(0) !== '!'
+ ? this.renderer.link(href, title, this.output(cap[1]))
+ : this.renderer.image(href, title, escape(cap[1]));
+};
+
+/**
+ * Smartypants Transformations
+ */
+
+InlineLexer.prototype.smartypants = function(text) {
+ if (!this.options.smartypants) return text;
+ return text
+ // em-dashes
+ .replace(/--/g, '\u2014')
+ // opening singles
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
+ // closing singles & apostrophes
+ .replace(/'/g, '\u2019')
+ // opening doubles
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
+ // closing doubles
+ .replace(/"/g, '\u201d')
+ // ellipses
+ .replace(/\.{3}/g, '\u2026');
+};
+
+/**
+ * Mangle Links
+ */
+
+InlineLexer.prototype.mangle = function(text) {
+ var out = ''
+ , l = text.length
+ , i = 0
+ , ch;
+
+ for (; i < l; i++) {
+ ch = text.charCodeAt(i);
+ if (Math.random() > 0.5) {
+ ch = 'x' + ch.toString(16);
+ }
+ out += '&#' + ch + ';';
+ }
+
+ return out;
+};
+
+/**
+ * Renderer
+ */
+
+function Renderer(options) {
+ this.options = options || {};
+}
+
+Renderer.prototype.code = function(code, lang, escaped) {
+ if (this.options.highlight) {
+ var out = this.options.highlight(code, lang);
+ if (out != null && out !== code) {
+ escaped = true;
+ code = out;
+ }
+ }
+
+ if (!lang) {
+ return '<pre><code>'
+ + (escaped ? code : escape(code, true))
+ + '\n</code></pre>';
+ }
+
+ return '<pre><code class="'
+ + this.options.langPrefix
+ + escape(lang, true)
+ + '">'
+ + (escaped ? code : escape(code, true))
+ + '\n</code></pre>\n';
+};
+
+Renderer.prototype.blockquote = function(quote) {
+ return '<blockquote>\n' + quote + '</blockquote>\n';
+};
+
+Renderer.prototype.html = function(html) {
+ return html;
+};
+
+Renderer.prototype.heading = function(text, level, raw) {
+ return '<h'
+ + level
+ + ' id="'
+ + this.options.headerPrefix
+ + raw.toLowerCase().replace(/[^\w]+/g, '-')
+ + '">'
+ + text
+ + '</h'
+ + level
+ + '>\n';
+};
+
+Renderer.prototype.hr = function() {
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
+};
+
+Renderer.prototype.list = function(body, ordered) {
+ var type = ordered ? 'ol' : 'ul';
+ return '<' + type + '>\n' + body + '</' + type + '>\n';
+};
+
+Renderer.prototype.listitem = function(text) {
+ return '<li>' + text + '</li>\n';
+};
+
+Renderer.prototype.paragraph = function(text) {
+ return '<p>' + text + '</p>\n';
+};
+
+Renderer.prototype.table = function(header, body) {
+ return '<table>\n'
+ + '<thead>\n'
+ + header
+ + '</thead>\n'
+ + '<tbody>\n'
+ + body
+ + '</tbody>\n'
+ + '</table>\n';
+};
+
+Renderer.prototype.tablerow = function(content) {
+ return '<tr>\n' + content + '</tr>\n';
+};
+
+Renderer.prototype.tablecell = function(content, flags) {
+ var type = flags.header ? 'th' : 'td';
+ var tag = flags.align
+ ? '<' + type + ' style="text-align:' + flags.align + '">'
+ : '<' + type + '>';
+ return tag + content + '</' + type + '>\n';
+};
+
+// span level renderer
+Renderer.prototype.strong = function(text) {
+ return '<strong>' + text + '</strong>';
+};
+
+Renderer.prototype.em = function(text) {
+ return '<em>' + text + '</em>';
+};
+
+Renderer.prototype.codespan = function(text) {
+ return '<code>' + text + '</code>';
+};
+
+Renderer.prototype.br = function() {
+ return this.options.xhtml ? '<br/>' : '<br>';
+};
+
+Renderer.prototype.del = function(text) {
+ return '<del>' + text + '</del>';
+};
+
+Renderer.prototype.link = function(href, title, text) {
+ if (this.options.sanitize) {
+ try {
+ var prot = decodeURIComponent(unescape(href))
+ .replace(/[^\w:]/g, '')
+ .toLowerCase();
+ } catch (e) {
+ return '';
+ }
+ if (prot.indexOf('javascript:') === 0) {
+ return '';
+ }
+ }
+ var out = '<a href="' + href + '"';
+ if (title) {
+ out += ' title="' + title + '"';
+ }
+ out += '>' + text + '</a>';
+ return out;
+};
+
+Renderer.prototype.image = function(href, title, text) {
+ var out = '<img src="' + href + '" alt="' + text + '"';
+ if (title) {
+ out += ' title="' + title + '"';
+ }
+ out += this.options.xhtml ? '/>' : '>';
+ return out;
+};
+
+/**
+ * Parsing & Compiling
+ */
+
+function Parser(options) {
+ this.tokens = [];
+ this.token = null;
+ this.options = options || marked.defaults;
+ this.options.renderer = this.options.renderer || new Renderer;
+ this.renderer = this.options.renderer;
+ this.renderer.options = this.options;
+}
+
+/**
+ * Static Parse Method
+ */
+
+Parser.parse = function(src, options, renderer) {
+ var parser = new Parser(options, renderer);
+ return parser.parse(src);
+};
+
+/**
+ * Parse Loop
+ */
+
+Parser.prototype.parse = function(src) {
+ this.inline = new InlineLexer(src.links, this.options, this.renderer);
+ this.tokens = src.reverse();
+
+ var out = '';
+ while (this.next()) {
+ out += this.tok();
+ }
+
+ return out;
+};
+
+/**
+ * Next Token
+ */
+
+Parser.prototype.next = function() {
+ return this.token = this.tokens.pop();
+};
+
+/**
+ * Preview Next Token
+ */
+
+Parser.prototype.peek = function() {
+ return this.tokens[this.tokens.length - 1] || 0;
+};
+
+/**
+ * Parse Text Tokens
+ */
+
+Parser.prototype.parseText = function() {
+ var body = this.token.text;
+
+ while (this.peek().type === 'text') {
+ body += '\n' + this.next().text;
+ }
+
+ return this.inline.output(body);
+};
+
+/**
+ * Parse Current Token
+ */
+
+Parser.prototype.tok = function() {
+ switch (this.token.type) {
+ case 'space': {
+ return '';
+ }
+ case 'hr': {
+ return this.renderer.hr();
+ }
+ case 'heading': {
+ return this.renderer.heading(
+ this.inline.output(this.token.text),
+ this.token.depth,
+ this.token.text);
+ }
+ case 'code': {
+ return this.renderer.code(this.token.text,
+ this.token.lang,
+ this.token.escaped);
+ }
+ case 'table': {
+ var header = ''
+ , body = ''
+ , i
+ , row
+ , cell
+ , flags
+ , j;
+
+ // header
+ cell = '';
+ for (i = 0; i < this.token.header.length; i++) {
+ flags = { header: true, align: this.token.align[i] };
+ cell += this.renderer.tablecell(
+ this.inline.output(this.token.header[i]),
+ { header: true, align: this.token.align[i] }
+ );
+ }
+ header += this.renderer.tablerow(cell);
+
+ for (i = 0; i < this.token.cells.length; i++) {
+ row = this.token.cells[i];
+
+ cell = '';
+ for (j = 0; j < row.length; j++) {
+ cell += this.renderer.tablecell(
+ this.inline.output(row[j]),
+ { header: false, align: this.token.align[j] }
+ );
+ }
+
+ body += this.renderer.tablerow(cell);
+ }
+ return this.renderer.table(header, body);
+ }
+ case 'blockquote_start': {
+ var body = '';
+
+ while (this.next().type !== 'blockquote_end') {
+ body += this.tok();
+ }
+
+ return this.renderer.blockquote(body);
+ }
+ case 'list_start': {
+ var body = ''
+ , ordered = this.token.ordered;
+
+ while (this.next().type !== 'list_end') {
+ body += this.tok();
+ }
+
+ return this.renderer.list(body, ordered);
+ }
+ case 'list_item_start': {
+ var body = '';
+
+ while (this.next().type !== 'list_item_end') {
+ body += this.token.type === 'text'
+ ? this.parseText()
+ : this.tok();
+ }
+
+ return this.renderer.listitem(body);
+ }
+ case 'loose_item_start': {
+ var body = '';
+
+ while (this.next().type !== 'list_item_end') {
+ body += this.tok();
+ }
+
+ return this.renderer.listitem(body);
+ }
+ case 'html': {
+ var html = !this.token.pre && !this.options.pedantic
+ ? this.inline.output(this.token.text)
+ : this.token.text;
+ return this.renderer.html(html);
+ }
+ case 'paragraph': {
+ return this.renderer.paragraph(this.inline.output(this.token.text));
+ }
+ case 'text': {
+ return this.renderer.paragraph(this.parseText());
+ }
+ }
+};
+
+/**
+ * Helpers
+ */
+
+function escape(html, encode) {
+ return html
+ .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&#39;');
+}
+
+function unescape(html) {
+ return html.replace(/&([#\w]+);/g, function(_, n) {
+ n = n.toLowerCase();
+ if (n === 'colon') return ':';
+ if (n.charAt(0) === '#') {
+ return n.charAt(1) === 'x'
+ ? String.fromCharCode(parseInt(n.substring(2), 16))
+ : String.fromCharCode(+n.substring(1));
+ }
+ return '';
+ });
+}
+
+function replace(regex, opt) {
+ regex = regex.source;
+ opt = opt || '';
+ return function self(name, val) {
+ if (!name) return new RegExp(regex, opt);
+ val = val.source || val;
+ val = val.replace(/(^|[^\[])\^/g, '$1');
+ regex = regex.replace(name, val);
+ return self;
+ };
+}
+
+function noop() {}
+noop.exec = noop;
+
+function merge(obj) {
+ var i = 1
+ , target
+ , key;
+
+ for (; i < arguments.length; i++) {
+ target = arguments[i];
+ for (key in target) {
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
+ obj[key] = target[key];
+ }
+ }
+ }
+
+ return obj;
+}
+
+
+/**
+ * Marked
+ */
+
+function marked(src, opt, callback) {
+ if (callback || typeof opt === 'function') {
+ if (!callback) {
+ callback = opt;
+ opt = null;
+ }
+
+ opt = merge({}, marked.defaults, opt || {});
+
+ var highlight = opt.highlight
+ , tokens
+ , pending
+ , i = 0;
+
+ try {
+ tokens = Lexer.lex(src, opt)
+ } catch (e) {
+ return callback(e);
+ }
+
+ pending = tokens.length;
+
+ var done = function(err) {
+ if (err) {
+ opt.highlight = highlight;
+ return callback(err);
+ }
+
+ var out;
+
+ try {
+ out = Parser.parse(tokens, opt);
+ } catch (e) {
+ err = e;
+ }
+
+ opt.highlight = highlight;
+
+ return err
+ ? callback(err)
+ : callback(null, out);
+ };
+
+ if (!highlight || highlight.length < 3) {
+ return done();
+ }
+
+ delete opt.highlight;
+
+ if (!pending) return done();
+
+ for (; i < tokens.length; i++) {
+ (function(token) {
+ if (token.type !== 'code') {
+ return --pending || done();
+ }
+ return highlight(token.text, token.lang, function(err, code) {
+ if (err) return done(err);
+ if (code == null || code === token.text) {
+ return --pending || done();
+ }
+ token.text = code;
+ token.escaped = true;
+ --pending || done();
+ });
+ })(tokens[i]);
+ }
+
+ return;
+ }
+ try {
+ if (opt) opt = merge({}, marked.defaults, opt);
+ return Parser.parse(Lexer.lex(src, opt), opt);
+ } catch (e) {
+ e.message += '\nPlease report this to https://github.com/chjj/marked.';
+ if ((opt || marked.defaults).silent) {
+ return '<p>An error occured:</p><pre>'
+ + escape(e.message + '', true)
+ + '</pre>';
+ }
+ throw e;
+ }
+}
+
+/**
+ * Options
+ */
+
+marked.options =
+marked.setOptions = function(opt) {
+ merge(marked.defaults, opt);
+ return marked;
+};
+
+marked.defaults = {
+ gfm: true,
+ tables: true,
+ breaks: false,
+ pedantic: false,
+ sanitize: false,
+ smartLists: false,
+ silent: false,
+ highlight: null,
+ langPrefix: 'lang-',
+ smartypants: false,
+ headerPrefix: '',
+ renderer: new Renderer,
+ xhtml: false
+};
+
+/**
+ * Expose
+ */
+
+marked.Parser = Parser;
+marked.parser = Parser.parse;
+
+marked.Renderer = Renderer;
+
+marked.Lexer = Lexer;
+marked.lexer = Lexer.lex;
+
+marked.InlineLexer = InlineLexer;
+marked.inlineLexer = InlineLexer.output;
+
+marked.parse = marked;
+
+if (typeof module !== 'undefined' && typeof exports === 'object') {
+ module.exports = marked;
+} else if (typeof define === 'function' && define.amd) {
+ define(function() { return marked; });
+} else {
+ this.marked = marked;
+}
+
+}).call(function() {
+ return this || (typeof window !== 'undefined' ? window : global);
+}());
diff --git a/catalog-be/src/main/resources/swagger/lib/swagger-oauth.js b/catalog-be/src/main/resources/swagger/lib/swagger-oauth.js
new file mode 100644
index 0000000000..d44bdf8fde
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/swagger-oauth.js
@@ -0,0 +1,304 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR 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 appName;
+var popupMask;
+var popupDialog;
+var clientId;
+var realm;
+var oauth2KeyName;
+var redirect_uri;
+
+function handleLogin() {
+ var scopes = [];
+
+ var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
+ if(auths) {
+ var key;
+ var defs = auths;
+ for(key in defs) {
+ var auth = defs[key];
+ if(auth.type === 'oauth2' && auth.scopes) {
+ oauth2KeyName = key;
+ var scope;
+ if(Array.isArray(auth.scopes)) {
+ // 1.2 support
+ var i;
+ for(i = 0; i < auth.scopes.length; i++) {
+ scopes.push(auth.scopes[i]);
+ }
+ }
+ else {
+ // 2.0 support
+ for(scope in auth.scopes) {
+ scopes.push({scope: scope, description: auth.scopes[scope]});
+ }
+ }
+ }
+ }
+ }
+
+ if(window.swaggerUi.api
+ && window.swaggerUi.api.info) {
+ appName = window.swaggerUi.api.info.title;
+ }
+
+ popupDialog = $(
+ [
+ '<div class="api-popup-dialog">',
+ '<div class="api-popup-title">Select OAuth2.0 Scopes</div>',
+ '<div class="api-popup-content">',
+ '<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.',
+ '<a href="#">Learn how to use</a>',
+ '</p>',
+ '<p><strong>' + appName + '</strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>',
+ '<ul class="api-popup-scopes">',
+ '</ul>',
+ '<p class="error-msg"></p>',
+ '<div class="api-popup-actions"><button class="api-popup-authbtn api-button green" type="button">Authorize</button><button class="api-popup-cancel api-button gray" type="button">Cancel</button></div>',
+ '</div>',
+ '</div>'].join(''));
+ $(document.body).append(popupDialog);
+
+ popup = popupDialog.find('ul.api-popup-scopes').empty();
+ for (i = 0; i < scopes.length; i ++) {
+ scope = scopes[i];
+ str = '<li><input type="checkbox" id="scope_' + i + '" scope="' + scope.scope + '"/>' + '<label for="scope_' + i + '">' + scope.scope;
+ if (scope.description) {
+ str += '<br/><span class="api-scope-desc">' + scope.description + '</span>';
+ }
+ str += '</label></li>';
+ popup.append(str);
+ }
+
+ var $win = $(window),
+ dw = $win.width(),
+ dh = $win.height(),
+ st = $win.scrollTop(),
+ dlgWd = popupDialog.outerWidth(),
+ dlgHt = popupDialog.outerHeight(),
+ top = (dh -dlgHt)/2 + st,
+ left = (dw - dlgWd)/2;
+
+ popupDialog.css({
+ top: (top < 0? 0 : top) + 'px',
+ left: (left < 0? 0 : left) + 'px'
+ });
+
+ popupDialog.find('button.api-popup-cancel').click(function() {
+ popupMask.hide();
+ popupDialog.hide();
+ popupDialog.empty();
+ popupDialog = [];
+ });
+
+ $('button.api-popup-authbtn').unbind();
+ popupDialog.find('button.api-popup-authbtn').click(function() {
+ popupMask.hide();
+ popupDialog.hide();
+
+ var authSchemes = window.swaggerUi.api.authSchemes;
+ var host = window.location;
+ var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/"));
+ var defaultRedirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
+ var redirectUrl = window.oAuthRedirectUrl || defaultRedirectUrl;
+ var url = null;
+
+ for (var key in authSchemes) {
+ if (authSchemes.hasOwnProperty(key)) {
+ var flow = authSchemes[key].flow;
+
+ if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
+ var dets = authSchemes[key];
+ url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
+ window.swaggerUi.tokenName = dets.tokenName || 'access_token';
+ window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
+ }
+ else if(authSchemes[key].grantTypes) {
+ // 1.2 support
+ var o = authSchemes[key].grantTypes;
+ for(var t in o) {
+ if(o.hasOwnProperty(t) && t === 'implicit') {
+ var dets = o[t];
+ var ep = dets.loginEndpoint.url;
+ url = dets.loginEndpoint.url + '?response_type=token';
+ window.swaggerUi.tokenName = dets.tokenName;
+ }
+ else if (o.hasOwnProperty(t) && t === 'accessCode') {
+ var dets = o[t];
+ var ep = dets.tokenRequestEndpoint.url;
+ url = dets.tokenRequestEndpoint.url + '?response_type=code';
+ window.swaggerUi.tokenName = dets.tokenName;
+ }
+ }
+ }
+ }
+ }
+ var scopes = []
+ var o = $('.api-popup-scopes').find('input:checked');
+
+ for(k =0; k < o.length; k++) {
+ var scope = $(o[k]).attr('scope');
+
+ if (scopes.indexOf(scope) === -1)
+ scopes.push(scope);
+ }
+
+ // Implicit auth recommends a state parameter.
+ var state = Math.random ();
+
+ window.enabledScopes=scopes;
+
+ redirect_uri = redirectUrl;
+
+ url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
+ url += '&realm=' + encodeURIComponent(realm);
+ url += '&client_id=' + encodeURIComponent(clientId);
+ url += '&scope=' + encodeURIComponent(scopes.join(' '));
+ url += '&state=' + encodeURIComponent(state);
+
+ window.open(url);
+ });
+
+ popupMask.show();
+ popupDialog.show();
+ return;
+}
+
+
+function handleLogout() {
+ for(key in window.authorizations.authz){
+ window.authorizations.remove(key)
+ }
+ window.enabledScopes = null;
+ $('.api-ic.ic-on').addClass('ic-off');
+ $('.api-ic.ic-on').removeClass('ic-on');
+
+ // set the info box
+ $('.api-ic.ic-warning').addClass('ic-error');
+ $('.api-ic.ic-warning').removeClass('ic-warning');
+}
+
+function initOAuth(opts) {
+ var o = (opts||{});
+ var errors = [];
+
+ appName = (o.appName||errors.push('missing appName'));
+ popupMask = (o.popupMask||$('#api-common-mask'));
+ popupDialog = (o.popupDialog||$('.api-popup-dialog'));
+ clientId = (o.clientId||errors.push('missing client id'));
+ realm = (o.realm||errors.push('missing realm'));
+
+ if(errors.length > 0){
+ log('auth unable initialize oauth: ' + errors);
+ return;
+ }
+
+ $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
+ $('.api-ic').unbind();
+ $('.api-ic').click(function(s) {
+ if($(s.target).hasClass('ic-off'))
+ handleLogin();
+ else {
+ handleLogout();
+ }
+ false;
+ });
+}
+
+window.processOAuthCode = function processOAuthCode(data) {
+ var params = {
+ 'client_id': clientId,
+ 'code': data.code,
+ 'grant_type': 'authorization_code',
+ 'redirect_uri': redirect_uri
+ }
+ $.ajax(
+ {
+ url : window.swaggerUi.tokenUrl,
+ type: "POST",
+ data: params,
+ success:function(data, textStatus, jqXHR)
+ {
+ onOAuthComplete(data);
+ },
+ error: function(jqXHR, textStatus, errorThrown)
+ {
+ onOAuthComplete("");
+ }
+ });
+}
+
+window.onOAuthComplete = function onOAuthComplete(token) {
+ if(token) {
+ if(token.error) {
+ var checkbox = $('input[type=checkbox],.secured')
+ checkbox.each(function(pos){
+ checkbox[pos].checked = false;
+ });
+ alert(token.error);
+ }
+ else {
+ var b = token[window.swaggerUi.tokenName];
+ if(b){
+ // if all roles are satisfied
+ var o = null;
+ $.each($('.auth #api_information_panel'), function(k, v) {
+ var children = v;
+ if(children && children.childNodes) {
+ var requiredScopes = [];
+ $.each((children.childNodes), function (k1, v1){
+ var inner = v1.innerHTML;
+ if(inner)
+ requiredScopes.push(inner);
+ });
+ var diff = [];
+ for(var i=0; i < requiredScopes.length; i++) {
+ var s = requiredScopes[i];
+ if(window.enabledScopes && window.enabledScopes.indexOf(s) == -1) {
+ diff.push(s);
+ }
+ }
+ if(diff.length > 0){
+ o = v.parentNode;
+ $(o.parentNode).find('.api-ic.ic-on').addClass('ic-off');
+ $(o.parentNode).find('.api-ic.ic-on').removeClass('ic-on');
+
+ // sorry, not all scopes are satisfied
+ $(o).find('.api-ic').addClass('ic-warning');
+ $(o).find('.api-ic').removeClass('ic-error');
+ }
+ else {
+ o = v.parentNode;
+ $(o.parentNode).find('.api-ic.ic-off').addClass('ic-on');
+ $(o.parentNode).find('.api-ic.ic-off').removeClass('ic-off');
+
+ // all scopes are satisfied
+ $(o).find('.api-ic').addClass('ic-info');
+ $(o).find('.api-ic').removeClass('ic-warning');
+ $(o).find('.api-ic').removeClass('ic-error');
+ }
+ }
+ });
+ window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/resources/swagger/lib/underscore-min.js b/catalog-be/src/main/resources/swagger/lib/underscore-min.js
new file mode 100644
index 0000000000..56cf7330d2
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/underscore-min.js
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+// Underscore.js 1.7.0
+// http://underscorejs.org
+// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// Underscore may be freely distributed under the MIT license.
+(function(){var n=this,t=n._,r=Array.prototype,e=Object.prototype,u=Function.prototype,i=r.push,a=r.slice,o=r.concat,l=e.toString,c=e.hasOwnProperty,f=Array.isArray,s=Object.keys,p=u.bind,h=function(n){return n instanceof h?n:this instanceof h?void(this._wrapped=n):new h(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=h),exports._=h):n._=h,h.VERSION="1.7.0";var g=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}};h.iteratee=function(n,t,r){return null==n?h.identity:h.isFunction(n)?g(n,t,r):h.isObject(n)?h.matches(n):h.property(n)},h.each=h.forEach=function(n,t,r){if(null==n)return n;t=g(t,r);var e,u=n.length;if(u===+u)for(e=0;u>e;e++)t(n[e],e,n);else{var i=h.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},h.map=h.collect=function(n,t,r){if(null==n)return[];t=h.iteratee(t,r);for(var e,u=n.length!==+n.length&&h.keys(n),i=(u||n).length,a=Array(i),o=0;i>o;o++)e=u?u[o]:o,a[o]=t(n[e],e,n);return a};var v="Reduce of empty array with no initial value";h.reduce=h.foldl=h.inject=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length,o=0;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[o++]:o++]}for(;a>o;o++)u=i?i[o]:o,r=t(r,n[u],u,n);return r},h.reduceRight=h.foldr=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[--a]:--a]}for(;a--;)u=i?i[a]:a,r=t(r,n[u],u,n);return r},h.find=h.detect=function(n,t,r){var e;return t=h.iteratee(t,r),h.some(n,function(n,r,u){return t(n,r,u)?(e=n,!0):void 0}),e},h.filter=h.select=function(n,t,r){var e=[];return null==n?e:(t=h.iteratee(t,r),h.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e)},h.reject=function(n,t,r){return h.filter(n,h.negate(h.iteratee(t)),r)},h.every=h.all=function(n,t,r){if(null==n)return!0;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,!t(n[u],u,n))return!1;return!0},h.some=h.any=function(n,t,r){if(null==n)return!1;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,t(n[u],u,n))return!0;return!1},h.contains=h.include=function(n,t){return null==n?!1:(n.length!==+n.length&&(n=h.values(n)),h.indexOf(n,t)>=0)},h.invoke=function(n,t){var r=a.call(arguments,2),e=h.isFunction(t);return h.map(n,function(n){return(e?t:n[t]).apply(n,r)})},h.pluck=function(n,t){return h.map(n,h.property(t))},h.where=function(n,t){return h.filter(n,h.matches(t))},h.findWhere=function(n,t){return h.find(n,h.matches(t))},h.max=function(n,t,r){var e,u,i=-1/0,a=-1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],e>i&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(u>a||u===-1/0&&i===-1/0)&&(i=n,a=u)});return i},h.min=function(n,t,r){var e,u,i=1/0,a=1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],i>e&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(a>u||1/0===u&&1/0===i)&&(i=n,a=u)});return i},h.shuffle=function(n){for(var t,r=n&&n.length===+n.length?n:h.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=h.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},h.sample=function(n,t,r){return null==t||r?(n.length!==+n.length&&(n=h.values(n)),n[h.random(n.length-1)]):h.shuffle(n).slice(0,Math.max(0,t))},h.sortBy=function(n,t,r){return t=h.iteratee(t,r),h.pluck(h.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var m=function(n){return function(t,r,e){var u={};return r=h.iteratee(r,e),h.each(t,function(e,i){var a=r(e,i,t);n(u,e,a)}),u}};h.groupBy=m(function(n,t,r){h.has(n,r)?n[r].push(t):n[r]=[t]}),h.indexBy=m(function(n,t,r){n[r]=t}),h.countBy=m(function(n,t,r){h.has(n,r)?n[r]++:n[r]=1}),h.sortedIndex=function(n,t,r,e){r=h.iteratee(r,e,1);for(var u=r(t),i=0,a=n.length;a>i;){var o=i+a>>>1;r(n[o])<u?i=o+1:a=o}return i},h.toArray=function(n){return n?h.isArray(n)?a.call(n):n.length===+n.length?h.map(n,h.identity):h.values(n):[]},h.size=function(n){return null==n?0:n.length===+n.length?n.length:h.keys(n).length},h.partition=function(n,t,r){t=h.iteratee(t,r);var e=[],u=[];return h.each(n,function(n,r,i){(t(n,r,i)?e:u).push(n)}),[e,u]},h.first=h.head=h.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:0>t?[]:a.call(n,0,t)},h.initial=function(n,t,r){return a.call(n,0,Math.max(0,n.length-(null==t||r?1:t)))},h.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:a.call(n,Math.max(n.length-t,0))},h.rest=h.tail=h.drop=function(n,t,r){return a.call(n,null==t||r?1:t)},h.compact=function(n){return h.filter(n,h.identity)};var y=function(n,t,r,e){if(t&&h.every(n,h.isArray))return o.apply(e,n);for(var u=0,a=n.length;a>u;u++){var l=n[u];h.isArray(l)||h.isArguments(l)?t?i.apply(e,l):y(l,t,r,e):r||e.push(l)}return e};h.flatten=function(n,t){return y(n,t,!1,[])},h.without=function(n){return h.difference(n,a.call(arguments,1))},h.uniq=h.unique=function(n,t,r,e){if(null==n)return[];h.isBoolean(t)||(e=r,r=t,t=!1),null!=r&&(r=h.iteratee(r,e));for(var u=[],i=[],a=0,o=n.length;o>a;a++){var l=n[a];if(t)a&&i===l||u.push(l),i=l;else if(r){var c=r(l,a,n);h.indexOf(i,c)<0&&(i.push(c),u.push(l))}else h.indexOf(u,l)<0&&u.push(l)}return u},h.union=function(){return h.uniq(y(arguments,!0,!0,[]))},h.intersection=function(n){if(null==n)return[];for(var t=[],r=arguments.length,e=0,u=n.length;u>e;e++){var i=n[e];if(!h.contains(t,i)){for(var a=1;r>a&&h.contains(arguments[a],i);a++);a===r&&t.push(i)}}return t},h.difference=function(n){var t=y(a.call(arguments,1),!0,!0,[]);return h.filter(n,function(n){return!h.contains(t,n)})},h.zip=function(n){if(null==n)return[];for(var t=h.max(arguments,"length").length,r=Array(t),e=0;t>e;e++)r[e]=h.pluck(arguments,e);return r},h.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},h.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=h.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}for(;u>e;e++)if(n[e]===t)return e;return-1},h.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=n.length;for("number"==typeof r&&(e=0>r?e+r+1:Math.min(e,r+1));--e>=0;)if(n[e]===t)return e;return-1},h.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=r||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=Array(e),i=0;e>i;i++,n+=r)u[i]=n;return u};var d=function(){};h.bind=function(n,t){var r,e;if(p&&n.bind===p)return p.apply(n,a.call(arguments,1));if(!h.isFunction(n))throw new TypeError("Bind must be called on a function");return r=a.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(a.call(arguments)));d.prototype=n.prototype;var u=new d;d.prototype=null;var i=n.apply(u,r.concat(a.call(arguments)));return h.isObject(i)?i:u}},h.partial=function(n){var t=a.call(arguments,1);return function(){for(var r=0,e=t.slice(),u=0,i=e.length;i>u;u++)e[u]===h&&(e[u]=arguments[r++]);for(;r<arguments.length;)e.push(arguments[r++]);return n.apply(this,e)}},h.bindAll=function(n){var t,r,e=arguments.length;if(1>=e)throw new Error("bindAll must be passed function names");for(t=1;e>t;t++)r=arguments[t],n[r]=h.bind(n[r],n);return n},h.memoize=function(n,t){var r=function(e){var u=r.cache,i=t?t.apply(this,arguments):e;return h.has(u,i)||(u[i]=n.apply(this,arguments)),u[i]};return r.cache={},r},h.delay=function(n,t){var r=a.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},h.defer=function(n){return h.delay.apply(h,[n,1].concat(a.call(arguments,1)))},h.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var l=function(){o=r.leading===!1?0:h.now(),a=null,i=n.apply(e,u),a||(e=u=null)};return function(){var c=h.now();o||r.leading!==!1||(o=c);var f=t-(c-o);return e=this,u=arguments,0>=f||f>t?(clearTimeout(a),a=null,o=c,i=n.apply(e,u),a||(e=u=null)):a||r.trailing===!1||(a=setTimeout(l,f)),i}},h.debounce=function(n,t,r){var e,u,i,a,o,l=function(){var c=h.now()-a;t>c&&c>0?e=setTimeout(l,t-c):(e=null,r||(o=n.apply(i,u),e||(i=u=null)))};return function(){i=this,u=arguments,a=h.now();var c=r&&!e;return e||(e=setTimeout(l,t)),c&&(o=n.apply(i,u),i=u=null),o}},h.wrap=function(n,t){return h.partial(t,n)},h.negate=function(n){return function(){return!n.apply(this,arguments)}},h.compose=function(){var n=arguments,t=n.length-1;return function(){for(var r=t,e=n[t].apply(this,arguments);r--;)e=n[r].call(this,e);return e}},h.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},h.before=function(n,t){var r;return function(){return--n>0?r=t.apply(this,arguments):t=null,r}},h.once=h.partial(h.before,2),h.keys=function(n){if(!h.isObject(n))return[];if(s)return s(n);var t=[];for(var r in n)h.has(n,r)&&t.push(r);return t},h.values=function(n){for(var t=h.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},h.pairs=function(n){for(var t=h.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},h.invert=function(n){for(var t={},r=h.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},h.functions=h.methods=function(n){var t=[];for(var r in n)h.isFunction(n[r])&&t.push(r);return t.sort()},h.extend=function(n){if(!h.isObject(n))return n;for(var t,r,e=1,u=arguments.length;u>e;e++){t=arguments[e];for(r in t)c.call(t,r)&&(n[r]=t[r])}return n},h.pick=function(n,t,r){var e,u={};if(null==n)return u;if(h.isFunction(t)){t=g(t,r);for(e in n){var i=n[e];t(i,e,n)&&(u[e]=i)}}else{var l=o.apply([],a.call(arguments,1));n=new Object(n);for(var c=0,f=l.length;f>c;c++)e=l[c],e in n&&(u[e]=n[e])}return u},h.omit=function(n,t,r){if(h.isFunction(t))t=h.negate(t);else{var e=h.map(o.apply([],a.call(arguments,1)),String);t=function(n,t){return!h.contains(e,t)}}return h.pick(n,t,r)},h.defaults=function(n){if(!h.isObject(n))return n;for(var t=1,r=arguments.length;r>t;t++){var e=arguments[t];for(var u in e)n[u]===void 0&&(n[u]=e[u])}return n},h.clone=function(n){return h.isObject(n)?h.isArray(n)?n.slice():h.extend({},n):n},h.tap=function(n,t){return t(n),n};var b=function(n,t,r,e){if(n===t)return 0!==n||1/n===1/t;if(null==n||null==t)return n===t;n instanceof h&&(n=n._wrapped),t instanceof h&&(t=t._wrapped);var u=l.call(n);if(u!==l.call(t))return!1;switch(u){case"[object RegExp]":case"[object String]":return""+n==""+t;case"[object Number]":return+n!==+n?+t!==+t:0===+n?1/+n===1/t:+n===+t;case"[object Date]":case"[object Boolean]":return+n===+t}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]===n)return e[i]===t;var a=n.constructor,o=t.constructor;if(a!==o&&"constructor"in n&&"constructor"in t&&!(h.isFunction(a)&&a instanceof a&&h.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c,f;if("[object Array]"===u){if(c=n.length,f=c===t.length)for(;c--&&(f=b(n[c],t[c],r,e)););}else{var s,p=h.keys(n);if(c=p.length,f=h.keys(t).length===c)for(;c--&&(s=p[c],f=h.has(t,s)&&b(n[s],t[s],r,e)););}return r.pop(),e.pop(),f};h.isEqual=function(n,t){return b(n,t,[],[])},h.isEmpty=function(n){if(null==n)return!0;if(h.isArray(n)||h.isString(n)||h.isArguments(n))return 0===n.length;for(var t in n)if(h.has(n,t))return!1;return!0},h.isElement=function(n){return!(!n||1!==n.nodeType)},h.isArray=f||function(n){return"[object Array]"===l.call(n)},h.isObject=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},h.each(["Arguments","Function","String","Number","Date","RegExp"],function(n){h["is"+n]=function(t){return l.call(t)==="[object "+n+"]"}}),h.isArguments(arguments)||(h.isArguments=function(n){return h.has(n,"callee")}),"function"!=typeof/./&&(h.isFunction=function(n){return"function"==typeof n||!1}),h.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},h.isNaN=function(n){return h.isNumber(n)&&n!==+n},h.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"===l.call(n)},h.isNull=function(n){return null===n},h.isUndefined=function(n){return n===void 0},h.has=function(n,t){return null!=n&&c.call(n,t)},h.noConflict=function(){return n._=t,this},h.identity=function(n){return n},h.constant=function(n){return function(){return n}},h.noop=function(){},h.property=function(n){return function(t){return t[n]}},h.matches=function(n){var t=h.pairs(n),r=t.length;return function(n){if(null==n)return!r;n=new Object(n);for(var e=0;r>e;e++){var u=t[e],i=u[0];if(u[1]!==n[i]||!(i in n))return!1}return!0}},h.times=function(n,t,r){var e=Array(Math.max(0,n));t=g(t,r,1);for(var u=0;n>u;u++)e[u]=t(u);return e},h.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},h.now=Date.now||function(){return(new Date).getTime()};var _={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},w=h.invert(_),j=function(n){var t=function(t){return n[t]},r="(?:"+h.keys(n).join("|")+")",e=RegExp(r),u=RegExp(r,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};h.escape=j(_),h.unescape=j(w),h.result=function(n,t){if(null==n)return void 0;var r=n[t];return h.isFunction(r)?n[t]():r};var x=0;h.uniqueId=function(n){var t=++x+"";return n?n+t:t},h.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var A=/(.)^/,k={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},O=/\\|'|\r|\n|\u2028|\u2029/g,F=function(n){return"\\"+k[n]};h.template=function(n,t,r){!t&&r&&(t=r),t=h.defaults({},t,h.templateSettings);var e=RegExp([(t.escape||A).source,(t.interpolate||A).source,(t.evaluate||A).source].join("|")+"|$","g"),u=0,i="__p+='";n.replace(e,function(t,r,e,a,o){return i+=n.slice(u,o).replace(O,F),u=o+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":e?i+="'+\n((__t=("+e+"))==null?'':__t)+\n'":a&&(i+="';\n"+a+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var a=new Function(t.variable||"obj","_",i)}catch(o){throw o.source=i,o}var l=function(n){return a.call(this,n,h)},c=t.variable||"obj";return l.source="function("+c+"){\n"+i+"}",l},h.chain=function(n){var t=h(n);return t._chain=!0,t};var E=function(n){return this._chain?h(n).chain():n};h.mixin=function(n){h.each(h.functions(n),function(t){var r=h[t]=n[t];h.prototype[t]=function(){var n=[this._wrapped];return i.apply(n,arguments),E.call(this,r.apply(h,n))}})},h.mixin(h),h.each(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=r[n];h.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==n&&"splice"!==n||0!==r.length||delete r[0],E.call(this,r)}}),h.each(["concat","join","slice"],function(n){var t=r[n];h.prototype[n]=function(){return E.call(this,t.apply(this._wrapped,arguments))}}),h.prototype.value=function(){return this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return h})}).call(this);
+//# sourceMappingURL=underscore-min.map
diff --git a/catalog-be/src/main/resources/swagger/lib/underscore-min.map b/catalog-be/src/main/resources/swagger/lib/underscore-min.map
new file mode 100644
index 0000000000..b31e43590a
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/lib/underscore-min.map
@@ -0,0 +1 @@
+{"version":3,"file":"underscore-min.js","sources":["underscore.js"],"names":["createReduce","dir","iterator","obj","iteratee","memo","keys","index","length","currentKey","context","optimizeCb","isArrayLike","_","arguments","createIndexFinder","array","predicate","cb","collectNonEnumProps","nonEnumIdx","nonEnumerableProps","constructor","proto","isFunction","prototype","ObjProto","prop","has","contains","push","root","this","previousUnderscore","ArrayProto","Array","Object","FuncProto","Function","slice","toString","hasOwnProperty","nativeIsArray","isArray","nativeKeys","nativeBind","bind","nativeCreate","create","Ctor","_wrapped","exports","module","VERSION","func","argCount","value","call","other","collection","accumulator","apply","identity","isObject","matcher","property","Infinity","createAssigner","keysFunc","undefinedOnly","source","l","i","key","baseCreate","result","MAX_ARRAY_INDEX","Math","pow","each","forEach","map","collect","results","reduce","foldl","inject","reduceRight","foldr","find","detect","findIndex","findKey","filter","select","list","reject","negate","every","all","some","any","includes","include","target","fromIndex","values","indexOf","invoke","method","args","isFunc","pluck","where","attrs","findWhere","max","computed","lastComputed","min","shuffle","rand","set","shuffled","random","sample","n","guard","sortBy","criteria","sort","left","right","a","b","group","behavior","groupBy","indexBy","countBy","toArray","size","partition","pass","fail","first","head","take","initial","last","rest","tail","drop","compact","flatten","input","shallow","strict","startIndex","output","idx","isArguments","j","len","without","difference","uniq","unique","isSorted","isBoolean","seen","union","intersection","argsLength","item","zip","unzip","object","sortedIndex","isNaN","lastIndexOf","from","findLastIndex","low","high","mid","floor","range","start","stop","step","ceil","executeBound","sourceFunc","boundFunc","callingContext","self","TypeError","bound","concat","partial","boundArgs","position","bindAll","Error","memoize","hasher","cache","address","delay","wait","setTimeout","defer","throttle","options","timeout","previous","later","leading","now","remaining","clearTimeout","trailing","debounce","immediate","timestamp","callNow","wrap","wrapper","compose","after","times","before","once","hasEnumBug","propertyIsEnumerable","allKeys","mapObject","pairs","invert","functions","methods","names","extend","extendOwn","assign","pick","oiteratee","omit","String","defaults","clone","tap","interceptor","isMatch","eq","aStack","bStack","className","areArrays","aCtor","bCtor","pop","isEqual","isEmpty","isString","isElement","nodeType","type","name","Int8Array","isFinite","parseFloat","isNumber","isNull","isUndefined","noConflict","constant","noop","propertyOf","matches","accum","Date","getTime","escapeMap","&","<",">","\"","'","`","unescapeMap","createEscaper","escaper","match","join","testRegexp","RegExp","replaceRegexp","string","test","replace","escape","unescape","fallback","idCounter","uniqueId","prefix","id","templateSettings","evaluate","interpolate","noMatch","escapes","\\","\r","\n","
","
","escapeChar","template","text","settings","oldSettings","offset","variable","render","e","data","argument","chain","instance","_chain","mixin","valueOf","toJSON","define","amd"],"mappings":";;;;CAKC,WAoKC,QAASA,GAAaC,GAGpB,QAASC,GAASC,EAAKC,EAAUC,EAAMC,EAAMC,EAAOC,GAClD,KAAOD,GAAS,GAAaC,EAARD,EAAgBA,GAASN,EAAK,CACjD,GAAIQ,GAAaH,EAAOA,EAAKC,GAASA,CACtCF,GAAOD,EAASC,EAAMF,EAAIM,GAAaA,EAAYN,GAErD,MAAOE,GAGT,MAAO,UAASF,EAAKC,EAAUC,EAAMK,GACnCN,EAAWO,EAAWP,EAAUM,EAAS,EACzC,IAAIJ,IAAQM,EAAYT,IAAQU,EAAEP,KAAKH,GACnCK,GAAUF,GAAQH,GAAKK,OACvBD,EAAQN,EAAM,EAAI,EAAIO,EAAS,CAMnC,OAJIM,WAAUN,OAAS,IACrBH,EAAOF,EAAIG,EAAOA,EAAKC,GAASA,GAChCA,GAASN,GAEJC,EAASC,EAAKC,EAAUC,EAAMC,EAAMC,EAAOC,I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,GAAS3E,EAAW2O,EACxBhQ,GAAEY,UAAUoP,GAAQ,WAClB,GAAI1Q,GAAM6B,KAAKkB,QAGf,OAFA2D,GAAOhD,MAAM1D,EAAKW,WACJ,UAAT+P,GAA6B,WAATA,GAAqC,IAAf1Q,EAAIK,cAAqBL,GAAI,GACrEwE,EAAO3C,KAAM7B,MAKxBU,EAAEkE,MAAM,SAAU,OAAQ,SAAU,SAAS8L,GAC3C,GAAIhK,GAAS3E,EAAW2O,EACxBhQ,GAAEY,UAAUoP,GAAQ,WAClB,MAAOlM,GAAO3C,KAAM6E,EAAOhD,MAAM7B,KAAKkB,SAAUpC,eAKpDD,EAAEY,UAAU+B,MAAQ,WAClB,MAAOxB,MAAKkB,UAKdrC,EAAEY,UAAUqT,QAAUjU,EAAEY,UAAUsT,OAASlU,EAAEY,UAAU+B,MAEvD3C,EAAEY,UAAUe,SAAW,WACrB,MAAO,GAAKR,KAAKkB,UAUG,kBAAX8R,SAAyBA,OAAOC,KACzCD,OAAO,gBAAkB,WACvB,MAAOnU,OAGX4C,KAAKzB"} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/swagger/o2c.html b/catalog-be/src/main/resources/swagger/o2c.html
new file mode 100644
index 0000000000..88e8bf114b
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/o2c.html
@@ -0,0 +1,20 @@
+<script>
+var qp = null;
+if(window.location.hash) {
+ qp = location.hash.substring(1);
+}
+else {
+ qp = location.search.substring(1);
+}
+qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
+ function(key, value) {
+ return key===""?value:decodeURIComponent(value) }
+ ):{}
+
+if (window.opener.swaggerUi.tokenUrl)
+ window.opener.processOAuthCode(qp);
+else
+ window.opener.onOAuthComplete(qp);
+
+window.close();
+</script> \ No newline at end of file
diff --git a/catalog-be/src/main/resources/swagger/swagger-ui.js b/catalog-be/src/main/resources/swagger/swagger-ui.js
new file mode 100644
index 0000000000..96b6ed7cb6
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/swagger-ui.js
@@ -0,0 +1,21738 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * swagger-ui - Swagger UI is a dependency-free collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API
+ * @version v2.1.0-M2
+ * @link http://swagger.io
+ * @license Apache 2.0
+ */
+(function(){this["Handlebars"] = this["Handlebars"] || {};
+this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
+this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return "<!--div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div-->\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>"
+ + escapeExpression(((helper = (helper = helpers.keyName || (depth0 != null ? depth0.keyName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"keyName","hash":{},"data":data}) : helper)))
+ + "</div>\n <input placeholder=\"api_key\" class=\"auth_input\" id=\"input_apiKey_entry\" name=\"apiKey\" type=\"text\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_api_key\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
+},"useData":true});
+this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
+ },"useData":true});
+this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"2":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, buffer = " <option value=\"";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\">";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</option>\n";
+},"4":function(depth0,helpers,partials,data) {
+ return " <option value=\"application/json\">application/json</option>\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "<label for=\"contentType\"></label>\n<select name=\"contentType\">\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</select>\n";
+},"useData":true});
+'use strict';
+
+
+$(function() {
+
+ // Helper function for vertically aligning DOM elements
+ // http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
+ $.fn.vAlign = function() {
+ return this.each(function(){
+ var ah = $(this).height();
+ var ph = $(this).parent().height();
+ var mh = (ph - ah) / 2;
+ $(this).css('margin-top', mh);
+ });
+ };
+
+ $.fn.stretchFormtasticInputWidthToParent = function() {
+ return this.each(function(){
+ var p_width = $(this).closest("form").innerWidth();
+ var p_padding = parseInt($(this).closest("form").css('padding-left') ,10) + parseInt($(this).closest('form').css('padding-right'), 10);
+ var this_padding = parseInt($(this).css('padding-left'), 10) + parseInt($(this).css('padding-right'), 10);
+ $(this).css('width', p_width - p_padding - this_padding);
+ });
+ };
+
+ $('form.formtastic li.string input, form.formtastic textarea').stretchFormtasticInputWidthToParent();
+
+ // Vertically center these paragraphs
+ // Parent may need a min-height for this to work..
+ $('ul.downplayed li div.content p').vAlign();
+
+ // When a sandbox form is submitted..
+ $("form.sandbox").submit(function(){
+
+ var error_free = true;
+
+ // Cycle through the forms required inputs
+ $(this).find("input.required").each(function() {
+
+ // Remove any existing error styles from the input
+ $(this).removeClass('error');
+
+ // Tack the error style on if the input is empty..
+ if ($(this).val() === '') {
+ $(this).addClass('error');
+ $(this).wiggle();
+ error_free = false;
+ }
+
+ });
+
+ return error_free;
+ });
+
+});
+
+function clippyCopiedCallback() {
+ $('#api_key_copied').fadeIn().delay(1000).fadeOut();
+
+ // var b = $("#clippy_tooltip_" + a);
+ // b.length != 0 && (b.attr("title", "copied!").trigger("tipsy.reload"), setTimeout(function() {
+ // b.attr("title", "copy to clipboard")
+ // },
+ // 500))
+}
+
+// Logging function that accounts for browsers that don't have window.console
+function log(){
+ log.history = log.history || [];
+ log.history.push(arguments);
+ if(this.console){
+ console.log( Array.prototype.slice.call(arguments)[0] );
+ }
+}
+
+// Handle browsers that do console incorrectly (IE9 and below, see http://stackoverflow.com/a/5539378/7913)
+if (Function.prototype.bind && console && typeof console.log === "object") {
+ [
+ "log","info","warn","error","assert","dir","clear","profile","profileEnd"
+ ].forEach(function (method) {
+ console[method] = this.bind(console[method], console);
+ }, Function.prototype.call);
+}
+
+window.Docs = {
+
+ shebang: function() {
+
+ // If shebang has an operation nickname in it..
+ // e.g. /docs/#!/words/get_search
+ var fragments = $.param.fragment().split('/');
+ fragments.shift(); // get rid of the bang
+
+ switch (fragments.length) {
+ case 1:
+ // Expand all operations for the resource and scroll to it
+ var dom_id = 'resource_' + fragments[0];
+
+ Docs.expandEndpointListForResource(fragments[0]);
+ $("#"+dom_id).slideto({highlight: false});
+ break;
+ case 2:
+ // Refer to the endpoint DOM element, e.g. #words_get_search
+
+ // Expand Resource
+ Docs.expandEndpointListForResource(fragments[0]);
+ $("#"+dom_id).slideto({highlight: false});
+
+ // Expand operation
+ var li_dom_id = fragments.join('_');
+ var li_content_dom_id = li_dom_id + "_content";
+
+
+ Docs.expandOperation($('#'+li_content_dom_id));
+ $('#'+li_dom_id).slideto({highlight: false});
+ break;
+ }
+
+ },
+
+ toggleEndpointListForResource: function(resource) {
+ var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
+ if (elem.is(':visible')) {
+ Docs.collapseEndpointListForResource(resource);
+ } else {
+ Docs.expandEndpointListForResource(resource);
+ }
+ },
+
+ // Expand resource
+ expandEndpointListForResource: function(resource) {
+ var resource = Docs.escapeResourceName(resource);
+ if (resource == '') {
+ $('.resource ul.endpoints').slideDown();
+ return;
+ }
+
+ $('li#resource_' + resource).addClass('active');
+
+ var elem = $('li#resource_' + resource + ' ul.endpoints');
+ elem.slideDown();
+ },
+
+ // Collapse resource and mark as explicitly closed
+ collapseEndpointListForResource: function(resource) {
+ var resource = Docs.escapeResourceName(resource);
+ if (resource == '') {
+ $('.resource ul.endpoints').slideUp();
+ return;
+ }
+
+ $('li#resource_' + resource).removeClass('active');
+
+ var elem = $('li#resource_' + resource + ' ul.endpoints');
+ elem.slideUp();
+ },
+
+ expandOperationsForResource: function(resource) {
+ // Make sure the resource container is open..
+ Docs.expandEndpointListForResource(resource);
+
+ if (resource == '') {
+ $('.resource ul.endpoints li.operation div.content').slideDown();
+ return;
+ }
+
+ $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
+ Docs.expandOperation($(this));
+ });
+ },
+
+ collapseOperationsForResource: function(resource) {
+ // Make sure the resource container is open..
+ Docs.expandEndpointListForResource(resource);
+
+ if (resource == '') {
+ $('.resource ul.endpoints li.operation div.content').slideUp();
+ return;
+ }
+
+ $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
+ Docs.collapseOperation($(this));
+ });
+ },
+
+ escapeResourceName: function(resource) {
+ return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&");
+ },
+
+ expandOperation: function(elem) {
+ elem.slideDown();
+ },
+
+ collapseOperation: function(elem) {
+ elem.slideUp();
+ }
+};
+
+'use strict';
+
+Handlebars.registerHelper('sanitize', function(html) {
+ // Strip the script tags from the html, and return it as a Handlebars.SafeString
+ html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
+ return new Handlebars.SafeString(html);
+});
+this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">"
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0))
+ + "</div>\n <div class=\"info_description markdown\">";
+ stack1 = lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.description : stack1), depth0);
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</div>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.externalDocs : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += " ";
+ stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.termsOfServiceUrl : stack1), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n ";
+ stack1 = helpers['if'].call(depth0, ((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.name : stack1), {"name":"if","hash":{},"fn":this.program(6, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n ";
+ stack1 = helpers['if'].call(depth0, ((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.url : stack1), {"name":"if","hash":{},"fn":this.program(8, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n ";
+ stack1 = helpers['if'].call(depth0, ((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.email : stack1), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n ";
+ stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.license : stack1), {"name":"if","hash":{},"fn":this.program(12, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "\n";
+},"2":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return " <h5>More documentations</h5>\n <p>"
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.externalDocs : depth0)) != null ? stack1.description : stack1), depth0))
+ + "</p>\n <a href=\""
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.externalDocs : depth0)) != null ? stack1.url : stack1), depth0))
+ + "\" target=\"_blank\">"
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.externalDocs : depth0)) != null ? stack1.url : stack1), depth0))
+ + "</a>\n";
+},"4":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return "<div class=\"info_tos\"><a href=\""
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.termsOfServiceUrl : stack1), depth0))
+ + "\">Terms of service</a></div>";
+},"6":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return "<div class='info_name'>Created by "
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.name : stack1), depth0))
+ + "</div>";
+},"8":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return "<div class='info_url'>See more at <a href=\""
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.url : stack1), depth0))
+ + "\">"
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.url : stack1), depth0))
+ + "</a></div>";
+},"10":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return "<div class='info_email'><a href=\"mailto:"
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.email : stack1), depth0))
+ + "?subject="
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0))
+ + "\">Contact the developer</a></div>";
+},"12":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return "<div class='info_license'><a href='"
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.license : stack1)) != null ? stack1.url : stack1), depth0))
+ + "'>"
+ + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.license : stack1)) != null ? stack1.name : stack1), depth0))
+ + "</a></div>";
+},"14":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return " , <span style=\"font-variant: small-caps\">api version</span>: "
+ + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), depth0))
+ + "\n ";
+},"16":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <span style=\"float:right\"><a href=\""
+ + escapeExpression(((helper = (helper = helpers.validatorUrl || (depth0 != null ? depth0.validatorUrl : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"validatorUrl","hash":{},"data":data}) : helper)))
+ + "/debug?url="
+ + escapeExpression(((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"url","hash":{},"data":data}) : helper)))
+ + "\"><img id=\"validator\" src=\""
+ + escapeExpression(((helper = (helper = helpers.validatorUrl || (depth0 != null ? depth0.validatorUrl : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"validatorUrl","hash":{},"data":data}) : helper)))
+ + "?url="
+ + escapeExpression(((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"url","hash":{},"data":data}) : helper)))
+ + "\"></a>\n </span>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div class='info' id='api_info'>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.info : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</div>\n<div class='container' id='resources_container'>\n <ul id='resources'></ul>\n\n <div class=\"footer\">\n <br>\n <br>\n <h4 style=\"color: #999\">[ <span style=\"font-variant: small-caps\">base url</span>: "
+ + escapeExpression(((helper = (helper = helpers.basePath || (depth0 != null ? depth0.basePath : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"basePath","hash":{},"data":data}) : helper)))
+ + "\n";
+ stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), {"name":"if","hash":{},"fn":this.program(14, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "]\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.validatorUrl : depth0), {"name":"if","hash":{},"fn":this.program(16, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + " </h4>\n </div>\n</div>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ return "deprecated";
+ },"3":function(depth0,helpers,partials,data) {
+ return " <h4>Warning: Deprecated</h4>\n";
+ },"5":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = " <h4>Implementation Notes</h4>\n <div class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</div>\n";
+},"7":function(depth0,helpers,partials,data) {
+ return " <div class=\"auth\">\n <span class=\"api-ic ic-error\"></span>";
+ },"9":function(depth0,helpers,partials,data) {
+ var stack1, buffer = " <div id=\"api_information_panel\" style=\"top: 526px; left: 776px; display: none;\">\n";
+ stack1 = helpers.each.call(depth0, depth0, {"name":"each","hash":{},"fn":this.program(10, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + " </div>\n";
+},"10":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div title='";
+ stack1 = lambda((depth0 != null ? depth0.description : depth0), depth0);
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "'>"
+ + escapeExpression(lambda((depth0 != null ? depth0.scope : depth0), depth0))
+ + "</div>\n";
+},"12":function(depth0,helpers,partials,data) {
+ return "</div>";
+ },"14":function(depth0,helpers,partials,data) {
+ return " <div class='access'>\n <span class=\"api-ic ic-off\" title=\"click to authenticate\"></span>\n </div>\n";
+ },"16":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <h4>Response Class (Status "
+ + escapeExpression(((helper = (helper = helpers.successCode || (depth0 != null ? depth0.successCode : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"successCode","hash":{},"data":data}) : helper)))
+ + ")</h4>\n <p><span class=\"model-signature\" /></p>\n <br/>\n <div class=\"response-content-type\" />\n";
+},"18":function(depth0,helpers,partials,data) {
+ return " <h4>Parameters</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th style=\"width: 100px; max-width: 100px\">Parameter</th>\n <th style=\"width: 310px; max-width: 310px\">Value</th>\n <th style=\"width: 200px; max-width: 200px\">Description</th>\n <th style=\"width: 100px; max-width: 100px\">Parameter Type</th>\n <th style=\"width: 220px; max-width: 230px\">Data Type</th>\n </tr>\n </thead>\n <tbody class=\"operation-params\">\n\n </tbody>\n </table>\n";
+ },"20":function(depth0,helpers,partials,data) {
+ return " <div style='margin:0;padding:0;display:inline'></div>\n <h4>Response Messages</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n <th>Response Model</th>\n <th>Headers</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n\n </tbody>\n </table>\n";
+ },"22":function(depth0,helpers,partials,data) {
+ return "";
+},"24":function(depth0,helpers,partials,data) {
+ return " <div class='sandbox_header'>\n <input class='submit' name='commit' type='button' value='Try it out!' />\n <a href='#' class='response_hider' style='display:none'>Hide Response</a>\n <span class='response_throbber' style='display:none'></span>\n </div>\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "\n <ul class='operations' >\n <li class='"
+ + escapeExpression(((helper = (helper = helpers.method || (depth0 != null ? depth0.method : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"method","hash":{},"data":data}) : helper)))
+ + " operation' id='"
+ + escapeExpression(((helper = (helper = helpers.parentId || (depth0 != null ? depth0.parentId : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"parentId","hash":{},"data":data}) : helper)))
+ + "_"
+ + escapeExpression(((helper = (helper = helpers.nickname || (depth0 != null ? depth0.nickname : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"nickname","hash":{},"data":data}) : helper)))
+ + "'>\n <div class='heading'>\n <h3>\n <span class='http_method'>\n <a href='#!/"
+ + escapeExpression(((helper = (helper = helpers.encodedParentId || (depth0 != null ? depth0.encodedParentId : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"encodedParentId","hash":{},"data":data}) : helper)))
+ + "/"
+ + escapeExpression(((helper = (helper = helpers.nickname || (depth0 != null ? depth0.nickname : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"nickname","hash":{},"data":data}) : helper)))
+ + "' class=\"toggleOperation\">"
+ + escapeExpression(((helper = (helper = helpers.method || (depth0 != null ? depth0.method : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"method","hash":{},"data":data}) : helper)))
+ + "</a>\n </span>\n <span class='path'>\n <a href='#!/"
+ + escapeExpression(((helper = (helper = helpers.encodedParentId || (depth0 != null ? depth0.encodedParentId : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"encodedParentId","hash":{},"data":data}) : helper)))
+ + "/"
+ + escapeExpression(((helper = (helper = helpers.nickname || (depth0 != null ? depth0.nickname : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"nickname","hash":{},"data":data}) : helper)))
+ + "' class=\"toggleOperation ";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.deprecated : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\">"
+ + escapeExpression(((helper = (helper = helpers.path || (depth0 != null ? depth0.path : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"path","hash":{},"data":data}) : helper)))
+ + "</a>\n </span>\n </h3>\n <ul class='options'>\n <li>\n <a href='#!/"
+ + escapeExpression(((helper = (helper = helpers.encodedParentId || (depth0 != null ? depth0.encodedParentId : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"encodedParentId","hash":{},"data":data}) : helper)))
+ + "/"
+ + escapeExpression(((helper = (helper = helpers.nickname || (depth0 != null ? depth0.nickname : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"nickname","hash":{},"data":data}) : helper)))
+ + "' class=\"toggleOperation\">";
+ stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"summary","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</a>\n </li>\n </ul>\n </div>\n <div class='content' id='"
+ + escapeExpression(((helper = (helper = helpers.parentId || (depth0 != null ? depth0.parentId : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"parentId","hash":{},"data":data}) : helper)))
+ + "_"
+ + escapeExpression(((helper = (helper = helpers.nickname || (depth0 != null ? depth0.nickname : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"nickname","hash":{},"data":data}) : helper)))
+ + "_content' style='display:none'>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.deprecated : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.description : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = ((helper = (helper = helpers.oauth || (depth0 != null ? depth0.oauth : depth0)) != null ? helper : helperMissing),(options={"name":"oauth","hash":{},"fn":this.program(7, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper));
+ if (!helpers.oauth) { stack1 = blockHelperMissing.call(depth0, stack1, options); }
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n";
+ stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.oauth : depth0), {"name":"each","hash":{},"fn":this.program(9, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += " ";
+ stack1 = ((helper = (helper = helpers.oauth || (depth0 != null ? depth0.oauth : depth0)) != null ? helper : helperMissing),(options={"name":"oauth","hash":{},"fn":this.program(12, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper));
+ if (!helpers.oauth) { stack1 = blockHelperMissing.call(depth0, stack1, options); }
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n";
+ stack1 = ((helper = (helper = helpers.oauth || (depth0 != null ? depth0.oauth : depth0)) != null ? helper : helperMissing),(options={"name":"oauth","hash":{},"fn":this.program(14, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper));
+ if (!helpers.oauth) { stack1 = blockHelperMissing.call(depth0, stack1, options); }
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.type : depth0), {"name":"if","hash":{},"fn":this.program(16, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += " <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.parameters : depth0), {"name":"if","hash":{},"fn":this.program(18, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.responseMessages : depth0), {"name":"if","hash":{},"fn":this.program(20, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isReadOnly : depth0), {"name":"if","hash":{},"fn":this.program(22, data),"inverse":this.program(24, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + " </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return "<td class='code required'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n";
+},"3":function(depth0,helpers,partials,data) {
+ return " multiple='multiple'";
+ },"5":function(depth0,helpers,partials,data) {
+ return "";
+},"7":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(8, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"8":function(depth0,helpers,partials,data) {
+ var stack1, helperMissing=helpers.helperMissing, buffer = "";
+ stack1 = ((helpers.isArray || (depth0 && depth0.isArray) || helperMissing).call(depth0, depth0, {"name":"isArray","hash":{},"fn":this.program(5, data),"inverse":this.program(9, data),"data":data}));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"9":function(depth0,helpers,partials,data) {
+ return " <option selected=\"\" value=''></option>\n";
+ },"11":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isDefault : depth0), {"name":"if","hash":{},"fn":this.program(12, data),"inverse":this.program(14, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"12":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <option selected=\"\" value='"
+ + escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"value","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"value","hash":{},"data":data}) : helper)))
+ + " (default)</option>\n";
+},"14":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <option value='"
+ + escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"value","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"value","hash":{},"data":data}) : helper)))
+ + "</option>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.required : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "<td class='code'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>\n <select ";
+ stack1 = ((helpers.isArray || (depth0 && depth0.isArray) || helperMissing).call(depth0, depth0, {"name":"isArray","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += " class='parameter' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.required : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = helpers.each.call(depth0, ((stack1 = (depth0 != null ? depth0.allowableValues : depth0)) != null ? stack1.descriptiveValues : stack1), {"name":"each","hash":{},"fn":this.program(11, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += " </select>\n</td>\n<td class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>";
+},"useData":true});
+this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "</textarea>\n";
+},"3":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"4":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " "
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "\n";
+},"6":function(depth0,helpers,partials,data) {
+ return " (empty)\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code required'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea' readonly='readonly' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "</textarea>\n";
+},"3":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"4":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " "
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "\n";
+},"6":function(depth0,helpers,partials,data) {
+ return " (empty)\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["param_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"2":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input type=\"file\" name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'/>\n";
+},"4":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"5":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea required' placeholder='(required)' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "</textarea>\n <br />\n <div class=\"parameter-content-type\" />\n";
+},"7":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea required' placeholder='(required)' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'></textarea>\n <br />\n <div class=\"parameter-content-type\" />\n";
+},"9":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.program(12, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"10":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input class='parameter' class='required' type='file' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'/>\n";
+},"12":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(13, data),"inverse":this.program(15, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"13":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input class='parameter required' minlength='1' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "' placeholder='(required)' type='text' value='"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "'/>\n";
+},"15":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input class='parameter required' minlength='1' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "' placeholder='(required)' type='text' value=''/>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code required'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(9, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td>\n <strong><span class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</span></strong>\n</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["param"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"2":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input type=\"file\" name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'/>\n <div class=\"parameter-content-type\" />\n";
+},"4":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"5":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'>"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "</textarea>\n <br />\n <div class=\"parameter-content-type\" />\n";
+},"7":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <textarea class='body-textarea' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "'></textarea>\n <br />\n <div class=\"parameter-content-type\" />\n";
+},"9":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(10, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"10":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(11, data),"inverse":this.program(13, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"11":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input class='parameter' minlength='0' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "' placeholder='' type='text' value='"
+ + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ + "'/>\n";
+},"13":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <input class='parameter' minlength='0' name='"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "' placeholder='' type='text' value=''/>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code'>"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>\n\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(9, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n</td>\n<td class=\"markdown\">";
+ stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</td>\n<td>\n <span class=\"model-signature\"></span>\n</td>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.consumes : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"2":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, buffer = " <option value=\"";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\">";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</option>\n";
+},"4":function(depth0,helpers,partials,data) {
+ return " <option value=\"application/json\">application/json</option>\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "<label for=\"parameterContentType\"></label>\n<select name=\"parameterContentType\">\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.consumes : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</select>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ return " : ";
+ },"3":function(depth0,helpers,partials,data) {
+ var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
+ return " <li>\n <a href='"
+ + escapeExpression(((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"url","hash":{},"data":data}) : helper)))
+ + "'>Raw</a>\n </li>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "<div class='heading'>\n <h2>\n <a href='#!/"
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "' class=\"toggleEndpointList\" data-id=\""
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "\">"
+ + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ + "</a> ";
+ stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(options={"name":"summary","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper));
+ if (!helpers.summary) { stack1 = blockHelperMissing.call(depth0, stack1, options); }
+ if (stack1 != null) { buffer += stack1; }
+ stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"summary","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\n </h2>\n <ul class='options'>\n <li>\n <a href='#!/"
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "' id='endpointListTogger_"
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "' class=\"toggleEndpointList\" data-id=\""
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "\">Show/Hide</a>\n </li>\n <li>\n <a href='#' class=\"collapseResource\" data-id=\""
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "\">\n List Operations\n </a>\n </li>\n <li>\n <a href='#' class=\"expandResource\" data-id=\""
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "\">\n Expand Operations\n </a>\n </li>\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.url : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + " </ul>\n</div>\n<ul class='endpoints' id='"
+ + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ + "_endpoint_list' style='display:none'>\n\n</ul>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "";
+ stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer;
+},"2":function(depth0,helpers,partials,data) {
+ var stack1, lambda=this.lambda, buffer = " <option value=\"";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "\">";
+ stack1 = lambda(depth0, depth0);
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</option>\n";
+},"4":function(depth0,helpers,partials,data) {
+ return " <option value=\"application/json\">application/json</option>\n";
+ },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, buffer = "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</select>\n";
+},"useData":true});
+this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n ";
+ stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "\n </div>\n\n <div class=\"snippet\">\n <pre><code>"
+ + escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ + "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
+},"useData":true});
+this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
+ var lambda=this.lambda, escapeExpression=this.escapeExpression;
+ return " <tr>\n <td>"
+ + escapeExpression(lambda((data && data.key), depth0))
+ + "</td>\n <td>"
+ + escapeExpression(lambda((depth0 != null ? depth0.description : depth0), depth0))
+ + "</td>\n <td>"
+ + escapeExpression(lambda((depth0 != null ? depth0.type : depth0), depth0))
+ + "</td>\n </tr>\n";
+},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>"
+ + escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper)))
+ + "</td>\n<td>";
+ stack1 = ((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"message","hash":{},"data":data}) : helper));
+ if (stack1 != null) { buffer += stack1; }
+ buffer += "</td>\n<td width='50%'><span class=\"model-signature\" /></td>\n<td class=\"headers\">\n <table>\n <tbody>\n";
+ stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.headers : depth0), {"name":"each","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + " </tbody>\n </table>\n</td>";
+},"useData":true});
+/**
+ * swagger-client - swagger-client is a javascript client for use with swaggering APIs.
+ * @version v2.1.0
+ * @link http://swagger.io
+ * @license apache 2.0
+ */
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SwaggerClient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
+'use strict';
+
+var auth = require('./lib/auth');
+var helpers = require('./lib/helpers');
+var SwaggerClient = require('./lib/client');
+var deprecationWrapper = function (url, options) {
+ helpers.log('This is deprecated, use "new SwaggerClient" instead.');
+
+ return new SwaggerClient(url, options);
+};
+
+/* Here for IE8 Support */
+if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function(obj, start) {
+ for (var i = (start || 0), j = this.length; i < j; i++) {
+ if (this[i] === obj) { return i; }
+ }
+ return -1;
+ };
+};
+
+/* Here for node 10.x support */
+if (!String.prototype.endsWith) {
+ String.prototype.endsWith = function(suffix) {
+ return this.indexOf(suffix, this.length - suffix.length) !== -1;
+ };
+};
+
+module.exports = SwaggerClient;
+
+SwaggerClient.ApiKeyAuthorization = auth.ApiKeyAuthorization;
+SwaggerClient.PasswordAuthorization = auth.PasswordAuthorization;
+SwaggerClient.CookieAuthorization = auth.CookieAuthorization;
+SwaggerClient.SwaggerApi = deprecationWrapper;
+SwaggerClient.SwaggerClient = deprecationWrapper;
+
+},{"./lib/auth":2,"./lib/client":3,"./lib/helpers":4}],2:[function(require,module,exports){
+'use strict';
+
+var btoa = require('btoa'); // jshint ignore:line
+var CookieJar = require('cookiejar');
+
+/**
+ * SwaggerAuthorizations applys the correct authorization to an operation being executed
+ */
+var SwaggerAuthorizations = module.exports.SwaggerAuthorizations = function () {
+ this.authz = {};
+};
+
+SwaggerAuthorizations.prototype.add = function (name, auth) {
+ this.authz[name] = auth;
+
+ return auth;
+};
+
+SwaggerAuthorizations.prototype.remove = function (name) {
+ return delete this.authz[name];
+};
+
+SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
+ var status = null;
+ var key, name, value, result;
+
+ // if the 'authorizations' key is undefined, or has an empty array, add all keys
+ if (typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
+ for (key in this.authz) {
+ value = this.authz[key];
+ result = value.apply(obj, authorizations);
+
+ if (result === true) {
+ status = true;
+ }
+ }
+ } else {
+ // 2.0 support
+ if (Array.isArray(authorizations)) {
+ for (var i = 0; i < authorizations.length; i++) {
+ var auth = authorizations[i];
+
+ for (name in auth) {
+ for (key in this.authz) {
+ if (key === name) {
+ value = this.authz[key];
+ result = value.apply(obj, authorizations);
+
+ if (result === true) {
+ status = true;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ // 1.2 support
+ for (name in authorizations) {
+ for (key in this.authz) {
+ if (key === name) {
+ value = this.authz[key];
+ result = value.apply(obj, authorizations);
+
+ if (result === true) {
+ status = true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return status;
+};
+
+/**
+ * ApiKeyAuthorization allows a query param or header to be injected
+ */
+var ApiKeyAuthorization = module.exports.ApiKeyAuthorization = function (name, value, type) {
+ this.name = name;
+ this.value = value;
+ this.type = type;
+};
+
+ApiKeyAuthorization.prototype.apply = function (obj) {
+ if (this.type === 'query') {
+ if (obj.url.indexOf('?') > 0) {
+ obj.url = obj.url + '&' + this.name + '=' + this.value;
+ } else {
+ obj.url = obj.url + '?' + this.name + '=' + this.value;
+ }
+
+ return true;
+ } else if (this.type === 'header') {
+ obj.headers[this.name] = this.value;
+
+ return true;
+ }
+};
+
+var CookieAuthorization = module.exports.CookieAuthorization = function (cookie) {
+ this.cookie = cookie;
+};
+
+CookieAuthorization.prototype.apply = function (obj) {
+ obj.cookieJar = obj.cookieJar || new CookieJar();
+ obj.cookieJar.setCookie(this.cookie);
+
+ return true;
+};
+
+/**
+ * Password Authorization is a basic auth implementation
+ */
+var PasswordAuthorization = module.exports.PasswordAuthorization = function (name, username, password) {
+ this.name = name;
+ this.username = username;
+ this.password = password;
+};
+
+PasswordAuthorization.prototype.apply = function (obj) {
+ obj.headers.Authorization = 'Basic ' + btoa(this.username + ':' + this.password);
+
+ return true;
+};
+
+},{"btoa":16,"cookiejar":17}],3:[function(require,module,exports){
+'use strict';
+
+var _ = {
+ bind: require('lodash-compat/function/bind'),
+ cloneDeep: require('lodash-compat/lang/cloneDeep'),
+ find: require('lodash-compat/collection/find'),
+ forEach: require('lodash-compat/collection/forEach'),
+ indexOf: require('lodash-compat/array/indexOf'),
+ isArray: require('lodash-compat/lang/isArray'),
+ isFunction: require('lodash-compat/lang/isFunction'),
+ isPlainObject: require('lodash-compat/lang/isPlainObject'),
+ isUndefined: require('lodash-compat/lang/isUndefined')
+};
+var auth = require('./auth');
+var helpers = require('./helpers');
+var Model = require('./types/model');
+var Operation = require('./types/operation');
+var OperationGroup = require('./types/operationGroup');
+var Resolver = require('./resolver');
+var SwaggerHttp = require('./http');
+var SwaggerSpecConverter = require('./spec-converter');
+
+// We have to keep track of the function/property names to avoid collisions for tag names which are used to allow the
+// following usage: 'client.{tagName}'
+var reservedClientTags = [
+ 'authorizationScheme',
+ 'authorizations',
+ 'basePath',
+ 'build',
+ 'buildFrom1_1Spec',
+ 'buildFrom1_2Spec',
+ 'buildFromSpec',
+ 'clientAuthorizations',
+ 'convertInfo',
+ 'debug',
+ 'defaultErrorCallback',
+ 'defaultSuccessCallback',
+ 'fail',
+ 'failure',
+ 'finish',
+ 'help',
+ 'idFromOp',
+ 'info',
+ 'initialize',
+ 'isBuilt',
+ 'isValid',
+ 'models',
+ 'modelsArray',
+ 'options',
+ 'parseUri',
+ 'progress',
+ 'resourceCount',
+ 'sampleModels',
+ 'selfReflect',
+ 'setConsolidatedModels',
+ 'spec',
+ 'supportedSubmitMethods',
+ 'swaggerRequestHeaders',
+ 'tagFromLabel',
+ 'url',
+ 'useJQuery'
+];
+// We have to keep track of the function/property names to avoid collisions for tag names which are used to allow the
+// following usage: 'client.apis.{tagName}'
+var reservedApiTags = [
+ 'apis',
+ 'asCurl',
+ 'description',
+ 'externalDocs',
+ 'help',
+ 'label',
+ 'name',
+ 'operation',
+ 'operations',
+ 'operationsArray',
+ 'path',
+ 'tag'
+];
+var supportedOperationMethods = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put'];
+var SwaggerClient = module.exports = function (url, options) {
+ this.authorizationScheme = null;
+ this.authorizations = null;
+ this.basePath = null;
+ this.debug = false;
+ this.info = null;
+ this.isBuilt = false;
+ this.isValid = false;
+ this.modelsArray = [];
+ this.resourceCount = 0;
+ this.url = null;
+ this.useJQuery = false;
+
+ if (typeof url !== 'undefined') {
+ return this.initialize(url, options);
+ } else {
+ return this;
+ }
+};
+
+SwaggerClient.prototype.initialize = function (url, options) {
+ this.models = {};
+ this.sampleModels = {};
+
+ options = (options || {});
+
+ if (typeof url === 'string') {
+ this.url = url;
+ } else if (typeof url === 'object') {
+ options = url;
+ this.url = options.url;
+ }
+
+ this.swaggerRequestHeaders = options.swaggerRequestHeaders || 'application/json;charset=utf-8,*/*';
+ this.defaultSuccessCallback = options.defaultSuccessCallback || null;
+ this.defaultErrorCallback = options.defaultErrorCallback || null;
+
+ if (typeof options.success === 'function') {
+ this.success = options.success;
+ }
+
+ if (options.useJQuery) {
+ this.useJQuery = options.useJQuery;
+ }
+
+ if (options.authorizations) {
+ this.clientAuthorizations = options.authorizations;
+ } else {
+ this.clientAuthorizations = new auth.SwaggerAuthorizations();
+ }
+
+ this.supportedSubmitMethods = options.supportedSubmitMethods || [];
+ this.failure = options.failure || function () {};
+ this.progress = options.progress || function () {};
+ this.spec = _.cloneDeep(options.spec); // Clone so we do not alter the provided document
+ this.options = options;
+
+ if (typeof options.success === 'function') {
+ this.ready = true;
+ this.build();
+ }
+};
+
+SwaggerClient.prototype.build = function (mock) {
+ if (this.isBuilt) {
+ return this;
+ }
+
+ var self = this;
+
+ this.progress('fetching resource list: ' + this.url);
+
+ var obj = {
+ useJQuery: this.useJQuery,
+ url: this.url,
+ method: 'get',
+ headers: {
+ accept: this.swaggerRequestHeaders
+ },
+ on: {
+ error: function (response) {
+ if (self.url.substring(0, 4) !== 'http') {
+ return self.fail('Please specify the protocol for ' + self.url);
+ } else if (response.status === 0) {
+ return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
+ } else if (response.status === 404) {
+ return self.fail('Can\'t read swagger JSON from ' + self.url);
+ } else {
+ return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url);
+ }
+ },
+ response: function (resp) {
+ var responseObj = resp.obj || JSON.parse(resp.data);
+ self.swaggerVersion = responseObj.swaggerVersion;
+
+ if (responseObj.swagger && parseInt(responseObj.swagger) === 2) {
+ self.swaggerVersion = responseObj.swagger;
+
+ new Resolver().resolve(responseObj, self.buildFromSpec, self);
+
+ self.isValid = true;
+ } else {
+ var converter = new SwaggerSpecConverter();
+ converter.setDocumentationLocation(self.url);
+ converter.convert(responseObj, function(spec) {
+ new Resolver().resolve(spec, self.buildFromSpec, self);
+ self.isValid = true;
+ });
+ }
+ }
+ }
+ };
+
+ if (this.spec) {
+ setTimeout(function () {
+ new Resolver().resolve(self.spec, self.buildFromSpec, self);
+ }, 10);
+ } else {
+ this.clientAuthorizations.apply(obj);
+
+ if (mock) {
+ return obj;
+ }
+
+ new SwaggerHttp().execute(obj);
+ }
+
+ return this;
+};
+
+SwaggerClient.prototype.buildFromSpec = function (response) {
+ if (this.isBuilt) {
+ return this;
+ }
+
+ this.apis = {};
+ this.apisArray = [];
+ this.basePath = response.basePath || '';
+ this.consumes = response.consumes;
+ this.host = response.host || '';
+ this.info = response.info || {};
+ this.produces = response.produces;
+ this.schemes = response.schemes || [];
+ this.securityDefinitions = response.securityDefinitions;
+ this.title = response.title || '';
+
+ if (response.externalDocs) {
+ this.externalDocs = response.externalDocs;
+ }
+
+ // legacy support
+ this.authSchemes = response.securityDefinitions;
+
+ var definedTags = {};
+ var k;
+
+ if (Array.isArray(response.tags)) {
+ definedTags = {};
+
+ for (k = 0; k < response.tags.length; k++) {
+ var t = response.tags[k];
+
+ definedTags[t.name] = t;
+ }
+ }
+
+ var location;
+
+ if (typeof this.url === 'string') {
+ location = this.parseUri(this.url);
+ }
+
+ if (typeof this.schemes === 'undefined' || this.schemes.length === 0) {
+ this.scheme = location.scheme || 'http';
+ } else {
+ this.scheme = this.schemes[0];
+ }
+
+ if (typeof this.host === 'undefined' || this.host === '') {
+ this.host = location.host;
+
+ if (location.port) {
+ this.host = this.host + ':' + location.port;
+ }
+ }
+
+ this.definitions = response.definitions;
+
+ var key;
+
+ for (key in this.definitions) {
+ var model = new Model(key, this.definitions[key], this.models);
+
+ if (model) {
+ this.models[key] = model;
+ }
+ }
+
+ // get paths, create functions for each operationId
+ var self = this;
+
+ // Bind help to 'client.apis'
+ self.apis.help = _.bind(self.help, self);
+
+ _.forEach(response.paths, function (pathObj, path) {
+ // Only process a path if it's an object
+ if (!_.isPlainObject(pathObj)) {
+ return;
+ }
+
+ _.forEach(supportedOperationMethods, function (method) {
+ var operation = pathObj[method];
+
+ if (_.isUndefined(operation)) {
+ // Operation does not exist
+ return;
+ } else if (!_.isPlainObject(operation)) {
+ // Operation exists but it is not an Operation Object. Since this is invalid, log it.
+ helpers.log('The \'' + method + '\' operation for \'' + path + '\' path is not an Operation Object');
+
+ return;
+ }
+
+ var tags = operation.tags;
+
+ if (_.isUndefined(tags) || !_.isArray(tags) || tags.length === 0) {
+ tags = operation.tags = [ 'default' ];
+ }
+
+ var operationId = self.idFromOp(path, method, operation);
+ var operationObject = new Operation(self, operation.scheme, operationId, method, path, operation,
+ self.definitions, self.models, self.clientAuthorizations);
+
+ // bind self operation's execute command to the api
+ _.forEach(tags, function (tag) {
+ var clientProperty = _.indexOf(reservedClientTags, tag) > -1 ? '_' + tag : tag;
+ var apiProperty = _.indexOf(reservedApiTags, tag) > -1 ? '_' + tag : tag;
+ var operationGroup = self[clientProperty];
+
+ if (clientProperty !== tag) {
+ helpers.log('The \'' + tag + '\' tag conflicts with a SwaggerClient function/property name. Use \'client.' +
+ clientProperty + '\' or \'client.apis.' + tag + '\' instead of \'client.' + tag + '\'.');
+ }
+
+ if (apiProperty !== tag) {
+ helpers.log('The \'' + tag + '\' tag conflicts with a SwaggerClient operation function/property name. Use ' +
+ '\'client.apis.' + apiProperty + '\' instead of \'client.apis.' + tag + '\'.');
+ }
+
+ if (_.indexOf(reservedApiTags, operationId) > -1) {
+ helpers.log('The \'' + operationId + '\' operationId conflicts with a SwaggerClient operation ' +
+ 'function/property name. Use \'client.apis.' + apiProperty + '._' + operationId +
+ '\' instead of \'client.apis.' + apiProperty + '.' + operationId + '\'.');
+
+ operationId = '_' + operationId;
+ operationObject.nickname = operationId; // So 'client.apis.[tag].operationId.help() works properly
+ }
+
+ if (_.isUndefined(operationGroup)) {
+ operationGroup = self[clientProperty] = self.apis[apiProperty] = {};
+
+ operationGroup.operations = {};
+ operationGroup.label = apiProperty;
+ operationGroup.apis = {};
+
+ var tagDef = definedTags[tag];
+
+ if (!_.isUndefined(tagDef)) {
+ operationGroup.description = tagDef.description;
+ operationGroup.externalDocs = tagDef.externalDocs;
+ }
+
+ self[clientProperty].help = _.bind(self.help, operationGroup);
+ self.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
+ }
+
+ // Bind tag help
+ if (!_.isFunction(operationGroup.help)) {
+ operationGroup.help = _.bind(self.help, operationGroup);
+ }
+
+ // bind to the apis object
+ self.apis[apiProperty][operationId] = operationGroup[operationId]= _.bind(operationObject.execute,
+ operationObject);
+ self.apis[apiProperty][operationId].help = operationGroup[operationId].help = _.bind(operationObject.help,
+ operationObject);
+ self.apis[apiProperty][operationId].asCurl = operationGroup[operationId].asCurl = _.bind(operationObject.asCurl,
+ operationObject);
+
+ operationGroup.apis[operationId] = operationGroup.operations[operationId] = operationObject;
+
+ // legacy UI feature
+ var api = _.find(self.apisArray, function (api) {
+ return api.tag === tag;
+ });
+
+ if (api) {
+ api.operationsArray.push(operationObject);
+ }
+ });
+ });
+ });
+
+ this.isBuilt = true;
+
+ if (this.success) {
+ this.isValid = true;
+ this.isBuilt = true;
+ this.success();
+ }
+
+ return this;
+};
+
+SwaggerClient.prototype.parseUri = function (uri) {
+ var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
+ var parts = urlParseRE.exec(uri);
+
+ return {
+ scheme: parts[4].replace(':',''),
+ host: parts[11],
+ port: parts[12],
+ path: parts[15]
+ };
+};
+
+SwaggerClient.prototype.help = function (dontPrint) {
+ var output = '';
+
+ if (this instanceof SwaggerClient) {
+ _.forEach(this.apis, function (api, name) {
+ if (_.isPlainObject(api)) {
+ output += 'operations for the \'' + name + '\' tag\n';
+
+ _.forEach(api.operations, function (operation, name) {
+ output += ' * ' + name + ': ' + operation.summary + '\n';
+ });
+ }
+ });
+ } else if (this instanceof OperationGroup || _.isPlainObject(this)) {
+ output += 'operations for the \'' + this.label + '\' tag\n';
+
+ _.forEach(this.apis, function (operation, name) {
+ output += ' * ' + name + ': ' + operation.summary + '\n';
+ });
+ }
+
+ if (dontPrint) {
+ return output;
+ } else {
+ helpers.log(output);
+
+ return output;
+ }
+};
+
+SwaggerClient.prototype.tagFromLabel = function (label) {
+ return label;
+};
+
+SwaggerClient.prototype.idFromOp = function (path, httpMethod, op) {
+ if(!op || !op.operationId) {
+ op = op || {};
+ op.operationId = httpMethod + '_' + path;
+ }
+ var opId = op.operationId.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g, '_') || (path.substring(1) + '_' + httpMethod);
+
+ opId = opId.replace(/((_){2,})/g, '_');
+ opId = opId.replace(/^(_)*/g, '');
+ opId = opId.replace(/([_])*$/g, '');
+ return opId;
+};
+
+SwaggerClient.prototype.fail = function (message) {
+ this.failure(message);
+
+ throw message;
+};
+
+},{"./auth":2,"./helpers":4,"./http":5,"./resolver":6,"./spec-converter":7,"./types/model":8,"./types/operation":9,"./types/operationGroup":10,"lodash-compat/array/indexOf":19,"lodash-compat/collection/find":21,"lodash-compat/collection/forEach":22,"lodash-compat/function/bind":25,"lodash-compat/lang/cloneDeep":94,"lodash-compat/lang/isArray":96,"lodash-compat/lang/isFunction":97,"lodash-compat/lang/isPlainObject":100,"lodash-compat/lang/isUndefined":103}],4:[function(require,module,exports){
+(function (process){
+'use strict';
+
+module.exports.__bind = function (fn, me) {
+ return function(){
+ return fn.apply(me, arguments);
+ };
+};
+
+var log = module.exports.log = function() {
+ log.history = log.history || [];
+ log.history.push(arguments);
+
+ // Only log if available and we're not testing
+ if (console && process.env.NODE_ENV !== 'test') {
+ console.log(Array.prototype.slice.call(arguments)[0]);
+ }
+};
+
+module.exports.fail = function (message) {
+ log(message);
+};
+
+module.exports.optionHtml = function (label, value) {
+ return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
+};
+
+module.exports.typeFromJsonSchema = function (type, format) {
+ var str;
+
+ if (type === 'integer' && format === 'int32') {
+ str = 'integer';
+ } else if (type === 'integer' && format === 'int64') {
+ str = 'long';
+ } else if (type === 'integer' && typeof format === 'undefined') {
+ str = 'long';
+ } else if (type === 'string' && format === 'date-time') {
+ str = 'date-time';
+ } else if (type === 'string' && format === 'date') {
+ str = 'date';
+ } else if (type === 'number' && format === 'float') {
+ str = 'float';
+ } else if (type === 'number' && format === 'double') {
+ str = 'double';
+ } else if (type === 'number' && typeof format === 'undefined') {
+ str = 'double';
+ } else if (type === 'boolean') {
+ str = 'boolean';
+ } else if (type === 'string') {
+ str = 'string';
+ }
+
+ return str;
+};
+
+var simpleRef = module.exports.simpleRef = function (name) {
+ if (typeof name === 'undefined') {
+ return null;
+ }
+
+ if (name.indexOf('#/definitions/') === 0) {
+ return name.substring('#/definitions/'.length);
+ } else {
+ return name;
+ }
+};
+
+var getStringSignature = module.exports.getStringSignature = function (obj, baseComponent) {
+ var str = '';
+
+ if (typeof obj.$ref !== 'undefined') {
+ str += simpleRef(obj.$ref);
+ } else if (typeof obj.type === 'undefined') {
+ str += 'object';
+ } else if (obj.type === 'array') {
+ if (baseComponent) {
+ str += getStringSignature((obj.items || obj.$ref || {}));
+ } else {
+ str += 'Array[';
+ str += getStringSignature((obj.items || obj.$ref || {}));
+ str += ']';
+ }
+ } else if (obj.type === 'integer' && obj.format === 'int32') {
+ str += 'integer';
+ } else if (obj.type === 'integer' && obj.format === 'int64') {
+ str += 'long';
+ } else if (obj.type === 'integer' && typeof obj.format === 'undefined') {
+ str += 'long';
+ } else if (obj.type === 'string' && obj.format === 'date-time') {
+ str += 'date-time';
+ } else if (obj.type === 'string' && obj.format === 'date') {
+ str += 'date';
+ } else if (obj.type === 'string' && typeof obj.format === 'undefined') {
+ str += 'string';
+ } else if (obj.type === 'number' && obj.format === 'float') {
+ str += 'float';
+ } else if (obj.type === 'number' && obj.format === 'double') {
+ str += 'double';
+ } else if (obj.type === 'number' && typeof obj.format === 'undefined') {
+ str += 'double';
+ } else if (obj.type === 'boolean') {
+ str += 'boolean';
+ } else if (obj.$ref) {
+ str += simpleRef(obj.$ref);
+ } else {
+ str += obj.type;
+ }
+
+ return str;
+};
+
+}).call(this,require('_process'))
+
+},{"_process":15}],5:[function(require,module,exports){
+'use strict';
+
+var helpers = require('./helpers');
+var jQuery = require('jquery');
+var request = require('superagent');
+
+/*
+ * JQueryHttpClient is a light-weight, node or browser HTTP client
+ */
+var JQueryHttpClient = function () {};
+
+/*
+ * SuperagentHttpClient is a light-weight, node or browser HTTP client
+ */
+var SuperagentHttpClient = function () {};
+
+/**
+ * SwaggerHttp is a wrapper for executing requests
+ */
+var SwaggerHttp = module.exports = function () {};
+
+SwaggerHttp.prototype.execute = function (obj, opts) {
+ if (obj && (typeof obj.useJQuery === 'boolean')) {
+ this.useJQuery = obj.useJQuery;
+ } else {
+ this.useJQuery = this.isIE8();
+ }
+
+ if (obj && typeof obj.body === 'object') {
+ // special processing for file uploads via jquery
+ if (obj.body.type && obj.body.type === 'formData'){
+ obj.contentType = false;
+ obj.processData = false;
+
+ delete obj.headers['Content-Type'];
+ } else {
+ obj.body = JSON.stringify(obj.body);
+ }
+ }
+
+ if (this.useJQuery) {
+ return new JQueryHttpClient(opts).execute(obj);
+ } else {
+ return new SuperagentHttpClient(opts).execute(obj);
+ }
+};
+
+SwaggerHttp.prototype.isIE8 = function () {
+ var detectedIE = false;
+
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
+ var nav = navigator.userAgent.toLowerCase();
+
+ if (nav.indexOf('msie') !== -1) {
+ var version = parseInt(nav.split('msie')[1]);
+
+ if (version <= 8) {
+ detectedIE = true;
+ }
+ }
+ }
+
+ return detectedIE;
+};
+
+JQueryHttpClient.prototype.execute = function (obj) {
+ var cb = obj.on;
+ var request = obj;
+
+ obj.type = obj.method;
+ obj.cache = false;
+ delete obj.useJQuery;
+
+ /*
+ obj.beforeSend = function (xhr) {
+ var key, results;
+ if (obj.headers) {
+ results = [];
+ for (key in obj.headers) {
+ if (key.toLowerCase() === 'content-type') {
+ results.push(obj.contentType = obj.headers[key]);
+ } else if (key.toLowerCase() === 'accept') {
+ results.push(obj.accepts = obj.headers[key]);
+ } else {
+ results.push(xhr.setRequestHeader(key, obj.headers[key]));
+ }
+ }
+ return results;
+ }
+ };*/
+
+ obj.data = obj.body;
+
+ delete obj.body;
+
+ obj.complete = function (response) {
+ var headers = {};
+ var headerArray = response.getAllResponseHeaders().split('\n');
+
+ for (var i = 0; i < headerArray.length; i++) {
+ var toSplit = headerArray[i].trim();
+
+ if (toSplit.length === 0) {
+ continue;
+ }
+
+ var separator = toSplit.indexOf(':');
+
+ if (separator === -1) {
+ // Name but no value in the header
+ headers[toSplit] = null;
+
+ continue;
+ }
+
+ var name = toSplit.substring(0, separator).trim();
+ var value = toSplit.substring(separator + 1).trim();
+
+ headers[name] = value;
+ }
+
+ var out = {
+ url: request.url,
+ method: request.method,
+ status: response.status,
+ statusText: response.statusText,
+ data: response.responseText,
+ headers: headers
+ };
+
+ var contentType = (headers['content-type'] || headers['Content-Type'] || null);
+
+ if (contentType) {
+ if (contentType.indexOf('application/json') === 0 || contentType.indexOf('+json') > 0) {
+ try {
+ out.obj = response.responseJSON || JSON.parse(out.data) || {};
+ } catch (ex) {
+ // do not set out.obj
+ helpers.log('unable to parse JSON content');
+ }
+ }
+ }
+
+ if (response.status >= 200 && response.status < 300) {
+ cb.response(out);
+ } else if (response.status === 0 || (response.status >= 400 && response.status < 599)) {
+ cb.error(out);
+ } else {
+ return cb.response(out);
+ }
+ };
+
+ jQuery.support.cors = true;
+
+ return jQuery.ajax(obj);
+};
+
+SuperagentHttpClient.prototype.execute = function (obj) {
+ var method = obj.method.toLowerCase();
+
+ if (method === 'delete') {
+ method = 'del';
+ }
+
+ var headers = obj.headers || {};
+ var r = request[method](obj.url);
+ var name;
+
+ for (name in headers) {
+ r.set(name, headers[name]);
+ }
+
+ if (obj.body) {
+ r.send(obj.body);
+ }
+
+ r.end(function (err, res) {
+ res = res || {
+ status: 0,
+ headers: {error: 'no response from server'}
+ };
+ var response = {
+ url: obj.url,
+ method: obj.method,
+ headers: res.headers
+ };
+ var cb;
+
+ if (!err && res.error) {
+ err = res.error;
+ }
+
+ if (err && obj.on && obj.on.error) {
+ response.obj = err;
+ response.status = res ? res.status : 500;
+ response.statusText = res ? res.text : err.message;
+ cb = obj.on.error;
+ } else if (res && obj.on && obj.on.response) {
+ response.obj = (typeof res.body !== 'undefined') ? res.body : res.text;
+ response.status = res.status;
+ response.statusText = res.text;
+ cb = obj.on.response;
+ }
+ response.data = response.statusText;
+
+ if (cb) {
+ cb(response);
+ }
+ });
+};
+
+},{"./helpers":4,"jquery":18,"superagent":111}],6:[function(require,module,exports){
+'use strict';
+
+var SwaggerHttp = require('./http');
+
+/**
+ * Resolves a spec's remote references
+ */
+var Resolver = module.exports = function () {};
+
+Resolver.prototype.resolve = function (spec, callback, scope) {
+ this.scope = (scope || this);
+
+ var host, name, path, property, propertyName;
+ var processedCalls = 0, resolvedRefs = {}, unresolvedRefs = {};
+ var resolutionTable = {}; // store objects for dereferencing
+
+ // models
+ for (name in spec.definitions) {
+ var model = spec.definitions[name];
+
+ for (propertyName in model.properties) {
+ property = model.properties[propertyName];
+
+ this.resolveTo(property, resolutionTable);
+ }
+ }
+
+ // operations
+ for (name in spec.paths) {
+ var method, operation, responseCode;
+
+ path = spec.paths[name];
+
+ for (method in path) {
+ if(method === '$ref') {
+ this.resolveInline(spec, path, resolutionTable, unresolvedRefs);
+ }
+ else {
+ operation = path[method];
+
+ var i, parameters = operation.parameters;
+
+ for (i in parameters) {
+ var parameter = parameters[i];
+
+ if (parameter.in === 'body' && parameter.schema) {
+ this.resolveTo(parameter.schema, resolutionTable);
+ }
+
+ if (parameter.$ref) {
+ this.resolveInline(spec, parameter, resolutionTable, unresolvedRefs);
+ }
+ }
+
+ for (responseCode in operation.responses) {
+ var response = operation.responses[responseCode];
+ if(typeof response === 'object') {
+ if(response.$ref) {
+ this.resolveInline(spec, response, resolutionTable, unresolvedRefs);
+ }
+ }
+ if (response.schema) {
+ this.resolveTo(response.schema, resolutionTable);
+ }
+ }
+ }
+ }
+ }
+
+ // get hosts
+ var opts = {}, expectedCalls = 0;
+
+ for (name in resolutionTable) {
+ var parts = name.split('#');
+
+ if (parts.length === 2) {
+ host = parts[0]; path = parts[1];
+
+ if (!Array.isArray(opts[host])) {
+ opts[host] = [];
+ expectedCalls += 1;
+ }
+
+ opts[host].push(path);
+ }
+ else {
+ if (!Array.isArray(opts[name])) {
+ opts[name] = [];
+ expectedCalls += 1;
+ }
+
+ opts[name].push(null);
+ }
+ }
+
+ for (name in opts) {
+ var self = this, opt = opts[name];
+
+ host = name;
+
+ var obj = {
+ useJQuery: false, // TODO
+ url: host,
+ method: 'get',
+ headers: {
+ accept: this.scope.swaggerRequestHeaders || 'application/json'
+ },
+ on: {
+ error: function () {
+ processedCalls += 1;
+
+ var i;
+
+ for (i = 0; i < opt.length; i++) {
+ // fail all of these
+ var resolved = host + '#' + opt[i];
+
+ unresolvedRefs[resolved] = null;
+ }
+
+ if (processedCalls === expectedCalls) {
+ self.finish(spec, resolutionTable, resolvedRefs, unresolvedRefs, callback);
+ }
+ }, // jshint ignore:line
+ response: function (response) {
+
+ var i, j, swagger = response.obj;
+
+ if(swagger === null || Object.keys(swagger).length === 0) {
+ try {
+ swagger = JSON.parse(response.data);
+ }
+ catch (e){
+ swagger = {};
+ }
+ }
+
+ processedCalls += 1;
+
+ for (i = 0; i < opt.length; i++) {
+ var path = opt[i];
+ if(path == null) {
+ resolvedRefs[name] = {
+ name: name,
+ obj: swagger
+ };
+ }
+ else {
+ var location = swagger, parts = path.split('/');
+ for (j = 0; j < parts.length; j++) {
+ var segment = parts[j];
+ if(segment.indexOf('~1') !== -1) {
+ segment = parts[j].replace(/~0/g, '~').replace(/~1/g, '/');
+ if(segment.charAt(0) !== '/') {
+ segment = '/' + segment;
+ }
+ }
+
+ if (typeof location === 'undefined') {
+ break;
+ }
+
+ if (segment.length > 0) {
+ location = location[segment];
+ }
+ }
+ var resolved = host + '#' + path, resolvedName = parts[j-1];
+
+ if (typeof location !== 'undefined') {
+ resolvedRefs[resolved] = {
+ name: resolvedName,
+ obj: location
+ };
+ } else {
+ unresolvedRefs[resolved] = null;
+ }
+ }
+ }
+ if (processedCalls === expectedCalls) {
+ self.finish(spec, resolutionTable, resolvedRefs, unresolvedRefs, callback);
+ }
+ }
+ } // jshint ignore:line
+ };
+
+ if (scope && scope.clientAuthorizations) {
+ scope.clientAuthorizations.apply(obj);
+ }
+
+ new SwaggerHttp().execute(obj);
+ }
+
+ if (Object.keys(opts).length === 0) {
+ callback.call(this.scope, spec, unresolvedRefs);
+ }
+};
+
+Resolver.prototype.finish = function (spec, resolutionTable, resolvedRefs, unresolvedRefs, callback) {
+ // walk resolution table and replace with resolved refs
+ var ref;
+
+ for (ref in resolutionTable) {
+ var i, locations = resolutionTable[ref];
+
+ for (i = 0; i < locations.length; i++) {
+ var resolvedTo = resolvedRefs[locations[i].obj.$ref];
+
+ if (resolvedTo) {
+ if (!spec.definitions) {
+ spec.definitions = {};
+ }
+
+ if (locations[i].resolveAs === '$ref') {
+ spec.definitions[resolvedTo.name] = resolvedTo.obj;
+ locations[i].obj.$ref = '#/definitions/' + resolvedTo.name;
+ } else if (locations[i].resolveAs === 'inline') {
+ var targetObj = locations[i].obj;
+ var key;
+
+ delete targetObj.$ref;
+
+ for (key in resolvedTo.obj) {
+ targetObj[key] = resolvedTo.obj[key];
+ }
+ }
+ }
+ }
+ }
+
+ callback.call(this.scope, spec, unresolvedRefs);
+};
+
+/**
+ * immediately in-lines local refs, queues remote refs
+ * for inline resolution
+ */
+Resolver.prototype.resolveInline = function (spec, property, objs, unresolvedRefs) {
+ var ref = property.$ref;
+
+ if (ref) {
+ if (ref.indexOf('http') === 0) {
+ if (Array.isArray(objs[ref])) {
+ objs[ref].push({obj: property, resolveAs: 'inline'});
+ } else {
+ objs[ref] = [{obj: property, resolveAs: 'inline'}];
+ }
+ } else if (ref.indexOf('#') === 0) {
+ // local resolve
+ var shortenedRef = ref.substring(1);
+ var i, parts = shortenedRef.split('/'), location = spec;
+
+ for (i = 0; i < parts.length; i++) {
+ var part = parts[i];
+
+ if (part.length > 0) {
+ location = location[part];
+ }
+ }
+
+ if (location) {
+ delete property.$ref;
+
+ var key;
+
+ for (key in location) {
+ property[key] = location[key];
+ }
+ } else {
+ unresolvedRefs[ref] = null;
+ }
+ }
+ } else if (property.type === 'array') {
+ this.resolveTo(property.items, objs);
+ }
+};
+
+Resolver.prototype.resolveTo = function (property, objs) {
+ var ref = property.$ref;
+
+ if (ref) {
+ if (ref.indexOf('http') === 0) {
+ if (Array.isArray(objs[ref])) {
+ objs[ref].push({obj: property, resolveAs: '$ref'});
+ } else {
+ objs[ref] = [{obj: property, resolveAs: '$ref'}];
+ }
+ }
+ } else if (property.type === 'array') {
+ var items = property.items;
+
+ this.resolveTo(items, objs);
+ }
+};
+
+},{"./http":5}],7:[function(require,module,exports){
+'use strict';
+
+var SwaggerClient = require('./client');
+var SwaggerHttp = require('./http');
+
+var SwaggerSpecConverter = module.exports = function () {
+ this.errors = [];
+ this.warnings = [];
+ this.modelMap = {};
+};
+
+SwaggerSpecConverter.prototype.setDocumentationLocation = function (location) {
+ this.docLocation = location;
+};
+
+/**
+ * converts a resource listing OR api declaration
+ **/
+SwaggerSpecConverter.prototype.convert = function (obj, callback) {
+ // not a valid spec
+ if(!obj || !Array.isArray(obj.apis)) {
+ return this.finish(callback, null);
+ }
+
+ // create a new swagger object to return
+ var swagger = { swagger: '2.0' };
+
+ swagger.originalVersion = obj.swaggerVersion;
+
+ // add the info
+ this.apiInfo(obj, swagger);
+
+ // add security definitions
+ this.securityDefinitions(obj, swagger);
+
+ // see if this is a single-file swagger definition
+ var isSingleFileSwagger = false;
+ var i;
+ for(i = 0; i < obj.apis.length; i++) {
+ var api = obj.apis[i];
+ if(Array.isArray(api.operations)) {
+ isSingleFileSwagger = true;
+ }
+ }
+ if(isSingleFileSwagger) {
+ this.declaration(obj, swagger);
+ this.finish(callback, swagger);
+ }
+ else {
+ this.resourceListing(obj, swagger, callback);
+ }
+};
+
+SwaggerSpecConverter.prototype.declaration = function(obj, swagger) {
+ var name, i;
+ if(!obj.apis) {
+ return;
+ }
+
+ var basePath = obj.basePath;
+ if(obj.basePath.indexOf('http://') === 0) {
+ var p = obj.basePath.substring('http://'.length);
+ var pos = p.indexOf('/');
+ if(pos > 0) {
+ swagger.host = p.substring(0, pos);
+ swagger.basePath = p.substring(pos);
+ }
+ else{
+ swagger.host = p;
+ swagger.basePath = '/';
+ }
+ }
+ var resourceLevelAuth;
+ if(obj.authorizations) {
+ resourceLevelAuth = obj.authorizations;
+ }
+ if(obj.consumes) {
+ swagger.consumes = obj.consumes;
+ }
+ if(obj.produces) {
+ swagger.produces = obj.produces;
+ }
+
+ // build a mapping of id to name for 1.0 model resolutions
+ if(typeof obj === 'object') {
+ for(name in obj.models) {
+ var existingModel = obj.models[name];
+ var key = (existingModel.id || name);
+ this.modelMap[key] = name;
+ }
+ }
+
+ for(i = 0; i < obj.apis.length; i++) {
+ var api = obj.apis[i];
+ var path = api.path;
+ var operations = api.operations;
+ this.operations(path, obj.resourcePath, operations, resourceLevelAuth, swagger);
+ }
+
+ var models = obj.models;
+ this.models(models, swagger);
+};
+
+SwaggerSpecConverter.prototype.models = function(obj, swagger) {
+ if(typeof obj !== 'object') {
+ return;
+ }
+ var name;
+
+ swagger.definitions = swagger.definitions || {};
+ for(name in obj) {
+ var existingModel = obj[name];
+ var _enum = [];
+ var schema = { properties: {}};
+ var propertyName;
+ for(propertyName in existingModel.properties) {
+ var existingProperty = existingModel.properties[propertyName];
+ var property = {};
+ this.dataType(existingProperty, property);
+ if(existingProperty.description) {
+ property.description = existingProperty.description;
+ }
+ if(existingProperty['enum']) {
+ property['enum'] = existingProperty['enum'];
+ }
+ if(typeof existingProperty.required === 'boolean' && existingProperty.required === true) {
+ _enum.push(propertyName);
+ }
+ if(typeof existingProperty.required === 'string' && existingProperty.required === 'true') {
+ _enum.push(propertyName);
+ }
+ schema.properties[propertyName] = property;
+ }
+ if(_enum.length > 0) {
+ schema['enum'] = _enum;
+ }
+ swagger.definitions[name] = schema;
+ }
+};
+
+SwaggerSpecConverter.prototype.extractTag = function(resourcePath) {
+ var pathString = resourcePath || 'default';
+ if(pathString.indexOf('http:') === 0 || pathString.indexOf('https:') === 0) {
+ pathString = pathString.split(['/']);
+ pathString = pathString[pathString.length -1].substring();
+ }
+ return pathString.replace('/','');
+}
+
+SwaggerSpecConverter.prototype.operations = function(path, resourcePath, obj, resourceLevelAuth, swagger) {
+ if(!Array.isArray(obj)) {
+ return;
+ }
+ var i;
+
+ if(!swagger.paths) {
+ swagger.paths = {};
+ }
+
+ var pathObj = swagger.paths[path] || {};
+ var tag = this.extractTag(resourcePath);
+ swagger.tags = swagger.tags || [];
+ var matched = false;
+ for(i = 0; i < swagger.tags.length; i++) {
+ var tagObject = swagger.tags[i];
+ if(tagObject.name === tag) {
+ matched = true;
+ }
+ }
+ if(!matched) {
+ swagger.tags.push({name: tag});
+ }
+
+ for(i = 0; i < obj.length; i++) {
+ var existingOperation = obj[i];
+ var method = (existingOperation.method || existingOperation.httpMethod).toLowerCase();
+ var operation = {tags: [tag]};
+ var existingAuthorizations = existingOperation.authorizations;
+
+ if(existingAuthorizations && Object.keys(existingAuthorizations).length === 0) {
+ existingAuthorizations = resourceLevelAuth;
+ }
+
+ if(typeof existingAuthorizations !== 'undefined') {
+ for(var key in existingAuthorizations) {
+ operation.security = operation.security || [];
+ var scopes = existingAuthorizations[key];
+ if(scopes) {
+ var securityScopes = [];
+ for(var j in scopes) {
+ securityScopes.push(scopes[j].scope);
+ }
+ var scopesObject = {};
+ scopesObject[key] = securityScopes;
+ operation.security.push(scopesObject);
+ }
+ else {
+ var scopesObject = {};
+ scopesObject[key] = [];
+ operation.security.push(scopesObject);
+ }
+ }
+ }
+
+ if(existingOperation.consumes) {
+ operation.consumes = existingOperation.consumes;
+ }
+ else if(swagger.consumes) {
+ operation.consumes = swagger.consumes;
+ }
+ if(existingOperation.produces) {
+ operation.produces = existingOperation.produces;
+ }
+ else if(swagger.produces) {
+ operation.produces = swagger.produces;
+ }
+ if(existingOperation.summary) {
+ operation.summary = existingOperation.summary;
+ }
+ if(existingOperation.notes) {
+ operation.description = existingOperation.notes;
+ }
+ if(existingOperation.nickname) {
+ operation.operationId = existingOperation.nickname;
+ }
+ if(existingOperation.deprecated) {
+ operation.deprecated = existingOperation.deprecated;
+ }
+
+ this.authorizations(existingAuthorizations, swagger);
+ this.parameters(operation, existingOperation.parameters, swagger);
+ this.responseMessages(operation, existingOperation, swagger);
+
+ pathObj[method] = operation;
+ }
+
+ swagger.paths[path] = pathObj;
+};
+
+SwaggerSpecConverter.prototype.responseMessages = function(operation, existingOperation, swagger) {
+ if(typeof existingOperation !== 'object') {
+ return;
+ }
+ // build default response from the operation (1.x)
+ var defaultResponse = {};
+ this.dataType(existingOperation, defaultResponse);
+ if(!defaultResponse.schema) {
+ defaultResponse = {schema: defaultResponse};
+ }
+
+ operation.responses = operation.responses || {};
+
+ // grab from responseMessages (1.2)
+ var has200 = false;
+ if(Array.isArray(existingOperation.responseMessages)) {
+ var i;
+ var existingResponses = existingOperation.responseMessages;
+ for(i = 0; i < existingResponses.length; i++) {
+ var existingResponse = existingResponses[i];
+ var response = { description: existingResponse.message };
+ if(existingResponse.code === 200) {
+ has200 = true;
+ }
+ operation.responses['' + existingResponse.code] = response;
+ // TODO: schema
+ }
+ }
+
+ if(has200) {
+ operation.responses['default'] = defaultResponse;
+ }
+ else {
+ operation.responses['200'] = defaultResponse;
+ }
+};
+
+SwaggerSpecConverter.prototype.authorizations = function(obj, swagger) {
+ // TODO
+ if(typeof obj !== 'object') {
+ return;
+ }
+};
+
+SwaggerSpecConverter.prototype.parameters = function(operation, obj, swagger) {
+ if(!Array.isArray(obj)) {
+ return;
+ }
+ var i;
+ for(i = 0; i < obj.length; i++) {
+ var existingParameter = obj[i];
+ var parameter = {};
+ parameter.name = existingParameter.name;
+ parameter.description = existingParameter.description;
+ parameter.required = existingParameter.required;
+ parameter.in = existingParameter.paramType;
+
+ // per #168
+ if(parameter.in === 'body') {
+ parameter.name = 'body';
+ }
+ if(parameter.in === 'form') {
+ parameter.in = 'formData';
+ }
+
+ if(existingParameter.allowMultiple === true || existingParameter.allowMultiple === 'true') {
+ var innerType = {};
+ this.dataType(existingParameter, innerType);
+ parameter.type = 'array';
+ parameter.items = innerType;
+
+ if(existingParameter.allowableValues) {
+ var av = existingParameter.allowableValues;
+ if(av.valueType === 'LIST') {
+ parameter['enum'] = av.values;
+ }
+ }
+ }
+ else {
+ this.dataType(existingParameter, parameter);
+ }
+
+ operation.parameters = operation.parameters || [];
+ operation.parameters.push(parameter);
+ }
+};
+
+SwaggerSpecConverter.prototype.dataType = function(source, target) {
+ if(typeof source !== 'object') {
+ return;
+ }
+
+ if(source.minimum) {
+ target.minimum = source.minimum;
+ }
+ if(source.maximum) {
+ target.maximum = source.maximum;
+ }
+ if(source.defaultValue) {
+ target.default = source.defaultValue;
+ }
+
+ var jsonSchemaType = this.toJsonSchema(source);
+ if(jsonSchemaType) {
+ target = target || {};
+ if(jsonSchemaType.type) {
+ target.type = jsonSchemaType.type;
+ }
+ if(jsonSchemaType.format) {
+ target.format = jsonSchemaType.format;
+ }
+ if(jsonSchemaType.$ref) {
+ target.schema = {$ref: jsonSchemaType.$ref};
+ }
+ if(jsonSchemaType.items) {
+ target.items = jsonSchemaType.items;
+ }
+ }
+};
+
+SwaggerSpecConverter.prototype.toJsonSchema = function(source) {
+ if(!source) {
+ return 'object';
+ }
+ var detectedType = (source.type || source.dataType || source.responseClass || '');
+ var lcType = detectedType.toLowerCase();
+ var format = (source.format || '').toLowerCase();
+
+ if(lcType.indexOf('list[') === 0) {
+ var innerType = detectedType.substring(5, detectedType.length - 1);
+ var jsonType = this.toJsonSchema({type: innerType});
+ return {type: 'array', items: jsonType};
+ }
+ else if(lcType === 'int' || (lcType === 'integer' && format === 'int32'))
+ {return {type: 'integer', format: 'int32'};}
+ else if(lcType === 'long' || (lcType === 'integer' && format === 'int64'))
+ {return {type: 'integer', format: 'int64'};}
+ else if(lcType === 'integer')
+ {return {type: 'integer', format: 'int64'};}
+ else if(lcType === 'float' || (lcType === 'number' && format === 'float'))
+ {return {type: 'number', format: 'float'};}
+ else if(lcType === 'double' || (lcType === 'number' && format === 'double'))
+ {return {type: 'number', format: 'double'};}
+ else if((lcType === 'string' && format === 'date-time') || (lcType === 'date'))
+ {return {type: 'string', format: 'date-time'};}
+ else if(lcType === 'string')
+ {return {type: 'string'};}
+ else if(lcType === 'file')
+ {return {type: 'file'};}
+ else if(lcType === 'boolean')
+ {return {type: 'boolean'};}
+ else if(lcType === 'array' || lcType === 'list') {
+ if(source.items) {
+ var it = this.toJsonSchema(source.items);
+ return {type: 'array', items: it};
+ }
+ else {
+ return {type: 'array', items: {type: 'object'}};
+ }
+ }
+ else if(source.$ref) {
+ return {$ref: '#/definitions/' + this.modelMap[source.$ref] || source.$ref};
+ }
+ else {
+ return {$ref: '#/definitions/' + this.modelMap[source.type] || source.type};
+ }
+};
+
+SwaggerSpecConverter.prototype.resourceListing = function(obj, swagger, callback) {
+ var i, processedCount = 0;
+ var self = this;
+ var expectedCount = obj.apis.length;
+ var _swagger = swagger;
+
+ if(expectedCount === 0) {
+ this.finish(callback, swagger);
+ }
+
+ for(i = 0; i < expectedCount; i++) {
+ var api = obj.apis[i];
+ var path = api.path;
+ var absolutePath = this.getAbsolutePath(obj.swaggerVersion, this.docLocation, path);
+
+ if(api.description) {
+ swagger.tags = swagger.tags || [];
+ swagger.tags.push({
+ name : this.extractTag(api.path),
+ description : api.description || ''
+ });
+ };
+ var http = {
+ url: absolutePath,
+ headers: {accept: 'application/json'},
+ on: {},
+ method: 'get'
+ };
+ http.on.response = function(data) {
+ processedCount += 1;
+ if(data.obj) {
+ self.declaration(data.obj, _swagger);
+ }
+ if(processedCount === expectedCount) {
+ self.finish(callback, _swagger);
+ }
+ };
+ http.on.error = function(data) {
+ console.error(data);
+ processedCount += 1;
+ if(processedCount === expectedCount) {
+ self.finish(callback, _swagger);
+ }
+ };
+ new SwaggerHttp().execute(http);
+ }
+};
+
+SwaggerSpecConverter.prototype.getAbsolutePath = function(version, docLocation, path) {
+ if(version === '1.0') {
+ if(docLocation.endsWith('.json')) {
+ // get root path
+ var pos = docLocation.lastIndexOf('/');
+ if(pos > 0) {
+ docLocation = docLocation.substring(0, pos);
+ }
+ }
+ }
+
+ var location = docLocation;
+ if(path.indexOf('http://') === 0 || path.indexOf('https://') === 0) {
+ location = path;
+ }
+ else {
+ if(docLocation.endsWith('/')) {
+ location = docLocation.substring(0, docLocation.length - 1);
+ }
+ location += path;
+ }
+ location = location.replace('{format}', 'json');
+ return location;
+};
+
+SwaggerSpecConverter.prototype.securityDefinitions = function(obj, swagger) {
+ if(obj.authorizations) {
+ var name;
+ for(name in obj.authorizations) {
+ var isValid = false;
+ var securityDefinition = {};
+ var definition = obj.authorizations[name];
+ if(definition.type === 'apiKey') {
+ securityDefinition.type = 'apiKey';
+ securityDefinition.in = definition.passAs;
+ securityDefinition.name = definition.keyname || name;
+ isValid = true;
+ }
+ else if(definition.type === 'oauth2') {
+ var existingScopes = definition.scopes || [];
+ var scopes = {};
+ var i;
+ for(i in existingScopes) {
+ var scope = existingScopes[i];
+ scopes[scope.scope] = scope.description;
+ }
+ securityDefinition.type = 'oauth2';
+ if(i > 0) {
+ securityDefinition.scopes = scopes;
+ }
+ if(definition.grantTypes) {
+ if(definition.grantTypes.implicit) {
+ var implicit = definition.grantTypes.implicit;
+ securityDefinition.flow = 'implicit';
+ securityDefinition.authorizationUrl = implicit.loginEndpoint;
+ isValid = true;
+ }
+ if(definition.grantTypes.authorization_code) {
+ if(!securityDefinition.flow) {
+ // cannot set if flow is already defined
+ var authCode = definition.grantTypes.authorization_code;
+ securityDefinition.flow = 'accessCode';
+ securityDefinition.authorizationUrl = authCode.tokenRequestEndpoint.url;
+ securityDefinition.tokenUrl = authCode.tokenEndpoint.url;
+ isValid = true;
+ }
+ }
+ }
+ }
+ if(isValid) {
+ swagger.securityDefinitions = swagger.securityDefinitions || {};
+ swagger.securityDefinitions[name] = securityDefinition;
+ }
+ }
+ }
+};
+
+SwaggerSpecConverter.prototype.apiInfo = function(obj, swagger) {
+ // info section
+ if(obj.info) {
+ var info = obj.info;
+ swagger.info = {};
+
+ if(info.contact) {
+ swagger.info.contact = {};
+ swagger.info.contact.email = info.contact;
+ }
+ if(info.description) {
+ swagger.info.description = info.description;
+ }
+ if(info.title) {
+ swagger.info.title = info.title;
+ }
+ if(info.termsOfServiceUrl) {
+ swagger.info.termsOfService = info.termsOfServiceUrl;
+ }
+ if(info.license || info.licenseUrl) {
+ swagger.license = {};
+ if(info.license) {
+ swagger.license.name = info.license;
+ }
+ if(info.licenseUrl) {
+ swagger.license.url = info.licenseUrl;
+ }
+ }
+ }
+ else {
+ this.warnings.push('missing info section');
+ }
+};
+
+SwaggerSpecConverter.prototype.finish = function (callback, obj) {
+ callback(obj);
+};
+},{"./client":3,"./http":5}],8:[function(require,module,exports){
+'use strict';
+
+var _ = {
+ forEach: require('lodash-compat/collection/forEach'),
+ indexOf: require('lodash-compat/array/indexOf'),
+ isArray: require('lodash-compat/lang/isArray'),
+ isPlainObject: require('lodash-compat/lang/isPlainObject'),
+ isString: require('lodash-compat/lang/isString'),
+ isUndefined: require('lodash-compat/lang/isUndefined'),
+ keys: require('lodash-compat/object/keys'),
+ map: require('lodash-compat/collection/map')
+};
+var helpers = require('../helpers');
+
+
+/**
+ * allows override of the default value based on the parameter being
+ * supplied
+ **/
+var applyParameterMacro = function (operation, parameter) {
+ // TODO the reference to operation.api is not available
+ if (operation.api && operation.api.parameterMacro) {
+ return operation.api.parameterMacro(operation, parameter);
+ } else {
+ return parameter.defaultValue;
+ }
+};
+
+/**
+ * allows overriding the default value of an model property
+ **/
+var applyModelPropertyMacro = function (model, property) {
+ // TODO the reference to model.api is not available
+ if (model.api && model.api.modelPropertyMacro) {
+ return model.api.modelPropertyMacro(model, property);
+ } else {
+ return property.default;
+ }
+};
+
+var Model = module.exports = function (name, definition, models) {
+ this.definition = definition || {};
+ this.isArray = definition.type === 'array';
+ this.models = models || {};
+ this.name = name || 'Inline Model';
+
+ return this;
+};
+
+var schemaToHTML = function (name, schema, models) {
+ var strongOpen = '<span class="strong">';
+ var strongClose = '</span>';
+ var references = {};
+ var seenModels = [];
+ var inlineModels = 0;
+ var addReference = function (schema, name, skipRef) {
+ var modelName = name;
+ var model;
+
+ if (schema.$ref) {
+ modelName = helpers.simpleRef(schema.$ref);
+ model = models[modelName];
+ } else if (_.isUndefined(name)) {
+ modelName = 'Inline Model ' + (++inlineModels);
+ model = new Model(modelName, schema, models);
+ }
+
+ if (skipRef !== true) {
+ references[modelName] = _.isUndefined(model) ? {} : model.definition;
+ }
+
+ return modelName;
+ };
+ var primitiveToHTML = function (schema) {
+ var html = '<span class="propType">';
+ var type = schema.type || 'object';
+
+ if (schema.$ref) {
+ html += addReference(schema, helpers.simpleRef(schema.$ref));
+ } else if (type === 'object') {
+ if (!_.isUndefined(schema.properties)) {
+ html += addReference(schema);
+ } else {
+ html += 'object';
+ }
+ } else if (type === 'array') {
+ html += 'Array[';
+
+ if (_.isArray(schema.items)) {
+ html += _.map(schema.items, addReference).join(',');
+ } else if (_.isPlainObject(schema.items)) {
+ if (_.isUndefined(schema.items.$ref)) {
+ if (!_.isUndefined(schema.items.type) && _.indexOf(['array', 'object'], schema.items.type) === -1) {
+ html += schema.items.type;
+ } else {
+ html += addReference(schema.items);
+ }
+ } else {
+ html += addReference(schema.items, helpers.simpleRef(schema.items.$ref));
+ }
+ } else {
+ helpers.log('Array type\'s \'items\' schema is not an array or an object, cannot process');
+ html += 'object';
+ }
+
+ html += ']';
+ } else {
+ html += schema.type;
+ }
+
+ html += '</span>';
+
+ return html;
+ };
+ var primitiveToOptionsHTML = function (schema, html) {
+ var options = '';
+ var type = schema.type || 'object';
+ var isArray = type === 'array';
+
+ if (isArray) {
+ if (_.isPlainObject(schema.items) && !_.isUndefined(schema.items.type)) {
+ type = schema.items.type;
+ } else {
+ type = 'object';
+ }
+ }
+
+ if (schema.default) {
+ options += helpers.optionHtml('Default', schema.default);
+ }
+
+ switch (type) {
+ case 'string':
+ if (schema.minLength) {
+ options += helpers.optionHtml('Min. Length', schema.minLength);
+ }
+
+ if (schema.maxLength) {
+ options += helpers.optionHtml('Max. Length', schema.maxLength);
+ }
+
+ if (schema.pattern) {
+ options += helpers.optionHtml('Reg. Exp.', schema.pattern);
+ }
+ break;
+ case 'integer':
+ case 'number':
+ if (schema.minimum) {
+ options += helpers.optionHtml('Min. Value', schema.minimum);
+ }
+
+ if (schema.exclusiveMinimum) {
+ options += helpers.optionHtml('Exclusive Min.', 'true');
+ }
+
+ if (schema.maximum) {
+ options += helpers.optionHtml('Max. Value', schema.maximum);
+ }
+
+ if (schema.exclusiveMaximum) {
+ options += helpers.optionHtml('Exclusive Max.', 'true');
+ }
+
+ if (schema.multipleOf) {
+ options += helpers.optionHtml('Multiple Of', schema.multipleOf);
+ }
+
+ break;
+ }
+
+ if (isArray) {
+ if (schema.minItems) {
+ options += helpers.optionHtml('Min. Items', schema.minItems);
+ }
+
+ if (schema.maxItems) {
+ options += helpers.optionHtml('Max. Items', schema.maxItems);
+ }
+
+ if (schema.uniqueItems) {
+ options += helpers.optionHtml('Unique Items', 'true');
+ }
+
+ if (schema.collectionFormat) {
+ options += helpers.optionHtml('Coll. Format', schema.collectionFormat);
+ }
+ }
+
+ if (_.isUndefined(schema.items)) {
+ if (_.isArray(schema.enum)) {
+ var enumString;
+
+ if (type === 'number' || type === 'integer') {
+ enumString = schema.enum.join(', ');
+ } else {
+ enumString = '"' + schema.enum.join('", "') + '"';
+ }
+
+ options += helpers.optionHtml('Enum', enumString);
+ }
+ }
+
+ if (options.length > 0) {
+ html = '<span class="propWrap">' + html + '<table class="optionsWrapper"><tr><th colspan="2">' + type + '</th></tr>' + options + '</table></span>';
+ }
+
+ return html;
+ };
+ var processModel = function (schema, name) {
+ var type = schema.type || 'object';
+ var isArray = schema.type === 'array';
+ var html = strongOpen + name + ' ' + (isArray ? '[' : '{') + strongClose;
+
+ if (name) {
+ seenModels.push(name);
+ }
+
+ if (isArray) {
+ if (_.isArray(schema.items)) {
+ html += '<div>' + _.map(schema.items, function (item) {
+ var type = item.type || 'object';
+
+ if (_.isUndefined(item.$ref)) {
+ if (_.indexOf(['array', 'object'], type) > -1) {
+ if (type === 'object' && _.isUndefined(item.properties)) {
+ return 'object';
+ } else {
+ return addReference(item);
+ }
+ } else {
+ return primitiveToOptionsHTML(item, type);
+ }
+ } else {
+ return addReference(item, helpers.simpleRef(item.$ref));
+ }
+ }).join(',</div><div>');
+ } else if (_.isPlainObject(schema.items)) {
+ if (_.isUndefined(schema.items.$ref)) {
+ if (_.indexOf(['array', 'object'], schema.items.type || 'object') > -1) {
+ if ((_.isUndefined(schema.items.type) || schema.items.type === 'object') && _.isUndefined(schema.items.properties)) {
+ html += '<div>object</div>';
+ } else {
+ html += '<div>' + addReference(schema.items) + '</div>';
+ }
+ } else {
+ html += '<div>' + primitiveToOptionsHTML(schema.items, schema.items.type) + '</div>';
+ }
+ } else {
+ html += '<div>' + addReference(schema.items, helpers.simpleRef(schema.items.$ref)) + '</div>';
+ }
+ } else {
+ helpers.log('Array type\'s \'items\' property is not an array or an object, cannot process');
+ html += '<div>object</div>';
+ }
+ } else {
+ if (schema.$ref) {
+ html += '<div>' + addReference(schema, name) + '</div>';
+ } else if (type === 'object') {
+ html += '<div>';
+
+ if (_.isPlainObject(schema.properties)) {
+ html += _.map(schema.properties, function (property, name) {
+ var required = _.indexOf(schema.required || [], name) > -1;
+ var html = '<span class="propName ' + required + '">' + name + '</span> (';
+
+ html += primitiveToHTML(property);
+
+ if (!required) {
+ html += ', <span class="propOptKey">optional</span>';
+ }
+
+ html += ')';
+
+ if (!_.isUndefined(property.description)) {
+ html += ': ' + property.description;
+ }
+
+ if (property.enum) {
+ html += ' = <span class="propVals">[\'' + property.enum.join('\' or \'') + '\']</span>';
+ }
+
+ return primitiveToOptionsHTML(property, html);
+ }).join(',</div><div>');
+ }
+
+ html += '</div>';
+ } else {
+ html = '<div>' + primitiveToOptionsHTML(schema, type) + '</div>';
+ }
+ }
+
+ return html + strongOpen + (isArray ? ']' : '}') + strongClose;
+ };
+
+
+ // Generate current HTML
+ var html = processModel(schema, name);
+
+ // Generate references HTML
+ while (_.keys(references).length > 0) {
+ _.forEach(references, function (schema, name) {
+ var seenModel = _.indexOf(seenModels, name) > -1;
+
+ delete references[name];
+
+ if (!seenModel) {
+ seenModels.push(name);
+
+ html += '<br />' + processModel(schema, name);
+ }
+ });
+ }
+
+ return html;
+};
+
+var schemaToJSON = function (schema, models, modelsToIgnore) {
+ var type = schema.type || 'object';
+ var model;
+ var output;
+
+ if (schema.example) {
+ output = schema.example;
+ } else if (_.isUndefined(schema.items) && _.isArray(schema.enum)) {
+ output = schema.enum[0];
+ }
+
+ if (_.isUndefined(output)) {
+ if (schema.$ref) {
+ model = models[helpers.simpleRef(schema.$ref)];
+
+ if (!_.isUndefined(model)) {
+ if (_.isUndefined(modelsToIgnore[model.name])) {
+ modelsToIgnore[model.name] = model;
+ output = schemaToJSON(model.definition, models, modelsToIgnore);
+ delete modelsToIgnore[model.name];
+ } else {
+ if (model.type === 'array') {
+ output = [];
+ } else {
+ output = {};
+ }
+ }
+ }
+ } else if (schema.default) {
+ output = schema.default;
+ } else if (type === 'date-time') {
+ output = new Date().toISOString();
+ } else if (type === 'date') {
+ output = new Date().toISOString().split('T')[0];
+ } else if (type === 'string') {
+ output = 'string';
+ } else if (type === 'integer') {
+ output = 0;
+ } else if (type === 'long') {
+ output = 0;
+ } else if (type === 'float') {
+ output = 0.0;
+ } else if (type === 'double') {
+ output = 0.0;
+ } else if (type === 'boolean') {
+ output = true;
+ } else if (type === 'object') {
+ output = {};
+
+ _.forEach(schema.properties, function (property, name) {
+ output[name] = schemaToJSON(property, models, modelsToIgnore);
+ });
+ } else if (type === 'array') {
+ output = [];
+
+ if (_.isArray(schema.items)) {
+ _.forEach(schema.items, function (item) {
+ output.push(schemaToJSON(item, models, modelsToIgnore));
+ });
+ } else if (_.isPlainObject(schema.items)) {
+ output.push(schemaToJSON(schema.items, models, modelsToIgnore));
+ } else if (_.isUndefined(schema.items)) {
+ output.push({});
+ } else {
+ helpers.log('Array type\'s \'items\' property is not an array or an object, cannot process');
+ }
+ }
+ }
+
+ return output;
+};
+
+Model.prototype.createJSONSample = Model.prototype.getSampleValue = function (modelsToIgnore) {
+ modelsToIgnore = modelsToIgnore || {};
+
+ modelsToIgnore[this.name] = this;
+
+ // Response support
+ if (this.examples && _.isPlainObject(this.examples) && this.examples['application/json']) {
+ this.definition.example = this.examples['application/json'];
+
+ if (_.isString(this.definition.example)) {
+ this.definition.example = JSON.parse(this.definition.example);
+ }
+ } else {
+ this.definition.example = this.examples;
+ }
+
+
+ return schemaToJSON(this.definition, this.models, modelsToIgnore);
+};
+
+Model.prototype.getMockSignature = function () {
+ return schemaToHTML(this.name, this.definition, this.models);
+};
+
+},{"../helpers":4,"lodash-compat/array/indexOf":19,"lodash-compat/collection/forEach":22,"lodash-compat/collection/map":23,"lodash-compat/lang/isArray":96,"lodash-compat/lang/isPlainObject":100,"lodash-compat/lang/isString":101,"lodash-compat/lang/isUndefined":103,"lodash-compat/object/keys":104}],9:[function(require,module,exports){
+'use strict';
+
+var _ = {
+ isUndefined: require('lodash-compat/lang/isUndefined')
+};
+var helpers = require('../helpers');
+var Model = require('./model');
+var SwaggerHttp = require('../http');
+
+var Operation = module.exports = function (parent, scheme, operationId, httpMethod, path, args, definitions, models, clientAuthorizations) {
+ var errors = [];
+
+ parent = parent || {};
+ args = args || {};
+
+ this.authorizations = args.security;
+ this.basePath = parent.basePath || '/';
+ this.clientAuthorizations = clientAuthorizations;
+ this.consumes = args.consumes;
+ this.deprecated = args.deprecated;
+ this.description = args.description;
+ this.host = parent.host || 'localhost';
+ this.method = (httpMethod || errors.push('Operation ' + operationId + ' is missing method.'));
+ this.models = models || {};
+ this.nickname = (operationId || errors.push('Operations must have a nickname.'));
+ this.operation = args;
+ this.operations = {};
+ this.parameters = args !== null ? (args.parameters || []) : {};
+ this.parent = parent;
+ this.path = (path || errors.push('Operation ' + this.nickname + ' is missing path.'));
+ this.produces = args.produces;
+ this.responses = (args.responses || {});
+ this.scheme = scheme || parent.scheme || 'http';
+ this.schemes = parent.schemes;
+ this.security = args.security;
+ this.summary = args.summary || '';
+ this.type = null;
+ this.useJQuery = parent.useJQuery;
+
+ if (typeof this.deprecated === 'string') {
+ switch(this.deprecated.toLowerCase()) {
+ case 'true': case 'yes': case '1': {
+ this.deprecated = true;
+ break;
+ }
+
+ case 'false': case 'no': case '0': case null: {
+ this.deprecated = false;
+ break;
+ }
+
+ default: this.deprecated = Boolean(this.deprecated);
+ }
+ }
+
+ var i, model;
+
+ if (definitions) {
+ // add to global models
+ var key;
+
+ for (key in this.definitions) {
+ model = new Model(key, definitions[key], this.models);
+
+ if (model) {
+ this.models[key] = model;
+ }
+ }
+ }
+ for (i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+
+ if (param.type === 'array') {
+ param.isList = true;
+ param.allowMultiple = true;
+ }
+
+ var innerType = this.getType(param);
+
+ if (innerType && innerType.toString().toLowerCase() === 'boolean') {
+ param.allowableValues = {};
+ param.isList = true;
+ param['enum'] = ['true', 'false'];
+ }
+
+ if (typeof param['enum'] !== 'undefined') {
+ var id;
+
+ param.allowableValues = {};
+ param.allowableValues.values = [];
+ param.allowableValues.descriptiveValues = [];
+
+ for (id = 0; id < param['enum'].length; id++) {
+ var value = param['enum'][id];
+ var isDefault = (value === param.default) ? true : false;
+
+ param.allowableValues.values.push(value);
+ param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
+ }
+ }
+
+ if (param.type === 'array') {
+ innerType = [innerType];
+
+ if (typeof param.allowableValues === 'undefined') {
+ // can't show as a list if no values to select from
+ delete param.isList;
+ delete param.allowMultiple;
+ }
+ }
+
+ param.signature = this.getModelSignature(innerType, this.models).toString();
+ param.sampleJSON = this.getModelSampleJSON(innerType, this.models);
+ param.responseClassSignature = param.signature;
+ }
+
+ var defaultResponseCode, response, responses = this.responses;
+
+ if (responses['200']) {
+ response = responses['200'];
+ defaultResponseCode = '200';
+ } else if (responses['201']) {
+ response = responses['201'];
+ defaultResponseCode = '201';
+ } else if (responses['202']) {
+ response = responses['202'];
+ defaultResponseCode = '202';
+ } else if (responses['203']) {
+ response = responses['203'];
+ defaultResponseCode = '203';
+ } else if (responses['204']) {
+ response = responses['204'];
+ defaultResponseCode = '204';
+ } else if (responses['205']) {
+ response = responses['205'];
+ defaultResponseCode = '205';
+ } else if (responses['206']) {
+ response = responses['206'];
+ defaultResponseCode = '206';
+ } else if (responses['default']) {
+ response = responses['default'];
+ defaultResponseCode = 'default';
+ }
+
+ if (response && response.schema) {
+ var resolvedModel = this.resolveModel(response.schema, definitions);
+ var successResponse;
+
+ delete responses[defaultResponseCode];
+
+ if (resolvedModel) {
+ this.successResponse = {};
+ successResponse = this.successResponse[defaultResponseCode] = resolvedModel;
+ } else if (!response.schema.type || response.schema.type === 'object' || response.schema.type === 'array') {
+ // Inline model
+ this.successResponse = {};
+ successResponse = this.successResponse[defaultResponseCode] = new Model(undefined, response.schema || {}, this.models);
+ } else {
+ // Primitive
+ this.successResponse = {};
+ successResponse = this.successResponse[defaultResponseCode] = response.schema;
+ }
+
+ if (successResponse) {
+ // Attach response properties
+ if (response.description) {
+ successResponse.description = response.description;
+ }
+
+ if (response.examples) {
+ successResponse.examples = response.examples;
+ }
+
+ if (response.headers) {
+ successResponse.headers = response.headers;
+ }
+ }
+
+ this.type = response;
+ }
+
+ if (errors.length > 0) {
+ if (this.resource && this.resource.api && this.resource.api.fail) {
+ this.resource.api.fail(errors);
+ }
+ }
+
+ return this;
+};
+
+Operation.prototype.getType = function (param) {
+ var type = param.type;
+ var format = param.format;
+ var isArray = false;
+ var str;
+
+ if (type === 'integer' && format === 'int32') {
+ str = 'integer';
+ } else if (type === 'integer' && format === 'int64') {
+ str = 'long';
+ } else if (type === 'integer') {
+ str = 'integer';
+ } else if (type === 'string') {
+ if (format === 'date-time') {
+ str = 'date-time';
+ } else if (format === 'date') {
+ str = 'date';
+ } else {
+ str = 'string';
+ }
+ } else if (type === 'number' && format === 'float') {
+ str = 'float';
+ } else if (type === 'number' && format === 'double') {
+ str = 'double';
+ } else if (type === 'number') {
+ str = 'double';
+ } else if (type === 'boolean') {
+ str = 'boolean';
+ } else if (type === 'array') {
+ isArray = true;
+
+ if (param.items) {
+ str = this.getType(param.items);
+ }
+ }
+
+ if (param.$ref) {
+ str = param.$ref;
+ }
+
+ var schema = param.schema;
+
+ if (schema) {
+ var ref = schema.$ref;
+
+ if (ref) {
+ ref = helpers.simpleRef(ref);
+
+ if (isArray) {
+ return [ ref ];
+ } else {
+ return ref;
+ }
+ } else {
+ return this.getType(schema);
+ }
+ }
+ if (isArray) {
+ return [ str ];
+ } else {
+ return str;
+ }
+};
+
+Operation.prototype.resolveModel = function (schema, definitions) {
+ if (typeof schema.$ref !== 'undefined') {
+ var ref = schema.$ref;
+
+ if (ref.indexOf('#/definitions/') === 0) {
+ ref = ref.substring('#/definitions/'.length);
+ }
+
+ if (definitions[ref]) {
+ return new Model(ref, definitions[ref], this.models);
+ }
+ } else if (schema.type === 'object' || _.isUndefined(schema.type)) {
+ return new Model(undefined, schema, this.models);
+ }
+
+ return null;
+};
+
+Operation.prototype.help = function (dontPrint) {
+ var out = this.nickname + ': ' + this.summary + '\n';
+
+ for (var i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+ var typeInfo = param.signature;
+
+ out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description;
+ }
+
+ if (typeof dontPrint === 'undefined') {
+ helpers.log(out);
+ }
+
+ return out;
+};
+
+Operation.prototype.getModelSignature = function (type, definitions) {
+ var isPrimitive, listType;
+
+ if (type instanceof Array) {
+ listType = true;
+ type = type[0];
+ } else if (typeof type === 'undefined') {
+ type = 'undefined';
+ }
+
+ if (type === 'string') {
+ isPrimitive = true;
+ } else {
+ isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
+ }
+
+ if (isPrimitive) {
+ if (listType) {
+ return 'Array[' + type + ']';
+ } else {
+ return type.toString();
+ }
+ } else {
+ if (listType) {
+ return 'Array[' + definitions[type].getMockSignature() + ']';
+ } else {
+ return definitions[type].getMockSignature();
+ }
+ }
+};
+
+Operation.prototype.supportHeaderParams = function () {
+ return true;
+};
+
+Operation.prototype.supportedSubmitMethods = function () {
+ return this.parent.supportedSubmitMethods;
+};
+
+Operation.prototype.getHeaderParams = function (args) {
+ var headers = this.setContentTypes(args, {});
+
+ for (var i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+
+ if (typeof args[param.name] !== 'undefined') {
+ if (param.in === 'header') {
+ var value = args[param.name];
+
+ if (Array.isArray(value)) {
+ value = value.toString();
+ }
+
+ headers[param.name] = value;
+ }
+ }
+ }
+
+ return headers;
+};
+
+Operation.prototype.urlify = function (args) {
+ var formParams = {};
+ var requestUrl = this.path;
+ var querystring = ''; // grab params from the args, build the querystring along the way
+
+ for (var i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+
+ if (typeof args[param.name] !== 'undefined') {
+ if (param.in === 'path') {
+ var reg = new RegExp('\{' + param.name + '\}', 'gi');
+ var value = args[param.name];
+
+ if (Array.isArray(value)) {
+ value = this.encodePathCollection(param.collectionFormat, param.name, value);
+ } else {
+ value = this.encodePathParam(value);
+ }
+
+ requestUrl = requestUrl.replace(reg, value);
+ } else if (param.in === 'query' && typeof args[param.name] !== 'undefined') {
+ if (querystring === '') {
+ querystring += '?';
+ } else {
+ querystring += '&';
+ }
+
+ if (typeof param.collectionFormat !== 'undefined') {
+ var qp = args[param.name];
+
+ if (Array.isArray(qp)) {
+ querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp);
+ } else {
+ querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]);
+ }
+ } else {
+ querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]);
+ }
+ } else if (param.in === 'formData') {
+ formParams[param.name] = args[param.name];
+ }
+ }
+ }
+ var url = this.scheme + '://' + this.host;
+
+ if (this.basePath !== '/') {
+ url += this.basePath;
+ }
+ return url + requestUrl + querystring;
+};
+
+Operation.prototype.getMissingParams = function (args) {
+ var missingParams = []; // check required params, track the ones that are missing
+ var i;
+
+ for (i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+
+ if (param.required === true) {
+ if (typeof args[param.name] === 'undefined') {
+ missingParams = param.name;
+ }
+ }
+ }
+
+ return missingParams;
+};
+
+Operation.prototype.getBody = function (headers, args, opts) {
+ var formParams = {}, body, key, value;
+
+ for (var i = 0; i < this.parameters.length; i++) {
+ var param = this.parameters[i];
+
+ if (typeof args[param.name] !== 'undefined') {
+ if (param.in === 'body') {
+ body = args[param.name];
+ } else if (param.in === 'formData') {
+ formParams[param.name] = args[param.name];
+ }
+ }
+ }
+
+ // handle form params
+ if (headers['Content-Type'] === 'application/x-www-form-urlencoded') {
+ var encoded = '';
+
+ for (key in formParams) {
+ value = formParams[key];
+
+ if (typeof value !== 'undefined') {
+ if (encoded !== '') {
+ encoded += '&';
+ }
+
+ encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
+ }
+ }
+
+ body = encoded;
+ } else if (headers['Content-Type'] && headers['Content-Type'].indexOf('multipart/form-data') >= 0) {
+ if (opts.useJQuery) {
+ var bodyParam = new FormData();
+
+ bodyParam.type = 'formData';
+
+ for (key in formParams) {
+ value = args[key];
+
+ if (typeof value !== 'undefined') {
+ // required for jquery file upload
+ if (value.type === 'file' && value.value) {
+ delete headers['Content-Type'];
+
+ bodyParam.append(key, value.value);
+ } else {
+ bodyParam.append(key, value);
+ }
+ }
+ }
+
+ body = bodyParam;
+ }
+ }
+
+ return body;
+};
+
+/**
+ * gets sample response for a single operation
+ **/
+Operation.prototype.getModelSampleJSON = function (type, models) {
+ var isPrimitive, listType, sampleJson;
+
+ listType = (type instanceof Array);
+ isPrimitive = models[type] ? false : true;
+ sampleJson = isPrimitive ? void 0 : models[type].createJSONSample();
+
+ if (sampleJson) {
+ sampleJson = listType ? [sampleJson] : sampleJson;
+
+ if (typeof sampleJson === 'string') {
+ return sampleJson;
+ } else if (typeof sampleJson === 'object') {
+ var t = sampleJson;
+
+ if (sampleJson instanceof Array && sampleJson.length > 0) {
+ t = sampleJson[0];
+ }
+
+ if (t.nodeName) {
+ var xmlString = new XMLSerializer().serializeToString(t);
+
+ return this.formatXml(xmlString);
+ } else {
+ return JSON.stringify(sampleJson, null, 2);
+ }
+ } else {
+ return sampleJson;
+ }
+ }
+};
+
+/**
+ * legacy binding
+ **/
+Operation.prototype.do = function (args, opts, callback, error, parent) {
+ return this.execute(args, opts, callback, error, parent);
+};
+
+/**
+ * executes an operation
+ **/
+Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
+ var args = arg1 || {};
+ var opts = {}, success, error;
+
+ if (typeof arg2 === 'object') {
+ opts = arg2;
+ success = arg3;
+ error = arg4;
+ }
+
+ if (typeof arg2 === 'function') {
+ success = arg2;
+ error = arg3;
+ }
+
+ success = (success || helpers.log);
+ error = (error || helpers.log);
+
+ if (opts.useJQuery) {
+ this.useJQuery = opts.useJQuery;
+ }
+
+ var missingParams = this.getMissingParams(args);
+
+ if (missingParams.length > 0) {
+ var message = 'missing required params: ' + missingParams;
+
+ helpers.fail(message);
+
+ return;
+ }
+
+ var allHeaders = this.getHeaderParams(args);
+ var contentTypeHeaders = this.setContentTypes(args, opts);
+ var headers = {}, attrname;
+
+ for (attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
+ for (attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
+
+ var body = this.getBody(headers, args, opts);
+ var url = this.urlify(args);
+
+ if(url.indexOf('.{format}') > 0) {
+ if(headers) {
+ var format = headers.Accept || headers.accept;
+ if(format && format.indexOf('json') > 0) {
+ url = url.replace('.{format}', '.json');
+ }
+ else if(format && format.indexOf('xml') > 0) {
+ url = url.replace('.{format}', '.xml');
+ }
+ }
+ }
+
+ var obj = {
+ url: url,
+ method: this.method.toUpperCase(),
+ body: body,
+ useJQuery: this.useJQuery,
+ headers: headers,
+ on: {
+ response: function (response) {
+ return success(response, parent);
+ },
+ error: function (response) {
+ return error(response, parent);
+ }
+ }
+ };
+
+ this.clientAuthorizations.apply(obj, this.operation.security);
+ if (opts.mock === true) {
+ return obj;
+ } else {
+ new SwaggerHttp().execute(obj, opts);
+ }
+};
+
+Operation.prototype.setContentTypes = function (args, opts) {
+ // default type
+ var accepts = 'application/json';
+ var allDefinedParams = this.parameters;
+ var body;
+ var consumes = args.parameterContentType || 'application/json';
+ var definedFileParams = [];
+ var definedFormParams = [];
+ var headers = {};
+ var i;
+
+ // get params from the operation and set them in definedFileParams, definedFormParams, headers
+ for (i = 0; i < allDefinedParams.length; i++) {
+ var param = allDefinedParams[i];
+
+ if (param.in === 'formData') {
+ if (param.type === 'file') {
+ definedFileParams.push(param);
+ } else {
+ definedFormParams.push(param);
+ }
+ } else if (param.in === 'header' && opts) {
+ var key = param.name;
+ var headerValue = opts[param.name];
+
+ if (typeof opts[param.name] !== 'undefined') {
+ headers[key] = headerValue;
+ }
+ } else if (param.in === 'body' && typeof args[param.name] !== 'undefined') {
+ body = args[param.name];
+ }
+ }
+
+ // if there's a body, need to set the consumes header via requestContentType
+ if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) {
+ if (opts.requestContentType) {
+ consumes = opts.requestContentType;
+ }
+ } else {
+ // if any form params, content type must be set
+ if (definedFormParams.length > 0) {
+ if (opts.requestContentType) { // override if set
+ consumes = opts.requestContentType;
+ } else if (definedFileParams.length > 0) { // if a file, must be multipart/form-data
+ consumes = 'multipart/form-data';
+ } else { // default to x-www-from-urlencoded
+ consumes = 'application/x-www-form-urlencoded';
+ }
+ } else if (this.type === 'DELETE') {
+ body = '{}';
+ } else if (this.type !== 'DELETE') {
+ consumes = null;
+ }
+ }
+
+ if (consumes && this.consumes) {
+ if (this.consumes.indexOf(consumes) === -1) {
+ helpers.log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes));
+ }
+ }
+
+ if (opts.responseContentType) {
+ accepts = opts.responseContentType;
+ } else {
+ accepts = 'application/json';
+ }
+
+ if (accepts && this.produces) {
+ if (this.produces.indexOf(accepts) === -1) {
+ helpers.log('server can\'t produce ' + accepts);
+ }
+ }
+
+ if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) {
+ headers['Content-Type'] = consumes;
+ }
+
+ if (accepts) {
+ headers.Accept = accepts;
+ }
+
+ return headers;
+};
+
+Operation.prototype.asCurl = function (args) {
+ var obj = this.execute(args, {mock: true});
+
+ this.clientAuthorizations.apply(obj);
+
+ var results = [];
+
+ results.push('-X ' + this.method.toUpperCase());
+
+ if (obj.headers) {
+ var key;
+
+ for (key in obj.headers) {
+ results.push('--header "' + key + ': ' + obj.headers[key] + '"');
+ }
+ }
+
+ if (obj.body) {
+ var body;
+
+ if (typeof obj.body === 'object') {
+ body = JSON.stringify(obj.body);
+ } else {
+ body = obj.body;
+ }
+
+ results.push('-d "' + body.replace(/"/g, '\\"') + '"');
+ }
+
+ return 'curl ' + (results.join(' ')) + ' "' + obj.url + '"';
+};
+
+Operation.prototype.encodePathCollection = function (type, name, value) {
+ var encoded = '';
+ var i;
+ var separator = '';
+
+ if (type === 'ssv') {
+ separator = '%20';
+ } else if (type === 'tsv') {
+ separator = '\\t';
+ } else if (type === 'pipes') {
+ separator = '|';
+ } else {
+ separator = ',';
+ }
+
+ for (i = 0; i < value.length; i++) {
+ if (i === 0) {
+ encoded = this.encodeQueryParam(value[i]);
+ } else {
+ encoded += separator + this.encodeQueryParam(value[i]);
+ }
+ }
+
+ return encoded;
+};
+
+Operation.prototype.encodeQueryCollection = function (type, name, value) {
+ var encoded = '';
+ var i;
+
+ if (type === 'default' || type === 'multi') {
+ for (i = 0; i < value.length; i++) {
+ if (i > 0) {encoded += '&';}
+
+ encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]);
+ }
+ } else {
+ var separator = '';
+
+ if (type === 'csv') {
+ separator = ',';
+ } else if (type === 'ssv') {
+ separator = '%20';
+ } else if (type === 'tsv') {
+ separator = '\\t';
+ } else if (type === 'pipes') {
+ separator = '|';
+ } else if (type === 'brackets') {
+ for (i = 0; i < value.length; i++) {
+ if (i !== 0) {
+ encoded += '&';
+ }
+
+ encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]);
+ }
+ }
+
+ if (separator !== '') {
+ for (i = 0; i < value.length; i++) {
+ if (i === 0) {
+ encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]);
+ } else {
+ encoded += separator + this.encodeQueryParam(value[i]);
+ }
+ }
+ }
+ }
+
+ return encoded;
+};
+
+Operation.prototype.encodeQueryParam = function (arg) {
+ return encodeURIComponent(arg);
+};
+
+/**
+ * TODO revisit, might not want to leave '/'
+ **/
+Operation.prototype.encodePathParam = function (pathParam) {
+ var encParts, parts, i, len;
+
+ pathParam = pathParam.toString();
+
+ if (pathParam.indexOf('/') === -1) {
+ return encodeURIComponent(pathParam);
+ } else {
+ parts = pathParam.split('/');
+ encParts = [];
+
+ for (i = 0, len = parts.length; i < len; i++) {
+ encParts.push(encodeURIComponent(parts[i]));
+ }
+
+ return encParts.join('/');
+ }
+};
+
+},{"../helpers":4,"../http":5,"./model":8,"lodash-compat/lang/isUndefined":103}],10:[function(require,module,exports){
+'use strict';
+
+var OperationGroup = module.exports = function (tag, description, externalDocs, operation) {
+ this.description = description;
+ this.externalDocs = externalDocs;
+ this.name = tag;
+ this.operation = operation;
+ this.operationsArray = [];
+ this.path = tag;
+ this.tag = tag;
+};
+
+OperationGroup.prototype.sort = function () {
+
+};
+
+
+},{}],11:[function(require,module,exports){
+/*!
+ * The buffer module from node.js, for the browser.
+ *
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
+ * @license MIT
+ */
+
+var base64 = require('base64-js')
+var ieee754 = require('ieee754')
+var isArray = require('is-array')
+
+exports.Buffer = Buffer
+exports.SlowBuffer = SlowBuffer
+exports.INSPECT_MAX_BYTES = 50
+Buffer.poolSize = 8192 // not used by this implementation
+
+var kMaxLength = 0x3fffffff
+var rootParent = {}
+
+/**
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
+ * === true Use Uint8Array implementation (fastest)
+ * === false Use Object implementation (most compatible, even IE6)
+ *
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
+ * Opera 11.6+, iOS 4.2+.
+ *
+ * Note:
+ *
+ * - Implementation must support adding new properties to `Uint8Array` instances.
+ * Firefox 4-29 lacked support, fixed in Firefox 30+.
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
+ *
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
+ *
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
+ * incorrect length in some situations.
+ *
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will
+ * get the Object implementation, which is slower but will work correctly.
+ */
+Buffer.TYPED_ARRAY_SUPPORT = (function () {
+ try {
+ var buf = new ArrayBuffer(0)
+ var arr = new Uint8Array(buf)
+ arr.foo = function () { return 42 }
+ return arr.foo() === 42 && // typed array instances can be augmented
+ typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
+ new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
+ } catch (e) {
+ return false
+ }
+})()
+
+/**
+ * Class: Buffer
+ * =============
+ *
+ * The Buffer constructor returns instances of `Uint8Array` that are augmented
+ * with function properties for all the node `Buffer` API functions. We use
+ * `Uint8Array` so that square bracket notation works as expected -- it returns
+ * a single octet.
+ *
+ * By augmenting the instances, we can avoid modifying the `Uint8Array`
+ * prototype.
+ */
+function Buffer (subject, encoding) {
+ var self = this
+ if (!(self instanceof Buffer)) return new Buffer(subject, encoding)
+
+ var type = typeof subject
+ var length
+
+ if (type === 'number') {
+ length = +subject
+ } else if (type === 'string') {
+ length = Buffer.byteLength(subject, encoding)
+ } else if (type === 'object' && subject !== null) {
+ // assume object is array-like
+ if (subject.type === 'Buffer' && isArray(subject.data)) subject = subject.data
+ length = +subject.length
+ } else {
+ throw new TypeError('must start with number, buffer, array or string')
+ }
+
+ if (length > kMaxLength) {
+ throw new RangeError('Attempt to allocate Buffer larger than maximum size: 0x' +
+ kMaxLength.toString(16) + ' bytes')
+ }
+
+ if (length < 0) length = 0
+ else length >>>= 0 // coerce to uint32
+
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ // Preferred: Return an augmented `Uint8Array` instance for best performance
+ self = Buffer._augment(new Uint8Array(length)) // eslint-disable-line consistent-this
+ } else {
+ // Fallback: Return THIS instance of Buffer (created by `new`)
+ self.length = length
+ self._isBuffer = true
+ }
+
+ var i
+ if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
+ // Speed optimization -- use set if we're copying from a typed array
+ self._set(subject)
+ } else if (isArrayish(subject)) {
+ // Treat array-ish objects as a byte array
+ if (Buffer.isBuffer(subject)) {
+ for (i = 0; i < length; i++) {
+ self[i] = subject.readUInt8(i)
+ }
+ } else {
+ for (i = 0; i < length; i++) {
+ self[i] = ((subject[i] % 256) + 256) % 256
+ }
+ }
+ } else if (type === 'string') {
+ self.write(subject, 0, encoding)
+ } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT) {
+ for (i = 0; i < length; i++) {
+ self[i] = 0
+ }
+ }
+
+ if (length > 0 && length <= Buffer.poolSize) self.parent = rootParent
+
+ return self
+}
+
+function SlowBuffer (subject, encoding) {
+ if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding)
+
+ var buf = new Buffer(subject, encoding)
+ delete buf.parent
+ return buf
+}
+
+Buffer.isBuffer = function isBuffer (b) {
+ return !!(b != null && b._isBuffer)
+}
+
+Buffer.compare = function compare (a, b) {
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
+ throw new TypeError('Arguments must be Buffers')
+ }
+
+ if (a === b) return 0
+
+ var x = a.length
+ var y = b.length
+ for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
+ if (i !== len) {
+ x = a[i]
+ y = b[i]
+ }
+ if (x < y) return -1
+ if (y < x) return 1
+ return 0
+}
+
+Buffer.isEncoding = function isEncoding (encoding) {
+ switch (String(encoding).toLowerCase()) {
+ case 'hex':
+ case 'utf8':
+ case 'utf-8':
+ case 'ascii':
+ case 'binary':
+ case 'base64':
+ case 'raw':
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return true
+ default:
+ return false
+ }
+}
+
+Buffer.concat = function concat (list, totalLength) {
+ if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.')
+
+ if (list.length === 0) {
+ return new Buffer(0)
+ } else if (list.length === 1) {
+ return list[0]
+ }
+
+ var i
+ if (totalLength === undefined) {
+ totalLength = 0
+ for (i = 0; i < list.length; i++) {
+ totalLength += list[i].length
+ }
+ }
+
+ var buf = new Buffer(totalLength)
+ var pos = 0
+ for (i = 0; i < list.length; i++) {
+ var item = list[i]
+ item.copy(buf, pos)
+ pos += item.length
+ }
+ return buf
+}
+
+Buffer.byteLength = function byteLength (str, encoding) {
+ var ret
+ str = str + ''
+ switch (encoding || 'utf8') {
+ case 'ascii':
+ case 'binary':
+ case 'raw':
+ ret = str.length
+ break
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ ret = str.length * 2
+ break
+ case 'hex':
+ ret = str.length >>> 1
+ break
+ case 'utf8':
+ case 'utf-8':
+ ret = utf8ToBytes(str).length
+ break
+ case 'base64':
+ ret = base64ToBytes(str).length
+ break
+ default:
+ ret = str.length
+ }
+ return ret
+}
+
+// pre-set for values that may exist in the future
+Buffer.prototype.length = undefined
+Buffer.prototype.parent = undefined
+
+// toString(encoding, start=0, end=buffer.length)
+Buffer.prototype.toString = function toString (encoding, start, end) {
+ var loweredCase = false
+
+ start = start >>> 0
+ end = end === undefined || end === Infinity ? this.length : end >>> 0
+
+ if (!encoding) encoding = 'utf8'
+ if (start < 0) start = 0
+ if (end > this.length) end = this.length
+ if (end <= start) return ''
+
+ while (true) {
+ switch (encoding) {
+ case 'hex':
+ return hexSlice(this, start, end)
+
+ case 'utf8':
+ case 'utf-8':
+ return utf8Slice(this, start, end)
+
+ case 'ascii':
+ return asciiSlice(this, start, end)
+
+ case 'binary':
+ return binarySlice(this, start, end)
+
+ case 'base64':
+ return base64Slice(this, start, end)
+
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ return utf16leSlice(this, start, end)
+
+ default:
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
+ encoding = (encoding + '').toLowerCase()
+ loweredCase = true
+ }
+ }
+}
+
+Buffer.prototype.equals = function equals (b) {
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
+ if (this === b) return true
+ return Buffer.compare(this, b) === 0
+}
+
+Buffer.prototype.inspect = function inspect () {
+ var str = ''
+ var max = exports.INSPECT_MAX_BYTES
+ if (this.length > 0) {
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
+ if (this.length > max) str += ' ... '
+ }
+ return '<Buffer ' + str + '>'
+}
+
+Buffer.prototype.compare = function compare (b) {
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
+ if (this === b) return 0
+ return Buffer.compare(this, b)
+}
+
+Buffer.prototype.indexOf = function indexOf (val, byteOffset) {
+ if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff
+ else if (byteOffset < -0x80000000) byteOffset = -0x80000000
+ byteOffset >>= 0
+
+ if (this.length === 0) return -1
+ if (byteOffset >= this.length) return -1
+
+ // Negative offsets start from the end of the buffer
+ if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
+
+ if (typeof val === 'string') {
+ if (val.length === 0) return -1 // special case: looking for empty string always fails
+ return String.prototype.indexOf.call(this, val, byteOffset)
+ }
+ if (Buffer.isBuffer(val)) {
+ return arrayIndexOf(this, val, byteOffset)
+ }
+ if (typeof val === 'number') {
+ if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
+ return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
+ }
+ return arrayIndexOf(this, [ val ], byteOffset)
+ }
+
+ function arrayIndexOf (arr, val, byteOffset) {
+ var foundIndex = -1
+ for (var i = 0; byteOffset + i < arr.length; i++) {
+ if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) {
+ if (foundIndex === -1) foundIndex = i
+ if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex
+ } else {
+ foundIndex = -1
+ }
+ }
+ return -1
+ }
+
+ throw new TypeError('val must be string, number or Buffer')
+}
+
+// `get` will be removed in Node 0.13+
+Buffer.prototype.get = function get (offset) {
+ console.log('.get() is deprecated. Access using array indexes instead.')
+ return this.readUInt8(offset)
+}
+
+// `set` will be removed in Node 0.13+
+Buffer.prototype.set = function set (v, offset) {
+ console.log('.set() is deprecated. Access using array indexes instead.')
+ return this.writeUInt8(v, offset)
+}
+
+function hexWrite (buf, string, offset, length) {
+ offset = Number(offset) || 0
+ var remaining = buf.length - offset
+ if (!length) {
+ length = remaining
+ } else {
+ length = Number(length)
+ if (length > remaining) {
+ length = remaining
+ }
+ }
+
+ // must be an even number of digits
+ var strLen = string.length
+ if (strLen % 2 !== 0) throw new Error('Invalid hex string')
+
+ if (length > strLen / 2) {
+ length = strLen / 2
+ }
+ for (var i = 0; i < length; i++) {
+ var parsed = parseInt(string.substr(i * 2, 2), 16)
+ if (isNaN(parsed)) throw new Error('Invalid hex string')
+ buf[offset + i] = parsed
+ }
+ return i
+}
+
+function utf8Write (buf, string, offset, length) {
+ var charsWritten = blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
+ return charsWritten
+}
+
+function asciiWrite (buf, string, offset, length) {
+ var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
+ return charsWritten
+}
+
+function binaryWrite (buf, string, offset, length) {
+ return asciiWrite(buf, string, offset, length)
+}
+
+function base64Write (buf, string, offset, length) {
+ var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
+ return charsWritten
+}
+
+function utf16leWrite (buf, string, offset, length) {
+ var charsWritten = blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
+ return charsWritten
+}
+
+Buffer.prototype.write = function write (string, offset, length, encoding) {
+ // Support both (string, offset, length, encoding)
+ // and the legacy (string, encoding, offset, length)
+ if (isFinite(offset)) {
+ if (!isFinite(length)) {
+ encoding = length
+ length = undefined
+ }
+ } else { // legacy
+ var swap = encoding
+ encoding = offset
+ offset = length
+ length = swap
+ }
+
+ offset = Number(offset) || 0
+
+ if (length < 0 || offset < 0 || offset > this.length) {
+ throw new RangeError('attempt to write outside buffer bounds')
+ }
+
+ var remaining = this.length - offset
+ if (!length) {
+ length = remaining
+ } else {
+ length = Number(length)
+ if (length > remaining) {
+ length = remaining
+ }
+ }
+ encoding = String(encoding || 'utf8').toLowerCase()
+
+ var ret
+ switch (encoding) {
+ case 'hex':
+ ret = hexWrite(this, string, offset, length)
+ break
+ case 'utf8':
+ case 'utf-8':
+ ret = utf8Write(this, string, offset, length)
+ break
+ case 'ascii':
+ ret = asciiWrite(this, string, offset, length)
+ break
+ case 'binary':
+ ret = binaryWrite(this, string, offset, length)
+ break
+ case 'base64':
+ ret = base64Write(this, string, offset, length)
+ break
+ case 'ucs2':
+ case 'ucs-2':
+ case 'utf16le':
+ case 'utf-16le':
+ ret = utf16leWrite(this, string, offset, length)
+ break
+ default:
+ throw new TypeError('Unknown encoding: ' + encoding)
+ }
+ return ret
+}
+
+Buffer.prototype.toJSON = function toJSON () {
+ return {
+ type: 'Buffer',
+ data: Array.prototype.slice.call(this._arr || this, 0)
+ }
+}
+
+function base64Slice (buf, start, end) {
+ if (start === 0 && end === buf.length) {
+ return base64.fromByteArray(buf)
+ } else {
+ return base64.fromByteArray(buf.slice(start, end))
+ }
+}
+
+function utf8Slice (buf, start, end) {
+ var res = ''
+ var tmp = ''
+ end = Math.min(buf.length, end)
+
+ for (var i = start; i < end; i++) {
+ if (buf[i] <= 0x7F) {
+ res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
+ tmp = ''
+ } else {
+ tmp += '%' + buf[i].toString(16)
+ }
+ }
+
+ return res + decodeUtf8Char(tmp)
+}
+
+function asciiSlice (buf, start, end) {
+ var ret = ''
+ end = Math.min(buf.length, end)
+
+ for (var i = start; i < end; i++) {
+ ret += String.fromCharCode(buf[i] & 0x7F)
+ }
+ return ret
+}
+
+function binarySlice (buf, start, end) {
+ var ret = ''
+ end = Math.min(buf.length, end)
+
+ for (var i = start; i < end; i++) {
+ ret += String.fromCharCode(buf[i])
+ }
+ return ret
+}
+
+function hexSlice (buf, start, end) {
+ var len = buf.length
+
+ if (!start || start < 0) start = 0
+ if (!end || end < 0 || end > len) end = len
+
+ var out = ''
+ for (var i = start; i < end; i++) {
+ out += toHex(buf[i])
+ }
+ return out
+}
+
+function utf16leSlice (buf, start, end) {
+ var bytes = buf.slice(start, end)
+ var res = ''
+ for (var i = 0; i < bytes.length; i += 2) {
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
+ }
+ return res
+}
+
+Buffer.prototype.slice = function slice (start, end) {
+ var len = this.length
+ start = ~~start
+ end = end === undefined ? len : ~~end
+
+ if (start < 0) {
+ start += len
+ if (start < 0) start = 0
+ } else if (start > len) {
+ start = len
+ }
+
+ if (end < 0) {
+ end += len
+ if (end < 0) end = 0
+ } else if (end > len) {
+ end = len
+ }
+
+ if (end < start) end = start
+
+ var newBuf
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ newBuf = Buffer._augment(this.subarray(start, end))
+ } else {
+ var sliceLen = end - start
+ newBuf = new Buffer(sliceLen, undefined)
+ for (var i = 0; i < sliceLen; i++) {
+ newBuf[i] = this[i + start]
+ }
+ }
+
+ if (newBuf.length) newBuf.parent = this.parent || this
+
+ return newBuf
+}
+
+/*
+ * Need to make sure that buffer isn't trying to write out of bounds.
+ */
+function checkOffset (offset, ext, length) {
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
+}
+
+Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var val = this[offset]
+ var mul = 1
+ var i = 0
+ while (++i < byteLength && (mul *= 0x100)) {
+ val += this[offset + i] * mul
+ }
+
+ return val
+}
+
+Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) {
+ checkOffset(offset, byteLength, this.length)
+ }
+
+ var val = this[offset + --byteLength]
+ var mul = 1
+ while (byteLength > 0 && (mul *= 0x100)) {
+ val += this[offset + --byteLength] * mul
+ }
+
+ return val
+}
+
+Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 1, this.length)
+ return this[offset]
+}
+
+Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ return this[offset] | (this[offset + 1] << 8)
+}
+
+Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ return (this[offset] << 8) | this[offset + 1]
+}
+
+Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return ((this[offset]) |
+ (this[offset + 1] << 8) |
+ (this[offset + 2] << 16)) +
+ (this[offset + 3] * 0x1000000)
+}
+
+Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset] * 0x1000000) +
+ ((this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ this[offset + 3])
+}
+
+Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var val = this[offset]
+ var mul = 1
+ var i = 0
+ while (++i < byteLength && (mul *= 0x100)) {
+ val += this[offset + i] * mul
+ }
+ mul *= 0x80
+
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
+
+ return val
+}
+
+Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
+
+ var i = byteLength
+ var mul = 1
+ var val = this[offset + --i]
+ while (i > 0 && (mul *= 0x100)) {
+ val += this[offset + --i] * mul
+ }
+ mul *= 0x80
+
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
+
+ return val
+}
+
+Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 1, this.length)
+ if (!(this[offset] & 0x80)) return (this[offset])
+ return ((0xff - this[offset] + 1) * -1)
+}
+
+Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ var val = this[offset] | (this[offset + 1] << 8)
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
+}
+
+Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 2, this.length)
+ var val = this[offset + 1] | (this[offset] << 8)
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
+}
+
+Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset]) |
+ (this[offset + 1] << 8) |
+ (this[offset + 2] << 16) |
+ (this[offset + 3] << 24)
+}
+
+Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+
+ return (this[offset] << 24) |
+ (this[offset + 1] << 16) |
+ (this[offset + 2] << 8) |
+ (this[offset + 3])
+}
+
+Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+ return ieee754.read(this, offset, true, 23, 4)
+}
+
+Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 4, this.length)
+ return ieee754.read(this, offset, false, 23, 4)
+}
+
+Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 8, this.length)
+ return ieee754.read(this, offset, true, 52, 8)
+}
+
+Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
+ if (!noAssert) checkOffset(offset, 8, this.length)
+ return ieee754.read(this, offset, false, 52, 8)
+}
+
+function checkInt (buf, value, offset, ext, max, min) {
+ if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
+ if (value > max || value < min) throw new RangeError('value is out of bounds')
+ if (offset + ext > buf.length) throw new RangeError('index out of range')
+}
+
+Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
+
+ var mul = 1
+ var i = 0
+ this[offset] = value & 0xFF
+ while (++i < byteLength && (mul *= 0x100)) {
+ this[offset + i] = (value / mul) >>> 0 & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ byteLength = byteLength >>> 0
+ if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
+
+ var i = byteLength - 1
+ var mul = 1
+ this[offset + i] = value & 0xFF
+ while (--i >= 0 && (mul *= 0x100)) {
+ this[offset + i] = (value / mul) >>> 0 & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
+ this[offset] = value
+ return offset + 1
+}
+
+function objectWriteUInt16 (buf, value, offset, littleEndian) {
+ if (value < 0) value = 0xffff + value + 1
+ for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
+ buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
+ (littleEndian ? i : 1 - i) * 8
+ }
+}
+
+Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = value
+ this[offset + 1] = (value >>> 8)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 8)
+ this[offset + 1] = value
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
+ return offset + 2
+}
+
+function objectWriteUInt32 (buf, value, offset, littleEndian) {
+ if (value < 0) value = 0xffffffff + value + 1
+ for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
+ buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
+ }
+}
+
+Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset + 3] = (value >>> 24)
+ this[offset + 2] = (value >>> 16)
+ this[offset + 1] = (value >>> 8)
+ this[offset] = value
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 24)
+ this[offset + 1] = (value >>> 16)
+ this[offset + 2] = (value >>> 8)
+ this[offset + 3] = value
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) {
+ checkInt(
+ this, value, offset, byteLength,
+ Math.pow(2, 8 * byteLength - 1) - 1,
+ -Math.pow(2, 8 * byteLength - 1)
+ )
+ }
+
+ var i = 0
+ var mul = 1
+ var sub = value < 0 ? 1 : 0
+ this[offset] = value & 0xFF
+ while (++i < byteLength && (mul *= 0x100)) {
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) {
+ checkInt(
+ this, value, offset, byteLength,
+ Math.pow(2, 8 * byteLength - 1) - 1,
+ -Math.pow(2, 8 * byteLength - 1)
+ )
+ }
+
+ var i = byteLength - 1
+ var mul = 1
+ var sub = value < 0 ? 1 : 0
+ this[offset + i] = value & 0xFF
+ while (--i >= 0 && (mul *= 0x100)) {
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
+ }
+
+ return offset + byteLength
+}
+
+Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
+ if (value < 0) value = 0xff + value + 1
+ this[offset] = value
+ return offset + 1
+}
+
+Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = value
+ this[offset + 1] = (value >>> 8)
+ } else {
+ objectWriteUInt16(this, value, offset, true)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 8)
+ this[offset + 1] = value
+ } else {
+ objectWriteUInt16(this, value, offset, false)
+ }
+ return offset + 2
+}
+
+Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = value
+ this[offset + 1] = (value >>> 8)
+ this[offset + 2] = (value >>> 16)
+ this[offset + 3] = (value >>> 24)
+ } else {
+ objectWriteUInt32(this, value, offset, true)
+ }
+ return offset + 4
+}
+
+Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
+ value = +value
+ offset = offset >>> 0
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
+ if (value < 0) value = 0xffffffff + value + 1
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ this[offset] = (value >>> 24)
+ this[offset + 1] = (value >>> 16)
+ this[offset + 2] = (value >>> 8)
+ this[offset + 3] = value
+ } else {
+ objectWriteUInt32(this, value, offset, false)
+ }
+ return offset + 4
+}
+
+function checkIEEE754 (buf, value, offset, ext, max, min) {
+ if (value > max || value < min) throw new RangeError('value is out of bounds')
+ if (offset + ext > buf.length) throw new RangeError('index out of range')
+ if (offset < 0) throw new RangeError('index out of range')
+}
+
+function writeFloat (buf, value, offset, littleEndian, noAssert) {
+ if (!noAssert) {
+ checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
+ }
+ ieee754.write(buf, value, offset, littleEndian, 23, 4)
+ return offset + 4
+}
+
+Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
+ return writeFloat(this, value, offset, true, noAssert)
+}
+
+Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
+ return writeFloat(this, value, offset, false, noAssert)
+}
+
+function writeDouble (buf, value, offset, littleEndian, noAssert) {
+ if (!noAssert) {
+ checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
+ }
+ ieee754.write(buf, value, offset, littleEndian, 52, 8)
+ return offset + 8
+}
+
+Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
+ return writeDouble(this, value, offset, true, noAssert)
+}
+
+Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
+ return writeDouble(this, value, offset, false, noAssert)
+}
+
+// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
+Buffer.prototype.copy = function copy (target, target_start, start, end) {
+ if (!start) start = 0
+ if (!end && end !== 0) end = this.length
+ if (target_start >= target.length) target_start = target.length
+ if (!target_start) target_start = 0
+ if (end > 0 && end < start) end = start
+
+ // Copy 0 bytes; we're done
+ if (end === start) return 0
+ if (target.length === 0 || this.length === 0) return 0
+
+ // Fatal error conditions
+ if (target_start < 0) {
+ throw new RangeError('targetStart out of bounds')
+ }
+ if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
+
+ // Are we oob?
+ if (end > this.length) end = this.length
+ if (target.length - target_start < end - start) {
+ end = target.length - target_start + start
+ }
+
+ var len = end - start
+
+ if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
+ for (var i = 0; i < len; i++) {
+ target[i + target_start] = this[i + start]
+ }
+ } else {
+ target._set(this.subarray(start, start + len), target_start)
+ }
+
+ return len
+}
+
+// fill(value, start=0, end=buffer.length)
+Buffer.prototype.fill = function fill (value, start, end) {
+ if (!value) value = 0
+ if (!start) start = 0
+ if (!end) end = this.length
+
+ if (end < start) throw new RangeError('end < start')
+
+ // Fill 0 bytes; we're done
+ if (end === start) return
+ if (this.length === 0) return
+
+ if (start < 0 || start >= this.length) throw new RangeError('start out of bounds')
+ if (end < 0 || end > this.length) throw new RangeError('end out of bounds')
+
+ var i
+ if (typeof value === 'number') {
+ for (i = start; i < end; i++) {
+ this[i] = value
+ }
+ } else {
+ var bytes = utf8ToBytes(value.toString())
+ var len = bytes.length
+ for (i = start; i < end; i++) {
+ this[i] = bytes[i % len]
+ }
+ }
+
+ return this
+}
+
+/**
+ * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
+ * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
+ */
+Buffer.prototype.toArrayBuffer = function toArrayBuffer () {
+ if (typeof Uint8Array !== 'undefined') {
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ return (new Buffer(this)).buffer
+ } else {
+ var buf = new Uint8Array(this.length)
+ for (var i = 0, len = buf.length; i < len; i += 1) {
+ buf[i] = this[i]
+ }
+ return buf.buffer
+ }
+ } else {
+ throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
+ }
+}
+
+// HELPER FUNCTIONS
+// ================
+
+var BP = Buffer.prototype
+
+/**
+ * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
+ */
+Buffer._augment = function _augment (arr) {
+ arr.constructor = Buffer
+ arr._isBuffer = true
+
+ // save reference to original Uint8Array set method before overwriting
+ arr._set = arr.set
+
+ // deprecated, will be removed in node 0.13+
+ arr.get = BP.get
+ arr.set = BP.set
+
+ arr.write = BP.write
+ arr.toString = BP.toString
+ arr.toLocaleString = BP.toString
+ arr.toJSON = BP.toJSON
+ arr.equals = BP.equals
+ arr.compare = BP.compare
+ arr.indexOf = BP.indexOf
+ arr.copy = BP.copy
+ arr.slice = BP.slice
+ arr.readUIntLE = BP.readUIntLE
+ arr.readUIntBE = BP.readUIntBE
+ arr.readUInt8 = BP.readUInt8
+ arr.readUInt16LE = BP.readUInt16LE
+ arr.readUInt16BE = BP.readUInt16BE
+ arr.readUInt32LE = BP.readUInt32LE
+ arr.readUInt32BE = BP.readUInt32BE
+ arr.readIntLE = BP.readIntLE
+ arr.readIntBE = BP.readIntBE
+ arr.readInt8 = BP.readInt8
+ arr.readInt16LE = BP.readInt16LE
+ arr.readInt16BE = BP.readInt16BE
+ arr.readInt32LE = BP.readInt32LE
+ arr.readInt32BE = BP.readInt32BE
+ arr.readFloatLE = BP.readFloatLE
+ arr.readFloatBE = BP.readFloatBE
+ arr.readDoubleLE = BP.readDoubleLE
+ arr.readDoubleBE = BP.readDoubleBE
+ arr.writeUInt8 = BP.writeUInt8
+ arr.writeUIntLE = BP.writeUIntLE
+ arr.writeUIntBE = BP.writeUIntBE
+ arr.writeUInt16LE = BP.writeUInt16LE
+ arr.writeUInt16BE = BP.writeUInt16BE
+ arr.writeUInt32LE = BP.writeUInt32LE
+ arr.writeUInt32BE = BP.writeUInt32BE
+ arr.writeIntLE = BP.writeIntLE
+ arr.writeIntBE = BP.writeIntBE
+ arr.writeInt8 = BP.writeInt8
+ arr.writeInt16LE = BP.writeInt16LE
+ arr.writeInt16BE = BP.writeInt16BE
+ arr.writeInt32LE = BP.writeInt32LE
+ arr.writeInt32BE = BP.writeInt32BE
+ arr.writeFloatLE = BP.writeFloatLE
+ arr.writeFloatBE = BP.writeFloatBE
+ arr.writeDoubleLE = BP.writeDoubleLE
+ arr.writeDoubleBE = BP.writeDoubleBE
+ arr.fill = BP.fill
+ arr.inspect = BP.inspect
+ arr.toArrayBuffer = BP.toArrayBuffer
+
+ return arr
+}
+
+var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g
+
+function base64clean (str) {
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
+ str = stringtrim(str).replace(INVALID_BASE64_RE, '')
+ // Node converts strings with length < 2 to ''
+ if (str.length < 2) return ''
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
+ while (str.length % 4 !== 0) {
+ str = str + '='
+ }
+ return str
+}
+
+function stringtrim (str) {
+ if (str.trim) return str.trim()
+ return str.replace(/^\s+|\s+$/g, '')
+}
+
+function isArrayish (subject) {
+ return isArray(subject) || Buffer.isBuffer(subject) ||
+ subject && typeof subject === 'object' &&
+ typeof subject.length === 'number'
+}
+
+function toHex (n) {
+ if (n < 16) return '0' + n.toString(16)
+ return n.toString(16)
+}
+
+function utf8ToBytes (string, units) {
+ units = units || Infinity
+ var codePoint
+ var length = string.length
+ var leadSurrogate = null
+ var bytes = []
+ var i = 0
+
+ for (; i < length; i++) {
+ codePoint = string.charCodeAt(i)
+
+ // is surrogate component
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
+ // last char was a lead
+ if (leadSurrogate) {
+ // 2 leads in a row
+ if (codePoint < 0xDC00) {
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ leadSurrogate = codePoint
+ continue
+ } else {
+ // valid surrogate pair
+ codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000
+ leadSurrogate = null
+ }
+ } else {
+ // no lead yet
+
+ if (codePoint > 0xDBFF) {
+ // unexpected trail
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ continue
+ } else if (i + 1 === length) {
+ // unpaired lead
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ continue
+ } else {
+ // valid lead
+ leadSurrogate = codePoint
+ continue
+ }
+ }
+ } else if (leadSurrogate) {
+ // valid bmp char, but last char was a lead
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
+ leadSurrogate = null
+ }
+
+ // encode utf8
+ if (codePoint < 0x80) {
+ if ((units -= 1) < 0) break
+ bytes.push(codePoint)
+ } else if (codePoint < 0x800) {
+ if ((units -= 2) < 0) break
+ bytes.push(
+ codePoint >> 0x6 | 0xC0,
+ codePoint & 0x3F | 0x80
+ )
+ } else if (codePoint < 0x10000) {
+ if ((units -= 3) < 0) break
+ bytes.push(
+ codePoint >> 0xC | 0xE0,
+ codePoint >> 0x6 & 0x3F | 0x80,
+ codePoint & 0x3F | 0x80
+ )
+ } else if (codePoint < 0x200000) {
+ if ((units -= 4) < 0) break
+ bytes.push(
+ codePoint >> 0x12 | 0xF0,
+ codePoint >> 0xC & 0x3F | 0x80,
+ codePoint >> 0x6 & 0x3F | 0x80,
+ codePoint & 0x3F | 0x80
+ )
+ } else {
+ throw new Error('Invalid code point')
+ }
+ }
+
+ return bytes
+}
+
+function asciiToBytes (str) {
+ var byteArray = []
+ for (var i = 0; i < str.length; i++) {
+ // Node's code seems to be doing this and not & 0x7F..
+ byteArray.push(str.charCodeAt(i) & 0xFF)
+ }
+ return byteArray
+}
+
+function utf16leToBytes (str, units) {
+ var c, hi, lo
+ var byteArray = []
+ for (var i = 0; i < str.length; i++) {
+ if ((units -= 2) < 0) break
+
+ c = str.charCodeAt(i)
+ hi = c >> 8
+ lo = c % 256
+ byteArray.push(lo)
+ byteArray.push(hi)
+ }
+
+ return byteArray
+}
+
+function base64ToBytes (str) {
+ return base64.toByteArray(base64clean(str))
+}
+
+function blitBuffer (src, dst, offset, length) {
+ for (var i = 0; i < length; i++) {
+ if ((i + offset >= dst.length) || (i >= src.length)) break
+ dst[i + offset] = src[i]
+ }
+ return i
+}
+
+function decodeUtf8Char (str) {
+ try {
+ return decodeURIComponent(str)
+ } catch (err) {
+ return String.fromCharCode(0xFFFD) // UTF 8 invalid char
+ }
+}
+
+},{"base64-js":12,"ieee754":13,"is-array":14}],12:[function(require,module,exports){
+var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+
+;(function (exports) {
+ 'use strict';
+
+ var Arr = (typeof Uint8Array !== 'undefined')
+ ? Uint8Array
+ : Array
+
+ var PLUS = '+'.charCodeAt(0)
+ var SLASH = '/'.charCodeAt(0)
+ var NUMBER = '0'.charCodeAt(0)
+ var LOWER = 'a'.charCodeAt(0)
+ var UPPER = 'A'.charCodeAt(0)
+ var PLUS_URL_SAFE = '-'.charCodeAt(0)
+ var SLASH_URL_SAFE = '_'.charCodeAt(0)
+
+ function decode (elt) {
+ var code = elt.charCodeAt(0)
+ if (code === PLUS ||
+ code === PLUS_URL_SAFE)
+ return 62 // '+'
+ if (code === SLASH ||
+ code === SLASH_URL_SAFE)
+ return 63 // '/'
+ if (code < NUMBER)
+ return -1 //no match
+ if (code < NUMBER + 10)
+ return code - NUMBER + 26 + 26
+ if (code < UPPER + 26)
+ return code - UPPER
+ if (code < LOWER + 26)
+ return code - LOWER + 26
+ }
+
+ function b64ToByteArray (b64) {
+ var i, j, l, tmp, placeHolders, arr
+
+ if (b64.length % 4 > 0) {
+ throw new Error('Invalid string. Length must be a multiple of 4')
+ }
+
+ // the number of equal signs (place holders)
+ // if there are two placeholders, than the two characters before it
+ // represent one byte
+ // if there is only one, then the three characters before it represent 2 bytes
+ // this is just a cheap hack to not do indexOf twice
+ var len = b64.length
+ placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
+
+ // base64 is 4/3 + up to two characters of the original data
+ arr = new Arr(b64.length * 3 / 4 - placeHolders)
+
+ // if there are placeholders, only get up to the last complete 4 chars
+ l = placeHolders > 0 ? b64.length - 4 : b64.length
+
+ var L = 0
+
+ function push (v) {
+ arr[L++] = v
+ }
+
+ for (i = 0, j = 0; i < l; i += 4, j += 3) {
+ tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
+ push((tmp & 0xFF0000) >> 16)
+ push((tmp & 0xFF00) >> 8)
+ push(tmp & 0xFF)
+ }
+
+ if (placeHolders === 2) {
+ tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
+ push(tmp & 0xFF)
+ } else if (placeHolders === 1) {
+ tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
+ push((tmp >> 8) & 0xFF)
+ push(tmp & 0xFF)
+ }
+
+ return arr
+ }
+
+ function uint8ToBase64 (uint8) {
+ var i,
+ extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
+ output = "",
+ temp, length
+
+ function encode (num) {
+ return lookup.charAt(num)
+ }
+
+ function tripletToBase64 (num) {
+ return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
+ }
+
+ // go through the array every three bytes, we'll deal with trailing stuff later
+ for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
+ temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
+ output += tripletToBase64(temp)
+ }
+
+ // pad the end with zeros, but make sure to not forget the extra bytes
+ switch (extraBytes) {
+ case 1:
+ temp = uint8[uint8.length - 1]
+ output += encode(temp >> 2)
+ output += encode((temp << 4) & 0x3F)
+ output += '=='
+ break
+ case 2:
+ temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
+ output += encode(temp >> 10)
+ output += encode((temp >> 4) & 0x3F)
+ output += encode((temp << 2) & 0x3F)
+ output += '='
+ break
+ }
+
+ return output
+ }
+
+ exports.toByteArray = b64ToByteArray
+ exports.fromByteArray = uint8ToBase64
+}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
+
+},{}],13:[function(require,module,exports){
+exports.read = function(buffer, offset, isLE, mLen, nBytes) {
+ var e, m,
+ eLen = nBytes * 8 - mLen - 1,
+ eMax = (1 << eLen) - 1,
+ eBias = eMax >> 1,
+ nBits = -7,
+ i = isLE ? (nBytes - 1) : 0,
+ d = isLE ? -1 : 1,
+ s = buffer[offset + i];
+
+ i += d;
+
+ e = s & ((1 << (-nBits)) - 1);
+ s >>= (-nBits);
+ nBits += eLen;
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
+
+ m = e & ((1 << (-nBits)) - 1);
+ e >>= (-nBits);
+ nBits += mLen;
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
+
+ if (e === 0) {
+ e = 1 - eBias;
+ } else if (e === eMax) {
+ return m ? NaN : ((s ? -1 : 1) * Infinity);
+ } else {
+ m = m + Math.pow(2, mLen);
+ e = e - eBias;
+ }
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
+};
+
+exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
+ var e, m, c,
+ eLen = nBytes * 8 - mLen - 1,
+ eMax = (1 << eLen) - 1,
+ eBias = eMax >> 1,
+ rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
+ i = isLE ? 0 : (nBytes - 1),
+ d = isLE ? 1 : -1,
+ s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
+
+ value = Math.abs(value);
+
+ if (isNaN(value) || value === Infinity) {
+ m = isNaN(value) ? 1 : 0;
+ e = eMax;
+ } else {
+ e = Math.floor(Math.log(value) / Math.LN2);
+ if (value * (c = Math.pow(2, -e)) < 1) {
+ e--;
+ c *= 2;
+ }
+ if (e + eBias >= 1) {
+ value += rt / c;
+ } else {
+ value += rt * Math.pow(2, 1 - eBias);
+ }
+ if (value * c >= 2) {
+ e++;
+ c /= 2;
+ }
+
+ if (e + eBias >= eMax) {
+ m = 0;
+ e = eMax;
+ } else if (e + eBias >= 1) {
+ m = (value * c - 1) * Math.pow(2, mLen);
+ e = e + eBias;
+ } else {
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
+ e = 0;
+ }
+ }
+
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
+
+ e = (e << mLen) | m;
+ eLen += mLen;
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
+
+ buffer[offset + i - d] |= s * 128;
+};
+
+},{}],14:[function(require,module,exports){
+
+/**
+ * isArray
+ */
+
+var isArray = Array.isArray;
+
+/**
+ * toString
+ */
+
+var str = Object.prototype.toString;
+
+/**
+ * Whether or not the given `val`
+ * is an array.
+ *
+ * example:
+ *
+ * isArray([]);
+ * // > true
+ * isArray(arguments);
+ * // > false
+ * isArray('');
+ * // > false
+ *
+ * @param {mixed} val
+ * @return {bool}
+ */
+
+module.exports = isArray || function (val) {
+ return !! val && '[object Array]' == str.call(val);
+};
+
+},{}],15:[function(require,module,exports){
+// shim for using process in browser
+
+var process = module.exports = {};
+var queue = [];
+var draining = false;
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ draining = true;
+ var currentQueue;
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ var i = -1;
+ while (++i < len) {
+ currentQueue[i]();
+ }
+ len = queue.length;
+ }
+ draining = false;
+}
+process.nextTick = function (fun) {
+ queue.push(fun);
+ if (!draining) {
+ setTimeout(drainQueue, 0);
+ }
+};
+
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+// TODO(shtylman)
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
+
+},{}],16:[function(require,module,exports){
+(function (Buffer){
+(function () {
+ "use strict";
+
+ function btoa(str) {
+ var buffer
+ ;
+
+ if (str instanceof Buffer) {
+ buffer = str;
+ } else {
+ buffer = new Buffer(str.toString(), 'binary');
+ }
+
+ return buffer.toString('base64');
+ }
+
+ module.exports = btoa;
+}());
+
+}).call(this,require("buffer").Buffer)
+
+},{"buffer":11}],17:[function(require,module,exports){
+/* jshint node: true */
+(function () {
+ "use strict";
+
+ function CookieAccessInfo(domain, path, secure, script) {
+ if (this instanceof CookieAccessInfo) {
+ this.domain = domain || undefined;
+ this.path = path || "/";
+ this.secure = !!secure;
+ this.script = !!script;
+ return this;
+ }
+ return new CookieAccessInfo(domain, path, secure, script);
+ }
+ exports.CookieAccessInfo = CookieAccessInfo;
+
+ function Cookie(cookiestr, request_domain, request_path) {
+ if (cookiestr instanceof Cookie) {
+ return cookiestr;
+ }
+ if (this instanceof Cookie) {
+ this.name = null;
+ this.value = null;
+ this.expiration_date = Infinity;
+ this.path = String(request_path || "/");
+ this.explicit_path = false;
+ this.domain = request_domain || null;
+ this.explicit_domain = false;
+ this.secure = false; //how to define default?
+ this.noscript = false; //httponly
+ if (cookiestr) {
+ this.parse(cookiestr, request_domain, request_path);
+ }
+ return this;
+ }
+ return new Cookie(cookiestr);
+ }
+ exports.Cookie = Cookie;
+
+ Cookie.prototype.toString = function toString() {
+ var str = [this.name + "=" + this.value];
+ if (this.expiration_date !== Infinity) {
+ str.push("expires=" + (new Date(this.expiration_date)).toGMTString());
+ }
+ if (this.domain) {
+ str.push("domain=" + this.domain);
+ }
+ if (this.path) {
+ str.push("path=" + this.path);
+ }
+ if (this.secure) {
+ str.push("secure");
+ }
+ if (this.noscript) {
+ str.push("httponly");
+ }
+ return str.join("; ");
+ };
+
+ Cookie.prototype.toValueString = function toValueString() {
+ return this.name + "=" + this.value;
+ };
+
+ var cookie_str_splitter = /[:](?=\s*[a-zA-Z0-9_\-]+\s*[=])/g;
+ Cookie.prototype.parse = function parse(str, request_domain, request_path) {
+ if (this instanceof Cookie) {
+ var parts = str.split(";").filter(function (value) {
+ return !!value;
+ }),
+ pair = parts[0].match(/([^=]+)=([\s\S]*)/),
+ key = pair[1],
+ value = pair[2],
+ i;
+ this.name = key;
+ this.value = value;
+
+ for (i = 1; i < parts.length; i += 1) {
+ pair = parts[i].match(/([^=]+)(?:=([\s\S]*))?/);
+ key = pair[1].trim().toLowerCase();
+ value = pair[2];
+ switch (key) {
+ case "httponly":
+ this.noscript = true;
+ break;
+ case "expires":
+ this.expiration_date = value ?
+ Number(Date.parse(value)) :
+ Infinity;
+ break;
+ case "path":
+ this.path = value ?
+ value.trim() :
+ "";
+ this.explicit_path = true;
+ break;
+ case "domain":
+ this.domain = value ?
+ value.trim() :
+ "";
+ this.explicit_domain = !!this.domain;
+ break;
+ case "secure":
+ this.secure = true;
+ break;
+ }
+ }
+
+ if (!this.explicit_path) {
+ this.path = request_path || "/";
+ }
+ if (!this.explicit_domain) {
+ this.domain = request_domain;
+ }
+
+ return this;
+ }
+ return new Cookie().parse(str, request_domain, request_path);
+ };
+
+ Cookie.prototype.matches = function matches(access_info) {
+ if (this.noscript && access_info.script ||
+ this.secure && !access_info.secure ||
+ !this.collidesWith(access_info)) {
+ return false;
+ }
+ return true;
+ };
+
+ Cookie.prototype.collidesWith = function collidesWith(access_info) {
+ if ((this.path && !access_info.path) || (this.domain && !access_info.domain)) {
+ return false;
+ }
+ if (this.path && access_info.path.indexOf(this.path) !== 0) {
+ return false;
+ }
+ if (!this.explicit_path) {
+ if (this.path !== access_info.path) {
+ return false;
+ }
+ }
+ var access_domain = access_info.domain && access_info.domain.replace(/^[\.]/,'');
+ var cookie_domain = this.domain && this.domain.replace(/^[\.]/,'');
+ if (cookie_domain === access_domain) {
+ return true;
+ }
+ if (cookie_domain) {
+ if (!this.explicit_domain) {
+ return false; // we already checked if the domains were exactly the same
+ }
+ var wildcard = access_domain.indexOf(cookie_domain);
+ if (wildcard === -1 || wildcard !== access_domain.length - cookie_domain.length) {
+ return false;
+ }
+ return true;
+ }
+ return true;
+ };
+
+ function CookieJar() {
+ var cookies, cookies_list, collidable_cookie;
+ if (this instanceof CookieJar) {
+ cookies = Object.create(null); //name: [Cookie]
+
+ this.setCookie = function setCookie(cookie, request_domain, request_path) {
+ var remove, i;
+ cookie = new Cookie(cookie, request_domain, request_path);
+ //Delete the cookie if the set is past the current time
+ remove = cookie.expiration_date <= Date.now();
+ if (cookies[cookie.name] !== undefined) {
+ cookies_list = cookies[cookie.name];
+ for (i = 0; i < cookies_list.length; i += 1) {
+ collidable_cookie = cookies_list[i];
+ if (collidable_cookie.collidesWith(cookie)) {
+ if (remove) {
+ cookies_list.splice(i, 1);
+ if (cookies_list.length === 0) {
+ delete cookies[cookie.name];
+ }
+ return false;
+ }
+ cookies_list[i] = cookie;
+ return cookie;
+ }
+ }
+ if (remove) {
+ return false;
+ }
+ cookies_list.push(cookie);
+ return cookie;
+ }
+ if (remove) {
+ return false;
+ }
+ cookies[cookie.name] = [cookie];
+ return cookies[cookie.name];
+ };
+ //returns a cookie
+ this.getCookie = function getCookie(cookie_name, access_info) {
+ var cookie, i;
+ cookies_list = cookies[cookie_name];
+ if (!cookies_list) {
+ return;
+ }
+ for (i = 0; i < cookies_list.length; i += 1) {
+ cookie = cookies_list[i];
+ if (cookie.expiration_date <= Date.now()) {
+ if (cookies_list.length === 0) {
+ delete cookies[cookie.name];
+ }
+ continue;
+ }
+ if (cookie.matches(access_info)) {
+ return cookie;
+ }
+ }
+ };
+ //returns a list of cookies
+ this.getCookies = function getCookies(access_info) {
+ var matches = [], cookie_name, cookie;
+ for (cookie_name in cookies) {
+ cookie = this.getCookie(cookie_name, access_info);
+ if (cookie) {
+ matches.push(cookie);
+ }
+ }
+ matches.toString = function toString() {
+ return matches.join(":");
+ };
+ matches.toValueString = function toValueString() {
+ return matches.map(function (c) {
+ return c.toValueString();
+ }).join(';');
+ };
+ return matches;
+ };
+
+ return this;
+ }
+ return new CookieJar();
+ }
+ exports.CookieJar = CookieJar;
+
+ //returns list of cookies that were set correctly. Cookies that are expired and removed are not returned.
+ CookieJar.prototype.setCookies = function setCookies(cookies, request_domain, request_path) {
+ cookies = Array.isArray(cookies) ?
+ cookies :
+ cookies.split(cookie_str_splitter);
+ var successful = [],
+ i,
+ cookie;
+ cookies = cookies.map(Cookie);
+ for (i = 0; i < cookies.length; i += 1) {
+ cookie = cookies[i];
+ if (this.setCookie(cookie, request_domain, request_path)) {
+ successful.push(cookie);
+ }
+ }
+ return successful;
+ };
+}());
+
+},{}],18:[function(require,module,exports){
+/*!
+ * jQuery JavaScript Library v2.1.3
+ * 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-12-18T15:11Z
+ */
+
+(function( global, factory ) {
+
+ 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 have a `window` with a `document`
+ // (such as Node.js), expose a 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 ) {
+
+// Support: Firefox 18+
+// Can't be in strict mode, several libs including ASP.NET trace
+// the stack via arguments.caller.callee and Firefox dies if
+// you try to trace through "use strict" call chains. (#13335)
+//
+
+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.3",
+
+ // 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() {},
+
+ 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
+ // adding 1 corrects loss of precision from parseFloat (#15100)
+ return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 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
+ // Support: IE9-11+
+ // 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 v2.2.0-pre
+ * http://sizzlejs.com/
+ *
+ * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
+ * Released under the MIT license
+ * http://jquery.org/license
+ *
+ * Date: 2014-12-16
+ */
+(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" + 1 * 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
+ 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 as it's faster than native
+ // http://jsperf.com/thor-indexof-vs-for/5
+ indexOf = function( list, elem ) {
+ var i = 0,
+ len = list.length;
+ for ( ; i < len; i++ ) {
+ if ( list[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
+ rwhitespace = new RegExp( whitespace + "+", "g" ),
+ 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 );
+ },
+
+ // Used for iframes
+ // See setDocument()
+ // Removing the function wrapper causes a "Permission Denied"
+ // error in IE
+ unloadHandler = function() {
+ setDocument();
+ };
+
+// 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 || [];
+ nodeType = context.nodeType;
+
+ if ( typeof selector !== "string" || !selector ||
+ nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
+
+ return results;
+ }
+
+ if ( !seed && documentIsHTML ) {
+
+ // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
+ if ( nodeType !== 11 && (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 ) {
+ push.apply( results, context.getElementsByClassName( m ) );
+ return results;
+ }
+ }
+
+ // QSA path
+ if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
+ nid = old = expando;
+ newContext = context;
+ newSelector = nodeType !== 1 && 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 !== "undefined" && 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, parent,
+ 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;
+ parent = doc.defaultView;
+
+ // 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", unloadHandler, false );
+ } else if ( parent.attachEvent ) {
+ parent.attachEvent( "onunload", unloadHandler );
+ }
+ }
+
+ /* Support tests
+ ---------------------------------------------------------------------- */
+ documentIsHTML = !isXML( doc );
+
+ /* 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;
+ });
+
+ // Support: IE<9
+ support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
+
+ // 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 !== "undefined" && 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 !== "undefined" && elem.getAttributeNode("id");
+ return node && node.value === attrId;
+ };
+ };
+ }
+
+ // Tag
+ Expr.find["TAG"] = support.getElementsByTagName ?
+ function( tag, context ) {
+ if ( typeof context.getElementsByTagName !== "undefined" ) {
+ return context.getElementsByTagName( tag );
+
+ // DocumentFragment nodes don't have gEBTN
+ } else if ( support.qsa ) {
+ return context.querySelectorAll( tag );
+ }
+ } :
+
+ function( tag, context ) {
+ var elem,
+ tmp = [],
+ i = 0,
+ // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
+ 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 ( 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
+ docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
+ "<select id='" + expando + "-\f]' msallowcapture=''>" +
+ "<option selected=''></option></select>";
+
+ // 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("[msallowcapture^='']").length ) {
+ rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
+ }
+
+ // Support: IE8
+ // Boolean attributes and "value" are not treated correctly
+ if ( !div.querySelectorAll("[selected]").length ) {
+ rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
+ }
+
+ // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
+ if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
+ rbuggyQSA.push("~=");
+ }
+
+ // 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");
+ }
+
+ // Support: Safari 8+, iOS 8+
+ // https://bugs.webkit.org/show_bug.cgi?id=136851
+ // In-page `selector#id sibing-combinator selector` fails
+ if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
+ rbuggyQSA.push(".#.+[+~]");
+ }
+ });
+
+ 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( sortInput, a ) - indexOf( 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( sortInput, a ) - indexOf( 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 !== "undefined" && 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.replace( rwhitespace, " " ) + " " ).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( 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 );
+ // Don't keep the element (issue #299)
+ input[0] = null;
+ return !results.pop();
+ };
+ }),
+
+ "has": markFunction(function( selector ) {
+ return function( elem ) {
+ return Sizzle( selector, elem ).length > 0;
+ };
+ }),
+
+ "contains": markFunction(function( text ) {
+ text = text.replace( runescape, funescape );
+ 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( 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( checkContext, elem ) > -1;
+ }, implicitRelative, true ),
+ matchers = [ function( elem, context, xml ) {
+ var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
+ (checkContext = context).nodeType ?
+ matchContext( elem, context, xml ) :
+ matchAnyContext( elem, context, xml ) );
+ // Avoid hanging onto element (issue #299)
+ checkContext = null;
+ return ret;
+ } ];
+
+ 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: <number>) 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-35+
+// 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 = "<a href='#'></a>";
+ 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 = "<input/>";
+ 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 <tag> 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;
+
+ // Option to run 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] );
+
+ // Support: Blackberry 4.6
+ // gEBID returns nodes 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 set
+ 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 + Data.uid++;
+}
+
+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 public - generate a queueHooks object, or return 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" );
+
+ // Support: Safari<=5.1
+ // Check state lost if the name is set (#11217)
+ // Support: Windows Web Apps (WWA)
+ // `name` and `type` must use .setAttribute for WWA (#14901)
+ input.setAttribute( "type", "radio" );
+ input.setAttribute( "checked", "checked" );
+ input.setAttribute( "name", "t" );
+
+ div.appendChild( input );
+
+ // Support: Safari<=5.1, Android<4.2
+ // Older WebKit doesn't clone checked state correctly in fragments
+ support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
+
+ // Support: IE<=11+
+ // Make sure textarea (and checkbox) defaultValue is properly cloned
+ div.innerHTML = "<textarea>x</textarea>";
+ 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 <use> 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;
+ }
+ };
+});
+
+// Support: Firefox, Chrome, Safari
+// Create "bubbling" focus and blur events
+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*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
+
+ // We have to close these tags to support XHTML (#13200)
+ wrapMap = {
+
+ // Support: IE9
+ option: [ 1, "<select multiple='multiple'>", "</select>" ],
+
+ thead: [ 1, "<table>", "</table>" ],
+ col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
+ tr: [ 2, "<table><tbody>", "</tbody></table>" ],
+ td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
+
+ _default: [ 0, "", "" ]
+ };
+
+// Support: IE9
+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;
+}
+
+// Fix IE bugs, see support tests
+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 );
+
+ // Fix IE 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, PhantomJS
+ // push.apply(_, arraylike) throws on ancient WebKit
+ 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></$2>" ) + wrap[ 2 ];
+
+ // Descend through wrappers to the right content
+ j = wrap[ 0 ];
+ while ( j-- ) {
+ tmp = tmp.lastChild;
+ }
+
+ // Support: QtWebKit, PhantomJS
+ // push.apply(_, arraylike) throws on ancient WebKit
+ jQuery.merge( nodes, tmp.childNodes );
+
+ // Remember the top-level container
+ tmp = fragment.firstChild;
+
+ // Ensure the created nodes are orphaned (#12392)
+ 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></$2>" );
+
+ 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 optimization) 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( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
+
+ // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
+ doc = iframe[ 0 ].contentDocument;
+
+ // Support: IE
+ doc.write();
+ doc.close();
+
+ display = actualDisplay( nodeName, doc );
+ iframe.detach();
+ }
+
+ // Store the correct default display
+ elemdisplay[ nodeName ] = display;
+ }
+
+ return display;
+}
+var rmargin = (/^margin/);
+
+var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
+
+var getStyles = function( elem ) {
+ // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
+ // IE throws on elements created in popups
+ // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
+ if ( elem.ownerDocument.defaultView.opener ) {
+ return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+ }
+
+ return window.getComputedStyle( elem, null );
+ };
+
+
+
+function curCSS( elem, name, computed ) {
+ var width, minWidth, maxWidth, ret,
+ style = elem.style;
+
+ computed = computed || getStyles( elem );
+
+ // Support: IE9
+ // getPropertyValue is only needed for .css('filter') (#12537)
+ if ( computed ) {
+ ret = computed.getPropertyValue( name ) || computed[ name ];
+ }
+
+ if ( computed ) {
+
+ if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
+ ret = jQuery.style( elem, name );
+ }
+
+ // Support: iOS < 6
+ // A tribute to the "awesome hack by Dean Edwards"
+ // iOS < 6 (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 !== undefined ?
+ // Support: IE
+ // IE returns zIndex value as an integer.
+ ret + "" :
+ ret;
+}
+
+
+function addGetHookIf( conditionFn, hookFn ) {
+ // Define the hook, we'll check on the first run if it's really needed.
+ return {
+ get: function() {
+ if ( conditionFn() ) {
+ // Hook not needed (or it's not possible to use it due
+ // to missing dependency), remove it.
+ delete this.get;
+ return;
+ }
+
+ // Hook needed; redefine it so that the support test is not executed again.
+ return (this.get = hookFn).apply( this, arguments );
+ }
+ };
+}
+
+
+(function() {
+ var pixelPositionVal, boxSizingReliableVal,
+ docElem = document.documentElement,
+ container = document.createElement( "div" ),
+ div = document.createElement( "div" );
+
+ if ( !div.style ) {
+ return;
+ }
+
+ // Support: IE9-11+
+ // Style of cloned element affects source element cloned (#8908)
+ div.style.backgroundClip = "content-box";
+ div.cloneNode( true ).style.backgroundClip = "";
+ support.clearCloneStyle = div.style.backgroundClip === "content-box";
+
+ container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
+ "position:absolute";
+ container.appendChild( div );
+
+ // Executing both pixelPosition & boxSizingReliable tests require only one layout
+ // so they're executed at the same time to save the second computation.
+ function computePixelPositionAndBoxSizingReliable() {
+ div.style.cssText =
+ // Support: Firefox<29, Android 2.3
+ // Vendor-prefix box-sizing
+ "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
+ "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
+ "border:1px;padding:1px;width:4px;position:absolute";
+ div.innerHTML = "";
+ docElem.appendChild( container );
+
+ var divStyle = window.getComputedStyle( div, null );
+ pixelPositionVal = divStyle.top !== "1%";
+ boxSizingReliableVal = divStyle.width === "4px";
+
+ docElem.removeChild( container );
+ }
+
+ // Support: node.js jsdom
+ // Don't assume that getComputedStyle is a property of the global object
+ if ( window.getComputedStyle ) {
+ jQuery.extend( support, {
+ pixelPosition: function() {
+
+ // This test is executed only once but we still do memoizing
+ // since we can use the boxSizingReliable pre-computing.
+ // No need to check if the test was already performed, though.
+ computePixelPositionAndBoxSizingReliable();
+ return pixelPositionVal;
+ },
+ boxSizingReliable: function() {
+ if ( boxSizingReliableVal == null ) {
+ computePixelPositionAndBoxSizingReliable();
+ }
+ return boxSizingReliableVal;
+ },
+ reliableMarginRight: function() {
+
+ // Support: Android 2.3
+ // Check if div with explicit width and no margin-right incorrectly
+ // gets computed margin-right based on width of container. (#3333)
+ // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
+ // This support function is only executed once so no memoizing is needed.
+ var ret,
+ marginDiv = div.appendChild( document.createElement( "div" ) );
+
+ // Reset CSS: box-sizing; display; margin; border; padding
+ marginDiv.style.cssText = div.style.cssText =
+ // Support: Firefox<29, Android 2.3
+ // Vendor-prefix box-sizing
+ "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
+ "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
+ marginDiv.style.marginRight = marginDiv.style.width = "0";
+ div.style.width = "1px";
+ docElem.appendChild( container );
+
+ ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
+
+ docElem.removeChild( container );
+ div.removeChild( marginDiv );
+
+ return ret;
+ }
+ });
+ }
+})();
+
+
+// A method for quickly swapping in/out CSS properties to get correct calculations.
+jQuery.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;
+};
+
+
+var
+ // 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]).+)/,
+ rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
+ rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
+
+ cssShow = { position: "absolute", visibility: "hidden", display: "block" },
+ cssNormalTransform = {
+ letterSpacing: "0",
+ fontWeight: "400"
+ },
+
+ 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[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 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.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;
+ }
+
+ // Check for style in case a browser which returns unreliable values
+ // for getComputedStyle silently falls back to the reliable elem.style
+ valueIsBorderBox = isBorderBox &&
+ ( 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";
+}
+
+function showHide( elements, show ) {
+ var display, elem, hidden,
+ values = [],
+ index = 0,
+ length = elements.length;
+
+ for ( ; index < length; index++ ) {
+ elem = elements[ index ];
+ if ( !elem.style ) {
+ continue;
+ }
+
+ values[ index ] = data_priv.get( elem, "olddisplay" );
+ display = elem.style.display;
+ if ( show ) {
+ // Reset the inline display of this element to learn if it is
+ // being hidden by cascaded rules or not
+ if ( !values[ index ] && 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 ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
+ }
+ } else {
+ hidden = isHidden( elem );
+
+ if ( display !== "none" || !hidden ) {
+ data_priv.set( elem, "olddisplay", hidden ? display : 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.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;
+ }
+ }
+ }
+ },
+
+ // Don't automatically add "px" to these possibly-unitless properties
+ cssNumber: {
+ "columnCount": true,
+ "fillOpacity": true,
+ "flexGrow": true,
+ "flexShrink": true,
+ "fontWeight": true,
+ "lineHeight": true,
+ "opacity": true,
+ "order": 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: {
+ "float": "cssFloat"
+ },
+
+ // 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, then unprefixed version
+ hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
+
+ // Check if we're setting a value
+ if ( value !== undefined ) {
+ type = typeof value;
+
+ // Convert "+=" 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 null and NaN values aren't set (#7116)
+ if ( value == null || value !== value ) {
+ return;
+ }
+
+ // If a number, add 'px' to the (except for certain CSS properties)
+ if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
+ value += "px";
+ }
+
+ // Support: IE9-11+
+ // background-* props affect original clone's values
+ if ( !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 ) {
+ style[ name ] = value;
+ }
+
+ } 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 ) );
+
+ // Try prefixed name followed by the unprefixed name
+ 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 ];
+ }
+
+ // Make numeric if forced or a qualifier was provided and val looks numeric
+ if ( extra === "" || extra ) {
+ num = parseFloat( val );
+ return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
+ }
+ return val;
+ }
+});
+
+jQuery.each([ "height", "width" ], function( i, name ) {
+ jQuery.cssHooks[ name ] = {
+ get: function( elem, computed, extra ) {
+ if ( computed ) {
+
+ // Certain elements can have dimension info if we invisibly show them
+ // but it must have a current display style that would benefit
+ return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
+ jQuery.swap( elem, cssShow, function() {
+ return getWidthOrHeight( elem, name, extra );
+ }) :
+ getWidthOrHeight( elem, name, extra );
+ }
+ },
+
+ set: function( elem, value, extra ) {
+ var styles = extra && getStyles( elem );
+ return setPositiveNumber( elem, value, extra ?
+ augmentWidthOrHeight(
+ elem,
+ name,
+ extra,
+ jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
+ styles
+ ) : 0
+ );
+ }
+ };
+});
+
+// Support: Android 2.3
+jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
+ function( elem, computed ) {
+ if ( computed ) {
+ return jQuery.swap( elem, { "display": "inline-block" },
+ curCSS, [ elem, "marginRight" ] );
+ }
+ }
+);
+
+// These hooks are used by animate to expand properties
+jQuery.each({
+ margin: "",
+ padding: "",
+ border: "Width"
+}, function( prefix, suffix ) {
+ jQuery.cssHooks[ prefix + suffix ] = {
+ expand: function( value ) {
+ var i = 0,
+ expanded = {},
+
+ // Assumes a single number if not a string
+ parts = typeof value === "string" ? value.split(" ") : [ value ];
+
+ for ( ; i < 4; i++ ) {
+ expanded[ prefix + cssExpand[ i ] + suffix ] =
+ parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
+ }
+
+ return expanded;
+ }
+ };
+
+ if ( !rmargin.test( prefix ) ) {
+ jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
+ }
+});
+
+jQuery.fn.extend({
+ css: function( name, value ) {
+ return 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 ) {
+ if ( typeof state === "boolean" ) {
+ return state ? this.show() : this.hide();
+ }
+
+ return this.each(function() {
+ if ( isHidden( this ) ) {
+ jQuery( this ).show();
+ } else {
+ jQuery( this ).hide();
+ }
+ });
+ }
+});
+
+
+function Tween( elem, options, prop, end, easing ) {
+ return new Tween.prototype.init( elem, options, prop, end, easing );
+}
+jQuery.Tween = Tween;
+
+Tween.prototype = {
+ constructor: Tween,
+ init: function( elem, options, prop, end, easing, unit ) {
+ this.elem = elem;
+ this.prop = prop;
+ this.easing = easing || "swing";
+ this.options = options;
+ this.start = this.now = this.cur();
+ this.end = end;
+ this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
+ },
+ cur: function() {
+ var hooks = Tween.propHooks[ this.prop ];
+
+ return hooks && hooks.get ?
+ hooks.get( this ) :
+ Tween.propHooks._default.get( this );
+ },
+ run: function( percent ) {
+ var eased,
+ hooks = Tween.propHooks[ this.prop ];
+
+ if ( this.options.duration ) {
+ this.pos = eased = jQuery.easing[ this.easing ](
+ percent, this.options.duration * percent, 0, 1, this.options.duration
+ );
+ } else {
+ this.pos = eased = percent;
+ }
+ this.now = ( this.end - this.start ) * eased + this.start;
+
+ if ( this.options.step ) {
+ this.options.step.call( this.elem, this.now, this );
+ }
+
+ if ( hooks && hooks.set ) {
+ hooks.set( this );
+ } else {
+ Tween.propHooks._default.set( this );
+ }
+ return this;
+ }
+};
+
+Tween.prototype.init.prototype = Tween.prototype;
+
+Tween.propHooks = {
+ _default: {
+ get: function( tween ) {
+ var result;
+
+ if ( tween.elem[ tween.prop ] != null &&
+ (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
+ return tween.elem[ tween.prop ];
+ }
+
+ // Passing an empty string as a 3rd parameter to .css will automatically
+ // attempt a parseFloat and fallback to a string if the parse fails.
+ // Simple values such as "10px" are parsed to Float;
+ // complex values such as "rotate(1rad)" are returned as-is.
+ result = jQuery.css( tween.elem, tween.prop, "" );
+ // Empty strings, null, undefined and "auto" are converted to 0.
+ return !result || result === "auto" ? 0 : result;
+ },
+ set: function( tween ) {
+ // Use step hook for back compat.
+ // Use cssHook if its there.
+ // Use .style if available and use plain properties where available.
+ if ( jQuery.fx.step[ tween.prop ] ) {
+ jQuery.fx.step[ tween.prop ]( tween );
+ } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
+ jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
+ } else {
+ tween.elem[ tween.prop ] = tween.now;
+ }
+ }
+ }
+};
+
+// Support: IE9
+// Panic based approach to setting things on disconnected nodes
+Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
+ set: function( tween ) {
+ if ( tween.elem.nodeType && tween.elem.parentNode ) {
+ tween.elem[ tween.prop ] = tween.now;
+ }
+ }
+};
+
+jQuery.easing = {
+ linear: function( p ) {
+ return p;
+ },
+ swing: function( p ) {
+ return 0.5 - Math.cos( p * Math.PI ) / 2;
+ }
+};
+
+jQuery.fx = Tween.prototype.init;
+
+// Back Compat <1.8 extension point
+jQuery.fx.step = {};
+
+
+
+
+var
+ fxNow, timerId,
+ rfxtypes = /^(?:toggle|show|hide)$/,
+ rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
+ rrun = /queueHooks$/,
+ animationPrefilters = [ defaultPrefilter ],
+ tweeners = {
+ "*": [ function( prop, value ) {
+ var tween = this.createTween( prop, value ),
+ target = tween.cur(),
+ parts = rfxnum.exec( value ),
+ unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
+
+ // Starting value computation is required for potential unit mismatches
+ start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
+ rfxnum.exec( jQuery.css( tween.elem, prop ) ),
+ scale = 1,
+ maxIterations = 20;
+
+ if ( start && start[ 3 ] !== unit ) {
+ // Trust units reported by jQuery.css
+ unit = unit || start[ 3 ];
+
+ // Make sure we update the tween properties later on
+ parts = parts || [];
+
+ // Iteratively approximate from a nonzero starting point
+ start = +target || 1;
+
+ do {
+ // If previous iteration zeroed out, double until we get *something*.
+ // Use string for doubling so we don't accidentally see scale as unchanged below
+ scale = scale || ".5";
+
+ // Adjust and apply
+ start = start / scale;
+ jQuery.style( tween.elem, prop, start + unit );
+
+ // Update scale, tolerating zero or NaN from tween.cur(),
+ // break the loop if scale is unchanged or perfect, or if we've just had enough
+ } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
+ }
+
+ // Update tween properties
+ if ( parts ) {
+ start = tween.start = +start || +target || 0;
+ tween.unit = unit;
+ // If a +=/-= token was provided, we're doing a relative animation
+ tween.end = parts[ 1 ] ?
+ start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
+ +parts[ 2 ];
+ }
+
+ return tween;
+ } ]
+ };
+
+// Animations created synchronously will run synchronously
+function createFxNow() {
+ setTimeout(function() {
+ fxNow = undefined;
+ });
+ return ( fxNow = jQuery.now() );
+}
+
+// Generate parameters to create a standard animation
+function genFx( type, includeWidth ) {
+ var which,
+ i = 0,
+ attrs = { height: type };
+
+ // If we include width, step value is 1 to do all cssExpand values,
+ // otherwise step value is 2 to skip over Left and Right
+ includeWidth = includeWidth ? 1 : 0;
+ for ( ; i < 4 ; i += 2 - includeWidth ) {
+ which = cssExpand[ i ];
+ attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
+ }
+
+ if ( includeWidth ) {
+ attrs.opacity = attrs.width = type;
+ }
+
+ return attrs;
+}
+
+function createTween( value, prop, animation ) {
+ var tween,
+ collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
+ index = 0,
+ length = collection.length;
+ for ( ; index < length; index++ ) {
+ if ( (tween = collection[ index ].call( animation, prop, value )) ) {
+
+ // We're done with this property
+ return tween;
+ }
+ }
+}
+
+function defaultPrefilter( elem, props, opts ) {
+ /* jshint validthis: true */
+ var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
+ anim = this,
+ orig = {},
+ style = elem.style,
+ hidden = elem.nodeType && isHidden( elem ),
+ dataShow = data_priv.get( elem, "fxshow" );
+
+ // Handle queue: false promises
+ if ( !opts.queue ) {
+ hooks = jQuery._queueHooks( elem, "fx" );
+ if ( hooks.unqueued == null ) {
+ hooks.unqueued = 0;
+ oldfire = hooks.empty.fire;
+ hooks.empty.fire = function() {
+ if ( !hooks.unqueued ) {
+ oldfire();
+ }
+ };
+ }
+ hooks.unqueued++;
+
+ anim.always(function() {
+ // Ensure the complete handler is called before this completes
+ anim.always(function() {
+ hooks.unqueued--;
+ if ( !jQuery.queue( elem, "fx" ).length ) {
+ hooks.empty.fire();
+ }
+ });
+ });
+ }
+
+ // Height/width overflow pass
+ if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
+ // Make sure that nothing sneaks out
+ // Record all 3 overflow attributes because IE9-10 do not
+ // change the overflow attribute when overflowX and
+ // overflowY are set to the same value
+ opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
+
+ // Set display property to inline-block for height/width
+ // animations on inline elements that are having width/height animated
+ display = jQuery.css( elem, "display" );
+
+ // Test default display if display is currently "none"
+ checkDisplay = display === "none" ?
+ data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
+
+ if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
+ style.display = "inline-block";
+ }
+ }
+
+ if ( opts.overflow ) {
+ style.overflow = "hidden";
+ anim.always(function() {
+ style.overflow = opts.overflow[ 0 ];
+ style.overflowX = opts.overflow[ 1 ];
+ style.overflowY = opts.overflow[ 2 ];
+ });
+ }
+
+ // show/hide pass
+ for ( prop in props ) {
+ value = props[ prop ];
+ if ( rfxtypes.exec( value ) ) {
+ delete props[ prop ];
+ toggle = toggle || value === "toggle";
+ if ( value === ( hidden ? "hide" : "show" ) ) {
+
+ // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
+ if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
+ hidden = true;
+ } else {
+ continue;
+ }
+ }
+ orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
+
+ // Any non-fx value stops us from restoring the original display value
+ } else {
+ display = undefined;
+ }
+ }
+
+ if ( !jQuery.isEmptyObject( orig ) ) {
+ if ( dataShow ) {
+ if ( "hidden" in dataShow ) {
+ hidden = dataShow.hidden;
+ }
+ } else {
+ dataShow = data_priv.access( elem, "fxshow", {} );
+ }
+
+ // Store state if its toggle - enables .stop().toggle() to "reverse"
+ if ( toggle ) {
+ dataShow.hidden = !hidden;
+ }
+ if ( hidden ) {
+ jQuery( elem ).show();
+ } else {
+ anim.done(function() {
+ jQuery( elem ).hide();
+ });
+ }
+ anim.done(function() {
+ var prop;
+
+ data_priv.remove( elem, "fxshow" );
+ for ( prop in orig ) {
+ jQuery.style( elem, prop, orig[ prop ] );
+ }
+ });
+ for ( prop in orig ) {
+ tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
+
+ if ( !( prop in dataShow ) ) {
+ dataShow[ prop ] = tween.start;
+ if ( hidden ) {
+ tween.end = tween.start;
+ tween.start = prop === "width" || prop === "height" ? 1 : 0;
+ }
+ }
+ }
+
+ // If this is a noop like .hide().hide(), restore an overwritten display value
+ } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
+ style.display = display;
+ }
+}
+
+function propFilter( props, specialEasing ) {
+ var index, name, easing, value, hooks;
+
+ // camelCase, specialEasing and expand cssHook pass
+ for ( index in props ) {
+ name = jQuery.camelCase( index );
+ easing = specialEasing[ name ];
+ value = props[ index ];
+ if ( jQuery.isArray( value ) ) {
+ easing = value[ 1 ];
+ value = props[ index ] = value[ 0 ];
+ }
+
+ if ( index !== name ) {
+ props[ name ] = value;
+ delete props[ index ];
+ }
+
+ hooks = jQuery.cssHooks[ name ];
+ if ( hooks && "expand" in hooks ) {
+ value = hooks.expand( value );
+ delete props[ name ];
+
+ // Not quite $.extend, this won't overwrite existing keys.
+ // Reusing 'index' because we have the correct "name"
+ for ( index in value ) {
+ if ( !( index in props ) ) {
+ props[ index ] = value[ index ];
+ specialEasing[ index ] = easing;
+ }
+ }
+ } else {
+ specialEasing[ name ] = easing;
+ }
+ }
+}
+
+function Animation( elem, properties, options ) {
+ var result,
+ stopped,
+ index = 0,
+ length = animationPrefilters.length,
+ deferred = jQuery.Deferred().always( function() {
+ // Don't match elem in the :animated selector
+ delete tick.elem;
+ }),
+ tick = function() {
+ if ( stopped ) {
+ return false;
+ }
+ var currentTime = fxNow || createFxNow(),
+ remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
+ // Support: Android 2.3
+ // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
+ temp = remaining / animation.duration || 0,
+ percent = 1 - temp,
+ index = 0,
+ length = animation.tweens.length;
+
+ for ( ; index < length ; index++ ) {
+ animation.tweens[ index ].run( percent );
+ }
+
+ deferred.notifyWith( elem, [ animation, percent, remaining ]);
+
+ if ( percent < 1 && length ) {
+ return remaining;
+ } else {
+ deferred.resolveWith( elem, [ animation ] );
+ return false;
+ }
+ },
+ animation = deferred.promise({
+ elem: elem,
+ props: jQuery.extend( {}, properties ),
+ opts: jQuery.extend( true, { specialEasing: {} }, options ),
+ originalProperties: properties,
+ originalOptions: options,
+ startTime: fxNow || createFxNow(),
+ duration: options.duration,
+ tweens: [],
+ createTween: function( prop, end ) {
+ var tween = jQuery.Tween( elem, animation.opts, prop, end,
+ animation.opts.specialEasing[ prop ] || animation.opts.easing );
+ animation.tweens.push( tween );
+ return tween;
+ },
+ stop: function( gotoEnd ) {
+ var index = 0,
+ // If we are going to the end, we want to run all the tweens
+ // otherwise we skip this part
+ length = gotoEnd ? animation.tweens.length : 0;
+ if ( stopped ) {
+ return this;
+ }
+ stopped = true;
+ for ( ; index < length ; index++ ) {
+ animation.tweens[ index ].run( 1 );
+ }
+
+ // Resolve when we played the last frame; otherwise, reject
+ if ( gotoEnd ) {
+ deferred.resolveWith( elem, [ animation, gotoEnd ] );
+ } else {
+ deferred.rejectWith( elem, [ animation, gotoEnd ] );
+ }
+ return this;
+ }
+ }),
+ props = animation.props;
+
+ propFilter( props, animation.opts.specialEasing );
+
+ for ( ; index < length ; index++ ) {
+ result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
+ if ( result ) {
+ return result;
+ }
+ }
+
+ jQuery.map( props, createTween, animation );
+
+ if ( jQuery.isFunction( animation.opts.start ) ) {
+ animation.opts.start.call( elem, animation );
+ }
+
+ jQuery.fx.timer(
+ jQuery.extend( tick, {
+ elem: elem,
+ anim: animation,
+ queue: animation.opts.queue
+ })
+ );
+
+ // attach callbacks from options
+ return animation.progress( animation.opts.progress )
+ .done( animation.opts.done, animation.opts.complete )
+ .fail( animation.opts.fail )
+ .always( animation.opts.always );
+}
+
+jQuery.Animation = jQuery.extend( Animation, {
+
+ tweener: function( props, callback ) {
+ if ( jQuery.isFunction( props ) ) {
+ callback = props;
+ props = [ "*" ];
+ } else {
+ props = props.split(" ");
+ }
+
+ var prop,
+ index = 0,
+ length = props.length;
+
+ for ( ; index < length ; index++ ) {
+ prop = props[ index ];
+ tweeners[ prop ] = tweeners[ prop ] || [];
+ tweeners[ prop ].unshift( callback );
+ }
+ },
+
+ prefilter: function( callback, prepend ) {
+ if ( prepend ) {
+ animationPrefilters.unshift( callback );
+ } else {
+ animationPrefilters.push( callback );
+ }
+ }
+});
+
+jQuery.speed = function( speed, easing, fn ) {
+ var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
+ complete: fn || !fn && easing ||
+ jQuery.isFunction( speed ) && speed,
+ duration: speed,
+ easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
+ };
+
+ opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
+ opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
+
+ // Normalize opt.queue - true/undefined/null -> "fx"
+ if ( opt.queue == null || opt.queue === true ) {
+ opt.queue = "fx";
+ }
+
+ // Queueing
+ opt.old = opt.complete;
+
+ opt.complete = function() {
+ if ( jQuery.isFunction( opt.old ) ) {
+ opt.old.call( this );
+ }
+
+ if ( opt.queue ) {
+ jQuery.dequeue( this, opt.queue );
+ }
+ };
+
+ return opt;
+};
+
+jQuery.fn.extend({
+ fadeTo: function( speed, to, easing, callback ) {
+
+ // Show any hidden elements after setting opacity to 0
+ return this.filter( isHidden ).css( "opacity", 0 ).show()
+
+ // Animate to the value specified
+ .end().animate({ opacity: to }, speed, easing, callback );
+ },
+ animate: function( prop, speed, easing, callback ) {
+ var empty = jQuery.isEmptyObject( prop ),
+ optall = jQuery.speed( speed, easing, callback ),
+ doAnimation = function() {
+ // Operate on a copy of prop so per-property easing won't be lost
+ var anim = Animation( this, jQuery.extend( {}, prop ), optall );
+
+ // Empty animations, or finishing resolves immediately
+ if ( empty || data_priv.get( this, "finish" ) ) {
+ anim.stop( true );
+ }
+ };
+ doAnimation.finish = doAnimation;
+
+ return empty || optall.queue === false ?
+ this.each( doAnimation ) :
+ this.queue( optall.queue, doAnimation );
+ },
+ stop: function( type, clearQueue, gotoEnd ) {
+ var stopQueue = function( hooks ) {
+ var stop = hooks.stop;
+ delete hooks.stop;
+ stop( gotoEnd );
+ };
+
+ if ( typeof type !== "string" ) {
+ gotoEnd = clearQueue;
+ clearQueue = type;
+ type = undefined;
+ }
+ if ( clearQueue && type !== false ) {
+ this.queue( type || "fx", [] );
+ }
+
+ return this.each(function() {
+ var dequeue = true,
+ index = type != null && type + "queueHooks",
+ timers = jQuery.timers,
+ data = data_priv.get( this );
+
+ if ( index ) {
+ if ( data[ index ] && data[ index ].stop ) {
+ stopQueue( data[ index ] );
+ }
+ } else {
+ for ( index in data ) {
+ if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
+ stopQueue( data[ index ] );
+ }
+ }
+ }
+
+ for ( index = timers.length; index--; ) {
+ if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
+ timers[ index ].anim.stop( gotoEnd );
+ dequeue = false;
+ timers.splice( index, 1 );
+ }
+ }
+
+ // Start the next in the queue if the last step wasn't forced.
+ // Timers currently will call their complete callbacks, which
+ // will dequeue but only if they were gotoEnd.
+ if ( dequeue || !gotoEnd ) {
+ jQuery.dequeue( this, type );
+ }
+ });
+ },
+ finish: function( type ) {
+ if ( type !== false ) {
+ type = type || "fx";
+ }
+ return this.each(function() {
+ var index,
+ data = data_priv.get( this ),
+ queue = data[ type + "queue" ],
+ hooks = data[ type + "queueHooks" ],
+ timers = jQuery.timers,
+ length = queue ? queue.length : 0;
+
+ // Enable finishing flag on private data
+ data.finish = true;
+
+ // Empty the queue first
+ jQuery.queue( this, type, [] );
+
+ if ( hooks && hooks.stop ) {
+ hooks.stop.call( this, true );
+ }
+
+ // Look for any active animations, and finish them
+ for ( index = timers.length; index--; ) {
+ if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
+ timers[ index ].anim.stop( true );
+ timers.splice( index, 1 );
+ }
+ }
+
+ // Look for any animations in the old queue and finish them
+ for ( index = 0; index < length; index++ ) {
+ if ( queue[ index ] && queue[ index ].finish ) {
+ queue[ index ].finish.call( this );
+ }
+ }
+
+ // Turn off finishing flag
+ delete data.finish;
+ });
+ }
+});
+
+jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
+ var cssFn = jQuery.fn[ name ];
+ jQuery.fn[ name ] = function( speed, easing, callback ) {
+ return speed == null || typeof speed === "boolean" ?
+ cssFn.apply( this, arguments ) :
+ this.animate( genFx( name, true ), speed, easing, callback );
+ };
+});
+
+// Generate shortcuts for custom animations
+jQuery.each({
+ slideDown: genFx("show"),
+ slideUp: genFx("hide"),
+ slideToggle: genFx("toggle"),
+ fadeIn: { opacity: "show" },
+ fadeOut: { opacity: "hide" },
+ fadeToggle: { opacity: "toggle" }
+}, function( name, props ) {
+ jQuery.fn[ name ] = function( speed, easing, callback ) {
+ return this.animate( props, speed, easing, callback );
+ };
+});
+
+jQuery.timers = [];
+jQuery.fx.tick = function() {
+ var timer,
+ i = 0,
+ timers = jQuery.timers;
+
+ fxNow = jQuery.now();
+
+ for ( ; i < timers.length; i++ ) {
+ timer = timers[ i ];
+ // Checks the timer has not already been removed
+ if ( !timer() && timers[ i ] === timer ) {
+ timers.splice( i--, 1 );
+ }
+ }
+
+ if ( !timers.length ) {
+ jQuery.fx.stop();
+ }
+ fxNow = undefined;
+};
+
+jQuery.fx.timer = function( timer ) {
+ jQuery.timers.push( timer );
+ if ( timer() ) {
+ jQuery.fx.start();
+ } else {
+ jQuery.timers.pop();
+ }
+};
+
+jQuery.fx.interval = 13;
+
+jQuery.fx.start = function() {
+ if ( !timerId ) {
+ timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
+ }
+};
+
+jQuery.fx.stop = function() {
+ clearInterval( timerId );
+ timerId = null;
+};
+
+jQuery.fx.speeds = {
+ slow: 600,
+ fast: 200,
+ // Default speed
+ _default: 400
+};
+
+
+// Based off of the plugin by Clint Helfers, with permission.
+// http://blindsignals.com/index.php/2009/07/jquery-delay/
+jQuery.fn.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 );
+ };
+ });
+};
+
+
+(function() {
+ var input = document.createElement( "input" ),
+ select = document.createElement( "select" ),
+ opt = select.appendChild( document.createElement( "option" ) );
+
+ input.type = "checkbox";
+
+ // Support: iOS<=5.1, Android<=4.2+
+ // Default value for a checkbox should be "on"
+ support.checkOn = input.value !== "";
+
+ // Support: IE<=11+
+ // Must access selectedIndex to make default options select
+ support.optSelected = opt.selected;
+
+ // Support: Android<=2.3
+ // Options inside disabled selects are incorrectly marked as disabled
+ select.disabled = true;
+ support.optDisabled = !opt.disabled;
+
+ // Support: IE<=11+
+ // An input loses its value after becoming a radio
+ input = document.createElement( "input" );
+ input.value = "t";
+ input.type = "radio";
+ support.radioValue = input.value === "t";
+})();
+
+
+var nodeHook, boolHook,
+ attrHandle = jQuery.expr.attrHandle;
+
+jQuery.fn.extend({
+ attr: function( name, value ) {
+ return access( this, jQuery.attr, name, value, arguments.length > 1 );
+ },
+
+ removeAttr: function( name ) {
+ return this.each(function() {
+ jQuery.removeAttr( this, name );
+ });
+ }
+});
+
+jQuery.extend({
+ attr: function( elem, name, value ) {
+ var hooks, ret,
+ 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 === strundefined ) {
+ return jQuery.prop( elem, name, value );
+ }
+
+ // All attributes are lowercase
+ // Grab necessary hook if one is defined
+ if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
+ name = name.toLowerCase();
+ hooks = jQuery.attrHooks[ name ] ||
+ ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
+ }
+
+ if ( value !== undefined ) {
+
+ if ( value === null ) {
+ jQuery.removeAttr( elem, name );
+
+ } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
+ return ret;
+
+ } else {
+ elem.setAttribute( name, value + "" );
+ return value;
+ }
+
+ } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
+ return ret;
+
+ } else {
+ ret = jQuery.find.attr( elem, 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( rnotwhite );
+
+ if ( attrNames && elem.nodeType === 1 ) {
+ while ( (name = attrNames[i++]) ) {
+ propName = jQuery.propFix[ name ] || name;
+
+ // Boolean attributes get special treatment (#10870)
+ if ( jQuery.expr.match.bool.test( name ) ) {
+ // Set corresponding property to false
+ elem[ propName ] = false;
+ }
+
+ elem.removeAttribute( name );
+ }
+ }
+ },
+
+ attrHooks: {
+ type: {
+ set: function( elem, value ) {
+ if ( !support.radioValue && value === "radio" &&
+ jQuery.nodeName( elem, "input" ) ) {
+ var val = elem.value;
+ elem.setAttribute( "type", value );
+ if ( val ) {
+ elem.value = val;
+ }
+ return value;
+ }
+ }
+ }
+ }
+});
+
+// Hooks for boolean attributes
+boolHook = {
+ set: function( elem, value, name ) {
+ if ( value === false ) {
+ // Remove boolean attributes when set to false
+ jQuery.removeAttr( elem, name );
+ } else {
+ elem.setAttribute( name, name );
+ }
+ return name;
+ }
+};
+jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
+ var getter = attrHandle[ name ] || jQuery.find.attr;
+
+ attrHandle[ name ] = function( elem, name, isXML ) {
+ var ret, handle;
+ if ( !isXML ) {
+ // Avoid an infinite loop by temporarily removing this function from the getter
+ handle = attrHandle[ name ];
+ attrHandle[ name ] = ret;
+ ret = getter( elem, name, isXML ) != null ?
+ name.toLowerCase() :
+ null;
+ attrHandle[ name ] = handle;
+ }
+ return ret;
+ };
+});
+
+
+
+
+var rfocusable = /^(?:input|select|textarea|button)$/i;
+
+jQuery.fn.extend({
+ prop: function( name, value ) {
+ return access( this, jQuery.prop, name, value, arguments.length > 1 );
+ },
+
+ removeProp: function( name ) {
+ return this.each(function() {
+ delete this[ jQuery.propFix[ name ] || name ];
+ });
+ }
+});
+
+jQuery.extend({
+ propFix: {
+ "for": "htmlFor",
+ "class": "className"
+ },
+
+ 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 ) {
+ return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
+ ret :
+ ( elem[ name ] = value );
+
+ } else {
+ return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
+ ret :
+ elem[ name ];
+ }
+ },
+
+ propHooks: {
+ tabIndex: {
+ get: function( elem ) {
+ return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
+ elem.tabIndex :
+ -1;
+ }
+ }
+ }
+});
+
+if ( !support.optSelected ) {
+ jQuery.propHooks.selected = {
+ get: function( elem ) {
+ var parent = elem.parentNode;
+ if ( parent && parent.parentNode ) {
+ parent.parentNode.selectedIndex;
+ }
+ return null;
+ }
+ };
+}
+
+jQuery.each([
+ "tabIndex",
+ "readOnly",
+ "maxLength",
+ "cellSpacing",
+ "cellPadding",
+ "rowSpan",
+ "colSpan",
+ "useMap",
+ "frameBorder",
+ "contentEditable"
+], function() {
+ jQuery.propFix[ this.toLowerCase() ] = this;
+});
+
+
+
+
+var rclass = /[\t\r\n\f]/g;
+
+jQuery.fn.extend({
+ addClass: function( value ) {
+ var classes, elem, cur, clazz, j, finalValue,
+ proceed = typeof value === "string" && value,
+ i = 0,
+ len = this.length;
+
+ 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( 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 + " ";
+ }
+ }
+
+ // only assign if different to avoid unneeded rendering.
+ finalValue = jQuery.trim( cur );
+ if ( elem.className !== finalValue ) {
+ elem.className = finalValue;
+ }
+ }
+ }
+ }
+
+ return this;
+ },
+
+ removeClass: function( value ) {
+ var classes, elem, cur, clazz, j, finalValue,
+ proceed = arguments.length === 0 || typeof value === "string" && value,
+ i = 0,
+ len = this.length;
+
+ if ( jQuery.isFunction( value ) ) {
+ return this.each(function( j ) {
+ jQuery( this ).removeClass( value.call( this, j, this.className ) );
+ });
+ }
+ if ( proceed ) {
+ classes = ( value || "" ).match( 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 + " ", " " );
+ }
+ }
+
+ // Only assign if different to avoid unneeded rendering.
+ finalValue = value ? jQuery.trim( cur ) : "";
+ if ( elem.className !== finalValue ) {
+ elem.className = finalValue;
+ }
+ }
+ }
+ }
+
+ return this;
+ },
+
+ toggleClass: function( value, stateVal ) {
+ var type = typeof value;
+
+ if ( typeof stateVal === "boolean" && type === "string" ) {
+ return stateVal ? this.addClass( value ) : this.removeClass( value );
+ }
+
+ 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 ),
+ classNames = value.match( rnotwhite ) || [];
+
+ while ( (className = classNames[ i++ ]) ) {
+ // Check each className given, space separated list
+ if ( self.hasClass( className ) ) {
+ self.removeClass( className );
+ } else {
+ self.addClass( className );
+ }
+ }
+
+ // Toggle whole class name
+ } else if ( type === strundefined || type === "boolean" ) {
+ if ( this.className ) {
+ // store className if set
+ data_priv.set( 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 ? "" : data_priv.get( 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;
+ }
+});
+
+
+
+
+var rreturn = /\r/g;
+
+jQuery.fn.extend({
+ 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;
+
+ if ( this.nodeType !== 1 ) {
+ return;
+ }
+
+ if ( isFunction ) {
+ val = value.call( this, i, jQuery( this ).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 ) {
+ var val = jQuery.find.attr( elem, "value" );
+ return val != null ?
+ val :
+ // Support: IE10-11+
+ // option.text throws exceptions (#14686, #14858)
+ jQuery.trim( jQuery.text( elem ) );
+ }
+ },
+ 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 ];
+
+ // IE6-9 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
+ ( 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 optionSet, option,
+ options = elem.options,
+ values = jQuery.makeArray( value ),
+ i = options.length;
+
+ while ( i-- ) {
+ option = options[ i ];
+ if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
+ optionSet = true;
+ }
+ }
+
+ // Force browsers to behave consistently when non-matching value is set
+ if ( !optionSet ) {
+ elem.selectedIndex = -1;
+ }
+ return values;
+ }
+ }
+ }
+});
+
+// Radios and checkboxes getter/setter
+jQuery.each([ "radio", "checkbox" ], function() {
+ jQuery.valHooks[ this ] = {
+ set: function( elem, value ) {
+ if ( jQuery.isArray( value ) ) {
+ return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
+ }
+ }
+ };
+ if ( !support.checkOn ) {
+ jQuery.valHooks[ this ].get = function( elem ) {
+ return elem.getAttribute("value") === null ? "on" : elem.value;
+ };
+ }
+});
+
+
+
+
+// Return jQuery for attributes-only inclusion
+
+
+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 );
+ };
+});
+
+jQuery.fn.extend({
+ hover: function( fnOver, fnOut ) {
+ return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
+ },
+
+ 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 );
+ }
+});
+
+
+var nonce = jQuery.now();
+
+var rquery = (/\?/);
+
+
+
+// Support: Android 2.3
+// Workaround failure to string-cast null input
+jQuery.parseJSON = function( data ) {
+ return JSON.parse( data + "" );
+};
+
+
+// Cross-browser xml parsing
+jQuery.parseXML = function( data ) {
+ var xml, tmp;
+ if ( !data || typeof data !== "string" ) {
+ return null;
+ }
+
+ // Support: IE9
+ try {
+ tmp = new DOMParser();
+ xml = tmp.parseFromString( data, "text/xml" );
+ } catch ( e ) {
+ xml = undefined;
+ }
+
+ if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
+ jQuery.error( "Invalid XML: " + data );
+ }
+ return xml;
+};
+
+
+var
+ rhash = /#.*$/,
+ rts = /([?&])_=[^&]*/,
+ rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
+ // #7653, #8125, #8152: local protocol detection
+ rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
+ rnoContent = /^(?:GET|HEAD)$/,
+ rprotocol = /^\/\//,
+ rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
+
+ /* Prefilters
+ * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
+ * 2) These are called:
+ * - BEFORE asking for a transport
+ * - AFTER param serialization (s.data is a string if s.processData is true)
+ * 3) key is the dataType
+ * 4) the catchall symbol "*" can be used
+ * 5) execution will start with transport dataType and THEN continue down to "*" if needed
+ */
+ prefilters = {},
+
+ /* Transports bindings
+ * 1) key is the dataType
+ * 2) the catchall symbol "*" can be used
+ * 3) selection will start with transport dataType and THEN go to "*" if needed
+ */
+ transports = {},
+
+ // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
+ allTypes = "*/".concat( "*" ),
+
+ // Document location
+ ajaxLocation = window.location.href,
+
+ // Segment location into parts
+ ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
+
+// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
+function addToPrefiltersOrTransports( structure ) {
+
+ // dataTypeExpression is optional and defaults to "*"
+ return function( dataTypeExpression, func ) {
+
+ if ( typeof dataTypeExpression !== "string" ) {
+ func = dataTypeExpression;
+ dataTypeExpression = "*";
+ }
+
+ var dataType,
+ i = 0,
+ dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
+
+ if ( jQuery.isFunction( func ) ) {
+ // For each dataType in the dataTypeExpression
+ while ( (dataType = dataTypes[i++]) ) {
+ // Prepend if requested
+ if ( dataType[0] === "+" ) {
+ dataType = dataType.slice( 1 ) || "*";
+ (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
+
+ // Otherwise append
+ } else {
+ (structure[ dataType ] = structure[ dataType ] || []).push( func );
+ }
+ }
+ }
+ };
+}
+
+// Base inspection function for prefilters and transports
+function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
+
+ var inspected = {},
+ seekingTransport = ( structure === transports );
+
+ function inspect( dataType ) {
+ var selected;
+ inspected[ dataType ] = true;
+ jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
+ var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
+ if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
+ options.dataTypes.unshift( dataTypeOrTransport );
+ inspect( dataTypeOrTransport );
+ return false;
+ } else if ( seekingTransport ) {
+ return !( selected = dataTypeOrTransport );
+ }
+ });
+ return selected;
+ }
+
+ return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
+}
+
+// A special extend for ajax options
+// that takes "flat" options (not to be deep extended)
+// Fixes #9887
+function ajaxExtend( target, src ) {
+ var key, deep,
+ flatOptions = jQuery.ajaxSettings.flatOptions || {};
+
+ for ( key in src ) {
+ if ( src[ key ] !== undefined ) {
+ ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
+ }
+ }
+ if ( deep ) {
+ jQuery.extend( true, target, deep );
+ }
+
+ return target;
+}
+
+/* Handles responses to an ajax request:
+ * - finds the right dataType (mediates between content-type and expected dataType)
+ * - returns the corresponding response
+ */
+function ajaxHandleResponses( s, jqXHR, responses ) {
+
+ var ct, type, finalDataType, firstDataType,
+ contents = s.contents,
+ dataTypes = s.dataTypes;
+
+ // Remove auto dataType and get content-type in the process
+ while ( dataTypes[ 0 ] === "*" ) {
+ dataTypes.shift();
+ if ( ct === undefined ) {
+ ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
+ }
+ }
+
+ // Check if we're dealing with a known content-type
+ if ( ct ) {
+ for ( type in contents ) {
+ if ( contents[ type ] && contents[ type ].test( ct ) ) {
+ dataTypes.unshift( type );
+ break;
+ }
+ }
+ }
+
+ // Check to see if we have a response for the expected dataType
+ if ( dataTypes[ 0 ] in responses ) {
+ finalDataType = dataTypes[ 0 ];
+ } else {
+ // Try convertible dataTypes
+ for ( type in responses ) {
+ if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
+ finalDataType = type;
+ break;
+ }
+ if ( !firstDataType ) {
+ firstDataType = type;
+ }
+ }
+ // Or just use first one
+ finalDataType = finalDataType || firstDataType;
+ }
+
+ // If we found a dataType
+ // We add the dataType to the list if needed
+ // and return the corresponding response
+ if ( finalDataType ) {
+ if ( finalDataType !== dataTypes[ 0 ] ) {
+ dataTypes.unshift( finalDataType );
+ }
+ return responses[ finalDataType ];
+ }
+}
+
+/* Chain conversions given the request and the original response
+ * Also sets the responseXXX fields on the jqXHR instance
+ */
+function ajaxConvert( s, response, jqXHR, isSuccess ) {
+ var conv2, current, conv, tmp, prev,
+ converters = {},
+ // Work with a copy of dataTypes in case we need to modify it for conversion
+ dataTypes = s.dataTypes.slice();
+
+ // Create converters map with lowercased keys
+ if ( dataTypes[ 1 ] ) {
+ for ( conv in s.converters ) {
+ converters[ conv.toLowerCase() ] = s.converters[ conv ];
+ }
+ }
+
+ current = dataTypes.shift();
+
+ // Convert to each sequential dataType
+ while ( current ) {
+
+ if ( s.responseFields[ current ] ) {
+ jqXHR[ s.responseFields[ current ] ] = response;
+ }
+
+ // Apply the dataFilter if provided
+ if ( !prev && isSuccess && s.dataFilter ) {
+ response = s.dataFilter( response, s.dataType );
+ }
+
+ prev = current;
+ current = dataTypes.shift();
+
+ if ( current ) {
+
+ // There's only work to do if current dataType is non-auto
+ if ( current === "*" ) {
+
+ current = prev;
+
+ // Convert response if prev dataType is non-auto and differs from current
+ } else if ( prev !== "*" && prev !== current ) {
+
+ // Seek a direct converter
+ conv = converters[ prev + " " + current ] || converters[ "* " + current ];
+
+ // If none found, seek a pair
+ if ( !conv ) {
+ for ( conv2 in converters ) {
+
+ // If conv2 outputs current
+ tmp = conv2.split( " " );
+ if ( tmp[ 1 ] === current ) {
+
+ // If prev can be converted to accepted input
+ conv = converters[ prev + " " + tmp[ 0 ] ] ||
+ converters[ "* " + tmp[ 0 ] ];
+ if ( conv ) {
+ // Condense equivalence converters
+ if ( conv === true ) {
+ conv = converters[ conv2 ];
+
+ // Otherwise, insert the intermediate dataType
+ } else if ( converters[ conv2 ] !== true ) {
+ current = tmp[ 0 ];
+ dataTypes.unshift( tmp[ 1 ] );
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // Apply converter (if not an equivalence)
+ if ( conv !== true ) {
+
+ // Unless errors are allowed to bubble, catch and return them
+ if ( conv && s[ "throws" ] ) {
+ response = conv( response );
+ } else {
+ try {
+ response = conv( response );
+ } catch ( e ) {
+ return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return { state: "success", data: response };
+}
+
+jQuery.extend({
+
+ // Counter for holding the number of active queries
+ active: 0,
+
+ // Last-Modified header cache for next request
+ lastModified: {},
+ etag: {},
+
+ ajaxSettings: {
+ url: ajaxLocation,
+ type: "GET",
+ isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
+ global: true,
+ processData: true,
+ async: true,
+ contentType: "application/x-www-form-urlencoded; charset=UTF-8",
+ /*
+ timeout: 0,
+ data: null,
+ dataType: null,
+ username: null,
+ password: null,
+ cache: null,
+ throws: false,
+ traditional: false,
+ headers: {},
+ */
+
+ accepts: {
+ "*": allTypes,
+ text: "text/plain",
+ html: "text/html",
+ xml: "application/xml, text/xml",
+ json: "application/json, text/javascript"
+ },
+
+ contents: {
+ xml: /xml/,
+ html: /html/,
+ json: /json/
+ },
+
+ responseFields: {
+ xml: "responseXML",
+ text: "responseText",
+ json: "responseJSON"
+ },
+
+ // Data converters
+ // Keys separate source (or catchall "*") and destination types with a single space
+ converters: {
+
+ // Convert anything to text
+ "* text": String,
+
+ // Text to html (true = no transformation)
+ "text html": true,
+
+ // Evaluate text as a json expression
+ "text json": jQuery.parseJSON,
+
+ // Parse text as xml
+ "text xml": jQuery.parseXML
+ },
+
+ // For options that shouldn't be deep extended:
+ // you can add your own custom options here if
+ // and when you create one that shouldn't be
+ // deep extended (see ajaxExtend)
+ flatOptions: {
+ url: true,
+ context: true
+ }
+ },
+
+ // Creates a full fledged settings object into target
+ // with both ajaxSettings and settings fields.
+ // If target is omitted, writes into ajaxSettings.
+ ajaxSetup: function( target, settings ) {
+ return settings ?
+
+ // Building a settings object
+ ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
+
+ // Extending ajaxSettings
+ ajaxExtend( jQuery.ajaxSettings, target );
+ },
+
+ ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
+ ajaxTransport: addToPrefiltersOrTransports( transports ),
+
+ // Main method
+ ajax: function( url, options ) {
+
+ // If url is an object, simulate pre-1.5 signature
+ if ( typeof url === "object" ) {
+ options = url;
+ url = undefined;
+ }
+
+ // Force options to be an object
+ options = options || {};
+
+ var transport,
+ // URL without anti-cache param
+ cacheURL,
+ // Response headers
+ responseHeadersString,
+ responseHeaders,
+ // timeout handle
+ timeoutTimer,
+ // Cross-domain detection vars
+ parts,
+ // To know if global events are to be dispatched
+ fireGlobals,
+ // Loop variable
+ i,
+ // Create the final options object
+ s = jQuery.ajaxSetup( {}, options ),
+ // Callbacks context
+ callbackContext = s.context || s,
+ // Context for global events is callbackContext if it is a DOM node or jQuery collection
+ globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
+ jQuery( callbackContext ) :
+ jQuery.event,
+ // Deferreds
+ deferred = jQuery.Deferred(),
+ completeDeferred = jQuery.Callbacks("once memory"),
+ // Status-dependent callbacks
+ statusCode = s.statusCode || {},
+ // Headers (they are sent all at once)
+ requestHeaders = {},
+ requestHeadersNames = {},
+ // The jqXHR state
+ state = 0,
+ // Default abort message
+ strAbort = "canceled",
+ // Fake xhr
+ jqXHR = {
+ readyState: 0,
+
+ // Builds headers hashtable if needed
+ getResponseHeader: function( key ) {
+ var match;
+ if ( state === 2 ) {
+ if ( !responseHeaders ) {
+ responseHeaders = {};
+ while ( (match = rheaders.exec( responseHeadersString )) ) {
+ responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
+ }
+ }
+ match = responseHeaders[ key.toLowerCase() ];
+ }
+ return match == null ? null : match;
+ },
+
+ // Raw string
+ getAllResponseHeaders: function() {
+ return state === 2 ? responseHeadersString : null;
+ },
+
+ // Caches the header
+ setRequestHeader: function( name, value ) {
+ var lname = name.toLowerCase();
+ if ( !state ) {
+ name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
+ requestHeaders[ name ] = value;
+ }
+ return this;
+ },
+
+ // Overrides response content-type header
+ overrideMimeType: function( type ) {
+ if ( !state ) {
+ s.mimeType = type;
+ }
+ return this;
+ },
+
+ // Status-dependent callbacks
+ statusCode: function( map ) {
+ var code;
+ if ( map ) {
+ if ( state < 2 ) {
+ for ( code in map ) {
+ // Lazy-add the new callback in a way that preserves old ones
+ statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
+ }
+ } else {
+ // Execute the appropriate callbacks
+ jqXHR.always( map[ jqXHR.status ] );
+ }
+ }
+ return this;
+ },
+
+ // Cancel the request
+ abort: function( statusText ) {
+ var finalText = statusText || strAbort;
+ if ( transport ) {
+ transport.abort( finalText );
+ }
+ done( 0, finalText );
+ return this;
+ }
+ };
+
+ // Attach deferreds
+ deferred.promise( jqXHR ).complete = completeDeferred.add;
+ jqXHR.success = jqXHR.done;
+ jqXHR.error = jqXHR.fail;
+
+ // Remove hash character (#7531: and string promotion)
+ // Add protocol if not provided (prefilters might expect it)
+ // Handle falsy url in the settings object (#10093: consistency with old signature)
+ // We also use the url parameter if available
+ s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
+ .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
+
+ // Alias method option to type as per ticket #12004
+ s.type = options.method || options.type || s.method || s.type;
+
+ // Extract dataTypes list
+ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
+
+ // A cross-domain request is in order when we have a protocol:host:port mismatch
+ if ( s.crossDomain == null ) {
+ parts = rurl.exec( s.url.toLowerCase() );
+ s.crossDomain = !!( parts &&
+ ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
+ ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
+ ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
+ );
+ }
+
+ // Convert data if not already a string
+ if ( s.data && s.processData && typeof s.data !== "string" ) {
+ s.data = jQuery.param( s.data, s.traditional );
+ }
+
+ // Apply prefilters
+ inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
+
+ // If request was aborted inside a prefilter, stop there
+ if ( state === 2 ) {
+ return jqXHR;
+ }
+
+ // We can fire global events as of now if asked to
+ // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
+ fireGlobals = jQuery.event && s.global;
+
+ // Watch for a new set of requests
+ if ( fireGlobals && jQuery.active++ === 0 ) {
+ jQuery.event.trigger("ajaxStart");
+ }
+
+ // Uppercase the type
+ s.type = s.type.toUpperCase();
+
+ // Determine if request has content
+ s.hasContent = !rnoContent.test( s.type );
+
+ // Save the URL in case we're toying with the If-Modified-Since
+ // and/or If-None-Match header later on
+ cacheURL = s.url;
+
+ // More options handling for requests with no content
+ if ( !s.hasContent ) {
+
+ // If data is available, append data to url
+ if ( s.data ) {
+ cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
+ // #9682: remove data so that it's not used in an eventual retry
+ delete s.data;
+ }
+
+ // Add anti-cache in url if needed
+ if ( s.cache === false ) {
+ s.url = rts.test( cacheURL ) ?
+
+ // If there is already a '_' parameter, set its value
+ cacheURL.replace( rts, "$1_=" + nonce++ ) :
+
+ // Otherwise add one to the end
+ cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
+ }
+ }
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+ if ( jQuery.lastModified[ cacheURL ] ) {
+ jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
+ }
+ if ( jQuery.etag[ cacheURL ] ) {
+ jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
+ }
+ }
+
+ // Set the correct header, if data is being sent
+ if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
+ jqXHR.setRequestHeader( "Content-Type", s.contentType );
+ }
+
+ // Set the Accepts header for the server, depending on the dataType
+ jqXHR.setRequestHeader(
+ "Accept",
+ s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
+ s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
+ s.accepts[ "*" ]
+ );
+
+ // Check for headers option
+ for ( i in s.headers ) {
+ jqXHR.setRequestHeader( i, s.headers[ i ] );
+ }
+
+ // Allow custom headers/mimetypes and early abort
+ if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
+ // Abort if not done already and return
+ return jqXHR.abort();
+ }
+
+ // Aborting is no longer a cancellation
+ strAbort = "abort";
+
+ // Install callbacks on deferreds
+ for ( i in { success: 1, error: 1, complete: 1 } ) {
+ jqXHR[ i ]( s[ i ] );
+ }
+
+ // Get transport
+ transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
+
+ // If no transport, we auto-abort
+ if ( !transport ) {
+ done( -1, "No Transport" );
+ } else {
+ jqXHR.readyState = 1;
+
+ // Send global event
+ if ( fireGlobals ) {
+ globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
+ }
+ // Timeout
+ if ( s.async && s.timeout > 0 ) {
+ timeoutTimer = setTimeout(function() {
+ jqXHR.abort("timeout");
+ }, s.timeout );
+ }
+
+ try {
+ state = 1;
+ transport.send( requestHeaders, done );
+ } catch ( e ) {
+ // Propagate exception as error if not done
+ if ( state < 2 ) {
+ done( -1, e );
+ // Simply rethrow otherwise
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ // Callback for when everything is done
+ function done( status, nativeStatusText, responses, headers ) {
+ var isSuccess, success, error, response, modified,
+ statusText = nativeStatusText;
+
+ // Called once
+ if ( state === 2 ) {
+ return;
+ }
+
+ // State is "done" now
+ state = 2;
+
+ // Clear timeout if it exists
+ if ( timeoutTimer ) {
+ clearTimeout( timeoutTimer );
+ }
+
+ // Dereference transport for early garbage collection
+ // (no matter how long the jqXHR object will be used)
+ transport = undefined;
+
+ // Cache response headers
+ responseHeadersString = headers || "";
+
+ // Set readyState
+ jqXHR.readyState = status > 0 ? 4 : 0;
+
+ // Determine if successful
+ isSuccess = status >= 200 && status < 300 || status === 304;
+
+ // Get response data
+ if ( responses ) {
+ response = ajaxHandleResponses( s, jqXHR, responses );
+ }
+
+ // Convert no matter what (that way responseXXX fields are always set)
+ response = ajaxConvert( s, response, jqXHR, isSuccess );
+
+ // If successful, handle type chaining
+ if ( isSuccess ) {
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+ modified = jqXHR.getResponseHeader("Last-Modified");
+ if ( modified ) {
+ jQuery.lastModified[ cacheURL ] = modified;
+ }
+ modified = jqXHR.getResponseHeader("etag");
+ if ( modified ) {
+ jQuery.etag[ cacheURL ] = modified;
+ }
+ }
+
+ // if no content
+ if ( status === 204 || s.type === "HEAD" ) {
+ statusText = "nocontent";
+
+ // if not modified
+ } else if ( status === 304 ) {
+ statusText = "notmodified";
+
+ // If we have data, let's convert it
+ } else {
+ statusText = response.state;
+ success = response.data;
+ error = response.error;
+ isSuccess = !error;
+ }
+ } else {
+ // Extract error from statusText and normalize for non-aborts
+ error = statusText;
+ if ( status || !statusText ) {
+ statusText = "error";
+ if ( status < 0 ) {
+ status = 0;
+ }
+ }
+ }
+
+ // Set data for the fake xhr object
+ jqXHR.status = status;
+ jqXHR.statusText = ( nativeStatusText || statusText ) + "";
+
+ // Success/Error
+ if ( isSuccess ) {
+ deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
+ } else {
+ deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
+ }
+
+ // Status-dependent callbacks
+ jqXHR.statusCode( statusCode );
+ statusCode = undefined;
+
+ if ( fireGlobals ) {
+ globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
+ [ jqXHR, s, isSuccess ? success : error ] );
+ }
+
+ // Complete
+ completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
+
+ if ( fireGlobals ) {
+ globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
+ // Handle the global AJAX counter
+ if ( !( --jQuery.active ) ) {
+ jQuery.event.trigger("ajaxStop");
+ }
+ }
+ }
+
+ return jqXHR;
+ },
+
+ getJSON: function( url, data, callback ) {
+ return jQuery.get( url, data, callback, "json" );
+ },
+
+ getScript: function( url, callback ) {
+ return jQuery.get( url, undefined, callback, "script" );
+ }
+});
+
+jQuery.each( [ "get", "post" ], function( i, method ) {
+ jQuery[ method ] = function( url, data, callback, type ) {
+ // Shift arguments if data argument was omitted
+ if ( jQuery.isFunction( data ) ) {
+ type = type || callback;
+ callback = data;
+ data = undefined;
+ }
+
+ return jQuery.ajax({
+ url: url,
+ type: method,
+ dataType: type,
+ data: data,
+ success: callback
+ });
+ };
+});
+
+
+jQuery._evalUrl = function( url ) {
+ return jQuery.ajax({
+ url: url,
+ type: "GET",
+ dataType: "script",
+ async: false,
+ global: false,
+ "throws": true
+ });
+};
+
+
+jQuery.fn.extend({
+ wrapAll: function( html ) {
+ var wrap;
+
+ 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
+ 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.firstElementChild ) {
+ elem = elem.firstElementChild;
+ }
+
+ 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();
+ }
+});
+
+
+jQuery.expr.filters.hidden = function( elem ) {
+ // Support: Opera <= 12.12
+ // Opera reports offsetWidths and offsetHeights less than zero on some elements
+ return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
+};
+jQuery.expr.filters.visible = function( elem ) {
+ return !jQuery.expr.filters.hidden( elem );
+};
+
+
+
+
+var r20 = /%20/g,
+ rbracket = /\[\]$/,
+ rCRLF = /\r?\n/g,
+ rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
+ rsubmittable = /^(?:input|select|textarea|keygen)/i;
+
+function buildParams( prefix, obj, traditional, add ) {
+ var name;
+
+ if ( jQuery.isArray( obj ) ) {
+ // Serialize array item.
+ jQuery.each( obj, function( i, v ) {
+ if ( traditional || rbracket.test( prefix ) ) {
+ // Treat each array item as a scalar.
+ add( prefix, v );
+
+ } else {
+ // Item is non-scalar (array or object), encode its numeric index.
+ buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
+ }
+ });
+
+ } else if ( !traditional && jQuery.type( obj ) === "object" ) {
+ // Serialize object item.
+ for ( name in obj ) {
+ buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
+ }
+
+ } else {
+ // Serialize scalar item.
+ add( prefix, obj );
+ }
+}
+
+// Serialize an array of form elements or a set of
+// key/values into a query string
+jQuery.param = function( a, traditional ) {
+ var prefix,
+ s = [],
+ add = function( key, value ) {
+ // If value is a function, invoke it and return its value
+ value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
+ s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
+ };
+
+ // Set traditional to true for jQuery <= 1.3.2 behavior.
+ if ( traditional === undefined ) {
+ traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
+ }
+
+ // If an array was passed in, assume that it is an array of form elements.
+ if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
+ // Serialize the form elements
+ jQuery.each( a, function() {
+ add( this.name, this.value );
+ });
+
+ } else {
+ // If traditional, encode the "old" way (the way 1.3.2 or older
+ // did it), otherwise encode params recursively.
+ for ( prefix in a ) {
+ buildParams( prefix, a[ prefix ], traditional, add );
+ }
+ }
+
+ // Return the resulting serialization
+ return s.join( "&" ).replace( r20, "+" );
+};
+
+jQuery.fn.extend({
+ serialize: function() {
+ return jQuery.param( this.serializeArray() );
+ },
+ serializeArray: function() {
+ return this.map(function() {
+ // Can add propHook for "elements" to filter or add form elements
+ var elements = jQuery.prop( this, "elements" );
+ return elements ? jQuery.makeArray( elements ) : this;
+ })
+ .filter(function() {
+ var type = this.type;
+
+ // Use .is( ":disabled" ) so that fieldset[disabled] works
+ return this.name && !jQuery( this ).is( ":disabled" ) &&
+ rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
+ ( this.checked || !rcheckableType.test( type ) );
+ })
+ .map(function( i, elem ) {
+ var val = jQuery( this ).val();
+
+ return val == null ?
+ null :
+ jQuery.isArray( val ) ?
+ jQuery.map( val, function( val ) {
+ return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+ }) :
+ { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+ }).get();
+ }
+});
+
+
+jQuery.ajaxSettings.xhr = function() {
+ try {
+ return new XMLHttpRequest();
+ } catch( e ) {}
+};
+
+var xhrId = 0,
+ xhrCallbacks = {},
+ xhrSuccessStatus = {
+ // file protocol always yields status code 0, assume 200
+ 0: 200,
+ // Support: IE9
+ // #1450: sometimes IE returns 1223 when it should be 204
+ 1223: 204
+ },
+ xhrSupported = jQuery.ajaxSettings.xhr();
+
+// Support: IE9
+// Open requests must be manually aborted on unload (#5280)
+// See https://support.microsoft.com/kb/2856746 for more info
+if ( window.attachEvent ) {
+ window.attachEvent( "onunload", function() {
+ for ( var key in xhrCallbacks ) {
+ xhrCallbacks[ key ]();
+ }
+ });
+}
+
+support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
+support.ajax = xhrSupported = !!xhrSupported;
+
+jQuery.ajaxTransport(function( options ) {
+ var callback;
+
+ // Cross domain only allowed if supported through XMLHttpRequest
+ if ( support.cors || xhrSupported && !options.crossDomain ) {
+ return {
+ send: function( headers, complete ) {
+ var i,
+ xhr = options.xhr(),
+ id = ++xhrId;
+
+ xhr.open( options.type, options.url, options.async, options.username, options.password );
+
+ // Apply custom fields if provided
+ if ( options.xhrFields ) {
+ for ( i in options.xhrFields ) {
+ xhr[ i ] = options.xhrFields[ i ];
+ }
+ }
+
+ // Override mime type if needed
+ if ( options.mimeType && xhr.overrideMimeType ) {
+ xhr.overrideMimeType( options.mimeType );
+ }
+
+ // X-Requested-With header
+ // For cross-domain requests, seeing as conditions for a preflight are
+ // akin to a jigsaw puzzle, we simply never set it to be sure.
+ // (it can always be set on a per-request basis or even using ajaxSetup)
+ // For same-domain requests, won't change header if already provided.
+ if ( !options.crossDomain && !headers["X-Requested-With"] ) {
+ headers["X-Requested-With"] = "XMLHttpRequest";
+ }
+
+ // Set headers
+ for ( i in headers ) {
+ xhr.setRequestHeader( i, headers[ i ] );
+ }
+
+ // Callback
+ callback = function( type ) {
+ return function() {
+ if ( callback ) {
+ delete xhrCallbacks[ id ];
+ callback = xhr.onload = xhr.onerror = null;
+
+ if ( type === "abort" ) {
+ xhr.abort();
+ } else if ( type === "error" ) {
+ complete(
+ // file: protocol always yields status 0; see #8605, #14207
+ xhr.status,
+ xhr.statusText
+ );
+ } else {
+ complete(
+ xhrSuccessStatus[ xhr.status ] || xhr.status,
+ xhr.statusText,
+ // Support: IE9
+ // Accessing binary-data responseText throws an exception
+ // (#11426)
+ typeof xhr.responseText === "string" ? {
+ text: xhr.responseText
+ } : undefined,
+ xhr.getAllResponseHeaders()
+ );
+ }
+ }
+ };
+ };
+
+ // Listen to events
+ xhr.onload = callback();
+ xhr.onerror = callback("error");
+
+ // Create the abort callback
+ callback = xhrCallbacks[ id ] = callback("abort");
+
+ try {
+ // Do send the request (this may raise an exception)
+ xhr.send( options.hasContent && options.data || null );
+ } catch ( e ) {
+ // #14683: Only rethrow if this hasn't been notified as an error yet
+ if ( callback ) {
+ throw e;
+ }
+ }
+ },
+
+ abort: function() {
+ if ( callback ) {
+ callback();
+ }
+ }
+ };
+ }
+});
+
+
+
+
+// Install script dataType
+jQuery.ajaxSetup({
+ accepts: {
+ script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
+ },
+ contents: {
+ script: /(?:java|ecma)script/
+ },
+ converters: {
+ "text script": function( text ) {
+ jQuery.globalEval( text );
+ return text;
+ }
+ }
+});
+
+// Handle cache's special case and crossDomain
+jQuery.ajaxPrefilter( "script", function( s ) {
+ if ( s.cache === undefined ) {
+ s.cache = false;
+ }
+ if ( s.crossDomain ) {
+ s.type = "GET";
+ }
+});
+
+// Bind script tag hack transport
+jQuery.ajaxTransport( "script", function( s ) {
+ // This transport only deals with cross domain requests
+ if ( s.crossDomain ) {
+ var script, callback;
+ return {
+ send: function( _, complete ) {
+ script = jQuery("<script>").prop({
+ async: true,
+ charset: s.scriptCharset,
+ src: s.url
+ }).on(
+ "load error",
+ callback = function( evt ) {
+ script.remove();
+ callback = null;
+ if ( evt ) {
+ complete( evt.type === "error" ? 404 : 200, evt.type );
+ }
+ }
+ );
+ document.head.appendChild( script[ 0 ] );
+ },
+ abort: function() {
+ if ( callback ) {
+ callback();
+ }
+ }
+ };
+ }
+});
+
+
+
+
+var oldCallbacks = [],
+ rjsonp = /(=)\?(?=&|$)|\?\?/;
+
+// Default jsonp settings
+jQuery.ajaxSetup({
+ jsonp: "callback",
+ jsonpCallback: function() {
+ var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
+ this[ callback ] = true;
+ return callback;
+ }
+});
+
+// Detect, normalize options and install callbacks for jsonp requests
+jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
+
+ var callbackName, overwritten, responseContainer,
+ jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
+ "url" :
+ typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
+ );
+
+ // Handle iff the expected data type is "jsonp" or we have a parameter to set
+ if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
+
+ // Get callback name, remembering preexisting value associated with it
+ callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
+ s.jsonpCallback() :
+ s.jsonpCallback;
+
+ // Insert callback into url or form data
+ if ( jsonProp ) {
+ s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
+ } else if ( s.jsonp !== false ) {
+ s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
+ }
+
+ // Use data converter to retrieve json after script execution
+ s.converters["script json"] = function() {
+ if ( !responseContainer ) {
+ jQuery.error( callbackName + " was not called" );
+ }
+ return responseContainer[ 0 ];
+ };
+
+ // force json dataType
+ s.dataTypes[ 0 ] = "json";
+
+ // Install callback
+ overwritten = window[ callbackName ];
+ window[ callbackName ] = function() {
+ responseContainer = arguments;
+ };
+
+ // Clean-up function (fires after converters)
+ jqXHR.always(function() {
+ // Restore preexisting value
+ window[ callbackName ] = overwritten;
+
+ // Save back as free
+ if ( s[ callbackName ] ) {
+ // make sure that re-using the options doesn't screw things around
+ s.jsonpCallback = originalSettings.jsonpCallback;
+
+ // save the callback name for future use
+ oldCallbacks.push( callbackName );
+ }
+
+ // Call if it was a function and we have a response
+ if ( responseContainer && jQuery.isFunction( overwritten ) ) {
+ overwritten( responseContainer[ 0 ] );
+ }
+
+ responseContainer = overwritten = undefined;
+ });
+
+ // Delegate to script
+ return "script";
+ }
+});
+
+
+
+
+// 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
+jQuery.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 && scripts.length ) {
+ jQuery( scripts ).remove();
+ }
+
+ return jQuery.merge( [], parsed.childNodes );
+};
+
+
+// Keep a copy of the old load method
+var _load = jQuery.fn.load;
+
+/**
+ * Load a url into a page
+ */
+jQuery.fn.load = function( url, params, callback ) {
+ if ( typeof url !== "string" && _load ) {
+ return _load.apply( this, arguments );
+ }
+
+ var selector, type, response,
+ self = this,
+ off = url.indexOf(" ");
+
+ if ( off >= 0 ) {
+ selector = jQuery.trim( url.slice( off ) );
+ url = url.slice( 0, off );
+ }
+
+ // If it's a function
+ if ( jQuery.isFunction( params ) ) {
+
+ // We assume that it's the callback
+ callback = params;
+ params = undefined;
+
+ // Otherwise, build a param string
+ } else if ( params && typeof params === "object" ) {
+ type = "POST";
+ }
+
+ // If we have elements to modify, make the request
+ if ( self.length > 0 ) {
+ jQuery.ajax({
+ url: url,
+
+ // if "type" variable is undefined, then "GET" method will be used
+ type: type,
+ dataType: "html",
+ data: params
+ }).done(function( responseText ) {
+
+ // Save response for use in complete callback
+ response = arguments;
+
+ self.html( selector ?
+
+ // If a selector was specified, locate the right elements in a dummy div
+ // Exclude scripts to avoid IE 'Permission Denied' errors
+ jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
+
+ // Otherwise use the full result
+ responseText );
+
+ }).complete( callback && function( jqXHR, status ) {
+ self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
+ });
+ }
+
+ return this;
+};
+
+
+
+
+// Attach a bunch of functions for handling common AJAX events
+jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
+ jQuery.fn[ type ] = function( fn ) {
+ return this.on( type, fn );
+ };
+});
+
+
+
+
+jQuery.expr.filters.animated = function( elem ) {
+ return jQuery.grep(jQuery.timers, function( fn ) {
+ return elem === fn.elem;
+ }).length;
+};
+
+
+
+
+var docElem = window.document.documentElement;
+
+/**
+ * Gets a window from an element
+ */
+function getWindow( elem ) {
+ return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
+}
+
+jQuery.offset = {
+ setOffset: function( elem, options, i ) {
+ var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
+ position = jQuery.css( elem, "position" ),
+ curElem = jQuery( elem ),
+ props = {};
+
+ // Set position first, in-case top/left are set even on static elem
+ if ( position === "static" ) {
+ elem.style.position = "relative";
+ }
+
+ curOffset = curElem.offset();
+ curCSSTop = jQuery.css( elem, "top" );
+ curCSSLeft = jQuery.css( elem, "left" );
+ calculatePosition = ( position === "absolute" || position === "fixed" ) &&
+ ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
+
+ // Need to be able to calculate position if either
+ // top or left is auto and position is either absolute or fixed
+ if ( calculatePosition ) {
+ curPosition = curElem.position();
+ curTop = curPosition.top;
+ curLeft = curPosition.left;
+
+ } else {
+ curTop = parseFloat( curCSSTop ) || 0;
+ curLeft = parseFloat( curCSSLeft ) || 0;
+ }
+
+ if ( jQuery.isFunction( options ) ) {
+ options = options.call( elem, i, curOffset );
+ }
+
+ if ( options.top != null ) {
+ props.top = ( options.top - curOffset.top ) + curTop;
+ }
+ if ( options.left != null ) {
+ props.left = ( options.left - curOffset.left ) + curLeft;
+ }
+
+ if ( "using" in options ) {
+ options.using.call( elem, props );
+
+ } else {
+ curElem.css( props );
+ }
+ }
+};
+
+jQuery.fn.extend({
+ offset: function( options ) {
+ if ( arguments.length ) {
+ return options === undefined ?
+ this :
+ this.each(function( i ) {
+ jQuery.offset.setOffset( this, options, i );
+ });
+ }
+
+ var docElem, win,
+ elem = this[ 0 ],
+ box = { top: 0, left: 0 },
+ doc = elem && elem.ownerDocument;
+
+ if ( !doc ) {
+ return;
+ }
+
+ docElem = doc.documentElement;
+
+ // Make sure it's not a disconnected DOM node
+ if ( !jQuery.contains( docElem, elem ) ) {
+ return box;
+ }
+
+ // Support: BlackBerry 5, iOS 3 (original iPhone)
+ // If we don't have gBCR, just use 0,0 rather than error
+ if ( typeof elem.getBoundingClientRect !== strundefined ) {
+ box = elem.getBoundingClientRect();
+ }
+ win = getWindow( doc );
+ return {
+ top: box.top + win.pageYOffset - docElem.clientTop,
+ left: box.left + win.pageXOffset - docElem.clientLeft
+ };
+ },
+
+ position: function() {
+ if ( !this[ 0 ] ) {
+ return;
+ }
+
+ var offsetParent, offset,
+ elem = this[ 0 ],
+ parentOffset = { top: 0, left: 0 };
+
+ // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
+ if ( jQuery.css( elem, "position" ) === "fixed" ) {
+ // Assume getBoundingClientRect is there when computed position is fixed
+ offset = elem.getBoundingClientRect();
+
+ } else {
+ // Get *real* offsetParent
+ offsetParent = this.offsetParent();
+
+ // Get correct offsets
+ offset = this.offset();
+ if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
+ parentOffset = offsetParent.offset();
+ }
+
+ // Add offsetParent borders
+ parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
+ parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
+ }
+
+ // Subtract parent offsets and element margins
+ return {
+ top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
+ left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
+ };
+ },
+
+ offsetParent: function() {
+ return this.map(function() {
+ var offsetParent = this.offsetParent || docElem;
+
+ while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
+ offsetParent = offsetParent.offsetParent;
+ }
+
+ return offsetParent || docElem;
+ });
+ }
+});
+
+// Create scrollLeft and scrollTop methods
+jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
+ var top = "pageYOffset" === prop;
+
+ jQuery.fn[ method ] = function( val ) {
+ return access( this, function( elem, method, val ) {
+ var win = getWindow( elem );
+
+ if ( val === undefined ) {
+ return win ? win[ prop ] : elem[ method ];
+ }
+
+ if ( win ) {
+ win.scrollTo(
+ !top ? val : window.pageXOffset,
+ top ? val : window.pageYOffset
+ );
+
+ } else {
+ elem[ method ] = val;
+ }
+ }, method, val, arguments.length, null );
+ };
+});
+
+// Support: Safari<7+, Chrome<37+
+// Add the top/left cssHooks using jQuery.fn.position
+// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
+// Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
+// getComputedStyle returns percent when specified for top/left/bottom/right;
+// rather than make the css module depend on the offset module, just check for it here
+jQuery.each( [ "top", "left" ], function( i, prop ) {
+ jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
+ function( elem, computed ) {
+ if ( computed ) {
+ computed = curCSS( elem, prop );
+ // If curCSS returns percentage, fallback to offset
+ return rnumnonpx.test( computed ) ?
+ jQuery( elem ).position()[ prop ] + "px" :
+ computed;
+ }
+ }
+ );
+});
+
+
+// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
+jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
+ jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
+ // Margin is only for outerHeight, outerWidth
+ jQuery.fn[ funcName ] = function( margin, value ) {
+ var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
+ extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
+
+ return access( this, function( elem, type, value ) {
+ var doc;
+
+ if ( jQuery.isWindow( elem ) ) {
+ // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
+ // isn't a whole lot we can do. See pull request at this URL for discussion:
+ // https://github.com/jquery/jquery/pull/764
+ return elem.document.documentElement[ "client" + name ];
+ }
+
+ // Get document width or height
+ if ( elem.nodeType === 9 ) {
+ doc = elem.documentElement;
+
+ // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
+ // whichever is greatest
+ return Math.max(
+ elem.body[ "scroll" + name ], doc[ "scroll" + name ],
+ elem.body[ "offset" + name ], doc[ "offset" + name ],
+ doc[ "client" + name ]
+ );
+ }
+
+ return value === undefined ?
+ // Get width or height on the element, requesting but not forcing parseFloat
+ jQuery.css( elem, type, extra ) :
+
+ // Set width or height on the element
+ jQuery.style( elem, type, value, extra );
+ }, type, chainable ? margin : undefined, chainable, null );
+ };
+ });
+});
+
+
+// The number of elements contained in the matched element set
+jQuery.fn.size = function() {
+ return this.length;
+};
+
+jQuery.fn.andSelf = jQuery.fn.addBack;
+
+
+
+
+// Register as a named AMD module, since jQuery can be concatenated with other
+// files that may use define, but not via a proper concatenation script that
+// understands anonymous AMD modules. A named AMD is safest and most robust
+// way to register. Lowercase jquery is used because AMD module names are
+// derived from file names, and jQuery is normally delivered in a lowercase
+// file name. Do this after creating the global so that if an AMD module wants
+// to call noConflict to hide this version of jQuery, it will work.
+
+// Note that for maximum portability, libraries that are not jQuery should
+// declare themselves as anonymous modules, and avoid setting a global if an
+// AMD loader is present. jQuery is a special case. For more information, see
+// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
+
+if ( typeof define === "function" && define.amd ) {
+ define( "jquery", [], function() {
+ return jQuery;
+ });
+}
+
+
+
+
+var
+ // Map over jQuery in case of overwrite
+ _jQuery = window.jQuery,
+
+ // Map over the $ in case of overwrite
+ _$ = window.$;
+
+jQuery.noConflict = function( deep ) {
+ if ( window.$ === jQuery ) {
+ window.$ = _$;
+ }
+
+ if ( deep && window.jQuery === jQuery ) {
+ window.jQuery = _jQuery;
+ }
+
+ return jQuery;
+};
+
+// Expose jQuery and $ identifiers, even in AMD
+// (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
+// and CommonJS for browser emulators (#13566)
+if ( typeof noGlobal === strundefined ) {
+ window.jQuery = window.$ = jQuery;
+}
+
+
+
+
+return jQuery;
+
+}));
+
+},{}],19:[function(require,module,exports){
+var baseIndexOf = require('../internal/baseIndexOf'),
+ binaryIndex = require('../internal/binaryIndex');
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * Gets the index at which the first occurrence of `value` is found in `array`
+ * using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
+ * it is used as the offset from the end of `array`. If `array` is sorted
+ * providing `true` for `fromIndex` performs a faster binary search.
+ *
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
+ *
+ * @static
+ * @memberOf _
+ * @category Array
+ * @param {Array} array The array to search.
+ * @param {*} value The value to search for.
+ * @param {boolean|number} [fromIndex=0] The index to search from or `true`
+ * to perform a binary search on a sorted array.
+ * @returns {number} Returns the index of the matched value, else `-1`.
+ * @example
+ *
+ * _.indexOf([1, 2, 1, 2], 2);
+ * // => 1
+ *
+ * // using `fromIndex`
+ * _.indexOf([1, 2, 1, 2], 2, 2);
+ * // => 3
+ *
+ * // performing a binary search
+ * _.indexOf([1, 1, 2, 2], 2, true);
+ * // => 2
+ */
+function indexOf(array, value, fromIndex) {
+ var length = array ? array.length : 0;
+ if (!length) {
+ return -1;
+ }
+ if (typeof fromIndex == 'number') {
+ fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
+ } else if (fromIndex) {
+ var index = binaryIndex(array, value),
+ other = array[index];
+
+ if (value === value ? (value === other) : (other !== other)) {
+ return index;
+ }
+ return -1;
+ }
+ return baseIndexOf(array, value, fromIndex || 0);
+}
+
+module.exports = indexOf;
+
+},{"../internal/baseIndexOf":42,"../internal/binaryIndex":54}],20:[function(require,module,exports){
+var LazyWrapper = require('../internal/LazyWrapper'),
+ LodashWrapper = require('../internal/LodashWrapper'),
+ baseLodash = require('../internal/baseLodash'),
+ isArray = require('../lang/isArray'),
+ isObjectLike = require('../internal/isObjectLike'),
+ wrapperClone = require('../internal/wrapperClone');
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Creates a `lodash` object which wraps `value` to enable implicit chaining.
+ * Methods that operate on and return arrays, collections, and functions can
+ * be chained together. Methods that return a boolean or single value will
+ * automatically end the chain returning the unwrapped value. Explicit chaining
+ * may be enabled using `_.chain`. The execution of chained methods is lazy,
+ * that is, execution is deferred until `_#value` is implicitly or explicitly
+ * called.
+ *
+ * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
+ * fusion is an optimization that merges iteratees to avoid creating intermediate
+ * arrays and reduce the number of iteratee executions.
+ *
+ * Chaining is supported in custom builds as long as the `_#value` method is
+ * directly or indirectly included in the build.
+ *
+ * In addition to lodash methods, wrappers have `Array` and `String` methods.
+ *
+ * The wrapper `Array` methods are:
+ * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
+ * `splice`, and `unshift`
+ *
+ * The wrapper `String` methods are:
+ * `replace` and `split`
+ *
+ * The wrapper methods that support shortcut fusion are:
+ * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
+ * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
+ * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
+ * and `where`
+ *
+ * The chainable wrapper methods are:
+ * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
+ * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
+ * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
+ * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
+ * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
+ * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
+ * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
+ * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
+ * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
+ * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
+ * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
+ * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
+ * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
+ * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
+ * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
+ * `without`, `wrap`, `xor`, `zip`, and `zipObject`
+ *
+ * The wrapper methods that are **not** chainable by default are:
+ * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
+ * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
+ * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
+ * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
+ * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
+ * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
+ * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
+ * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
+ * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
+ * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
+ * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
+ * `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
+ * `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
+ *
+ * The wrapper method `sample` will return a wrapped value when `n` is provided,
+ * otherwise an unwrapped value is returned.
+ *
+ * @name _
+ * @constructor
+ * @category Chain
+ * @param {*} value The value to wrap in a `lodash` instance.
+ * @returns {Object} Returns the new `lodash` wrapper instance.
+ * @example
+ *
+ * var wrapped = _([1, 2, 3]);
+ *
+ * // returns an unwrapped value
+ * wrapped.reduce(function(sum, n) {
+ * return sum + n;
+ * });
+ * // => 6
+ *
+ * // returns a wrapped value
+ * var squares = wrapped.map(function(n) {
+ * return n * n;
+ * });
+ *
+ * _.isArray(squares);
+ * // => false
+ *
+ * _.isArray(squares.value());
+ * // => true
+ */
+function lodash(value) {
+ if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
+ if (value instanceof LodashWrapper) {
+ return value;
+ }
+ if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
+ return wrapperClone(value);
+ }
+ }
+ return new LodashWrapper(value);
+}
+
+// Ensure wrappers are instances of `baseLodash`.
+lodash.prototype = baseLodash.prototype;
+
+module.exports = lodash;
+
+},{"../internal/LazyWrapper":27,"../internal/LodashWrapper":28,"../internal/baseLodash":47,"../internal/isObjectLike":82,"../internal/wrapperClone":93,"../lang/isArray":96}],21:[function(require,module,exports){
+var baseEach = require('../internal/baseEach'),
+ createFind = require('../internal/createFind');
+
+/**
+ * Iterates over elements of `collection`, returning the first element
+ * `predicate` returns truthy for. The predicate is bound to `thisArg` and
+ * invoked with three arguments: (value, index|key, collection).
+ *
+ * If a property name is provided for `predicate` the created `_.property`
+ * style callback returns the property value of the given element.
+ *
+ * If a value is also provided for `thisArg` the created `_.matchesProperty`
+ * style callback returns `true` for elements that have a matching property
+ * value, else `false`.
+ *
+ * If an object is provided for `predicate` the created `_.matches` style
+ * callback returns `true` for elements that have the properties of the given
+ * object, else `false`.
+ *
+ * @static
+ * @memberOf _
+ * @alias detect
+ * @category Collection
+ * @param {Array|Object|string} collection The collection to search.
+ * @param {Function|Object|string} [predicate=_.identity] The function invoked
+ * per iteration.
+ * @param {*} [thisArg] The `this` binding of `predicate`.
+ * @returns {*} Returns the matched element, else `undefined`.
+ * @example
+ *
+ * var users = [
+ * { 'user': 'barney', 'age': 36, 'active': true },
+ * { 'user': 'fred', 'age': 40, 'active': false },
+ * { 'user': 'pebbles', 'age': 1, 'active': true }
+ * ];
+ *
+ * _.result(_.find(users, function(chr) {
+ * return chr.age < 40;
+ * }), 'user');
+ * // => 'barney'
+ *
+ * // using the `_.matches` callback shorthand
+ * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
+ * // => 'pebbles'
+ *
+ * // using the `_.matchesProperty` callback shorthand
+ * _.result(_.find(users, 'active', false), 'user');
+ * // => 'fred'
+ *
+ * // using the `_.property` callback shorthand
+ * _.result(_.find(users, 'active'), 'user');
+ * // => 'barney'
+ */
+var find = createFind(baseEach);
+
+module.exports = find;
+
+},{"../internal/baseEach":36,"../internal/createFind":64}],22:[function(require,module,exports){
+var arrayEach = require('../internal/arrayEach'),
+ baseEach = require('../internal/baseEach'),
+ createForEach = require('../internal/createForEach');
+
+/**
+ * Iterates over elements of `collection` invoking `iteratee` for each element.
+ * The `iteratee` is bound to `thisArg` and invoked with three arguments:
+ * (value, index|key, collection). Iterator functions may exit iteration early
+ * by explicitly returning `false`.
+ *
+ * **Note:** As with other "Collections" methods, objects with a `length` property
+ * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
+ * may be used for object iteration.
+ *
+ * @static
+ * @memberOf _
+ * @alias each
+ * @category Collection
+ * @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function} [iteratee=_.identity] The function invoked per iteration.
+ * @param {*} [thisArg] The `this` binding of `iteratee`.
+ * @returns {Array|Object|string} Returns `collection`.
+ * @example
+ *
+ * _([1, 2]).forEach(function(n) {
+ * console.log(n);
+ * }).value();
+ * // => logs each value from left to right and returns the array
+ *
+ * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
+ * console.log(n, key);
+ * });
+ * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
+ */
+var forEach = createForEach(arrayEach, baseEach);
+
+module.exports = forEach;
+
+},{"../internal/arrayEach":30,"../internal/baseEach":36,"../internal/createForEach":65}],23:[function(require,module,exports){
+var arrayMap = require('../internal/arrayMap'),
+ baseCallback = require('../internal/baseCallback'),
+ baseMap = require('../internal/baseMap'),
+ isArray = require('../lang/isArray');
+
+/**
+ * Creates an array of values by running each element in `collection` through
+ * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
+ * arguments: (value, index|key, collection).
+ *
+ * If a property name is provided for `iteratee` the created `_.property`
+ * style callback returns the property value of the given element.
+ *
+ * If a value is also provided for `thisArg` the created `_.matchesProperty`
+ * style callback returns `true` for elements that have a matching property
+ * value, else `false`.
+ *
+ * If an object is provided for `iteratee` the created `_.matches` style
+ * callback returns `true` for elements that have the properties of the given
+ * object, else `false`.
+ *
+ * Many lodash methods are guarded to work as interatees for methods like
+ * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
+ *
+ * The guarded methods are:
+ * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
+ * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
+ * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
+ * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
+ *
+ * @static
+ * @memberOf _
+ * @alias collect
+ * @category Collection
+ * @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function|Object|string} [iteratee=_.identity] The function invoked
+ * per iteration.
+ * create a `_.property` or `_.matches` style callback respectively.
+ * @param {*} [thisArg] The `this` binding of `iteratee`.
+ * @returns {Array} Returns the new mapped array.
+ * @example
+ *
+ * function timesThree(n) {
+ * return n * 3;
+ * }
+ *
+ * _.map([1, 2], timesThree);
+ * // => [3, 6]
+ *
+ * _.map({ 'a': 1, 'b': 2 }, timesThree);
+ * // => [3, 6] (iteration order is not guaranteed)
+ *
+ * var users = [
+ * { 'user': 'barney' },
+ * { 'user': 'fred' }
+ * ];
+ *
+ * // using the `_.property` callback shorthand
+ * _.map(users, 'user');
+ * // => ['barney', 'fred']
+ */
+function map(collection, iteratee, thisArg) {
+ var func = isArray(collection) ? arrayMap : baseMap;
+ iteratee = baseCallback(iteratee, thisArg, 3);
+ return func(collection, iteratee);
+}
+
+module.exports = map;
+
+},{"../internal/arrayMap":31,"../internal/baseCallback":32,"../internal/baseMap":48,"../lang/isArray":96}],24:[function(require,module,exports){
+var isNative = require('../lang/isNative');
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
+
+/**
+ * Gets the number of milliseconds that have elapsed since the Unix epoch
+ * (1 January 1970 00:00:00 UTC).
+ *
+ * @static
+ * @memberOf _
+ * @category Date
+ * @example
+ *
+ * _.defer(function(stamp) {
+ * console.log(_.now() - stamp);
+ * }, _.now());
+ * // => logs the number of milliseconds it took for the deferred function to be invoked
+ */
+var now = nativeNow || function() {
+ return new Date().getTime();
+};
+
+module.exports = now;
+
+},{"../lang/isNative":98}],25:[function(require,module,exports){
+var createWrapper = require('../internal/createWrapper'),
+ replaceHolders = require('../internal/replaceHolders'),
+ restParam = require('./restParam');
+
+/** Used to compose bitmasks for wrapper metadata. */
+var BIND_FLAG = 1,
+ PARTIAL_FLAG = 32;
+
+/**
+ * Creates a function that invokes `func` with the `this` binding of `thisArg`
+ * and prepends any additional `_.bind` arguments to those provided to the
+ * bound function.
+ *
+ * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
+ * may be used as a placeholder for partially applied arguments.
+ *
+ * **Note:** Unlike native `Function#bind` this method does not set the `length`
+ * property of bound functions.
+ *
+ * @static
+ * @memberOf _
+ * @category Function
+ * @param {Function} func The function to bind.
+ * @param {*} thisArg The `this` binding of `func`.
+ * @param {...*} [partials] The arguments to be partially applied.
+ * @returns {Function} Returns the new bound function.
+ * @example
+ *
+ * var greet = function(greeting, punctuation) {
+ * return greeting + ' ' + this.user + punctuation;
+ * };
+ *
+ * var object = { 'user': 'fred' };
+ *
+ * var bound = _.bind(greet, object, 'hi');
+ * bound('!');
+ * // => 'hi fred!'
+ *
+ * // using placeholders
+ * var bound = _.bind(greet, object, _, '!');
+ * bound('hi');
+ * // => 'hi fred!'
+ */
+var bind = restParam(function(func, thisArg, partials) {
+ var bitmask = BIND_FLAG;
+ if (partials.length) {
+ var holders = replaceHolders(partials, bind.placeholder);
+ bitmask |= PARTIAL_FLAG;
+ }
+ return createWrapper(func, bitmask, thisArg, partials, holders);
+});
+
+// Assign default placeholders.
+bind.placeholder = {};
+
+module.exports = bind;
+
+},{"../internal/createWrapper":68,"../internal/replaceHolders":88,"./restParam":26}],26:[function(require,module,exports){
+/** Used as the `TypeError` message for "Functions" methods. */
+var FUNC_ERROR_TEXT = 'Expected a function';
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * Creates a function that invokes `func` with the `this` binding of the
+ * created function and arguments from `start` and beyond provided as an array.
+ *
+ * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
+ *
+ * @static
+ * @memberOf _
+ * @category Function
+ * @param {Function} func The function to apply a rest parameter to.
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var say = _.restParam(function(what, names) {
+ * return what + ' ' + _.initial(names).join(', ') +
+ * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
+ * });
+ *
+ * say('hello', 'fred', 'barney', 'pebbles');
+ * // => 'hello fred, barney, & pebbles'
+ */
+function restParam(func, start) {
+ if (typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT);
+ }
+ start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
+ return function() {
+ var args = arguments,
+ index = -1,
+ length = nativeMax(args.length - start, 0),
+ rest = Array(length);
+
+ while (++index < length) {
+ rest[index] = args[start + index];
+ }
+ switch (start) {
+ case 0: return func.call(this, rest);
+ case 1: return func.call(this, args[0], rest);
+ case 2: return func.call(this, args[0], args[1], rest);
+ }
+ var otherArgs = Array(start + 1);
+ index = -1;
+ while (++index < start) {
+ otherArgs[index] = args[index];
+ }
+ otherArgs[start] = rest;
+ return func.apply(this, otherArgs);
+ };
+}
+
+module.exports = restParam;
+
+},{}],27:[function(require,module,exports){
+var baseCreate = require('./baseCreate'),
+ baseLodash = require('./baseLodash');
+
+/** Used as references for `-Infinity` and `Infinity`. */
+var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
+
+/**
+ * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
+ *
+ * @private
+ * @param {*} value The value to wrap.
+ */
+function LazyWrapper(value) {
+ this.__wrapped__ = value;
+ this.__actions__ = null;
+ this.__dir__ = 1;
+ this.__dropCount__ = 0;
+ this.__filtered__ = false;
+ this.__iteratees__ = null;
+ this.__takeCount__ = POSITIVE_INFINITY;
+ this.__views__ = null;
+}
+
+LazyWrapper.prototype = baseCreate(baseLodash.prototype);
+LazyWrapper.prototype.constructor = LazyWrapper;
+
+module.exports = LazyWrapper;
+
+},{"./baseCreate":35,"./baseLodash":47}],28:[function(require,module,exports){
+var baseCreate = require('./baseCreate'),
+ baseLodash = require('./baseLodash');
+
+/**
+ * The base constructor for creating `lodash` wrapper objects.
+ *
+ * @private
+ * @param {*} value The value to wrap.
+ * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
+ * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
+ */
+function LodashWrapper(value, chainAll, actions) {
+ this.__wrapped__ = value;
+ this.__actions__ = actions || [];
+ this.__chain__ = !!chainAll;
+}
+
+LodashWrapper.prototype = baseCreate(baseLodash.prototype);
+LodashWrapper.prototype.constructor = LodashWrapper;
+
+module.exports = LodashWrapper;
+
+},{"./baseCreate":35,"./baseLodash":47}],29:[function(require,module,exports){
+/**
+ * Copies the values of `source` to `array`.
+ *
+ * @private
+ * @param {Array} source The array to copy values from.
+ * @param {Array} [array=[]] The array to copy values to.
+ * @returns {Array} Returns `array`.
+ */
+function arrayCopy(source, array) {
+ var index = -1,
+ length = source.length;
+
+ array || (array = Array(length));
+ while (++index < length) {
+ array[index] = source[index];
+ }
+ return array;
+}
+
+module.exports = arrayCopy;
+
+},{}],30:[function(require,module,exports){
+/**
+ * A specialized version of `_.forEach` for arrays without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns `array`.
+ */
+function arrayEach(array, iteratee) {
+ var index = -1,
+ length = array.length;
+
+ while (++index < length) {
+ if (iteratee(array[index], index, array) === false) {
+ break;
+ }
+ }
+ return array;
+}
+
+module.exports = arrayEach;
+
+},{}],31:[function(require,module,exports){
+/**
+ * A specialized version of `_.map` for arrays without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns the new mapped array.
+ */
+function arrayMap(array, iteratee) {
+ var index = -1,
+ length = array.length,
+ result = Array(length);
+
+ while (++index < length) {
+ result[index] = iteratee(array[index], index, array);
+ }
+ return result;
+}
+
+module.exports = arrayMap;
+
+},{}],32:[function(require,module,exports){
+var baseMatches = require('./baseMatches'),
+ baseMatchesProperty = require('./baseMatchesProperty'),
+ baseProperty = require('./baseProperty'),
+ bindCallback = require('./bindCallback'),
+ identity = require('../utility/identity');
+
+/**
+ * The base implementation of `_.callback` which supports specifying the
+ * number of arguments to provide to `func`.
+ *
+ * @private
+ * @param {*} [func=_.identity] The value to convert to a callback.
+ * @param {*} [thisArg] The `this` binding of `func`.
+ * @param {number} [argCount] The number of arguments to provide to `func`.
+ * @returns {Function} Returns the callback.
+ */
+function baseCallback(func, thisArg, argCount) {
+ var type = typeof func;
+ if (type == 'function') {
+ return typeof thisArg == 'undefined'
+ ? func
+ : bindCallback(func, thisArg, argCount);
+ }
+ if (func == null) {
+ return identity;
+ }
+ if (type == 'object') {
+ return baseMatches(func);
+ }
+ return typeof thisArg == 'undefined'
+ ? baseProperty(func + '')
+ : baseMatchesProperty(func + '', thisArg);
+}
+
+module.exports = baseCallback;
+
+},{"../utility/identity":109,"./baseMatches":49,"./baseMatchesProperty":50,"./baseProperty":51,"./bindCallback":56}],33:[function(require,module,exports){
+var arrayCopy = require('./arrayCopy'),
+ arrayEach = require('./arrayEach'),
+ baseCopy = require('./baseCopy'),
+ baseForOwn = require('./baseForOwn'),
+ initCloneArray = require('./initCloneArray'),
+ initCloneByTag = require('./initCloneByTag'),
+ initCloneObject = require('./initCloneObject'),
+ isArray = require('../lang/isArray'),
+ isHostObject = require('./isHostObject'),
+ isObject = require('../lang/isObject'),
+ keys = require('../object/keys');
+
+/** `Object#toString` result references. */
+var argsTag = '[object Arguments]',
+ arrayTag = '[object Array]',
+ boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ errorTag = '[object Error]',
+ funcTag = '[object Function]',
+ mapTag = '[object Map]',
+ numberTag = '[object Number]',
+ objectTag = '[object Object]',
+ regexpTag = '[object RegExp]',
+ setTag = '[object Set]',
+ stringTag = '[object String]',
+ weakMapTag = '[object WeakMap]';
+
+var arrayBufferTag = '[object ArrayBuffer]',
+ float32Tag = '[object Float32Array]',
+ float64Tag = '[object Float64Array]',
+ int8Tag = '[object Int8Array]',
+ int16Tag = '[object Int16Array]',
+ int32Tag = '[object Int32Array]',
+ uint8Tag = '[object Uint8Array]',
+ uint8ClampedTag = '[object Uint8ClampedArray]',
+ uint16Tag = '[object Uint16Array]',
+ uint32Tag = '[object Uint32Array]';
+
+/** Used to identify `toStringTag` values supported by `_.clone`. */
+var cloneableTags = {};
+cloneableTags[argsTag] = cloneableTags[arrayTag] =
+cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
+cloneableTags[dateTag] = cloneableTags[float32Tag] =
+cloneableTags[float64Tag] = cloneableTags[int8Tag] =
+cloneableTags[int16Tag] = cloneableTags[int32Tag] =
+cloneableTags[numberTag] = cloneableTags[objectTag] =
+cloneableTags[regexpTag] = cloneableTags[stringTag] =
+cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
+cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
+cloneableTags[errorTag] = cloneableTags[funcTag] =
+cloneableTags[mapTag] = cloneableTags[setTag] =
+cloneableTags[weakMapTag] = false;
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/**
+ * The base implementation of `_.clone` without support for argument juggling
+ * and `this` binding `customizer` functions.
+ *
+ * @private
+ * @param {*} value The value to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @param {Function} [customizer] The function to customize cloning values.
+ * @param {string} [key] The key of `value`.
+ * @param {Object} [object] The object `value` belongs to.
+ * @param {Array} [stackA=[]] Tracks traversed source objects.
+ * @param {Array} [stackB=[]] Associates clones with source counterparts.
+ * @returns {*} Returns the cloned value.
+ */
+function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
+ var result;
+ if (customizer) {
+ result = object ? customizer(value, key, object) : customizer(value);
+ }
+ if (typeof result != 'undefined') {
+ return result;
+ }
+ if (!isObject(value)) {
+ return value;
+ }
+ var isArr = isArray(value);
+ if (isArr) {
+ result = initCloneArray(value);
+ if (!isDeep) {
+ return arrayCopy(value, result);
+ }
+ } else {
+ var tag = objToString.call(value),
+ isFunc = tag == funcTag;
+
+ if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
+ if (isHostObject(value)) {
+ return object ? value : {};
+ }
+ result = initCloneObject(isFunc ? {} : value);
+ if (!isDeep) {
+ return baseCopy(value, result, keys(value));
+ }
+ } else {
+ return cloneableTags[tag]
+ ? initCloneByTag(value, tag, isDeep)
+ : (object ? value : {});
+ }
+ }
+ // Check for circular references and return corresponding clone.
+ stackA || (stackA = []);
+ stackB || (stackB = []);
+
+ var length = stackA.length;
+ while (length--) {
+ if (stackA[length] == value) {
+ return stackB[length];
+ }
+ }
+ // Add the source value to the stack of traversed objects and associate it with its clone.
+ stackA.push(value);
+ stackB.push(result);
+
+ // Recursively populate clone (susceptible to call stack limits).
+ (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
+ result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
+ });
+ return result;
+}
+
+module.exports = baseClone;
+
+},{"../lang/isArray":96,"../lang/isObject":99,"../object/keys":104,"./arrayCopy":29,"./arrayEach":30,"./baseCopy":34,"./baseForOwn":41,"./initCloneArray":75,"./initCloneByTag":76,"./initCloneObject":77,"./isHostObject":78}],34:[function(require,module,exports){
+/**
+ * Copies the properties of `source` to `object`.
+ *
+ * @private
+ * @param {Object} source The object to copy properties from.
+ * @param {Object} [object={}] The object to copy properties to.
+ * @param {Array} props The property names to copy.
+ * @returns {Object} Returns `object`.
+ */
+function baseCopy(source, object, props) {
+ if (!props) {
+ props = object;
+ object = {};
+ }
+ var index = -1,
+ length = props.length;
+
+ while (++index < length) {
+ var key = props[index];
+ object[key] = source[key];
+ }
+ return object;
+}
+
+module.exports = baseCopy;
+
+},{}],35:[function(require,module,exports){
+(function (global){
+var isObject = require('../lang/isObject');
+
+/**
+ * The base implementation of `_.create` without support for assigning
+ * properties to the created object.
+ *
+ * @private
+ * @param {Object} prototype The object to inherit from.
+ * @returns {Object} Returns the new object.
+ */
+var baseCreate = (function() {
+ function Object() {}
+ return function(prototype) {
+ if (isObject(prototype)) {
+ Object.prototype = prototype;
+ var result = new Object;
+ Object.prototype = null;
+ }
+ return result || global.Object();
+ };
+}());
+
+module.exports = baseCreate;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"../lang/isObject":99}],36:[function(require,module,exports){
+var baseForOwn = require('./baseForOwn'),
+ createBaseEach = require('./createBaseEach');
+
+/**
+ * The base implementation of `_.forEach` without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array|Object|string} Returns `collection`.
+ */
+var baseEach = createBaseEach(baseForOwn);
+
+module.exports = baseEach;
+
+},{"./baseForOwn":41,"./createBaseEach":60}],37:[function(require,module,exports){
+/**
+ * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
+ * without support for callback shorthands and `this` binding, which iterates
+ * over `collection` using the provided `eachFunc`.
+ *
+ * @private
+ * @param {Array|Object|string} collection The collection to search.
+ * @param {Function} predicate The function invoked per iteration.
+ * @param {Function} eachFunc The function to iterate over `collection`.
+ * @param {boolean} [retKey] Specify returning the key of the found element
+ * instead of the element itself.
+ * @returns {*} Returns the found element or its key, else `undefined`.
+ */
+function baseFind(collection, predicate, eachFunc, retKey) {
+ var result;
+ eachFunc(collection, function(value, key, collection) {
+ if (predicate(value, key, collection)) {
+ result = retKey ? key : value;
+ return false;
+ }
+ });
+ return result;
+}
+
+module.exports = baseFind;
+
+},{}],38:[function(require,module,exports){
+/**
+ * The base implementation of `_.findIndex` and `_.findLastIndex` without
+ * support for callback shorthands and `this` binding.
+ *
+ * @private
+ * @param {Array} array The array to search.
+ * @param {Function} predicate The function invoked per iteration.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {number} Returns the index of the matched value, else `-1`.
+ */
+function baseFindIndex(array, predicate, fromRight) {
+ var length = array.length,
+ index = fromRight ? length : -1;
+
+ while ((fromRight ? index-- : ++index < length)) {
+ if (predicate(array[index], index, array)) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+module.exports = baseFindIndex;
+
+},{}],39:[function(require,module,exports){
+var createBaseFor = require('./createBaseFor');
+
+/**
+ * The base implementation of `baseForIn` and `baseForOwn` which iterates
+ * over `object` properties returned by `keysFunc` invoking `iteratee` for
+ * each property. Iterator functions may exit iteration early by explicitly
+ * returning `false`.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @param {Function} keysFunc The function to get the keys of `object`.
+ * @returns {Object} Returns `object`.
+ */
+var baseFor = createBaseFor();
+
+module.exports = baseFor;
+
+},{"./createBaseFor":61}],40:[function(require,module,exports){
+var baseFor = require('./baseFor'),
+ keysIn = require('../object/keysIn');
+
+/**
+ * The base implementation of `_.forIn` without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Object} Returns `object`.
+ */
+function baseForIn(object, iteratee) {
+ return baseFor(object, iteratee, keysIn);
+}
+
+module.exports = baseForIn;
+
+},{"../object/keysIn":105,"./baseFor":39}],41:[function(require,module,exports){
+var baseFor = require('./baseFor'),
+ keys = require('../object/keys');
+
+/**
+ * The base implementation of `_.forOwn` without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Object} Returns `object`.
+ */
+function baseForOwn(object, iteratee) {
+ return baseFor(object, iteratee, keys);
+}
+
+module.exports = baseForOwn;
+
+},{"../object/keys":104,"./baseFor":39}],42:[function(require,module,exports){
+var indexOfNaN = require('./indexOfNaN');
+
+/**
+ * The base implementation of `_.indexOf` without support for binary searches.
+ *
+ * @private
+ * @param {Array} array The array to search.
+ * @param {*} value The value to search for.
+ * @param {number} fromIndex The index to search from.
+ * @returns {number} Returns the index of the matched value, else `-1`.
+ */
+function baseIndexOf(array, value, fromIndex) {
+ if (value !== value) {
+ return indexOfNaN(array, fromIndex);
+ }
+ var index = fromIndex - 1,
+ length = array.length;
+
+ while (++index < length) {
+ if (array[index] === value) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+module.exports = baseIndexOf;
+
+},{"./indexOfNaN":74}],43:[function(require,module,exports){
+var baseIsEqualDeep = require('./baseIsEqualDeep');
+
+/**
+ * The base implementation of `_.isEqual` without support for `this` binding
+ * `customizer` functions.
+ *
+ * @private
+ * @param {*} value The value to compare.
+ * @param {*} other The other value to compare.
+ * @param {Function} [customizer] The function to customize comparing values.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
+ * @param {Array} [stackA] Tracks traversed `value` objects.
+ * @param {Array} [stackB] Tracks traversed `other` objects.
+ * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
+ */
+function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
+ // Exit early for identical values.
+ if (value === other) {
+ // Treat `+0` vs. `-0` as not equal.
+ return value !== 0 || (1 / value == 1 / other);
+ }
+ var valType = typeof value,
+ othType = typeof other;
+
+ // Exit early for unlike primitive values.
+ if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
+ value == null || other == null) {
+ // Return `false` unless both values are `NaN`.
+ return value !== value && other !== other;
+ }
+ return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
+}
+
+module.exports = baseIsEqual;
+
+},{"./baseIsEqualDeep":44}],44:[function(require,module,exports){
+var equalArrays = require('./equalArrays'),
+ equalByTag = require('./equalByTag'),
+ equalObjects = require('./equalObjects'),
+ isArray = require('../lang/isArray'),
+ isHostObject = require('./isHostObject'),
+ isTypedArray = require('../lang/isTypedArray');
+
+/** `Object#toString` result references. */
+var argsTag = '[object Arguments]',
+ arrayTag = '[object Array]',
+ funcTag = '[object Function]',
+ objectTag = '[object Object]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/**
+ * A specialized version of `baseIsEqual` for arrays and objects which performs
+ * deep comparisons and tracks traversed objects enabling objects with circular
+ * references to be compared.
+ *
+ * @private
+ * @param {Object} object The object to compare.
+ * @param {Object} other The other object to compare.
+ * @param {Function} equalFunc The function to determine equivalents of values.
+ * @param {Function} [customizer] The function to customize comparing objects.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
+ * @param {Array} [stackA=[]] Tracks traversed `value` objects.
+ * @param {Array} [stackB=[]] Tracks traversed `other` objects.
+ * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
+ */
+function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
+ var objIsArr = isArray(object),
+ othIsArr = isArray(other),
+ objTag = arrayTag,
+ othTag = arrayTag;
+
+ if (!objIsArr) {
+ objTag = objToString.call(object);
+ if (objTag == argsTag) {
+ objTag = objectTag;
+ } else if (objTag != objectTag) {
+ objIsArr = isTypedArray(object);
+ }
+ }
+ if (!othIsArr) {
+ othTag = objToString.call(other);
+ if (othTag == argsTag) {
+ othTag = objectTag;
+ } else if (othTag != objectTag) {
+ othIsArr = isTypedArray(other);
+ }
+ }
+ var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)) && !isHostObject(object),
+ othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)) && !isHostObject(other),
+ isSameTag = objTag == othTag;
+
+ if (isSameTag && !(objIsArr || objIsObj)) {
+ return equalByTag(object, other, objTag);
+ }
+ if (isLoose) {
+ if (!isSameTag && !(objIsObj && othIsObj)) {
+ return false;
+ }
+ } else {
+ var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
+ othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
+
+ if (valWrapped || othWrapped) {
+ return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
+ }
+ if (!isSameTag) {
+ return false;
+ }
+ }
+ // Assume cyclic values are equal.
+ // For more information on detecting circular references see https://es5.github.io/#JO.
+ stackA || (stackA = []);
+ stackB || (stackB = []);
+
+ var length = stackA.length;
+ while (length--) {
+ if (stackA[length] == object) {
+ return stackB[length] == other;
+ }
+ }
+ // Add `object` and `other` to the stack of traversed objects.
+ stackA.push(object);
+ stackB.push(other);
+
+ var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
+
+ stackA.pop();
+ stackB.pop();
+
+ return result;
+}
+
+module.exports = baseIsEqualDeep;
+
+},{"../lang/isArray":96,"../lang/isTypedArray":102,"./equalArrays":69,"./equalByTag":70,"./equalObjects":71,"./isHostObject":78}],45:[function(require,module,exports){
+/**
+ * The base implementation of `_.isFunction` without support for environments
+ * with incorrect `typeof` results.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ */
+function baseIsFunction(value) {
+ // Avoid a Chakra JIT bug in compatibility modes of IE 11.
+ // See https://github.com/jashkenas/underscore/issues/1621 for more details.
+ return typeof value == 'function' || false;
+}
+
+module.exports = baseIsFunction;
+
+},{}],46:[function(require,module,exports){
+var baseIsEqual = require('./baseIsEqual');
+
+/**
+ * The base implementation of `_.isMatch` without support for callback
+ * shorthands and `this` binding.
+ *
+ * @private
+ * @param {Object} object The object to inspect.
+ * @param {Array} props The source property names to match.
+ * @param {Array} values The source values to match.
+ * @param {Array} strictCompareFlags Strict comparison flags for source values.
+ * @param {Function} [customizer] The function to customize comparing objects.
+ * @returns {boolean} Returns `true` if `object` is a match, else `false`.
+ */
+function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
+ var index = -1,
+ length = props.length,
+ noCustomizer = !customizer;
+
+ while (++index < length) {
+ if ((noCustomizer && strictCompareFlags[index])
+ ? values[index] !== object[props[index]]
+ : !(props[index] in object)
+ ) {
+ return false;
+ }
+ }
+ index = -1;
+ while (++index < length) {
+ var key = props[index],
+ objValue = object[key],
+ srcValue = values[index];
+
+ if (noCustomizer && strictCompareFlags[index]) {
+ var result = typeof objValue != 'undefined' || (key in object);
+ } else {
+ result = customizer ? customizer(objValue, srcValue, key) : undefined;
+ if (typeof result == 'undefined') {
+ result = baseIsEqual(srcValue, objValue, customizer, true);
+ }
+ }
+ if (!result) {
+ return false;
+ }
+ }
+ return true;
+}
+
+module.exports = baseIsMatch;
+
+},{"./baseIsEqual":43}],47:[function(require,module,exports){
+/**
+ * The function whose prototype all chaining wrappers inherit from.
+ *
+ * @private
+ */
+function baseLodash() {
+ // No operation performed.
+}
+
+module.exports = baseLodash;
+
+},{}],48:[function(require,module,exports){
+var baseEach = require('./baseEach');
+
+/**
+ * The base implementation of `_.map` without support for callback shorthands
+ * and `this` binding.
+ *
+ * @private
+ * @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns the new mapped array.
+ */
+function baseMap(collection, iteratee) {
+ var result = [];
+ baseEach(collection, function(value, key, collection) {
+ result.push(iteratee(value, key, collection));
+ });
+ return result;
+}
+
+module.exports = baseMap;
+
+},{"./baseEach":36}],49:[function(require,module,exports){
+var baseIsMatch = require('./baseIsMatch'),
+ constant = require('../utility/constant'),
+ isStrictComparable = require('./isStrictComparable'),
+ keys = require('../object/keys'),
+ toObject = require('./toObject');
+
+/**
+ * The base implementation of `_.matches` which does not clone `source`.
+ *
+ * @private
+ * @param {Object} source The object of property values to match.
+ * @returns {Function} Returns the new function.
+ */
+function baseMatches(source) {
+ var props = keys(source),
+ length = props.length;
+
+ if (!length) {
+ return constant(true);
+ }
+ if (length == 1) {
+ var key = props[0],
+ value = source[key];
+
+ if (isStrictComparable(value)) {
+ return function(object) {
+ return object != null && object[key] === value &&
+ (typeof value != 'undefined' || (key in toObject(object)));
+ };
+ }
+ }
+ var values = Array(length),
+ strictCompareFlags = Array(length);
+
+ while (length--) {
+ value = source[props[length]];
+ values[length] = value;
+ strictCompareFlags[length] = isStrictComparable(value);
+ }
+ return function(object) {
+ return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
+ };
+}
+
+module.exports = baseMatches;
+
+},{"../object/keys":104,"../utility/constant":108,"./baseIsMatch":46,"./isStrictComparable":83,"./toObject":92}],50:[function(require,module,exports){
+var baseIsEqual = require('./baseIsEqual'),
+ isStrictComparable = require('./isStrictComparable'),
+ toObject = require('./toObject');
+
+/**
+ * The base implementation of `_.matchesProperty` which does not coerce `key`
+ * to a string.
+ *
+ * @private
+ * @param {string} key The key of the property to get.
+ * @param {*} value The value to compare.
+ * @returns {Function} Returns the new function.
+ */
+function baseMatchesProperty(key, value) {
+ if (isStrictComparable(value)) {
+ return function(object) {
+ return object != null && object[key] === value &&
+ (typeof value != 'undefined' || (key in toObject(object)));
+ };
+ }
+ return function(object) {
+ return object != null && baseIsEqual(value, object[key], null, true);
+ };
+}
+
+module.exports = baseMatchesProperty;
+
+},{"./baseIsEqual":43,"./isStrictComparable":83,"./toObject":92}],51:[function(require,module,exports){
+/**
+ * The base implementation of `_.property` which does not coerce `key` to a string.
+ *
+ * @private
+ * @param {string} key The key of the property to get.
+ * @returns {Function} Returns the new function.
+ */
+function baseProperty(key) {
+ return function(object) {
+ return object == null ? undefined : object[key];
+ };
+}
+
+module.exports = baseProperty;
+
+},{}],52:[function(require,module,exports){
+var identity = require('../utility/identity'),
+ metaMap = require('./metaMap');
+
+/**
+ * The base implementation of `setData` without support for hot loop detection.
+ *
+ * @private
+ * @param {Function} func The function to associate metadata with.
+ * @param {*} data The metadata.
+ * @returns {Function} Returns `func`.
+ */
+var baseSetData = !metaMap ? identity : function(func, data) {
+ metaMap.set(func, data);
+ return func;
+};
+
+module.exports = baseSetData;
+
+},{"../utility/identity":109,"./metaMap":85}],53:[function(require,module,exports){
+/**
+ * Converts `value` to a string if it is not one. An empty string is returned
+ * for `null` or `undefined` values.
+ *
+ * @private
+ * @param {*} value The value to process.
+ * @returns {string} Returns the string.
+ */
+function baseToString(value) {
+ if (typeof value == 'string') {
+ return value;
+ }
+ return value == null ? '' : (value + '');
+}
+
+module.exports = baseToString;
+
+},{}],54:[function(require,module,exports){
+var binaryIndexBy = require('./binaryIndexBy'),
+ identity = require('../utility/identity');
+
+/** Used as references for the maximum length and index of an array. */
+var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
+ HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
+
+/**
+ * Performs a binary search of `array` to determine the index at which `value`
+ * should be inserted into `array` in order to maintain its sort order.
+ *
+ * @private
+ * @param {Array} array The sorted array to inspect.
+ * @param {*} value The value to evaluate.
+ * @param {boolean} [retHighest] Specify returning the highest qualified index.
+ * @returns {number} Returns the index at which `value` should be inserted
+ * into `array`.
+ */
+function binaryIndex(array, value, retHighest) {
+ var low = 0,
+ high = array ? array.length : low;
+
+ if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
+ while (low < high) {
+ var mid = (low + high) >>> 1,
+ computed = array[mid];
+
+ if (retHighest ? (computed <= value) : (computed < value)) {
+ low = mid + 1;
+ } else {
+ high = mid;
+ }
+ }
+ return high;
+ }
+ return binaryIndexBy(array, value, identity, retHighest);
+}
+
+module.exports = binaryIndex;
+
+},{"../utility/identity":109,"./binaryIndexBy":55}],55:[function(require,module,exports){
+/** Native method references. */
+var floor = Math.floor;
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMin = Math.min;
+
+/** Used as references for the maximum length and index of an array. */
+var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
+ MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
+
+/**
+ * This function is like `binaryIndex` except that it invokes `iteratee` for
+ * `value` and each element of `array` to compute their sort ranking. The
+ * iteratee is invoked with one argument; (value).
+ *
+ * @private
+ * @param {Array} array The sorted array to inspect.
+ * @param {*} value The value to evaluate.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @param {boolean} [retHighest] Specify returning the highest qualified index.
+ * @returns {number} Returns the index at which `value` should be inserted
+ * into `array`.
+ */
+function binaryIndexBy(array, value, iteratee, retHighest) {
+ value = iteratee(value);
+
+ var low = 0,
+ high = array ? array.length : 0,
+ valIsNaN = value !== value,
+ valIsUndef = typeof value == 'undefined';
+
+ while (low < high) {
+ var mid = floor((low + high) / 2),
+ computed = iteratee(array[mid]),
+ isReflexive = computed === computed;
+
+ if (valIsNaN) {
+ var setLow = isReflexive || retHighest;
+ } else if (valIsUndef) {
+ setLow = isReflexive && (retHighest || typeof computed != 'undefined');
+ } else {
+ setLow = retHighest ? (computed <= value) : (computed < value);
+ }
+ if (setLow) {
+ low = mid + 1;
+ } else {
+ high = mid;
+ }
+ }
+ return nativeMin(high, MAX_ARRAY_INDEX);
+}
+
+module.exports = binaryIndexBy;
+
+},{}],56:[function(require,module,exports){
+var identity = require('../utility/identity');
+
+/**
+ * A specialized version of `baseCallback` which only supports `this` binding
+ * and specifying the number of arguments to provide to `func`.
+ *
+ * @private
+ * @param {Function} func The function to bind.
+ * @param {*} thisArg The `this` binding of `func`.
+ * @param {number} [argCount] The number of arguments to provide to `func`.
+ * @returns {Function} Returns the callback.
+ */
+function bindCallback(func, thisArg, argCount) {
+ if (typeof func != 'function') {
+ return identity;
+ }
+ if (typeof thisArg == 'undefined') {
+ return func;
+ }
+ switch (argCount) {
+ case 1: return function(value) {
+ return func.call(thisArg, value);
+ };
+ case 3: return function(value, index, collection) {
+ return func.call(thisArg, value, index, collection);
+ };
+ case 4: return function(accumulator, value, index, collection) {
+ return func.call(thisArg, accumulator, value, index, collection);
+ };
+ case 5: return function(value, other, key, object, source) {
+ return func.call(thisArg, value, other, key, object, source);
+ };
+ }
+ return function() {
+ return func.apply(thisArg, arguments);
+ };
+}
+
+module.exports = bindCallback;
+
+},{"../utility/identity":109}],57:[function(require,module,exports){
+(function (global){
+var constant = require('../utility/constant'),
+ isNative = require('../lang/isNative');
+
+/** Native method references. */
+var ArrayBuffer = isNative(ArrayBuffer = global.ArrayBuffer) && ArrayBuffer,
+ bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
+ floor = Math.floor,
+ Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array;
+
+/** Used to clone array buffers. */
+var Float64Array = (function() {
+ // Safari 5 errors when using an array buffer to initialize a typed array
+ // where the array buffer's `byteLength` is not a multiple of the typed
+ // array's `BYTES_PER_ELEMENT`.
+ try {
+ var func = isNative(func = global.Float64Array) && func,
+ result = new func(new ArrayBuffer(10), 0, 1) && func;
+ } catch(e) {}
+ return result;
+}());
+
+/** Used as the size, in bytes, of each `Float64Array` element. */
+var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
+
+/**
+ * Creates a clone of the given array buffer.
+ *
+ * @private
+ * @param {ArrayBuffer} buffer The array buffer to clone.
+ * @returns {ArrayBuffer} Returns the cloned array buffer.
+ */
+function bufferClone(buffer) {
+ return bufferSlice.call(buffer, 0);
+}
+if (!bufferSlice) {
+ // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
+ bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
+ var byteLength = buffer.byteLength,
+ floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
+ offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
+ result = new ArrayBuffer(byteLength);
+
+ if (floatLength) {
+ var view = new Float64Array(result, 0, floatLength);
+ view.set(new Float64Array(buffer, 0, floatLength));
+ }
+ if (byteLength != offset) {
+ view = new Uint8Array(result, offset);
+ view.set(new Uint8Array(buffer, offset));
+ }
+ return result;
+ };
+}
+
+module.exports = bufferClone;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"../lang/isNative":98,"../utility/constant":108}],58:[function(require,module,exports){
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * Creates an array that is the composition of partially applied arguments,
+ * placeholders, and provided arguments into a single array of arguments.
+ *
+ * @private
+ * @param {Array|Object} args The provided arguments.
+ * @param {Array} partials The arguments to prepend to those provided.
+ * @param {Array} holders The `partials` placeholder indexes.
+ * @returns {Array} Returns the new array of composed arguments.
+ */
+function composeArgs(args, partials, holders) {
+ var holdersLength = holders.length,
+ argsIndex = -1,
+ argsLength = nativeMax(args.length - holdersLength, 0),
+ leftIndex = -1,
+ leftLength = partials.length,
+ result = Array(argsLength + leftLength);
+
+ while (++leftIndex < leftLength) {
+ result[leftIndex] = partials[leftIndex];
+ }
+ while (++argsIndex < holdersLength) {
+ result[holders[argsIndex]] = args[argsIndex];
+ }
+ while (argsLength--) {
+ result[leftIndex++] = args[argsIndex++];
+ }
+ return result;
+}
+
+module.exports = composeArgs;
+
+},{}],59:[function(require,module,exports){
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * This function is like `composeArgs` except that the arguments composition
+ * is tailored for `_.partialRight`.
+ *
+ * @private
+ * @param {Array|Object} args The provided arguments.
+ * @param {Array} partials The arguments to append to those provided.
+ * @param {Array} holders The `partials` placeholder indexes.
+ * @returns {Array} Returns the new array of composed arguments.
+ */
+function composeArgsRight(args, partials, holders) {
+ var holdersIndex = -1,
+ holdersLength = holders.length,
+ argsIndex = -1,
+ argsLength = nativeMax(args.length - holdersLength, 0),
+ rightIndex = -1,
+ rightLength = partials.length,
+ result = Array(argsLength + rightLength);
+
+ while (++argsIndex < argsLength) {
+ result[argsIndex] = args[argsIndex];
+ }
+ var pad = argsIndex;
+ while (++rightIndex < rightLength) {
+ result[pad + rightIndex] = partials[rightIndex];
+ }
+ while (++holdersIndex < holdersLength) {
+ result[pad + holders[holdersIndex]] = args[argsIndex++];
+ }
+ return result;
+}
+
+module.exports = composeArgsRight;
+
+},{}],60:[function(require,module,exports){
+var isLength = require('./isLength'),
+ toObject = require('./toObject');
+
+/**
+ * Creates a `baseEach` or `baseEachRight` function.
+ *
+ * @private
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new base function.
+ */
+function createBaseEach(eachFunc, fromRight) {
+ return function(collection, iteratee) {
+ var length = collection ? collection.length : 0;
+ if (!isLength(length)) {
+ return eachFunc(collection, iteratee);
+ }
+ var index = fromRight ? length : -1,
+ iterable = toObject(collection);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ if (iteratee(iterable[index], index, iterable) === false) {
+ break;
+ }
+ }
+ return collection;
+ };
+}
+
+module.exports = createBaseEach;
+
+},{"./isLength":81,"./toObject":92}],61:[function(require,module,exports){
+var toObject = require('./toObject');
+
+/**
+ * Creates a base function for `_.forIn` or `_.forInRight`.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new base function.
+ */
+function createBaseFor(fromRight) {
+ return function(object, iteratee, keysFunc) {
+ var iterable = toObject(object),
+ props = keysFunc(object),
+ length = props.length,
+ index = fromRight ? length : -1;
+
+ while ((fromRight ? index-- : ++index < length)) {
+ var key = props[index];
+ if (iteratee(iterable[key], key, iterable) === false) {
+ break;
+ }
+ }
+ return object;
+ };
+}
+
+module.exports = createBaseFor;
+
+},{"./toObject":92}],62:[function(require,module,exports){
+(function (global){
+var createCtorWrapper = require('./createCtorWrapper');
+
+/**
+ * Creates a function that wraps `func` and invokes it with the `this`
+ * binding of `thisArg`.
+ *
+ * @private
+ * @param {Function} func The function to bind.
+ * @param {*} [thisArg] The `this` binding of `func`.
+ * @returns {Function} Returns the new bound function.
+ */
+function createBindWrapper(func, thisArg) {
+ var Ctor = createCtorWrapper(func);
+
+ function wrapper() {
+ var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
+ return fn.apply(thisArg, arguments);
+ }
+ return wrapper;
+}
+
+module.exports = createBindWrapper;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"./createCtorWrapper":63}],63:[function(require,module,exports){
+var baseCreate = require('./baseCreate'),
+ isObject = require('../lang/isObject');
+
+/**
+ * Creates a function that produces an instance of `Ctor` regardless of
+ * whether it was invoked as part of a `new` expression or by `call` or `apply`.
+ *
+ * @private
+ * @param {Function} Ctor The constructor to wrap.
+ * @returns {Function} Returns the new wrapped function.
+ */
+function createCtorWrapper(Ctor) {
+ return function() {
+ var thisBinding = baseCreate(Ctor.prototype),
+ result = Ctor.apply(thisBinding, arguments);
+
+ // Mimic the constructor's `return` behavior.
+ // See https://es5.github.io/#x13.2.2 for more details.
+ return isObject(result) ? result : thisBinding;
+ };
+}
+
+module.exports = createCtorWrapper;
+
+},{"../lang/isObject":99,"./baseCreate":35}],64:[function(require,module,exports){
+var baseCallback = require('./baseCallback'),
+ baseFind = require('./baseFind'),
+ baseFindIndex = require('./baseFindIndex'),
+ isArray = require('../lang/isArray');
+
+/**
+ * Creates a `_.find` or `_.findLast` function.
+ *
+ * @private
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new find function.
+ */
+function createFind(eachFunc, fromRight) {
+ return function(collection, predicate, thisArg) {
+ predicate = baseCallback(predicate, thisArg, 3);
+ if (isArray(collection)) {
+ var index = baseFindIndex(collection, predicate, fromRight);
+ return index > -1 ? collection[index] : undefined;
+ }
+ return baseFind(collection, predicate, eachFunc);
+ }
+}
+
+module.exports = createFind;
+
+},{"../lang/isArray":96,"./baseCallback":32,"./baseFind":37,"./baseFindIndex":38}],65:[function(require,module,exports){
+var bindCallback = require('./bindCallback'),
+ isArray = require('../lang/isArray');
+
+/**
+ * Creates a function for `_.forEach` or `_.forEachRight`.
+ *
+ * @private
+ * @param {Function} arrayFunc The function to iterate over an array.
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @returns {Function} Returns the new each function.
+ */
+function createForEach(arrayFunc, eachFunc) {
+ return function(collection, iteratee, thisArg) {
+ return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
+ ? arrayFunc(collection, iteratee)
+ : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
+ };
+}
+
+module.exports = createForEach;
+
+},{"../lang/isArray":96,"./bindCallback":56}],66:[function(require,module,exports){
+(function (global){
+var arrayCopy = require('./arrayCopy'),
+ composeArgs = require('./composeArgs'),
+ composeArgsRight = require('./composeArgsRight'),
+ createCtorWrapper = require('./createCtorWrapper'),
+ isLaziable = require('./isLaziable'),
+ reorder = require('./reorder'),
+ replaceHolders = require('./replaceHolders'),
+ setData = require('./setData');
+
+/** Used to compose bitmasks for wrapper metadata. */
+var BIND_FLAG = 1,
+ BIND_KEY_FLAG = 2,
+ CURRY_BOUND_FLAG = 4,
+ CURRY_FLAG = 8,
+ CURRY_RIGHT_FLAG = 16,
+ PARTIAL_FLAG = 32,
+ PARTIAL_RIGHT_FLAG = 64,
+ ARY_FLAG = 128;
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * Creates a function that wraps `func` and invokes it with optional `this`
+ * binding of, partial application, and currying.
+ *
+ * @private
+ * @param {Function|string} func The function or method name to reference.
+ * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
+ * @param {*} [thisArg] The `this` binding of `func`.
+ * @param {Array} [partials] The arguments to prepend to those provided to the new function.
+ * @param {Array} [holders] The `partials` placeholder indexes.
+ * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
+ * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
+ * @param {Array} [argPos] The argument positions of the new function.
+ * @param {number} [ary] The arity cap of `func`.
+ * @param {number} [arity] The arity of `func`.
+ * @returns {Function} Returns the new wrapped function.
+ */
+function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
+ var isAry = bitmask & ARY_FLAG,
+ isBind = bitmask & BIND_FLAG,
+ isBindKey = bitmask & BIND_KEY_FLAG,
+ isCurry = bitmask & CURRY_FLAG,
+ isCurryBound = bitmask & CURRY_BOUND_FLAG,
+ isCurryRight = bitmask & CURRY_RIGHT_FLAG;
+
+ var Ctor = !isBindKey && createCtorWrapper(func),
+ key = func;
+
+ function wrapper() {
+ // Avoid `arguments` object use disqualifying optimizations by
+ // converting it to an array before providing it to other functions.
+ var length = arguments.length,
+ index = length,
+ args = Array(length);
+
+ while (index--) {
+ args[index] = arguments[index];
+ }
+ if (partials) {
+ args = composeArgs(args, partials, holders);
+ }
+ if (partialsRight) {
+ args = composeArgsRight(args, partialsRight, holdersRight);
+ }
+ if (isCurry || isCurryRight) {
+ var placeholder = wrapper.placeholder,
+ argsHolders = replaceHolders(args, placeholder);
+
+ length -= argsHolders.length;
+ if (length < arity) {
+ var newArgPos = argPos ? arrayCopy(argPos) : null,
+ newArity = nativeMax(arity - length, 0),
+ newsHolders = isCurry ? argsHolders : null,
+ newHoldersRight = isCurry ? null : argsHolders,
+ newPartials = isCurry ? args : null,
+ newPartialsRight = isCurry ? null : args;
+
+ bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
+ bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
+
+ if (!isCurryBound) {
+ bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
+ }
+ var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
+ result = createHybridWrapper.apply(undefined, newData);
+
+ if (isLaziable(func)) {
+ setData(result, newData);
+ }
+ result.placeholder = placeholder;
+ return result;
+ }
+ }
+ var thisBinding = isBind ? thisArg : this;
+ if (isBindKey) {
+ func = thisBinding[key];
+ }
+ if (argPos) {
+ args = reorder(args, argPos);
+ }
+ if (isAry && ary < args.length) {
+ args.length = ary;
+ }
+ var fn = (this && this !== global && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func;
+ return fn.apply(thisBinding, args);
+ }
+ return wrapper;
+}
+
+module.exports = createHybridWrapper;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"./arrayCopy":29,"./composeArgs":58,"./composeArgsRight":59,"./createCtorWrapper":63,"./isLaziable":80,"./reorder":87,"./replaceHolders":88,"./setData":89}],67:[function(require,module,exports){
+(function (global){
+var createCtorWrapper = require('./createCtorWrapper');
+
+/** Used to compose bitmasks for wrapper metadata. */
+var BIND_FLAG = 1;
+
+/**
+ * Creates a function that wraps `func` and invokes it with the optional `this`
+ * binding of `thisArg` and the `partials` prepended to those provided to
+ * the wrapper.
+ *
+ * @private
+ * @param {Function} func The function to partially apply arguments to.
+ * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
+ * @param {*} thisArg The `this` binding of `func`.
+ * @param {Array} partials The arguments to prepend to those provided to the new function.
+ * @returns {Function} Returns the new bound function.
+ */
+function createPartialWrapper(func, bitmask, thisArg, partials) {
+ var isBind = bitmask & BIND_FLAG,
+ Ctor = createCtorWrapper(func);
+
+ function wrapper() {
+ // Avoid `arguments` object use disqualifying optimizations by
+ // converting it to an array before providing it `func`.
+ var argsIndex = -1,
+ argsLength = arguments.length,
+ leftIndex = -1,
+ leftLength = partials.length,
+ args = Array(argsLength + leftLength);
+
+ while (++leftIndex < leftLength) {
+ args[leftIndex] = partials[leftIndex];
+ }
+ while (argsLength--) {
+ args[leftIndex++] = arguments[++argsIndex];
+ }
+ var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
+ return fn.apply(isBind ? thisArg : this, args);
+ }
+ return wrapper;
+}
+
+module.exports = createPartialWrapper;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"./createCtorWrapper":63}],68:[function(require,module,exports){
+var baseSetData = require('./baseSetData'),
+ createBindWrapper = require('./createBindWrapper'),
+ createHybridWrapper = require('./createHybridWrapper'),
+ createPartialWrapper = require('./createPartialWrapper'),
+ getData = require('./getData'),
+ mergeData = require('./mergeData'),
+ setData = require('./setData');
+
+/** Used to compose bitmasks for wrapper metadata. */
+var BIND_FLAG = 1,
+ BIND_KEY_FLAG = 2,
+ PARTIAL_FLAG = 32,
+ PARTIAL_RIGHT_FLAG = 64;
+
+/** Used as the `TypeError` message for "Functions" methods. */
+var FUNC_ERROR_TEXT = 'Expected a function';
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMax = Math.max;
+
+/**
+ * Creates a function that either curries or invokes `func` with optional
+ * `this` binding and partially applied arguments.
+ *
+ * @private
+ * @param {Function|string} func The function or method name to reference.
+ * @param {number} bitmask The bitmask of flags.
+ * The bitmask may be composed of the following flags:
+ * 1 - `_.bind`
+ * 2 - `_.bindKey`
+ * 4 - `_.curry` or `_.curryRight` of a bound function
+ * 8 - `_.curry`
+ * 16 - `_.curryRight`
+ * 32 - `_.partial`
+ * 64 - `_.partialRight`
+ * 128 - `_.rearg`
+ * 256 - `_.ary`
+ * @param {*} [thisArg] The `this` binding of `func`.
+ * @param {Array} [partials] The arguments to be partially applied.
+ * @param {Array} [holders] The `partials` placeholder indexes.
+ * @param {Array} [argPos] The argument positions of the new function.
+ * @param {number} [ary] The arity cap of `func`.
+ * @param {number} [arity] The arity of `func`.
+ * @returns {Function} Returns the new wrapped function.
+ */
+function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
+ var isBindKey = bitmask & BIND_KEY_FLAG;
+ if (!isBindKey && typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT);
+ }
+ var length = partials ? partials.length : 0;
+ if (!length) {
+ bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
+ partials = holders = null;
+ }
+ length -= (holders ? holders.length : 0);
+ if (bitmask & PARTIAL_RIGHT_FLAG) {
+ var partialsRight = partials,
+ holdersRight = holders;
+
+ partials = holders = null;
+ }
+ var data = isBindKey ? null : getData(func),
+ newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
+
+ if (data) {
+ mergeData(newData, data);
+ bitmask = newData[1];
+ arity = newData[9];
+ }
+ newData[9] = arity == null
+ ? (isBindKey ? 0 : func.length)
+ : (nativeMax(arity - length, 0) || 0);
+
+ if (bitmask == BIND_FLAG) {
+ var result = createBindWrapper(newData[0], newData[2]);
+ } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
+ result = createPartialWrapper.apply(undefined, newData);
+ } else {
+ result = createHybridWrapper.apply(undefined, newData);
+ }
+ var setter = data ? baseSetData : setData;
+ return setter(result, newData);
+}
+
+module.exports = createWrapper;
+
+},{"./baseSetData":52,"./createBindWrapper":62,"./createHybridWrapper":66,"./createPartialWrapper":67,"./getData":72,"./mergeData":84,"./setData":89}],69:[function(require,module,exports){
+/**
+ * A specialized version of `baseIsEqualDeep` for arrays with support for
+ * partial deep comparisons.
+ *
+ * @private
+ * @param {Array} array The array to compare.
+ * @param {Array} other The other array to compare.
+ * @param {Function} equalFunc The function to determine equivalents of values.
+ * @param {Function} [customizer] The function to customize comparing arrays.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
+ * @param {Array} [stackA] Tracks traversed `value` objects.
+ * @param {Array} [stackB] Tracks traversed `other` objects.
+ * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
+ */
+function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
+ var index = -1,
+ arrLength = array.length,
+ othLength = other.length,
+ result = true;
+
+ if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
+ return false;
+ }
+ // Deep compare the contents, ignoring non-numeric properties.
+ while (result && ++index < arrLength) {
+ var arrValue = array[index],
+ othValue = other[index];
+
+ result = undefined;
+ if (customizer) {
+ result = isLoose
+ ? customizer(othValue, arrValue, index)
+ : customizer(arrValue, othValue, index);
+ }
+ if (typeof result == 'undefined') {
+ // Recursively compare arrays (susceptible to call stack limits).
+ if (isLoose) {
+ var othIndex = othLength;
+ while (othIndex--) {
+ othValue = other[othIndex];
+ result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
+ if (result) {
+ break;
+ }
+ }
+ } else {
+ result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
+ }
+ }
+ }
+ return !!result;
+}
+
+module.exports = equalArrays;
+
+},{}],70:[function(require,module,exports){
+/** `Object#toString` result references. */
+var boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ errorTag = '[object Error]',
+ numberTag = '[object Number]',
+ regexpTag = '[object RegExp]',
+ stringTag = '[object String]';
+
+/**
+ * A specialized version of `baseIsEqualDeep` for comparing objects of
+ * the same `toStringTag`.
+ *
+ * **Note:** This function only supports comparing values with tags of
+ * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
+ *
+ * @private
+ * @param {Object} value The object to compare.
+ * @param {Object} other The other object to compare.
+ * @param {string} tag The `toStringTag` of the objects to compare.
+ * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
+ */
+function equalByTag(object, other, tag) {
+ switch (tag) {
+ case boolTag:
+ case dateTag:
+ // Coerce dates and booleans to numbers, dates to milliseconds and booleans
+ // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
+ return +object == +other;
+
+ case errorTag:
+ return object.name == other.name && object.message == other.message;
+
+ case numberTag:
+ // Treat `NaN` vs. `NaN` as equal.
+ return (object != +object)
+ ? other != +other
+ // But, treat `-0` vs. `+0` as not equal.
+ : (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
+
+ case regexpTag:
+ case stringTag:
+ // Coerce regexes to strings and treat strings primitives and string
+ // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
+ return object == (other + '');
+ }
+ return false;
+}
+
+module.exports = equalByTag;
+
+},{}],71:[function(require,module,exports){
+var keys = require('../object/keys');
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * A specialized version of `baseIsEqualDeep` for objects with support for
+ * partial deep comparisons.
+ *
+ * @private
+ * @param {Object} object The object to compare.
+ * @param {Object} other The other object to compare.
+ * @param {Function} equalFunc The function to determine equivalents of values.
+ * @param {Function} [customizer] The function to customize comparing values.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
+ * @param {Array} [stackA] Tracks traversed `value` objects.
+ * @param {Array} [stackB] Tracks traversed `other` objects.
+ * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
+ */
+function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
+ var objProps = keys(object),
+ objLength = objProps.length,
+ othProps = keys(other),
+ othLength = othProps.length;
+
+ if (objLength != othLength && !isLoose) {
+ return false;
+ }
+ var skipCtor = isLoose,
+ index = -1;
+
+ while (++index < objLength) {
+ var key = objProps[index],
+ result = isLoose ? key in other : hasOwnProperty.call(other, key);
+
+ if (result) {
+ var objValue = object[key],
+ othValue = other[key];
+
+ result = undefined;
+ if (customizer) {
+ result = isLoose
+ ? customizer(othValue, objValue, key)
+ : customizer(objValue, othValue, key);
+ }
+ if (typeof result == 'undefined') {
+ // Recursively compare objects (susceptible to call stack limits).
+ result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
+ }
+ }
+ if (!result) {
+ return false;
+ }
+ skipCtor || (skipCtor = key == 'constructor');
+ }
+ if (!skipCtor) {
+ var objCtor = object.constructor,
+ othCtor = other.constructor;
+
+ // Non `Object` object instances with different constructors are not equal.
+ if (objCtor != othCtor &&
+ ('constructor' in object && 'constructor' in other) &&
+ !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
+ typeof othCtor == 'function' && othCtor instanceof othCtor)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+module.exports = equalObjects;
+
+},{"../object/keys":104}],72:[function(require,module,exports){
+var metaMap = require('./metaMap'),
+ noop = require('../utility/noop');
+
+/**
+ * Gets metadata for `func`.
+ *
+ * @private
+ * @param {Function} func The function to query.
+ * @returns {*} Returns the metadata for `func`.
+ */
+var getData = !metaMap ? noop : function(func) {
+ return metaMap.get(func);
+};
+
+module.exports = getData;
+
+},{"../utility/noop":110,"./metaMap":85}],73:[function(require,module,exports){
+var baseProperty = require('./baseProperty'),
+ constant = require('../utility/constant'),
+ realNames = require('./realNames'),
+ support = require('../support');
+
+/**
+ * Gets the name of `func`.
+ *
+ * @private
+ * @param {Function} func The function to query.
+ * @returns {string} Returns the function name.
+ */
+var getFuncName = (function() {
+ if (!support.funcNames) {
+ return constant('');
+ }
+ if (constant.name == 'constant') {
+ return baseProperty('name');
+ }
+ return function(func) {
+ var result = func.name,
+ array = realNames[result],
+ length = array ? array.length : 0;
+
+ while (length--) {
+ var data = array[length],
+ otherFunc = data.func;
+
+ if (otherFunc == null || otherFunc == func) {
+ return data.name;
+ }
+ }
+ return result;
+ };
+}());
+
+module.exports = getFuncName;
+
+},{"../support":107,"../utility/constant":108,"./baseProperty":51,"./realNames":86}],74:[function(require,module,exports){
+/**
+ * Gets the index at which the first occurrence of `NaN` is found in `array`.
+ *
+ * @private
+ * @param {Array} array The array to search.
+ * @param {number} fromIndex The index to search from.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {number} Returns the index of the matched `NaN`, else `-1`.
+ */
+function indexOfNaN(array, fromIndex, fromRight) {
+ var length = array.length,
+ index = fromIndex + (fromRight ? 0 : -1);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ var other = array[index];
+ if (other !== other) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+module.exports = indexOfNaN;
+
+},{}],75:[function(require,module,exports){
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Initializes an array clone.
+ *
+ * @private
+ * @param {Array} array The array to clone.
+ * @returns {Array} Returns the initialized clone.
+ */
+function initCloneArray(array) {
+ var length = array.length,
+ result = new array.constructor(length);
+
+ // Add array properties assigned by `RegExp#exec`.
+ if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
+ result.index = array.index;
+ result.input = array.input;
+ }
+ return result;
+}
+
+module.exports = initCloneArray;
+
+},{}],76:[function(require,module,exports){
+(function (global){
+var bufferClone = require('./bufferClone');
+
+/** `Object#toString` result references. */
+var boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ numberTag = '[object Number]',
+ regexpTag = '[object RegExp]',
+ stringTag = '[object String]';
+
+var arrayBufferTag = '[object ArrayBuffer]',
+ float32Tag = '[object Float32Array]',
+ float64Tag = '[object Float64Array]',
+ int8Tag = '[object Int8Array]',
+ int16Tag = '[object Int16Array]',
+ int32Tag = '[object Int32Array]',
+ uint8Tag = '[object Uint8Array]',
+ uint8ClampedTag = '[object Uint8ClampedArray]',
+ uint16Tag = '[object Uint16Array]',
+ uint32Tag = '[object Uint32Array]';
+
+/** Used to match `RegExp` flags from their coerced string values. */
+var reFlags = /\w*$/;
+
+/** Used to lookup a type array constructors by `toStringTag`. */
+var ctorByTag = {};
+ctorByTag[float32Tag] = global.Float32Array;
+ctorByTag[float64Tag] = global.Float64Array;
+ctorByTag[int8Tag] = global.Int8Array;
+ctorByTag[int16Tag] = global.Int16Array;
+ctorByTag[int32Tag] = global.Int32Array;
+ctorByTag[uint8Tag] = global.Uint8Array;
+ctorByTag[uint8ClampedTag] = global.Uint8ClampedArray;
+ctorByTag[uint16Tag] = global.Uint16Array;
+ctorByTag[uint32Tag] = global.Uint32Array;
+
+/**
+ * Initializes an object clone based on its `toStringTag`.
+ *
+ * **Note:** This function only supports cloning values with tags of
+ * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
+ *
+ *
+ * @private
+ * @param {Object} object The object to clone.
+ * @param {string} tag The `toStringTag` of the object to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @returns {Object} Returns the initialized clone.
+ */
+function initCloneByTag(object, tag, isDeep) {
+ var Ctor = object.constructor;
+ switch (tag) {
+ case arrayBufferTag:
+ return bufferClone(object);
+
+ case boolTag:
+ case dateTag:
+ return new Ctor(+object);
+
+ case float32Tag: case float64Tag:
+ case int8Tag: case int16Tag: case int32Tag:
+ case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
+ // Safari 5 mobile incorrectly has `Object` as the constructor of typed arrays.
+ if (Ctor instanceof Ctor) {
+ Ctor = ctorByTag[tag];
+ }
+ var buffer = object.buffer;
+ return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
+
+ case numberTag:
+ case stringTag:
+ return new Ctor(object);
+
+ case regexpTag:
+ var result = new Ctor(object.source, reFlags.exec(object));
+ result.lastIndex = object.lastIndex;
+ }
+ return result;
+}
+
+module.exports = initCloneByTag;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"./bufferClone":57}],77:[function(require,module,exports){
+/**
+ * Initializes an object clone.
+ *
+ * @private
+ * @param {Object} object The object to clone.
+ * @returns {Object} Returns the initialized clone.
+ */
+function initCloneObject(object) {
+ var Ctor = object.constructor;
+ if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
+ Ctor = Object;
+ }
+ return new Ctor;
+}
+
+module.exports = initCloneObject;
+
+},{}],78:[function(require,module,exports){
+/**
+ * Checks if `value` is a host object in IE < 9.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
+ */
+var isHostObject = (function() {
+ try {
+ Object({ 'toString': 0 } + '');
+ } catch(e) {
+ return function() { return false; };
+ }
+ return function(value) {
+ // IE < 9 presents many host objects as `Object` objects that can coerce
+ // to strings despite having improperly defined `toString` methods.
+ return typeof value.toString != 'function' && typeof (value + '') == 'string';
+ };
+}());
+
+module.exports = isHostObject;
+
+},{}],79:[function(require,module,exports){
+/**
+ * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
+ * of an array-like value.
+ */
+var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
+
+/**
+ * Checks if `value` is a valid array-like index.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
+ * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
+ */
+function isIndex(value, length) {
+ value = +value;
+ length = length == null ? MAX_SAFE_INTEGER : length;
+ return value > -1 && value % 1 == 0 && value < length;
+}
+
+module.exports = isIndex;
+
+},{}],80:[function(require,module,exports){
+var LazyWrapper = require('./LazyWrapper'),
+ getFuncName = require('./getFuncName'),
+ lodash = require('../chain/lodash');
+
+/**
+ * Checks if `func` has a lazy counterpart.
+ *
+ * @private
+ * @param {Function} func The function to check.
+ * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
+ */
+function isLaziable(func) {
+ var funcName = getFuncName(func);
+ return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
+}
+
+module.exports = isLaziable;
+
+},{"../chain/lodash":20,"./LazyWrapper":27,"./getFuncName":73}],81:[function(require,module,exports){
+/**
+ * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
+ * of an array-like value.
+ */
+var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
+
+/**
+ * Checks if `value` is a valid array-like length.
+ *
+ * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
+ */
+function isLength(value) {
+ return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
+}
+
+module.exports = isLength;
+
+},{}],82:[function(require,module,exports){
+/**
+ * Checks if `value` is object-like.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
+ */
+function isObjectLike(value) {
+ return !!value && typeof value == 'object';
+}
+
+module.exports = isObjectLike;
+
+},{}],83:[function(require,module,exports){
+var isObject = require('../lang/isObject');
+
+/**
+ * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` if suitable for strict
+ * equality comparisons, else `false`.
+ */
+function isStrictComparable(value) {
+ return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
+}
+
+module.exports = isStrictComparable;
+
+},{"../lang/isObject":99}],84:[function(require,module,exports){
+var arrayCopy = require('./arrayCopy'),
+ composeArgs = require('./composeArgs'),
+ composeArgsRight = require('./composeArgsRight'),
+ replaceHolders = require('./replaceHolders');
+
+/** Used to compose bitmasks for wrapper metadata. */
+var BIND_FLAG = 1,
+ CURRY_BOUND_FLAG = 4,
+ CURRY_FLAG = 8,
+ ARY_FLAG = 128,
+ REARG_FLAG = 256;
+
+/** Used as the internal argument placeholder. */
+var PLACEHOLDER = '__lodash_placeholder__';
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMin = Math.min;
+
+/**
+ * Merges the function metadata of `source` into `data`.
+ *
+ * Merging metadata reduces the number of wrappers required to invoke a function.
+ * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
+ * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
+ * augment function arguments, making the order in which they are executed important,
+ * preventing the merging of metadata. However, we make an exception for a safe
+ * common case where curried functions have `_.ary` and or `_.rearg` applied.
+ *
+ * @private
+ * @param {Array} data The destination metadata.
+ * @param {Array} source The source metadata.
+ * @returns {Array} Returns `data`.
+ */
+function mergeData(data, source) {
+ var bitmask = data[1],
+ srcBitmask = source[1],
+ newBitmask = bitmask | srcBitmask,
+ isCommon = newBitmask < ARY_FLAG;
+
+ var isCombo =
+ (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
+ (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
+ (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
+
+ // Exit early if metadata can't be merged.
+ if (!(isCommon || isCombo)) {
+ return data;
+ }
+ // Use source `thisArg` if available.
+ if (srcBitmask & BIND_FLAG) {
+ data[2] = source[2];
+ // Set when currying a bound function.
+ newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
+ }
+ // Compose partial arguments.
+ var value = source[3];
+ if (value) {
+ var partials = data[3];
+ data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
+ data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
+ }
+ // Compose partial right arguments.
+ value = source[5];
+ if (value) {
+ partials = data[5];
+ data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
+ data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
+ }
+ // Use source `argPos` if available.
+ value = source[7];
+ if (value) {
+ data[7] = arrayCopy(value);
+ }
+ // Use source `ary` if it's smaller.
+ if (srcBitmask & ARY_FLAG) {
+ data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
+ }
+ // Use source `arity` if one is not provided.
+ if (data[9] == null) {
+ data[9] = source[9];
+ }
+ // Use source `func` and merge bitmasks.
+ data[0] = source[0];
+ data[1] = newBitmask;
+
+ return data;
+}
+
+module.exports = mergeData;
+
+},{"./arrayCopy":29,"./composeArgs":58,"./composeArgsRight":59,"./replaceHolders":88}],85:[function(require,module,exports){
+(function (global){
+var isNative = require('../lang/isNative');
+
+/** Native method references. */
+var WeakMap = isNative(WeakMap = global.WeakMap) && WeakMap;
+
+/** Used to store function metadata. */
+var metaMap = WeakMap && new WeakMap;
+
+module.exports = metaMap;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"../lang/isNative":98}],86:[function(require,module,exports){
+/** Used to lookup unminified function names. */
+var realNames = {};
+
+module.exports = realNames;
+
+},{}],87:[function(require,module,exports){
+var arrayCopy = require('./arrayCopy'),
+ isIndex = require('./isIndex');
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeMin = Math.min;
+
+/**
+ * Reorder `array` according to the specified indexes where the element at
+ * the first index is assigned as the first element, the element at
+ * the second index is assigned as the second element, and so on.
+ *
+ * @private
+ * @param {Array} array The array to reorder.
+ * @param {Array} indexes The arranged array indexes.
+ * @returns {Array} Returns `array`.
+ */
+function reorder(array, indexes) {
+ var arrLength = array.length,
+ length = nativeMin(indexes.length, arrLength),
+ oldArray = arrayCopy(array);
+
+ while (length--) {
+ var index = indexes[length];
+ array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
+ }
+ return array;
+}
+
+module.exports = reorder;
+
+},{"./arrayCopy":29,"./isIndex":79}],88:[function(require,module,exports){
+/** Used as the internal argument placeholder. */
+var PLACEHOLDER = '__lodash_placeholder__';
+
+/**
+ * Replaces all `placeholder` elements in `array` with an internal placeholder
+ * and returns an array of their indexes.
+ *
+ * @private
+ * @param {Array} array The array to modify.
+ * @param {*} placeholder The placeholder to replace.
+ * @returns {Array} Returns the new array of placeholder indexes.
+ */
+function replaceHolders(array, placeholder) {
+ var index = -1,
+ length = array.length,
+ resIndex = -1,
+ result = [];
+
+ while (++index < length) {
+ if (array[index] === placeholder) {
+ array[index] = PLACEHOLDER;
+ result[++resIndex] = index;
+ }
+ }
+ return result;
+}
+
+module.exports = replaceHolders;
+
+},{}],89:[function(require,module,exports){
+var baseSetData = require('./baseSetData'),
+ now = require('../date/now');
+
+/** Used to detect when a function becomes hot. */
+var HOT_COUNT = 150,
+ HOT_SPAN = 16;
+
+/**
+ * Sets metadata for `func`.
+ *
+ * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
+ * period of time, it will trip its breaker and transition to an identity function
+ * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
+ * for more details.
+ *
+ * @private
+ * @param {Function} func The function to associate metadata with.
+ * @param {*} data The metadata.
+ * @returns {Function} Returns `func`.
+ */
+var setData = (function() {
+ var count = 0,
+ lastCalled = 0;
+
+ return function(key, value) {
+ var stamp = now(),
+ remaining = HOT_SPAN - (stamp - lastCalled);
+
+ lastCalled = stamp;
+ if (remaining > 0) {
+ if (++count >= HOT_COUNT) {
+ return key;
+ }
+ } else {
+ count = 0;
+ }
+ return baseSetData(key, value);
+ };
+}());
+
+module.exports = setData;
+
+},{"../date/now":24,"./baseSetData":52}],90:[function(require,module,exports){
+var baseForIn = require('./baseForIn'),
+ isArguments = require('../lang/isArguments'),
+ isHostObject = require('./isHostObject'),
+ isObjectLike = require('./isObjectLike'),
+ support = require('../support');
+
+/** `Object#toString` result references. */
+var objectTag = '[object Object]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/**
+ * A fallback implementation of `_.isPlainObject` which checks if `value`
+ * is an object created by the `Object` constructor or has a `[[Prototype]]`
+ * of `null`.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
+ */
+function shimIsPlainObject(value) {
+ var Ctor;
+
+ // Exit early for non `Object` objects.
+ if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isHostObject(value)) ||
+ (!hasOwnProperty.call(value, 'constructor') &&
+ (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor))) ||
+ (!support.argsTag && isArguments(value))) {
+ return false;
+ }
+ // IE < 9 iterates inherited properties before own properties. If the first
+ // iterated property is an object's own property then there are no inherited
+ // enumerable properties.
+ var result;
+ if (support.ownLast) {
+ baseForIn(value, function(subValue, key, object) {
+ result = hasOwnProperty.call(object, key);
+ return false;
+ });
+ return result !== false;
+ }
+ // In most environments an object's own properties are iterated before
+ // its inherited properties. If the last iterated property is an object's
+ // own property then there are no inherited enumerable properties.
+ baseForIn(value, function(subValue, key) {
+ result = key;
+ });
+ return typeof result == 'undefined' || hasOwnProperty.call(value, result);
+}
+
+module.exports = shimIsPlainObject;
+
+},{"../lang/isArguments":95,"../support":107,"./baseForIn":40,"./isHostObject":78,"./isObjectLike":82}],91:[function(require,module,exports){
+var isArguments = require('../lang/isArguments'),
+ isArray = require('../lang/isArray'),
+ isIndex = require('./isIndex'),
+ isLength = require('./isLength'),
+ isString = require('../lang/isString'),
+ keysIn = require('../object/keysIn'),
+ support = require('../support');
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * A fallback implementation of `Object.keys` which creates an array of the
+ * own enumerable property names of `object`.
+ *
+ * @private
+ * @param {Object} object The object to inspect.
+ * @returns {Array} Returns the array of property names.
+ */
+function shimKeys(object) {
+ var props = keysIn(object),
+ propsLength = props.length,
+ length = propsLength && object.length;
+
+ var allowIndexes = length && isLength(length) &&
+ (isArray(object) || (support.nonEnumStrings && isString(object)) ||
+ (support.nonEnumArgs && isArguments(object)));
+
+ var index = -1,
+ result = [];
+
+ while (++index < propsLength) {
+ var key = props[index];
+ if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
+ result.push(key);
+ }
+ }
+ return result;
+}
+
+module.exports = shimKeys;
+
+},{"../lang/isArguments":95,"../lang/isArray":96,"../lang/isString":101,"../object/keysIn":105,"../support":107,"./isIndex":79,"./isLength":81}],92:[function(require,module,exports){
+var isObject = require('../lang/isObject'),
+ isString = require('../lang/isString'),
+ support = require('../support');
+
+/**
+ * Converts `value` to an object if it is not one.
+ *
+ * @private
+ * @param {*} value The value to process.
+ * @returns {Object} Returns the object.
+ */
+function toObject(value) {
+ if (support.unindexedChars && isString(value)) {
+ var index = -1,
+ length = value.length,
+ result = Object(value);
+
+ while (++index < length) {
+ result[index] = value.charAt(index);
+ }
+ return result;
+ }
+ return isObject(value) ? value : Object(value);
+}
+
+module.exports = toObject;
+
+},{"../lang/isObject":99,"../lang/isString":101,"../support":107}],93:[function(require,module,exports){
+var LazyWrapper = require('./LazyWrapper'),
+ LodashWrapper = require('./LodashWrapper'),
+ arrayCopy = require('./arrayCopy');
+
+/**
+ * Creates a clone of `wrapper`.
+ *
+ * @private
+ * @param {Object} wrapper The wrapper to clone.
+ * @returns {Object} Returns the cloned wrapper.
+ */
+function wrapperClone(wrapper) {
+ return wrapper instanceof LazyWrapper
+ ? wrapper.clone()
+ : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
+}
+
+module.exports = wrapperClone;
+
+},{"./LazyWrapper":27,"./LodashWrapper":28,"./arrayCopy":29}],94:[function(require,module,exports){
+var baseClone = require('../internal/baseClone'),
+ bindCallback = require('../internal/bindCallback');
+
+/**
+ * Creates a deep clone of `value`. If `customizer` is provided it is invoked
+ * to produce the cloned values. If `customizer` returns `undefined` cloning
+ * is handled by the method instead. The `customizer` is bound to `thisArg`
+ * and invoked with two argument; (value [, index|key, object]).
+ *
+ * **Note:** This method is loosely based on the
+ * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
+ * The enumerable properties of `arguments` objects and objects created by
+ * constructors other than `Object` are cloned to plain `Object` objects. An
+ * empty object is returned for uncloneable values such as functions, DOM nodes,
+ * Maps, Sets, and WeakMaps.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to deep clone.
+ * @param {Function} [customizer] The function to customize cloning values.
+ * @param {*} [thisArg] The `this` binding of `customizer`.
+ * @returns {*} Returns the deep cloned value.
+ * @example
+ *
+ * var users = [
+ * { 'user': 'barney' },
+ * { 'user': 'fred' }
+ * ];
+ *
+ * var deep = _.cloneDeep(users);
+ * deep[0] === users[0];
+ * // => false
+ *
+ * // using a customizer callback
+ * var el = _.cloneDeep(document.body, function(value) {
+ * if (_.isElement(value)) {
+ * return value.cloneNode(true);
+ * }
+ * });
+ *
+ * el === document.body
+ * // => false
+ * el.nodeName
+ * // => BODY
+ * el.childNodes.length;
+ * // => 20
+ */
+function cloneDeep(value, customizer, thisArg) {
+ customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
+ return baseClone(value, true, customizer);
+}
+
+module.exports = cloneDeep;
+
+},{"../internal/baseClone":33,"../internal/bindCallback":56}],95:[function(require,module,exports){
+var isLength = require('../internal/isLength'),
+ isObjectLike = require('../internal/isObjectLike'),
+ support = require('../support');
+
+/** `Object#toString` result references. */
+var argsTag = '[object Arguments]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Native method references. */
+var propertyIsEnumerable = objectProto.propertyIsEnumerable;
+
+/**
+ * Checks if `value` is classified as an `arguments` object.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ * @example
+ *
+ * _.isArguments(function() { return arguments; }());
+ * // => true
+ *
+ * _.isArguments([1, 2, 3]);
+ * // => false
+ */
+function isArguments(value) {
+ var length = isObjectLike(value) ? value.length : undefined;
+ return isLength(length) && objToString.call(value) == argsTag;
+}
+// Fallback for environments without a `toStringTag` for `arguments` objects.
+if (!support.argsTag) {
+ isArguments = function(value) {
+ var length = isObjectLike(value) ? value.length : undefined;
+ return isLength(length) && hasOwnProperty.call(value, 'callee') &&
+ !propertyIsEnumerable.call(value, 'callee');
+ };
+}
+
+module.exports = isArguments;
+
+},{"../internal/isLength":81,"../internal/isObjectLike":82,"../support":107}],96:[function(require,module,exports){
+var isLength = require('../internal/isLength'),
+ isNative = require('./isNative'),
+ isObjectLike = require('../internal/isObjectLike');
+
+/** `Object#toString` result references. */
+var arrayTag = '[object Array]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
+
+/**
+ * Checks if `value` is classified as an `Array` object.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ * @example
+ *
+ * _.isArray([1, 2, 3]);
+ * // => true
+ *
+ * _.isArray(function() { return arguments; }());
+ * // => false
+ */
+var isArray = nativeIsArray || function(value) {
+ return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
+};
+
+module.exports = isArray;
+
+},{"../internal/isLength":81,"../internal/isObjectLike":82,"./isNative":98}],97:[function(require,module,exports){
+(function (global){
+var baseIsFunction = require('../internal/baseIsFunction'),
+ isNative = require('./isNative');
+
+/** `Object#toString` result references. */
+var funcTag = '[object Function]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Native method references. */
+var Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array;
+
+/**
+ * Checks if `value` is classified as a `Function` object.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ * @example
+ *
+ * _.isFunction(_);
+ * // => true
+ *
+ * _.isFunction(/abc/);
+ * // => false
+ */
+var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
+ // The use of `Object#toString` avoids issues with the `typeof` operator
+ // in older versions of Chrome and Safari which return 'function' for regexes
+ // and Safari 8 equivalents which return 'object' for typed array constructors.
+ return objToString.call(value) == funcTag;
+};
+
+module.exports = isFunction;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"../internal/baseIsFunction":45,"./isNative":98}],98:[function(require,module,exports){
+var escapeRegExp = require('../string/escapeRegExp'),
+ isHostObject = require('../internal/isHostObject'),
+ isObjectLike = require('../internal/isObjectLike');
+
+/** `Object#toString` result references. */
+var funcTag = '[object Function]';
+
+/** Used to detect host constructors (Safari > 5). */
+var reHostCtor = /^\[object .+?Constructor\]$/;
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/** Used to resolve the decompiled source of functions. */
+var fnToString = Function.prototype.toString;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Used to detect if a method is native. */
+var reNative = RegExp('^' +
+ escapeRegExp(objToString)
+ .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
+);
+
+/**
+ * Checks if `value` is a native function.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
+ * @example
+ *
+ * _.isNative(Array.prototype.push);
+ * // => true
+ *
+ * _.isNative(_);
+ * // => false
+ */
+function isNative(value) {
+ if (value == null) {
+ return false;
+ }
+ if (objToString.call(value) == funcTag) {
+ return reNative.test(fnToString.call(value));
+ }
+ return isObjectLike(value) && (isHostObject(value) ? reNative : reHostCtor).test(value);
+}
+
+module.exports = isNative;
+
+},{"../internal/isHostObject":78,"../internal/isObjectLike":82,"../string/escapeRegExp":106}],99:[function(require,module,exports){
+/**
+ * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
+ * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
+ * @example
+ *
+ * _.isObject({});
+ * // => true
+ *
+ * _.isObject([1, 2, 3]);
+ * // => true
+ *
+ * _.isObject(1);
+ * // => false
+ */
+function isObject(value) {
+ // Avoid a V8 JIT bug in Chrome 19-20.
+ // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
+ var type = typeof value;
+ return type == 'function' || (!!value && type == 'object');
+}
+
+module.exports = isObject;
+
+},{}],100:[function(require,module,exports){
+var isArguments = require('./isArguments'),
+ isNative = require('./isNative'),
+ shimIsPlainObject = require('../internal/shimIsPlainObject'),
+ support = require('../support');
+
+/** `Object#toString` result references. */
+var objectTag = '[object Object]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Native method references. */
+var getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf;
+
+/**
+ * Checks if `value` is a plain object, that is, an object created by the
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
+ *
+ * **Note:** This method assumes objects created by the `Object` constructor
+ * have no inherited enumerable properties.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
+ * @example
+ *
+ * function Foo() {
+ * this.a = 1;
+ * }
+ *
+ * _.isPlainObject(new Foo);
+ * // => false
+ *
+ * _.isPlainObject([1, 2, 3]);
+ * // => false
+ *
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
+ * // => true
+ *
+ * _.isPlainObject(Object.create(null));
+ * // => true
+ */
+var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
+ if (!(value && objToString.call(value) == objectTag) || (!support.argsTag && isArguments(value))) {
+ return false;
+ }
+ var valueOf = value.valueOf,
+ objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
+
+ return objProto
+ ? (value == objProto || getPrototypeOf(value) == objProto)
+ : shimIsPlainObject(value);
+};
+
+module.exports = isPlainObject;
+
+},{"../internal/shimIsPlainObject":90,"../support":107,"./isArguments":95,"./isNative":98}],101:[function(require,module,exports){
+var isObjectLike = require('../internal/isObjectLike');
+
+/** `Object#toString` result references. */
+var stringTag = '[object String]';
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/**
+ * Checks if `value` is classified as a `String` primitive or object.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ * @example
+ *
+ * _.isString('abc');
+ * // => true
+ *
+ * _.isString(1);
+ * // => false
+ */
+function isString(value) {
+ return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
+}
+
+module.exports = isString;
+
+},{"../internal/isObjectLike":82}],102:[function(require,module,exports){
+var isLength = require('../internal/isLength'),
+ isObjectLike = require('../internal/isObjectLike');
+
+/** `Object#toString` result references. */
+var argsTag = '[object Arguments]',
+ arrayTag = '[object Array]',
+ boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ errorTag = '[object Error]',
+ funcTag = '[object Function]',
+ mapTag = '[object Map]',
+ numberTag = '[object Number]',
+ objectTag = '[object Object]',
+ regexpTag = '[object RegExp]',
+ setTag = '[object Set]',
+ stringTag = '[object String]',
+ weakMapTag = '[object WeakMap]';
+
+var arrayBufferTag = '[object ArrayBuffer]',
+ float32Tag = '[object Float32Array]',
+ float64Tag = '[object Float64Array]',
+ int8Tag = '[object Int8Array]',
+ int16Tag = '[object Int16Array]',
+ int32Tag = '[object Int32Array]',
+ uint8Tag = '[object Uint8Array]',
+ uint8ClampedTag = '[object Uint8ClampedArray]',
+ uint16Tag = '[object Uint16Array]',
+ uint32Tag = '[object Uint32Array]';
+
+/** Used to identify `toStringTag` values of typed arrays. */
+var typedArrayTags = {};
+typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
+typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
+typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
+typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
+typedArrayTags[uint32Tag] = true;
+typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
+typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
+typedArrayTags[dateTag] = typedArrayTags[errorTag] =
+typedArrayTags[funcTag] = typedArrayTags[mapTag] =
+typedArrayTags[numberTag] = typedArrayTags[objectTag] =
+typedArrayTags[regexpTag] = typedArrayTags[setTag] =
+typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
+
+/** Used for native method references. */
+var objectProto = Object.prototype;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/**
+ * Checks if `value` is classified as a typed array.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
+ * @example
+ *
+ * _.isTypedArray(new Uint8Array);
+ * // => true
+ *
+ * _.isTypedArray([]);
+ * // => false
+ */
+function isTypedArray(value) {
+ return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
+}
+
+module.exports = isTypedArray;
+
+},{"../internal/isLength":81,"../internal/isObjectLike":82}],103:[function(require,module,exports){
+/**
+ * Checks if `value` is `undefined`.
+ *
+ * @static
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
+ * @example
+ *
+ * _.isUndefined(void 0);
+ * // => true
+ *
+ * _.isUndefined(null);
+ * // => false
+ */
+function isUndefined(value) {
+ return typeof value == 'undefined';
+}
+
+module.exports = isUndefined;
+
+},{}],104:[function(require,module,exports){
+var isLength = require('../internal/isLength'),
+ isNative = require('../lang/isNative'),
+ isObject = require('../lang/isObject'),
+ shimKeys = require('../internal/shimKeys'),
+ support = require('../support');
+
+/* Native method references for those with the same name as other `lodash` methods. */
+var nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys;
+
+/**
+ * Creates an array of the own enumerable property names of `object`.
+ *
+ * **Note:** Non-object values are coerced to objects. See the
+ * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys)
+ * for more details.
+ *
+ * @static
+ * @memberOf _
+ * @category Object
+ * @param {Object} object The object to inspect.
+ * @returns {Array} Returns the array of property names.
+ * @example
+ *
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.keys(new Foo);
+ * // => ['a', 'b'] (iteration order is not guaranteed)
+ *
+ * _.keys('hi');
+ * // => ['0', '1']
+ */
+var keys = !nativeKeys ? shimKeys : function(object) {
+ if (object) {
+ var Ctor = object.constructor,
+ length = object.length;
+ }
+ if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
+ (typeof object == 'function' ? support.enumPrototypes : (length && isLength(length)))) {
+ return shimKeys(object);
+ }
+ return isObject(object) ? nativeKeys(object) : [];
+};
+
+module.exports = keys;
+
+},{"../internal/isLength":81,"../internal/shimKeys":91,"../lang/isNative":98,"../lang/isObject":99,"../support":107}],105:[function(require,module,exports){
+var arrayEach = require('../internal/arrayEach'),
+ isArguments = require('../lang/isArguments'),
+ isArray = require('../lang/isArray'),
+ isFunction = require('../lang/isFunction'),
+ isIndex = require('../internal/isIndex'),
+ isLength = require('../internal/isLength'),
+ isObject = require('../lang/isObject'),
+ isString = require('../lang/isString'),
+ support = require('../support');
+
+/** `Object#toString` result references. */
+var arrayTag = '[object Array]',
+ boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ errorTag = '[object Error]',
+ funcTag = '[object Function]',
+ numberTag = '[object Number]',
+ objectTag = '[object Object]',
+ regexpTag = '[object RegExp]',
+ stringTag = '[object String]';
+
+/** Used to fix the JScript `[[DontEnum]]` bug. */
+var shadowProps = [
+ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
+ 'toLocaleString', 'toString', 'valueOf'
+];
+
+/** Used for native method references. */
+var errorProto = Error.prototype,
+ objectProto = Object.prototype,
+ stringProto = String.prototype;
+
+/** Used to check objects for own properties. */
+var hasOwnProperty = objectProto.hasOwnProperty;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Used to avoid iterating over non-enumerable properties in IE < 9. */
+var nonEnumProps = {};
+nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
+nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
+nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
+nonEnumProps[objectTag] = { 'constructor': true };
+
+arrayEach(shadowProps, function(key) {
+ for (var tag in nonEnumProps) {
+ if (hasOwnProperty.call(nonEnumProps, tag)) {
+ var props = nonEnumProps[tag];
+ props[key] = hasOwnProperty.call(props, key);
+ }
+ }
+});
+
+/**
+ * Creates an array of the own and inherited enumerable property names of `object`.
+ *
+ * **Note:** Non-object values are coerced to objects.
+ *
+ * @static
+ * @memberOf _
+ * @category Object
+ * @param {Object} object The object to inspect.
+ * @returns {Array} Returns the array of property names.
+ * @example
+ *
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.keysIn(new Foo);
+ * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
+ */
+function keysIn(object) {
+ if (object == null) {
+ return [];
+ }
+ if (!isObject(object)) {
+ object = Object(object);
+ }
+ var length = object.length;
+
+ length = (length && isLength(length) &&
+ (isArray(object) || (support.nonEnumStrings && isString(object)) ||
+ (support.nonEnumArgs && isArguments(object))) && length) || 0;
+
+ var Ctor = object.constructor,
+ index = -1,
+ proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
+ isProto = proto === object,
+ result = Array(length),
+ skipIndexes = length > 0,
+ skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
+ skipProto = support.enumPrototypes && isFunction(object);
+
+ while (++index < length) {
+ result[index] = (index + '');
+ }
+ // lodash skips the `constructor` property when it infers it is iterating
+ // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
+ // attribute of an existing property and the `constructor` property of a
+ // prototype defaults to non-enumerable.
+ for (var key in object) {
+ if (!(skipProto && key == 'prototype') &&
+ !(skipErrorProps && (key == 'message' || key == 'name')) &&
+ !(skipIndexes && isIndex(key, length)) &&
+ !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
+ result.push(key);
+ }
+ }
+ if (support.nonEnumShadows && object !== objectProto) {
+ var tag = object === stringProto ? stringTag : (object === errorProto ? errorTag : objToString.call(object)),
+ nonEnums = nonEnumProps[tag] || nonEnumProps[objectTag];
+
+ if (tag == objectTag) {
+ proto = objectProto;
+ }
+ length = shadowProps.length;
+ while (length--) {
+ key = shadowProps[length];
+ var nonEnum = nonEnums[key];
+ if (!(isProto && nonEnum) &&
+ (nonEnum ? hasOwnProperty.call(object, key) : object[key] !== proto[key])) {
+ result.push(key);
+ }
+ }
+ }
+ return result;
+}
+
+module.exports = keysIn;
+
+},{"../internal/arrayEach":30,"../internal/isIndex":79,"../internal/isLength":81,"../lang/isArguments":95,"../lang/isArray":96,"../lang/isFunction":97,"../lang/isObject":99,"../lang/isString":101,"../support":107}],106:[function(require,module,exports){
+var baseToString = require('../internal/baseToString');
+
+/**
+ * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
+ * In addition to special characters the forward slash is escaped to allow for
+ * easier `eval` use and `Function` compilation.
+ */
+var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
+ reHasRegExpChars = RegExp(reRegExpChars.source);
+
+/**
+ * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
+ * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
+ *
+ * @static
+ * @memberOf _
+ * @category String
+ * @param {string} [string=''] The string to escape.
+ * @returns {string} Returns the escaped string.
+ * @example
+ *
+ * _.escapeRegExp('[lodash](https://lodash.com/)');
+ * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
+ */
+function escapeRegExp(string) {
+ string = baseToString(string);
+ return (string && reHasRegExpChars.test(string))
+ ? string.replace(reRegExpChars, '\\$&')
+ : string;
+}
+
+module.exports = escapeRegExp;
+
+},{"../internal/baseToString":53}],107:[function(require,module,exports){
+(function (global){
+/** `Object#toString` result references. */
+var argsTag = '[object Arguments]',
+ objectTag = '[object Object]';
+
+/** Used for native method references. */
+var arrayProto = Array.prototype,
+ errorProto = Error.prototype,
+ objectProto = Object.prototype;
+
+/** Used to detect DOM support. */
+var document = (document = global.window) && document.document;
+
+/**
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
+ */
+var objToString = objectProto.toString;
+
+/** Native method references. */
+var propertyIsEnumerable = objectProto.propertyIsEnumerable,
+ splice = arrayProto.splice;
+
+/**
+ * An object environment feature flags.
+ *
+ * @static
+ * @memberOf _
+ * @type Object
+ */
+var support = {};
+
+(function(x) {
+ var Ctor = function() { this.x = 1; },
+ object = { '0': 1, 'length': 1 },
+ props = [];
+
+ Ctor.prototype = { 'valueOf': 1, 'y': 1 };
+ for (var key in new Ctor) { props.push(key); }
+
+ /**
+ * Detect if the `toStringTag` of `arguments` objects is resolvable
+ * (all but Firefox < 4, IE < 9).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.argsTag = objToString.call(arguments) == argsTag;
+
+ /**
+ * Detect if `name` or `message` properties of `Error.prototype` are
+ * enumerable by default (IE < 9, Safari < 5.1).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
+ propertyIsEnumerable.call(errorProto, 'name');
+
+ /**
+ * Detect if `prototype` properties are enumerable by default.
+ *
+ * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
+ * (if the prototype or a property on the prototype has been set)
+ * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
+ * property to `true`.
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
+
+ /**
+ * Detect if functions can be decompiled by `Function#toString`
+ * (all but Firefox OS certified apps, older Opera mobile browsers, and
+ * the PlayStation 3; forced `false` for Windows 8 apps).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.funcDecomp = /\bthis\b/.test(function() { return this; });
+
+ /**
+ * Detect if `Function#name` is supported (all but IE).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.funcNames = typeof Function.name == 'string';
+
+ /**
+ * Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.nodeTag = objToString.call(document) != objectTag;
+
+ /**
+ * Detect if string indexes are non-enumerable
+ * (IE < 9, RingoJS, Rhino, Narwhal).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.nonEnumStrings = !propertyIsEnumerable.call('x', 0);
+
+ /**
+ * Detect if properties shadowing those on `Object.prototype` are
+ * non-enumerable.
+ *
+ * In IE < 9 an object's own properties, shadowing non-enumerable ones,
+ * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.nonEnumShadows = !/valueOf/.test(props);
+
+ /**
+ * Detect if own properties are iterated after inherited properties (IE < 9).
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.ownLast = props[0] != 'x';
+
+ /**
+ * Detect if `Array#shift` and `Array#splice` augment array-like objects
+ * correctly.
+ *
+ * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array `shift()`
+ * and `splice()` functions that fail to remove the last element, `value[0]`,
+ * of array-like objects even though the `length` property is set to `0`.
+ * The `shift()` method is buggy in compatibility modes of IE 8, while `splice()`
+ * is buggy regardless of mode in IE < 9.
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
+
+ /**
+ * Detect lack of support for accessing string characters by index.
+ *
+ * IE < 8 can't access characters by index. IE 8 can only access characters
+ * by index on string literals, not string objects.
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
+
+ /**
+ * Detect if the DOM is supported.
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ try {
+ support.dom = document.createDocumentFragment().nodeType === 11;
+ } catch(e) {
+ support.dom = false;
+ }
+
+ /**
+ * Detect if `arguments` object indexes are non-enumerable.
+ *
+ * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
+ * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
+ * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
+ * checks for indexes that exceed their function's formal parameters with
+ * associated values of `0`.
+ *
+ * @memberOf _.support
+ * @type boolean
+ */
+ try {
+ support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
+ } catch(e) {
+ support.nonEnumArgs = true;
+ }
+}(0, 0));
+
+module.exports = support;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{}],108:[function(require,module,exports){
+/**
+ * Creates a function that returns `value`.
+ *
+ * @static
+ * @memberOf _
+ * @category Utility
+ * @param {*} value The value to return from the new function.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var object = { 'user': 'fred' };
+ * var getter = _.constant(object);
+ *
+ * getter() === object;
+ * // => true
+ */
+function constant(value) {
+ return function() {
+ return value;
+ };
+}
+
+module.exports = constant;
+
+},{}],109:[function(require,module,exports){
+/**
+ * This method returns the first argument provided to it.
+ *
+ * @static
+ * @memberOf _
+ * @category Utility
+ * @param {*} value Any value.
+ * @returns {*} Returns `value`.
+ * @example
+ *
+ * var object = { 'user': 'fred' };
+ *
+ * _.identity(object) === object;
+ * // => true
+ */
+function identity(value) {
+ return value;
+}
+
+module.exports = identity;
+
+},{}],110:[function(require,module,exports){
+/**
+ * A no-operation function which returns `undefined` regardless of the
+ * arguments it receives.
+ *
+ * @static
+ * @memberOf _
+ * @category Utility
+ * @example
+ *
+ * var object = { 'user': 'fred' };
+ *
+ * _.noop(object) === undefined;
+ * // => true
+ */
+function noop() {
+ // No operation performed.
+}
+
+module.exports = noop;
+
+},{}],111:[function(require,module,exports){
+/**
+ * Module dependencies.
+ */
+
+var Emitter = require('emitter');
+var reduce = require('reduce');
+
+/**
+ * Root reference for iframes.
+ */
+
+var root = 'undefined' == typeof window
+ ? this
+ : window;
+
+/**
+ * Noop.
+ */
+
+function noop(){};
+
+/**
+ * Check if `obj` is a host object,
+ * we don't want to serialize these :)
+ *
+ * TODO: future proof, move to compoent land
+ *
+ * @param {Object} obj
+ * @return {Boolean}
+ * @api private
+ */
+
+function isHost(obj) {
+ var str = {}.toString.call(obj);
+
+ switch (str) {
+ case '[object File]':
+ case '[object Blob]':
+ case '[object FormData]':
+ return true;
+ default:
+ return false;
+ }
+}
+
+/**
+ * Determine XHR.
+ */
+
+function getXHR() {
+ if (root.XMLHttpRequest
+ && ('file:' != root.location.protocol || !root.ActiveXObject)) {
+ return new XMLHttpRequest;
+ } else {
+ try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
+ try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
+ try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
+ try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
+ }
+ return false;
+}
+
+/**
+ * Removes leading and trailing whitespace, added to support IE.
+ *
+ * @param {String} s
+ * @return {String}
+ * @api private
+ */
+
+var trim = ''.trim
+ ? function(s) { return s.trim(); }
+ : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
+
+/**
+ * Check if `obj` is an object.
+ *
+ * @param {Object} obj
+ * @return {Boolean}
+ * @api private
+ */
+
+function isObject(obj) {
+ return obj === Object(obj);
+}
+
+/**
+ * Serialize the given `obj`.
+ *
+ * @param {Object} obj
+ * @return {String}
+ * @api private
+ */
+
+function serialize(obj) {
+ if (!isObject(obj)) return obj;
+ var pairs = [];
+ for (var key in obj) {
+ if (null != obj[key]) {
+ pairs.push(encodeURIComponent(key)
+ + '=' + encodeURIComponent(obj[key]));
+ }
+ }
+ return pairs.join('&');
+}
+
+/**
+ * Expose serialization method.
+ */
+
+ request.serializeObject = serialize;
+
+ /**
+ * Parse the given x-www-form-urlencoded `str`.
+ *
+ * @param {String} str
+ * @return {Object}
+ * @api private
+ */
+
+function parseString(str) {
+ var obj = {};
+ var pairs = str.split('&');
+ var parts;
+ var pair;
+
+ for (var i = 0, len = pairs.length; i < len; ++i) {
+ pair = pairs[i];
+ parts = pair.split('=');
+ obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
+ }
+
+ return obj;
+}
+
+/**
+ * Expose parser.
+ */
+
+request.parseString = parseString;
+
+/**
+ * Default MIME type map.
+ *
+ * superagent.types.xml = 'application/xml';
+ *
+ */
+
+request.types = {
+ html: 'text/html',
+ json: 'application/json',
+ xml: 'application/xml',
+ urlencoded: 'application/x-www-form-urlencoded',
+ 'form': 'application/x-www-form-urlencoded',
+ 'form-data': 'application/x-www-form-urlencoded'
+};
+
+/**
+ * Default serialization map.
+ *
+ * superagent.serialize['application/xml'] = function(obj){
+ * return 'generated xml here';
+ * };
+ *
+ */
+
+ request.serialize = {
+ 'application/x-www-form-urlencoded': serialize,
+ 'application/json': JSON.stringify
+ };
+
+ /**
+ * Default parsers.
+ *
+ * superagent.parse['application/xml'] = function(str){
+ * return { object parsed from str };
+ * };
+ *
+ */
+
+request.parse = {
+ 'application/x-www-form-urlencoded': parseString,
+ 'application/json': JSON.parse
+};
+
+/**
+ * Parse the given header `str` into
+ * an object containing the mapped fields.
+ *
+ * @param {String} str
+ * @return {Object}
+ * @api private
+ */
+
+function parseHeader(str) {
+ var lines = str.split(/\r?\n/);
+ var fields = {};
+ var index;
+ var line;
+ var field;
+ var val;
+
+ lines.pop(); // trailing CRLF
+
+ for (var i = 0, len = lines.length; i < len; ++i) {
+ line = lines[i];
+ index = line.indexOf(':');
+ field = line.slice(0, index).toLowerCase();
+ val = trim(line.slice(index + 1));
+ fields[field] = val;
+ }
+
+ return fields;
+}
+
+/**
+ * Return the mime type for the given `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+function type(str){
+ return str.split(/ *; */).shift();
+};
+
+/**
+ * Return header field parameters.
+ *
+ * @param {String} str
+ * @return {Object}
+ * @api private
+ */
+
+function params(str){
+ return reduce(str.split(/ *; */), function(obj, str){
+ var parts = str.split(/ *= */)
+ , key = parts.shift()
+ , val = parts.shift();
+
+ if (key && val) obj[key] = val;
+ return obj;
+ }, {});
+};
+
+/**
+ * Initialize a new `Response` with the given `xhr`.
+ *
+ * - set flags (.ok, .error, etc)
+ * - parse header
+ *
+ * Examples:
+ *
+ * Aliasing `superagent` as `request` is nice:
+ *
+ * request = superagent;
+ *
+ * We can use the promise-like API, or pass callbacks:
+ *
+ * request.get('/').end(function(res){});
+ * request.get('/', function(res){});
+ *
+ * Sending data can be chained:
+ *
+ * request
+ * .post('/user')
+ * .send({ name: 'tj' })
+ * .end(function(res){});
+ *
+ * Or passed to `.send()`:
+ *
+ * request
+ * .post('/user')
+ * .send({ name: 'tj' }, function(res){});
+ *
+ * Or passed to `.post()`:
+ *
+ * request
+ * .post('/user', { name: 'tj' })
+ * .end(function(res){});
+ *
+ * Or further reduced to a single call for simple cases:
+ *
+ * request
+ * .post('/user', { name: 'tj' }, function(res){});
+ *
+ * @param {XMLHTTPRequest} xhr
+ * @param {Object} options
+ * @api private
+ */
+
+function Response(req, options) {
+ options = options || {};
+ this.req = req;
+ this.xhr = this.req.xhr;
+ this.text = this.req.method !='HEAD'
+ ? this.xhr.responseText
+ : null;
+ this.setStatusProperties(this.xhr.status);
+ this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
+ // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
+ // getResponseHeader still works. so we get content-type even if getting
+ // other headers fails.
+ this.header['content-type'] = this.xhr.getResponseHeader('content-type');
+ this.setHeaderProperties(this.header);
+ this.body = this.req.method != 'HEAD'
+ ? this.parseBody(this.text)
+ : null;
+}
+
+/**
+ * Get case-insensitive `field` value.
+ *
+ * @param {String} field
+ * @return {String}
+ * @api public
+ */
+
+Response.prototype.get = function(field){
+ return this.header[field.toLowerCase()];
+};
+
+/**
+ * Set header related properties:
+ *
+ * - `.type` the content type without params
+ *
+ * A response of "Content-Type: text/plain; charset=utf-8"
+ * will provide you with a `.type` of "text/plain".
+ *
+ * @param {Object} header
+ * @api private
+ */
+
+Response.prototype.setHeaderProperties = function(header){
+ // content-type
+ var ct = this.header['content-type'] || '';
+ this.type = type(ct);
+
+ // params
+ var obj = params(ct);
+ for (var key in obj) this[key] = obj[key];
+};
+
+/**
+ * Parse the given body `str`.
+ *
+ * Used for auto-parsing of bodies. Parsers
+ * are defined on the `superagent.parse` object.
+ *
+ * @param {String} str
+ * @return {Mixed}
+ * @api private
+ */
+
+Response.prototype.parseBody = function(str){
+ var parse = request.parse[this.type];
+ return parse && str && str.length
+ ? parse(str)
+ : null;
+};
+
+/**
+ * Set flags such as `.ok` based on `status`.
+ *
+ * For example a 2xx response will give you a `.ok` of __true__
+ * whereas 5xx will be __false__ and `.error` will be __true__. The
+ * `.clientError` and `.serverError` are also available to be more
+ * specific, and `.statusType` is the class of error ranging from 1..5
+ * sometimes useful for mapping respond colors etc.
+ *
+ * "sugar" properties are also defined for common cases. Currently providing:
+ *
+ * - .noContent
+ * - .badRequest
+ * - .unauthorized
+ * - .notAcceptable
+ * - .notFound
+ *
+ * @param {Number} status
+ * @api private
+ */
+
+Response.prototype.setStatusProperties = function(status){
+ var type = status / 100 | 0;
+
+ // status / class
+ this.status = status;
+ this.statusType = type;
+
+ // basics
+ this.info = 1 == type;
+ this.ok = 2 == type;
+ this.clientError = 4 == type;
+ this.serverError = 5 == type;
+ this.error = (4 == type || 5 == type)
+ ? this.toError()
+ : false;
+
+ // sugar
+ this.accepted = 202 == status;
+ this.noContent = 204 == status || 1223 == status;
+ this.badRequest = 400 == status;
+ this.unauthorized = 401 == status;
+ this.notAcceptable = 406 == status;
+ this.notFound = 404 == status;
+ this.forbidden = 403 == status;
+};
+
+/**
+ * Return an `Error` representative of this response.
+ *
+ * @return {Error}
+ * @api public
+ */
+
+Response.prototype.toError = function(){
+ var req = this.req;
+ var method = req.method;
+ var url = req.url;
+
+ var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
+ var err = new Error(msg);
+ err.status = this.status;
+ err.method = method;
+ err.url = url;
+
+ return err;
+};
+
+/**
+ * Expose `Response`.
+ */
+
+request.Response = Response;
+
+/**
+ * Initialize a new `Request` with the given `method` and `url`.
+ *
+ * @param {String} method
+ * @param {String} url
+ * @api public
+ */
+
+function Request(method, url) {
+ var self = this;
+ Emitter.call(this);
+ this._query = this._query || [];
+ this.method = method;
+ this.url = url;
+ this.header = {};
+ this._header = {};
+ this.on('end', function(){
+ var err = null;
+ var res = null;
+
+ try {
+ res = new Response(self);
+ } catch(e) {
+ err = new Error('Parser is unable to parse the response');
+ err.parse = true;
+ err.original = e;
+ }
+
+ self.callback(err, res);
+ });
+}
+
+/**
+ * Mixin `Emitter`.
+ */
+
+Emitter(Request.prototype);
+
+/**
+ * Allow for extension
+ */
+
+Request.prototype.use = function(fn) {
+ fn(this);
+ return this;
+}
+
+/**
+ * Set timeout to `ms`.
+ *
+ * @param {Number} ms
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.timeout = function(ms){
+ this._timeout = ms;
+ return this;
+};
+
+/**
+ * Clear previous timeout.
+ *
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.clearTimeout = function(){
+ this._timeout = 0;
+ clearTimeout(this._timer);
+ return this;
+};
+
+/**
+ * Abort the request, and clear potential timeout.
+ *
+ * @return {Request}
+ * @api public
+ */
+
+Request.prototype.abort = function(){
+ if (this.aborted) return;
+ this.aborted = true;
+ this.xhr.abort();
+ this.clearTimeout();
+ this.emit('abort');
+ return this;
+};
+
+/**
+ * Set header `field` to `val`, or multiple fields with one object.
+ *
+ * Examples:
+ *
+ * req.get('/')
+ * .set('Accept', 'application/json')
+ * .set('X-API-Key', 'foobar')
+ * .end(callback);
+ *
+ * req.get('/')
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
+ * .end(callback);
+ *
+ * @param {String|Object} field
+ * @param {String} val
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.set = function(field, val){
+ if (isObject(field)) {
+ for (var key in field) {
+ this.set(key, field[key]);
+ }
+ return this;
+ }
+ this._header[field.toLowerCase()] = val;
+ this.header[field] = val;
+ return this;
+};
+
+/**
+ * Remove header `field`.
+ *
+ * Example:
+ *
+ * req.get('/')
+ * .unset('User-Agent')
+ * .end(callback);
+ *
+ * @param {String} field
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.unset = function(field){
+ delete this._header[field.toLowerCase()];
+ delete this.header[field];
+ return this;
+};
+
+/**
+ * Get case-insensitive header `field` value.
+ *
+ * @param {String} field
+ * @return {String}
+ * @api private
+ */
+
+Request.prototype.getHeader = function(field){
+ return this._header[field.toLowerCase()];
+};
+
+/**
+ * Set Content-Type to `type`, mapping values from `request.types`.
+ *
+ * Examples:
+ *
+ * superagent.types.xml = 'application/xml';
+ *
+ * request.post('/')
+ * .type('xml')
+ * .send(xmlstring)
+ * .end(callback);
+ *
+ * request.post('/')
+ * .type('application/xml')
+ * .send(xmlstring)
+ * .end(callback);
+ *
+ * @param {String} type
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.type = function(type){
+ this.set('Content-Type', request.types[type] || type);
+ return this;
+};
+
+/**
+ * Set Accept to `type`, mapping values from `request.types`.
+ *
+ * Examples:
+ *
+ * superagent.types.json = 'application/json';
+ *
+ * request.get('/agent')
+ * .accept('json')
+ * .end(callback);
+ *
+ * request.get('/agent')
+ * .accept('application/json')
+ * .end(callback);
+ *
+ * @param {String} accept
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.accept = function(type){
+ this.set('Accept', request.types[type] || type);
+ return this;
+};
+
+/**
+ * Set Authorization field value with `user` and `pass`.
+ *
+ * @param {String} user
+ * @param {String} pass
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.auth = function(user, pass){
+ var str = btoa(user + ':' + pass);
+ this.set('Authorization', 'Basic ' + str);
+ return this;
+};
+
+/**
+* Add query-string `val`.
+*
+* Examples:
+*
+* request.get('/shoes')
+* .query('size=10')
+* .query({ color: 'blue' })
+*
+* @param {Object|String} val
+* @return {Request} for chaining
+* @api public
+*/
+
+Request.prototype.query = function(val){
+ if ('string' != typeof val) val = serialize(val);
+ if (val) this._query.push(val);
+ return this;
+};
+
+/**
+ * Write the field `name` and `val` for "multipart/form-data"
+ * request bodies.
+ *
+ * ``` js
+ * request.post('/upload')
+ * .field('foo', 'bar')
+ * .end(callback);
+ * ```
+ *
+ * @param {String} name
+ * @param {String|Blob|File} val
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.field = function(name, val){
+ if (!this._formData) this._formData = new FormData();
+ this._formData.append(name, val);
+ return this;
+};
+
+/**
+ * Queue the given `file` as an attachment to the specified `field`,
+ * with optional `filename`.
+ *
+ * ``` js
+ * request.post('/upload')
+ * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
+ * .end(callback);
+ * ```
+ *
+ * @param {String} field
+ * @param {Blob|File} file
+ * @param {String} filename
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.attach = function(field, file, filename){
+ if (!this._formData) this._formData = new FormData();
+ this._formData.append(field, file, filename);
+ return this;
+};
+
+/**
+ * Send `data`, defaulting the `.type()` to "json" when
+ * an object is given.
+ *
+ * Examples:
+ *
+ * // querystring
+ * request.get('/search')
+ * .end(callback)
+ *
+ * // multiple data "writes"
+ * request.get('/search')
+ * .send({ search: 'query' })
+ * .send({ range: '1..5' })
+ * .send({ order: 'desc' })
+ * .end(callback)
+ *
+ * // manual json
+ * request.post('/user')
+ * .type('json')
+ * .send('{"name":"tj"})
+ * .end(callback)
+ *
+ * // auto json
+ * request.post('/user')
+ * .send({ name: 'tj' })
+ * .end(callback)
+ *
+ * // manual x-www-form-urlencoded
+ * request.post('/user')
+ * .type('form')
+ * .send('name=tj')
+ * .end(callback)
+ *
+ * // auto x-www-form-urlencoded
+ * request.post('/user')
+ * .type('form')
+ * .send({ name: 'tj' })
+ * .end(callback)
+ *
+ * // defaults to x-www-form-urlencoded
+ * request.post('/user')
+ * .send('name=tobi')
+ * .send('species=ferret')
+ * .end(callback)
+ *
+ * @param {String|Object} data
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.send = function(data){
+ var obj = isObject(data);
+ var type = this.getHeader('Content-Type');
+
+ // merge
+ if (obj && isObject(this._data)) {
+ for (var key in data) {
+ this._data[key] = data[key];
+ }
+ } else if ('string' == typeof data) {
+ if (!type) this.type('form');
+ type = this.getHeader('Content-Type');
+ if ('application/x-www-form-urlencoded' == type) {
+ this._data = this._data
+ ? this._data + '&' + data
+ : data;
+ } else {
+ this._data = (this._data || '') + data;
+ }
+ } else {
+ this._data = data;
+ }
+
+ if (!obj) return this;
+ if (!type) this.type('json');
+ return this;
+};
+
+/**
+ * Invoke the callback with `err` and `res`
+ * and handle arity check.
+ *
+ * @param {Error} err
+ * @param {Response} res
+ * @api private
+ */
+
+Request.prototype.callback = function(err, res){
+ var fn = this._callback;
+ this.clearTimeout();
+ if (2 == fn.length) return fn(err, res);
+ if (err) return this.emit('error', err);
+ fn(res);
+};
+
+/**
+ * Invoke callback with x-domain error.
+ *
+ * @api private
+ */
+
+Request.prototype.crossDomainError = function(){
+ var err = new Error('Origin is not allowed by Access-Control-Allow-Origin');
+ err.crossDomain = true;
+ this.callback(err);
+};
+
+/**
+ * Invoke callback with timeout error.
+ *
+ * @api private
+ */
+
+Request.prototype.timeoutError = function(){
+ var timeout = this._timeout;
+ var err = new Error('timeout of ' + timeout + 'ms exceeded');
+ err.timeout = timeout;
+ this.callback(err);
+};
+
+/**
+ * Enable transmission of cookies with x-domain requests.
+ *
+ * Note that for this to work the origin must not be
+ * using "Access-Control-Allow-Origin" with a wildcard,
+ * and also must set "Access-Control-Allow-Credentials"
+ * to "true".
+ *
+ * @api public
+ */
+
+Request.prototype.withCredentials = function(){
+ this._withCredentials = true;
+ return this;
+};
+
+/**
+ * Initiate request, invoking callback `fn(res)`
+ * with an instanceof `Response`.
+ *
+ * @param {Function} fn
+ * @return {Request} for chaining
+ * @api public
+ */
+
+Request.prototype.end = function(fn){
+ var self = this;
+ var xhr = this.xhr = getXHR();
+ var query = this._query.join('&');
+ var timeout = this._timeout;
+ var data = this._formData || this._data;
+
+ // store callback
+ this._callback = fn || noop;
+
+ // state change
+ xhr.onreadystatechange = function(){
+ if (4 != xhr.readyState) return;
+ if (0 == xhr.status) {
+ if (self.aborted) return self.timeoutError();
+ return self.crossDomainError();
+ }
+ self.emit('end');
+ };
+
+ // progress
+ if (xhr.upload) {
+ xhr.upload.onprogress = function(e){
+ e.percent = e.loaded / e.total * 100;
+ self.emit('progress', e);
+ };
+ }
+
+ // timeout
+ if (timeout && !this._timer) {
+ this._timer = setTimeout(function(){
+ self.abort();
+ }, timeout);
+ }
+
+ // querystring
+ if (query) {
+ query = request.serializeObject(query);
+ this.url += ~this.url.indexOf('?')
+ ? '&' + query
+ : '?' + query;
+ }
+
+ // initiate request
+ xhr.open(this.method, this.url, true);
+
+ // CORS
+ if (this._withCredentials) xhr.withCredentials = true;
+
+ // body
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
+ // serialize stuff
+ var serialize = request.serialize[this.getHeader('Content-Type')];
+ if (serialize) data = serialize(data);
+ }
+
+ // set header fields
+ for (var field in this.header) {
+ if (null == this.header[field]) continue;
+ xhr.setRequestHeader(field, this.header[field]);
+ }
+
+ // send stuff
+ this.emit('request', this);
+ xhr.send(data);
+ return this;
+};
+
+/**
+ * Expose `Request`.
+ */
+
+request.Request = Request;
+
+/**
+ * Issue a request:
+ *
+ * Examples:
+ *
+ * request('GET', '/users').end(callback)
+ * request('/users').end(callback)
+ * request('/users', callback)
+ *
+ * @param {String} method
+ * @param {String|Function} url or callback
+ * @return {Request}
+ * @api public
+ */
+
+function request(method, url) {
+ // callback
+ if ('function' == typeof url) {
+ return new Request('GET', method).end(url);
+ }
+
+ // url first
+ if (1 == arguments.length) {
+ return new Request('GET', method);
+ }
+
+ return new Request(method, url);
+}
+
+/**
+ * GET `url` with optional callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed|Function} data or fn
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.get = function(url, data, fn){
+ var req = request('GET', url);
+ if ('function' == typeof data) fn = data, data = null;
+ if (data) req.query(data);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * HEAD `url` with optional callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed|Function} data or fn
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.head = function(url, data, fn){
+ var req = request('HEAD', url);
+ if ('function' == typeof data) fn = data, data = null;
+ if (data) req.send(data);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * DELETE `url` with optional callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.del = function(url, fn){
+ var req = request('DELETE', url);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * PATCH `url` with optional `data` and callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed} data
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.patch = function(url, data, fn){
+ var req = request('PATCH', url);
+ if ('function' == typeof data) fn = data, data = null;
+ if (data) req.send(data);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * POST `url` with optional `data` and callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed} data
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.post = function(url, data, fn){
+ var req = request('POST', url);
+ if ('function' == typeof data) fn = data, data = null;
+ if (data) req.send(data);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * PUT `url` with optional `data` and callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed|Function} data or fn
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+request.put = function(url, data, fn){
+ var req = request('PUT', url);
+ if ('function' == typeof data) fn = data, data = null;
+ if (data) req.send(data);
+ if (fn) req.end(fn);
+ return req;
+};
+
+/**
+ * Expose `request`.
+ */
+
+module.exports = request;
+
+},{"emitter":112,"reduce":113}],112:[function(require,module,exports){
+
+/**
+ * Expose `Emitter`.
+ */
+
+module.exports = Emitter;
+
+/**
+ * Initialize a new `Emitter`.
+ *
+ * @api public
+ */
+
+function Emitter(obj) {
+ if (obj) return mixin(obj);
+};
+
+/**
+ * Mixin the emitter properties.
+ *
+ * @param {Object} obj
+ * @return {Object}
+ * @api private
+ */
+
+function mixin(obj) {
+ for (var key in Emitter.prototype) {
+ obj[key] = Emitter.prototype[key];
+ }
+ return obj;
+}
+
+/**
+ * Listen on the given `event` with `fn`.
+ *
+ * @param {String} event
+ * @param {Function} fn
+ * @return {Emitter}
+ * @api public
+ */
+
+Emitter.prototype.on =
+Emitter.prototype.addEventListener = function(event, fn){
+ this._callbacks = this._callbacks || {};
+ (this._callbacks[event] = this._callbacks[event] || [])
+ .push(fn);
+ return this;
+};
+
+/**
+ * Adds an `event` listener that will be invoked a single
+ * time then automatically removed.
+ *
+ * @param {String} event
+ * @param {Function} fn
+ * @return {Emitter}
+ * @api public
+ */
+
+Emitter.prototype.once = function(event, fn){
+ var self = this;
+ this._callbacks = this._callbacks || {};
+
+ function on() {
+ self.off(event, on);
+ fn.apply(this, arguments);
+ }
+
+ on.fn = fn;
+ this.on(event, on);
+ return this;
+};
+
+/**
+ * Remove the given callback for `event` or all
+ * registered callbacks.
+ *
+ * @param {String} event
+ * @param {Function} fn
+ * @return {Emitter}
+ * @api public
+ */
+
+Emitter.prototype.off =
+Emitter.prototype.removeListener =
+Emitter.prototype.removeAllListeners =
+Emitter.prototype.removeEventListener = function(event, fn){
+ this._callbacks = this._callbacks || {};
+
+ // all
+ if (0 == arguments.length) {
+ this._callbacks = {};
+ return this;
+ }
+
+ // specific event
+ var callbacks = this._callbacks[event];
+ if (!callbacks) return this;
+
+ // remove all handlers
+ if (1 == arguments.length) {
+ delete this._callbacks[event];
+ return this;
+ }
+
+ // remove specific handler
+ var cb;
+ for (var i = 0; i < callbacks.length; i++) {
+ cb = callbacks[i];
+ if (cb === fn || cb.fn === fn) {
+ callbacks.splice(i, 1);
+ break;
+ }
+ }
+ return this;
+};
+
+/**
+ * Emit `event` with the given args.
+ *
+ * @param {String} event
+ * @param {Mixed} ...
+ * @return {Emitter}
+ */
+
+Emitter.prototype.emit = function(event){
+ this._callbacks = this._callbacks || {};
+ var args = [].slice.call(arguments, 1)
+ , callbacks = this._callbacks[event];
+
+ if (callbacks) {
+ callbacks = callbacks.slice(0);
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
+ callbacks[i].apply(this, args);
+ }
+ }
+
+ return this;
+};
+
+/**
+ * Return array of callbacks for `event`.
+ *
+ * @param {String} event
+ * @return {Array}
+ * @api public
+ */
+
+Emitter.prototype.listeners = function(event){
+ this._callbacks = this._callbacks || {};
+ return this._callbacks[event] || [];
+};
+
+/**
+ * Check if this emitter has `event` handlers.
+ *
+ * @param {String} event
+ * @return {Boolean}
+ * @api public
+ */
+
+Emitter.prototype.hasListeners = function(event){
+ return !! this.listeners(event).length;
+};
+
+},{}],113:[function(require,module,exports){
+
+/**
+ * Reduce `arr` with `fn`.
+ *
+ * @param {Array} arr
+ * @param {Function} fn
+ * @param {Mixed} initial
+ *
+ * TODO: combatible error handling?
+ */
+
+module.exports = function(arr, fn, initial){
+ var idx = 0;
+ var len = arr.length;
+ var curr = arguments.length == 3
+ ? initial
+ : arr[idx++];
+
+ while (idx < len) {
+ curr = fn.call(null, curr, arr[idx], ++idx, arr);
+ }
+
+ return curr;
+};
+},{}]},{},[1])(1)
+});
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJpbmRleC5qcyIsImxpYi9hdXRoLmpzIiwibGliL2NsaWVudC5qcyIsImxpYi9oZWxwZXJzLmpzIiwibGliL2h0dHAuanMiLCJsaWIvcmVzb2x2ZXIuanMi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gZm9yICh2YXIgaSA9IDA7IGkgPCBhdXRob3JpemF0aW9ucy5sZW5ndGg7IGkrKykge1xuICAgICAgICB2YXIgYXV0aCA9IGF1dGhvcml6YXRpb25zW2ldO1xuXG4gICAgICAgIGZvciAobmFtZSBpbiBhdXRoKSB7XG4gICAgICAgICAgZm9yIChrZXkgaW4gdGhpcy5hdXRoeikge1xuICAgICAgICAgICAgaWYgKGtleSA9PT0gbmFtZSkge1xuICAgICAgICAgICAgICB2YWx1ZSA9IHRoaXMuYXV0aHpba2V5XTtcbiAgICAgICAgICAgICAgcmVzdWx0ID0gdmFsdWUuYXBwbHkob2JqLCBhdXRob3JpemF0aW9ucyk7XG5cbiAgICAgICAgICAgICAgaWYgKHJlc3VsdCA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICAgIHN0YXR1cyA9IHRydWU7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgLy8gMS4yIHN1cHBvcnRcbiAgICAgIGZvciAobmFtZSBpbiBhdXRob3JpemF0aW9ucykge1xuICAgICAgICBmb3IgKGtleSBpbiB0aGlzLmF1dGh6KSB7XG4gICAgICAgICAgaWYgKGtleSA9PT0gbmFtZSkge1xuICAgICAgICAgICAgdmFsdWUgPSB0aGlzLmF1dGh6W2tleV07XG4gICAgICAgICAgICByZXN1bHQgPSB2YWx1ZS5hcHBseShvYmosIGF1dGhvcml6YXRpb25zKTtcblxuICAgICAgICAgICAgaWYgKHJlc3VsdCA9PT0gdHJ1ZSkge1xuICAgICAgICAgICAgICBzdGF0dXMgPSB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgfVxuXG4gIHJldHVybiBzdGF0dXM7XG59O1xuXG4vKipcbiAqIEFwaUtleUF1dGhvcml6YXRpb24gYWxsb3dzIGEgcXVlcnkgc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dXAuaGVscCkpIHtcbiAgICAgICAgICBvcGVyYXRpb25Hcm91cC5oZWxwID0gXy5iaW5kKHNlbGYuaGVscCwgb3BlcmF0aW9uR3JvdXApO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gYmluZCB0byB0aGUgYXBpcyBvYmplY3RcbiAgICAgICAgc2VsZi5hcGlzW2FwaVByb3BlcnR5XVtvcGVyYXRpb25JZF0gPSBvcGVyYXRpb25Hcm91cFtvcGVyYXRpb25JZF09IF8uYmluZChvcGVyYXRpb25PYmplY3QuZXhlY3V0ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcGVyYXRpb25PYmplY3QpO1xuICAgICAgICBzZWxmLmFwaXNbYXBpUHJvcGVydHldW29wZXJhdGlvbklkXS5oZWxwID0gb3BlcmF0aW9uR3JvdXBbb3BlcmF0aW9uSWRdLmhlbHAgPSBfLmJpbmQob3BlcmF0aW9uT2JqZWN0LmhlbHAsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcGVyYXRpb25PYmplY3QpO1xuICAgICAgICBzZWxmLmFwaXNbYXBpUHJvcGVydHldW29wZXJhdGlvbklkXS5hc0N1cmwgPSBvcGVyYXRpb25Hcm91cFtvcGVyYXRpb25JZF0uYXNDdXJsID0gXy5iaW5kKG9wZXJhdGlvbk9iamVjdC5hc0N1cmwsXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3BlcmF0aW9uT2JqZWN0KTtcblxuICAgICAgICBvcGVyYXRpb25Hcm91cC5hcGlzW29wZXJhdGlvbklkXSA9IG9wZXJhdGlvbkdyb3VwLm9wZXJhdGlvbnNbb3B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iwgc3dhZ2dlciA9IHJlc3BvbnNlLm9iajtcblxuICAgICAgICAgIGlmKHN3YWdnZXIgPT09IG51bGwgfHwgT2JqZWN0LmtleXMoc3dhZ2dlcikubGVuZ3RoID09PSAwKSB7XG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICBzd2FnZ2VyID0gSlNPTi5wYXJzZShyZXNwb25zZS5kYXRhKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlKXtcbiAgICAgICAgICAgICAgc3dhZ2dlciA9IHt9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIHByb2Nlc3NlZENhbGxzICs9IDE7XG5cbiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgb3B0Lmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICB2YXIgcGF0aCA9IG9wdFtpXTtcbiAgICAgICAgICAgIGlmKHBhdGggPT0gbnVsbCkge1xuICAgICAgICAgICAgICByZXNvbHZlZFJlZnNbbmFtZV0gPSB7XG4gICAgICAgICAgICAgICAgbmFtZTogbmFtZSxcbiAgICAgICAgICAgICAgICBvYmo6IHN3YWdnZXJcbiAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICB2YXIgbG9jYXRpb24gPSBzd2FnZ2VyLCBwYXJ0cyA9IHBhdGguc3BsaXQoJy8nKTtcbiAgICAgICAgICAgICAgZm9yIChqID0gMDsgaiA8IHBhcnRzLmxlbmd0aDsgaisrKSB7XG4gICAgICAgICAgICAgICAgdmFyIHNlZ21lbnQgPSBwYXJ0c1tqXTtcbiAgICAgICAgICAgICAgICBpZihzZWdtZW50LmluZGV4T2YoJ34xJykgIT09IC0xKSB7XG4gICAgICAgICAgICAgICAgICBzZWdtZW50ID0gcGFydHNbal0ucmVwbGFjZSgvfjAvZywgJ34nKS5yZXBsYWNlKC9+MS9nLCAnLycpO1xuICAgICAgICAgICAgICAgICAgaWYoc2VnbWVudC5jaGFyQXQoMCkgIT09ICcvJykge1xuICAgICAgICAgICAgICAgICAgICBzZWdtZW50ID0gJy8nICsgc2VnbWVudDtcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIGxvY2F0aW9uID09PSAndW5kZWZpbmVkJykge1xuICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgaWYgKHNlZ21lbnQubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgICAgICAgbG9jYXRpb24gPSBsb2NhdGlvbltzZWdtZW50XTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgdmFyIHJlc29sdmVkID0gaG9zdCArICcjJyArIHBhdGgsIHJlc29sdmVkTmFtZSA9IHBhcnRzW2otMV07XG5cbiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBsb2NhdGlvbiAhPT0gJ3VuZGVmaW5lZCcpIHtcbiAgICAgICAgICAgICAgICByZXNvbHZlZFJlZnNbcmVzb2x2ZWRdID0ge1xuICAgICAgICAgICAgICAgICAgbmFtZTogcmVzb2x2ZWROYW1lLFxuICAgICAgICAgICAgICAgICAgb2JqOiBsb2NhdGlvblxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdW5yZXNvbHZlZFJlZnNbcmVzb2x2ZWRdID0gbnVsbDtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAocHJvY2Vzc2VkQ2FsbHMgPT09IGV4cGVjdGVkQ2FsbHMpIHtcbiAgICAgICAgICAgIHNlbGYuZmluaXNoKHNwZWMsIHJlc29sdXRpb25UYWJsZSwgcmVzb2x2ZWRSZWZzLCB1bnJlc29sdmVkUmVmcywgY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uID0ge307XG4gICAgICB2YXIgZGVmaW5pdGlvbiA9IG9iai5hdXRob3JpemF0aW9uc1tuYW1lXTtcbiAgICAgIGlmKGRlZmluaXRpb24udHlwZSA9PT0gJ2FwaUtleScpIHtcbiAgICAgICAgc2VjdXJpdHlEZWZpbml0aW9uLnR5cGUgPSAnYXBpS2V5JztcbiAgICAgICAgc2VjdXJpdHlEZWZpbml0aW9uLmluID0gZGVmaW5pdGlvbi5wYXNzQXM7XG4gICAgICAgIHNlY3VyaXR5RGVmaW5pdGlvbi5uYW1lID0gZGVmaW5pdGlvbi5rZXluYW1lIHx8IG5hbWU7XG4gICAgICAgIGlzVmFsaWQgPSB0cnVlO1xuICAgICAgfVxuICAgICAgZWxzZSBpZihkZWZpbml0aW9uLnR5cGUgPT09ICdvYXV0aDInKSB7XG4gICAgICAgIHZhciBleGlzdGluZ1Njb3BlcyA9IGRlZmluaXRpb24uc2NvcGVzIHx8IFtdO1xuICAgICAgICB2YXIgc2NvcGVzID0ge307XG4gICAgICAgIHZhciBpO1xuICAgICAgICBmb3IoaSBpbiBleGlzdGluZ1Njb3Blcykge1xuICAgICAgICAgIHZhciBzY29wZSA9IGV4aXN0aW5nU2NvcGVzW2ldO1xuICAgICAgICAgIHNjb3Blc1tzY29wZS5zY29wZV0gPSBzY29wZS5kZXNjcmlwdGlvbjtcbiAgICAgICAgfVxuICAgICAgICBzZWN1cml0eURlZmluaXRpb24udHlwZSA9ICdvYXV0aDInO1xuICAgICAgICBpZihpID4gMCkge1xuICAgICAgICAgIHNlY3VyaXR5RGVmaW5pdGlvbi5zY29wZXMgPSBzY29wZXM7ICAgICAgICBcbiAgICAgICAgfVxuICAgICAgICBpZihkZWZpbml0aW9uLmdyYW50VHlwZXMpIHtcbiAgICAgICAgICBpZihkZWZpbml0aW9uLmdyYW50VHlwZXMuaW1wbGljaXQpIHtcbiAgICAgICAgICAgIHZhciBpbXBsaWNpdCA9IGRlZmluaXRpb24uZ3JhbnRUeXBlcy5pbXBsaWNpdDtcbiAgICAgICAgICAgIHNlY3VyaXR5RGVmaW5pdGlvbi5mbG93ID0gJ2ltcGxpY2l0JztcbiAgICAgICAgICAgIHNlY3VyaXR5RGVmaW5pdGlvbi5hdXRob3JpemF0aW9uVXJsID0gaW1wbGljaXQubG9naW5FbmRwb2ludDtcbiAgICAgICAgICAgIGlzVmFsaWQgPSB0cnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZihkZWZpbml0aW9uLmdyYW50VHlwZXMuYXV0aG9yaXphdGlvbl9jb2RlKSB7XG4gICAgICAgICAgICBpZighc2VjdXJpdHlEZWZpbml0aW9uLmZsb3cpIHtcbiAgICAgICAgICAgICAgLy8gY2Fubm90IHNldCBpZiBmbG93IGlzIGFscmVhZHkgZGVmaW5lZFxuICAgICAgICAgICAgICB2YXIgYXV0aENvZGUgPSBkZWZpbml0aW9uLmdyYW50VHlwZXMuYXV0aG9yaXphdGlvbl9jb2RlO1xuICAgICAgICAgICAgICBzZWN1cml0eURlZmluaXRpb24uZmxvdyA9ICdhY2Nlc3NDb2RlJztcbiAgICAgICAgICAgICAgc2VjdXJpdHlEZWZpbml0aW9uLmF1dGhvcml6YXRpb25VcmwgPSBhdXRoQ29kZS50b2tlblJlcXVlc3RFbmRwb2ludC51cmw7XG4gICAgICAgICAgICAgIHNlY3VyaXR5RGVmaW5pdGlvbi50b2tlblVybCA9IGF1dGhDb2RlLnRva2VuRW5kcG9pbnQudXJsO1xuICAgICAgICAgICAgICBpc1ZhbGlkID0gdHJ1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICAgIGlmKGlzVmFsaWQpIHtcbiAgICAgICAgc3dhZ2dlci5zZWN1cml0eURlZmluaXRpb25zID0gc3dhZ2dlci5zZWN1cml0eURlZmluaXRpb25zIHx8IHt9O1xuICAgICAgICBzd2FnZ2VyLnNlY3VyaXR5RGVmaW5pdGlvbnNbbmFtZV0gPSBzZWN1cml0eURlZmlu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ByZXR1cm4gY29va2llc3RyO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzIGluc3RhbmNlb2YgQ29va2llKSB7XG4gICAgICAgICAgICB0aGlzLm5hbWUgPSBudWxsO1xuICAgICAgICAgICAgdGhpcy52YWx1ZSA9IG51bGw7XG4gICAgICAgICAgICB0aGlzLmV4cGlyYXRpb25fZGF0ZSA9IEluZmluaXR5O1xuICAgICAgICAgICAgdGhpcy5wYXRoID0gU3RyaW5nKHJlcXVlc3RfcGF0aCB8fCBcIi9cIik7XG4gICAgICAgICAgICB0aGlzLmV4cGxpY2l0X3BhdGggPSBmYWxzZTtcbiAgICAgICAgICAgIHRoaXMuZG9tYWluID0gcmVxdWVzdF9kb21haW4gfHwgbnVsbDtcbiAgICAgICAgICAgIHRoaXMuZXhwbGljaXRfZG9tYWluID0gZmFsc2U7XG4gICAgICAgICAgICB0aGlzLnNlY3VyZSA9IGZhbHNlOyAvL2hvdyB0byBkZWZpbmUgZGVmYXVsdD9cbiAgICAgICAgICAgIHRoaXMubm9zY3JpcHQgPSBmYWxzZTsgLy9odHRwb25seVxuICAgICAgICAgICAgaWYgKGNvb2tpZXN0cikge1xuICAgICAgICAgICAgICAgIHRoaXMucGFyc2UoY29va2llc3RyLCByZXF1ZXN0X2RvbWFpbiwgcmVxdWVzdF9wYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybiB0aGlzO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBuZXcgQ29va2llKGNvb2tpZXN0cik7XG4gICAgfVxuICAgIGV4cG9ydHMuQ29va2llID0gQ29va2llO1xuXG4gICAgQ29va2llLnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkge1xuICAgICAgICB2YXIgc3RyID0gW3RoaXMubmFtZSArIFwiPVwiICsgdGhpcy52YWx1ZV07XG4gICAgICAgIGlmICh0aGlzLmV4cGlyYXRpb25fZGF0ZSAhPT0gSW5maW5pdHkpIHtcbiAgICAgICAgICAgIHN0ci5wdXNoKFwiZXhwaXJlcz1cIiArIChuZXcgRGF0ZSh0aGlzLmV4cGlyYXRpb25fZGF0ZSkpLnRvR01UU3RyaW5nKCkpO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLmRvbWFpbikge1xuICAgICAgICAgICAgc3RyLnB1c2goXCJkb21haW49XCIgKyB0aGlzLmRvbWFpbik7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHRoaXMucGF0aCkge1xuICAgICAgICAgICAgc3RyLnB1c2goXCJwYXRoPVwiICsgdGhpcy5wYXRoKTtcbiAgICAgICAgfVxuICAgICAgICBpZiAodGhpcy5zZWN1cmUpIHtcbiAgICAgICAgICAgIHN0ci5wdXNoKFwic2VjdXJlXCIpO1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLm5vc2NyaXB0KSB7XG4gICAgICAgICAgICBzdHIucHVzaChcImh0dHBvbmx5XCIpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBzdHIuam9pbihcIjsgXCIpO1xuICAgIH07XG5cbiAgICBDb29raWUucHJvdG90eXBlLnRvVmFsdWVTdHJpbmcgPSBmdW5jdGlvbiB0b1ZhbHVlU3RyaW5nKCkge1xuICAgICAgICByZXR1cm4gdGhpcy5uYW1lICsgXCI9XCIgKyB0aGlzLnZhbHVlO1xuICAgIH07XG5cbiAgICB2YXIgY29va2llX3N0cl9zcGxpdHRlciA9IC9bOl0oPz1cXHMqW2EtekEtWjAtOV9cXC1dK1xccypbPV0pL2c7XG4gICAgQ29va2llLnByb3RvdHlwZS5wYXJzZSA9IGZ1bmN0aW9uIHBhcnNlKHN0ciwgcmVxdWVzdF9kb21haW4sIHJlcXVlc3RfcGF0aCkge1xuICAgICAgICBpZiAodGhpcyBpbnN0YW5jZW9mIENvb2tpZSkge1xuICAgICAgICAgICAgdmFyIHBhcnRzID0gc3RyLnNwbGl0KFwiO1wiKS5maWx0ZXIoZnVuY3Rpb24gKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiAhIXZhbHVlO1xuICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgIHBhaXIgPSBwYXJ0c1swXS5tYXRjaCgvKFtePV0rKT0oW1xcc1xcU10qKS8pLFxuICAgICAgICAgICAgICAgIGtleSA9IHBhaXJbMV0sXG4gICAgICAgICAgICAgICAgdmFsdWUgPSBwYWlyWzJdLFxuICAgICAgICAgICAgICAgIGk7XG4gICAgICAgICAgICB0aGlzLm5hbWUgPSBrZXk7XG4gICAgICAgICAgICB0aGlzLnZhbHVlID0gdmFsdWU7XG5cbiAgICAgICAgICAgIGZvciAoaSA9IDE7IGkgPCBwYXJ0cy5sZW5ndGg7IGkgKz0gMSkge1xuICAgICAgICAgICAgICAgIHBhaXIgPSBwYXJ0c1tpXS5tYXRjaCgvKFtePV0rKSg/Oj0oW1xcc1xcU10qKSk/Lyk7XG4gICAgICAgICAgICAgICAga2V5ID0gcGFpclsxXS50cmltKCkudG9Mb3dlckNhc2UoKTtcbiAgICAgICAgICAgICAgICB2YWx1ZSA9IHBhaXJbMl07XG4gICAgICAgICAgICAgICAgc3dpdGNoIChrZXkpIHtcbiAgICAgICAgICAgICAgICBjYXNlIFwiaHR0cG9ubHlcIjpcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5ub3NjcmlwdCA9IHRydWU7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIGNhc2UgXCJleHBpcmVzXCI6XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZXhwaXJhdGlvbl9kYXRlID0gdmFsdWUgP1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIE51bWJlcihEYXRlLnBhcnNlKHZhbHVlKSkgOlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIEluZmluaXR5O1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFwicGF0aFwiOlxuICAgICAgICAgICAgICAgICAgICB0aGlzLnBhdGggPSB2YWx1ZSA/XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFsdWUudHJpbSgpIDpcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIlwiO1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmV4cGxpY2l0X3BhdGggPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFwiZG9tYWluXCI6XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuZG9tYWluID0gdmFsdWUgP1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlLnRyaW0oKSA6XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgXCJcIjtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5leHBsaWNpdF9kb21haW4gPSAhIXRoaXMuZG9tYWluO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFwic2VjdXJlXCI6XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuc2VjdXJlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoIXRoaXMuZXhwbGljaXRfcGF0aCkge1xuICAgICAgICAgICAgICAgdGhpcy5wYXRoID0gcmVxdWVzdF9wYXRoIHx8IFwiL1wiO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCF0aGlzLmV4cGxpY2l0X2RvbWFpbikge1xuICAgICAgICAgICAgICAgdGhpcy5kb21haW4gPSByZXF1ZXN0X2RvbWFpbjtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIG5ldyBDb29raWUoKS5wYXJzZShzdHIsIHJlcXVlc3RfZG9tYWluLCByZXF1ZXN0X3BhdGgpO1xuICAgIH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ICAgICB2YXIgY29va2llX2RvbWFpbiA9IHRoaXMuZG9tYWluICYmIHRoaXMuZG9tYWluLnJlcGxhY2UoL15bXFwuXS8sJycpO1xuICAgICAgICBpZiAoY29va2llX2RvbWFpbiA9PT0gYWNjZXNzX2RvbWFpbikge1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKGNvb2tpZV9kb21haW4pIHtcbiAgICAgICAgICAgIGlmICghdGhpcy5leHBsaWNpdF9kb21haW4pIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7IC8vIHdlIGFscmVhZHkgY2hlY2tlZCBpZiB0aGUgZG9tYWlucyB3ZXJlIGV4YWN0bHkgdGhlIHNhbWVcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciB3aWxkY2FyZCA9IGFjY2Vzc19kb21haW4uaW5kZXhPZihjb29raWVfZG9tYWluKTtcbiAgICAgICAgICAgIGlmICh3aWxkY2FyZCA9PT0gLTEgfHwgd2lsZGNhcmQgIT09IGFjY2Vzc19kb21haW4ubGVuZ3RoIC0gY29va2llX2RvbWFpbi5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICB9O1xuXG4gICAgZnVuY3Rpb24gQ29va2llSmFyKCkge1xuICAgICAgICB2YXIgY29va2llcywgY29va2llc19saXN0LCBjb2xsaWRhYmxlX2Nvb2tpZTtcbiAgICAgICAgaWYgKHRoaXMgaW5zdGFuY2VvZiBDb29raWVKYXIpIHtcbiAgICAgICAgICAgIGNvb2tpZXMgPSBPYmplY3QuY3JlYXRlKG51bGwpOyAvL25hbWU6IFtDb29raWVdXG5cbiAgICAgICAgICAgIHRoaXMuc2V0Q29va2llID0gZnVuY3Rpb24gc2V0Q29va2llKGNvb2tpZSwgcmVxdWVzdF9kb21haW4sIHJlcXVlc3RfcGF0aCkge1xuICAgICAgICAgICAgICAgIHZhciByZW1vdmUsIGk7XG4gICAgICAgICAgICAgICAgY29va2llID0gbmV3IENvb2tpZShjb29raWUsIHJlcXVlc3RfZG9tYWluLCByZXF1ZXN0X3BhdGgpO1xuICAgICAgICAgICAgICAgIC8vRGVsZXRlIHRoZSBjb29raWUgaWYgdGhlIHNldCBpcyBwYXN0IHRoZSBjdXJyZW50IHRpbWVcbiAgICAgICAgICAgICAgICByZW1vdmUgPSBjb29raWUuZXhwaXJhdGlvbl9kYXRlIDw9IERhdGUubm93KCk7XG4gICAgICAgICAgICAgICAgaWYgKGNvb2tpZXNbY29va2llLm5hbWVdICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgY29va2llc19saXN0ID0gY29va2llc1tjb29raWUubmFtZV07XG4gICAgICAgICAgICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBjb29raWVzX2xpc3QubGVuZ3RoOyBpICs9IDEpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbGxpZGFibGVfY29va2llID0gY29va2llc19saXN0W2ldO1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvbGxpZGFibGVfY29va2llLmNvbGxpZGVzV2l0aChjb29raWUpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHJlbW92ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb29raWVzX2xpc3Quc3BsaWNlKGksIDEpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29va2llc19saXN0Lmxlbmd0aCA9PT0gMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVsZXRlIGNvb2tpZXNbY29va2llLm5hbWVdO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgY29va2llc19saXN0W2ldID0gY29va2llO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjb29raWU7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgaWYgKHJlbW92ZSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIGNvb2tpZXNfbGlzdC5wdXNoKGNvb2tpZSk7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBjb29raWU7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGlmIChyZW1vdmUpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjb29raWVzW2Nvb2tpZS5uYW1lXSA9IFtjb29raWVdO1xuICAgICAgICAgICAgICAgIHJldHVybiBjb29raWVzW2Nvb2tpZS5uYW1lXTtcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICAvL3JldHVybnMgYSBjb29raWVcbiAgICAgICAgICAgIHRoaXMuZ2V0Q29va2llID0gZnVuY3Rpb24gZ2V0Q29va2llKGNvb2tpZV9uYW1lLCBhY2Nlc3NfaW5mbykge1xuICAgICAgICAgICAgICAgIHZhciBjb29raWUsIGk7XG4gICAgICAgICAgICAgICAgY29va2llc19saXN0ID0gY29va2llc1tjb29raWVfbmFtZV07XG4gICAgICAgICAgICAgICAgaWYgKCFjb29raWVzX2xpc3QpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgY29va2llc19saXN0Lmxlbmd0aDsgaSArPSAxKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvb2tpZSA9IGNvb2tpZXNfbGlzdFtpXTtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGNvb2tpZS5leHBpcmF0aW9uX2RhdGUgPD0gRGF0ZS5ub3coKSkge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvb2tpZXNfbGlzdC5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZWxldGUgY29va2llc1tjb29raWUubmFtZV07XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICBpZiAoY29va2llLm1hdGNoZXMoYWNjZXNzX2luZm8pKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gY29va2llO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIC8vcmV0dXJucyBhIGxpc3Qgb2YgY29va2llc1xuICAgICAgICAgICAgdGhpcy5nZXRDb29raWVzID0gZnVuY3Rpb24gZ2V0Q29va2llcyhhY2Nlc3NfaW5mbykge1xuICAgICAgICAgICAgICAgIHZhciBtYXRjaGVzID0gW10sIGNvb2tpZV9uYW1lLCBjb29raWU7XG4gICAgICAgICAgICAgICAgZm9yIChjb29raWVfbmFtZSBpbiBjb29raWVzKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvb2tpZSA9IHRoaXMuZ2V0Q29va2llKGNvb2tpZV9uYW1lLCBhY2Nlc3NfaW5mbyk7XG4gICAgICAgICAgICAgICAgICAgIGlmIChjb29raWUpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoZXMucHVzaChjb29raWUpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIG1hdGNoZXMudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZygpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG1hdGNoZXMuam9pbihcIjpcIik7XG4gICAgICAgICAgICAgICAgfTtcbiAgICAgICAgICAgICAgICBtYXRjaGVzLnRvVmFsdWVTdHJpbmcgPSBmdW5jdGlvbiB0b1ZhbHVlU3RyaW5nKCkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gbWF0Y2hlcy5tYXAoZnVuY3Rpb24gKGMpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjLnRvVmFsdWVTdHJpbmcoKTtcbiAgICAgICAgICAgICAgICAgICAgfSkuam9pbignOycpO1xuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgcmV0dXJuIG1hdGNoZXM7XG4gICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICByZXR1cm4gdGhpcztcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gbmV3IENvb2tpZUphcigpO1xuICAgIH1cbiAgICBleHBvcnRzLkNvb2tpZUphciA9IENvb2tpZUphcjtcblxuICAgIC8vcmV0dXJucyBsaXN0IG9mIGNvb2tpZXMgdGhhdCB3ZXJlIHNldCBjb3JyZWN0bHkuIENvb2tpZXMgdGhhdCBhcmUgZXhwaXJlZCBhbmQgcmVtb3ZlZCBhcmUgbm90IHJldHVybmVkLlxuICAgIENvb2tpZUphci5wcm90b3R5cGUuc2V0Q29va2llcyA9IGZ1bmN0aW9uIHNldENvb2tpZXMoY29va2llcywgcmVxdWVzdF9kb21haW4sIHJlcXVlc3RfcGF0aCkge1xuICAgICAgICBjb29raWVzID0gQXJyYXkuaXNBcnJheShjb29raWVzKSA/XG4gICAgICAgICAgICAgICAgY29va2llcyA6XG4gICAgICAgICAgICAgICAgY29va2llcy5zcGxpdChjb29raWVfc3RyX3NwbGl0dGVyKTtcbiAgICAgICAgdmFyIHN1Y2Nlc3NmdWwgPSBbXSxcbiAgICAgICAgICAgI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AgICAgICEoa2V5ID09ICdjb25zdHJ1Y3RvcicgJiYgKGlzUHJvdG8gfHwgIWhhc093blByb3BlcnR5LmNhbGwob2JqZWN0LCBrZXkpKSkpIHtcbiAgICAgIHJlc3VsdC5wdXNoKGtleSk7XG4gICAgfVxuICB9XG4gIGlmIChzdXBwb3J0Lm5vbkVudW1TaGFkb3dzICYmIG9iamVjdCAhPT0gb2JqZWN0UHJvdG8pIHtcbiAgICB2YXIgdGFnID0gb2JqZWN0ID09PSBzdHJpbmdQcm90byA/IHN0cmluZ1RhZyA6IChvYmplY3QgPT09IGVycm9yUHJvdG8gPyBlcnJvclRhZyA6IG9ialRvU3RyaW5nLmNhbGwob2JqZWN0KSksXG4gICAgICAgIG5vbkVudW1zID0gbm9uRW51bVByb3BzW3RhZ10gfHwgbm9uRW51bVByb3BzW29iamVjdFRhZ107XG5cbiAgICBpZiAodGFnID09IG9iamVjdFRhZykge1xuICAgICAgcHJvdG8gPSBvYmplY3RQcm90bztcbiAgICB9XG4gICAgbGVuZ3RoID0gc2hhZG93UHJvcHMubGVuZ3RoO1xuICAgIHdoaWxlIChsZW5ndGgtLSkge1xuICAgICAga2V5ID0gc2hhZG93UHJvcHNbbGVuZ3RoXTtcbiAgICAgIHZhciBub25FbnVtID0gbm9uRW51bXNba2V5XTtcbiAgICAgIGlmICghKGlzUHJvdG8gJiYgbm9uRW51bSkgJiZcbiAgICAgICAgICAobm9uRW51bSA/IGhhc093blByb3BlcnR5LmNhbGwob2JqZWN0LCBrZXkpIDogb2JqZWN0W2tleV0gIT09IHByb3RvW2tleV0pKSB7XG4gICAgICAgIHJlc3VsdC5wdXNoKGtleSk7XG4gICAgICB9XG4gICAgfVxuICB9XG4gIHJldHVybiByZXN1bHQ7XG59XG5cbm1vZHVsZS5leHBvcnRzID0ga2V5c0luO1xuIiwidmFyIGJhc2VUb1N0cmluZyA9IHJlcXVpcmUoJy4uL2ludGVybmFsL2Jhc2VUb1N0cmluZycpO1xuXG4vKipcbiAqIFV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xuICogU2VuZCBgZGF0YWAsIGRlZmF1bHRpbmcgdGhlIGAudHlwZSgpYCB0byBcImpzb25cIiB3aGVuXG4gKiBhbiBvYmplY3QgaXMgZ2l2ZW4uXG4gKlxuICogRXhhbXBsZXM6XG4gKlxuICogICAgICAgLy8gcXVlcnlzdHJpbmdcbiAqICAgICAgIHJlcXVlc3QuZ2V0KCcvc2VhcmNoJylcbiAqICAgICAgICAgLmVuZChjYWxsYmFjaylcbiAqXG4gKiAgICAgICAvLyBtdWx0aXBsZSBkYXRhIFwid3JpdGVzXCJcbiAqICAgICAgIHJlcXVlc3QuZ2V0KCcvc2VhcmNoJylcbiAqICAgICAgICAgLnNlbmQoeyBzZWFyY2g6ICdxdWVyeScgfSlcbiAqICAgICAgICAgLnNlbmQoeyByYW5nZTogJzEuLjUnIH0pXG4gKiAgICAgICAgIC5zZW5kKHsgb3JkZXI6ICdkZXNjJyB9KVxuICogICAgICAgICAuZW5kKGNhbGxiYWNrKVxuICpcbiAqICAgICAgIC8vIG1hbnVhbCBqc29uXG4gKiAgICAgICByZXF1ZXN0LnBvc3QoJy91c2VyJylcbiAqICAgICAgICAgLnR5cGUoJ2pzb24nKVxuICogICAgICAgICAuc2VuZCgne1wibmFtZVwiOlwidGpcIn0pXG4gKiAgICAgICAgIC5lbmQoY2FsbGJhY2spXG4gKlxuICogICAgICAgLy8gYXV0byBqc29uXG4gKiAgICAgICByZXF1ZXN0LnBvc3QoJy91c2VyJylcbiAqICAgICAgICAgLnNlbmQoeyBuYW1lOiAndGonIH0pXG4gKiAgICAgICAgIC5lbmQoY2FsbGJhY2spXG4gKlxuICogICAgICAgLy8gbWFudWFsIHgtd3d3LWZvcm0tdXJsZW5jb2RlZFxuICogICAgICAgcmVxdWVzdC5wb3N0KCcvdXNlcicpXG4gKiAgICAgICAgIC50eXBlKCdmb3JtJylcbiAqICAgICAgICAgLnNlbmQoJ25hbWU9dGonKVxuICogICAgICAgICAuZW5kKGNhbGxiYWNrKVxuICpcbiAqIC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PSBmdW5jdGlvbihhcnIsIGZuLCBpbml0aWFsKXsgIFxuICB2YXIgaWR4ID0gMDtcbiAgdmFyIGxlbiA9IGFyci5sZW5ndGg7XG4gIHZhciBjdXJyID0gYXJndW1lbnRzLmxlbmd0aCA9PSAzXG4gICAgPyBpbml0aWFsXG4gICAgOiBhcnJbaWR4KytdO1xuXG4gIHdoaWxlIChpZHggPCBsZW4pIHtcbiAgICBjdXJyID0gZm4uY2FsbChudWxsLCBjdXJyLCBhcnJbaWR4XSwgKytpZHgsIGFycik7XG4gIH1cbiAgXG4gIHJldHVybiBjdXJyO1xufTsiXX0=
+
+'use strict';
+
+window.SwaggerUi = Backbone.Router.extend({
+
+ dom_id: 'swagger_ui',
+
+ // Attributes
+ options: null,
+ api: null,
+ headerView: null,
+ mainView: null,
+
+ // SwaggerUi accepts all the same options as SwaggerApi
+ initialize: function(options) {
+ options = options || {};
+
+ // Allow dom_id to be overridden
+ if (options.dom_id) {
+ this.dom_id = options.dom_id;
+ delete options.dom_id;
+ }
+
+ if (!options.supportedSubmitMethods){
+ options.supportedSubmitMethods = [
+ 'get',
+ 'put',
+ 'post',
+ 'delete',
+ 'head',
+ 'options',
+ 'patch'
+ ];
+ }
+
+ if (typeof options.oauth2RedirectUrl === 'string') {
+ window.oAuthRedirectUrl = options.redirectUrl;
+ }
+
+ // Create an empty div which contains the dom_id
+ if (! $('#' + this.dom_id).length){
+ $('body').append('<div id="' + this.dom_id + '"></div>') ;
+ }
+
+ this.options = options;
+
+ // set marked options
+ marked.setOptions({gfm: true});
+
+ // Set the callbacks
+ var that = this;
+ this.options.success = function() { return that.render(); };
+ this.options.progress = function(d) { return that.showMessage(d); };
+ this.options.failure = function(d) { return that.onLoadFailure(d); };
+
+ // Create view to handle the header inputs
+ this.headerView = new SwaggerUi.Views.HeaderView({el: $('#header')});
+
+ // Event handler for when the baseUrl/apiKey is entered by user
+ this.headerView.on('update-swagger-ui', function(data) {
+ return that.updateSwaggerUi(data);
+ });
+ },
+
+ // Set an option after initializing
+ setOption: function(option, value) {
+ this.options[option] = value;
+ },
+
+ // Get the value of a previously set option
+ getOption: function(option) {
+ return this.options[option];
+ },
+
+ // Event handler for when url/key is received from user
+ updateSwaggerUi: function(data){
+ this.options.url = data.url;
+ this.load();
+ },
+
+ // Create an api and render
+ load: function(){
+ // Initialize the API object
+ if (this.mainView) {
+ this.mainView.clear();
+ }
+ var url = this.options.url;
+ if (url && url.indexOf('http') !== 0) {
+ url = this.buildUrl(window.location.href.toString(), url);
+ }
+
+ this.options.url = url;
+ this.headerView.update(url);
+
+ this.api = new SwaggerClient(this.options);
+ },
+
+ // collapse all sections
+ collapseAll: function(){
+ Docs.collapseEndpointListForResource('');
+ },
+
+ // list operations for all sections
+ listAll: function(){
+ Docs.collapseOperationsForResource('');
+ },
+
+ // expand operations for all sections
+ expandAll: function(){
+ Docs.expandOperationsForResource('');
+ },
+
+ // This is bound to success handler for SwaggerApi
+ // so it gets called when SwaggerApi completes loading
+ render: function(){
+ this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
+ this.mainView = new SwaggerUi.Views.MainView({
+ model: this.api,
+ el: $('#' + this.dom_id),
+ swaggerOptions: this.options,
+ router: this
+ }).render();
+ this.showMessage();
+ switch (this.options.docExpansion) {
+ case 'full':
+ this.expandAll(); break;
+ case 'list':
+ this.listAll(); break;
+ default:
+ break;
+ }
+ this.renderGFM();
+
+ if (this.options.onComplete){
+ this.options.onComplete(this.api, this);
+ }
+
+ setTimeout(Docs.shebang.bind(this), 100);
+ },
+
+ buildUrl: function(base, url){
+ if (url.indexOf('/') === 0) {
+ var parts = base.split('/');
+ base = parts[0] + '//' + parts[2];
+ return base + url;
+ } else {
+ var endOfPath = base.length;
+
+ if (base.indexOf('?') > -1){
+ endOfPath = Math.min(endOfPath, base.indexOf('?'));
+ }
+
+ if (base.indexOf('#') > -1){
+ endOfPath = Math.min(endOfPath, base.indexOf('#'));
+ }
+
+ base = base.substring(0, endOfPath);
+
+ if (base.indexOf('/', base.length - 1 ) !== -1){
+ return base + url;
+ }
+
+ return base + '/' + url;
+ }
+ },
+
+ // Shows message on topbar of the ui
+ showMessage: function(data){
+ if (data === undefined) {
+ data = '';
+ }
+ $('#message-bar').removeClass('message-fail');
+ $('#message-bar').addClass('message-success');
+ $('#message-bar').html(data);
+ },
+
+ // shows message in red
+ onLoadFailure: function(data){
+ if (data === undefined) {
+ data = '';
+ }
+ $('#message-bar').removeClass('message-success');
+ $('#message-bar').addClass('message-fail');
+
+ var val = $('#message-bar').html(data);
+
+ if (this.options.onFailure) {
+ this.options.onFailure(data);
+ }
+
+ return val;
+ },
+
+ // Renders GFM for elements with 'markdown' class
+ renderGFM: function(){
+ $('.markdown').each(function(){
+ $(this).html(marked($(this).html()));
+ });
+ }
+
+});
+
+window.SwaggerUi.Views = {};
+
+// don't break backward compatibility with previous versions and warn users to upgrade their code
+(function(){
+ window.authorizations = {
+ add: function() {
+ warn('Using window.authorizations is deprecated. Please use SwaggerUi.api.clientAuthorizations.add().');
+
+ if (typeof window.swaggerUi === 'undefined') {
+ throw new TypeError('window.swaggerUi is not defined');
+ }
+
+ if (window.swaggerUi instanceof SwaggerUi) {
+ window.swaggerUi.api.clientAuthorizations.add.apply(window.swaggerUi.api.clientAuthorizations, arguments);
+ }
+ }
+ };
+
+ window.ApiKeyAuthorization = function() {
+ warn('window.ApiKeyAuthorization is deprecated. Please use SwaggerClient.ApiKeyAuthorization.');
+ SwaggerClient.ApiKeyAuthorization.apply(window, arguments);
+ };
+
+ window.PasswordAuthorization = function() {
+ warn('window.PasswordAuthorization is deprecated. Please use SwaggerClient.PasswordAuthorization.');
+ SwaggerClient.PasswordAuthorization.apply(window, arguments);
+ };
+
+ function warn(message) {
+ if ('console' in window && typeof window.console.warn === 'function') {
+ console.warn(message);
+ }
+ }
+})();
+
+
+// UMD
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define(['b'], function (b) {
+ return (root.SwaggerUi = factory(b));
+ });
+ } else if (typeof exports === 'object') {
+ // Node. Does not work with strict CommonJS, but
+ // only CommonJS-like enviroments that support module.exports,
+ // like Node.
+ module.exports = factory(require('b'));
+ } else {
+ // Browser globals
+ root.SwaggerUi = factory(root.b);
+ }
+}(this, function () {
+ return SwaggerUi;
+}));
+'use strict';
+
+SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to global SwaggerUi
+
+ events:{
+ 'click #apikey_button' : 'toggleApiKeyContainer',
+ 'click #apply_api_key' : 'applyApiKey'
+ },
+
+ initialize: function(opts){
+ this.options = opts || {};
+ this.router = this.options.router;
+ },
+
+ render: function(){
+ var template = this.template();
+ $(this.el).html(template(this.model));
+
+ return this;
+ },
+
+
+ applyApiKey: function(){
+ var keyAuth = new SwaggerClient.ApiKeyAuthorization(
+ this.model.name,
+ $('#input_apiKey_entry').val(),
+ this.model.in
+ );
+ this.router.api.clientAuthorizations.add(this.model.name, keyAuth);
+ this.router.load();
+ $('#apikey_container').show();
+ },
+
+ toggleApiKeyContainer: function(){
+ if ($('#apikey_container').length) {
+
+ var elem = $('#apikey_container').first();
+
+ if (elem.is(':visible')){
+ elem.hide();
+ } else {
+
+ // hide others
+ $('.auth_container').hide();
+ elem.show();
+ }
+ }
+ },
+
+ template: function(){
+ return Handlebars.templates.apikey_button_view;
+ }
+
+});
+'use strict';
+
+SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({
+
+
+ initialize: function (opts) {
+ this.options = opts || {};
+ this.router = this.options.router;
+ },
+
+ render: function(){
+ var template = this.template();
+ $(this.el).html(template(this.model));
+
+ return this;
+ },
+
+ events: {
+ 'click #basic_auth_button' : 'togglePasswordContainer',
+ 'click #apply_basic_auth' : 'applyPassword'
+ },
+
+ applyPassword: function(){
+ var username = $('.input_username').val();
+ var password = $('.input_password').val();
+ var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
+ this.router.api.clientAuthorizations.add(this.model.type, basicAuth);
+ this.router.load();
+ $('#basic_auth_container').hide();
+ },
+
+ togglePasswordContainer: function(){
+ if ($('#basic_auth_container').length) {
+ var elem = $('#basic_auth_container').show();
+ if (elem.is(':visible')){
+ elem.slideUp();
+ } else {
+ // hide others
+ $('.auth_container').hide();
+ elem.show();
+ }
+ }
+ },
+
+ template: function(){
+ return Handlebars.templates.basic_auth_button_view;
+ }
+
+});
+'use strict';
+
+SwaggerUi.Views.ContentTypeView = Backbone.View.extend({
+ initialize: function() {},
+
+ render: function(){
+ $(this.el).html(Handlebars.templates.content_type(this.model));
+
+ $('label[for=contentType]', $(this.el)).text('Response Content Type');
+
+ return this;
+ }
+});
+'use strict';
+
+SwaggerUi.Views.HeaderView = Backbone.View.extend({
+ events: {
+ 'click #show-pet-store-icon' : 'showPetStore',
+ 'click #show-wordnik-dev-icon' : 'showWordnikDev',
+ 'click #explore' : 'showCustom',
+ 'keyup #input_baseUrl' : 'showCustomOnKeyup',
+ 'keyup #input_apiKey' : 'showCustomOnKeyup'
+ },
+
+ initialize: function(){},
+
+ showPetStore: function(){
+ this.trigger('update-swagger-ui', {
+ url:'http://petstore.swagger.io/v2/swagger.json'
+ });
+ },
+
+ showWordnikDev: function(){
+ this.trigger('update-swagger-ui', {
+ url: 'http://api.wordnik.com/v4/resources.json'
+ });
+ },
+
+ showCustomOnKeyup: function(e){
+ if (e.keyCode === 13) {
+ this.showCustom();
+ }
+ },
+
+ showCustom: function(e){
+ if (e) {
+ e.preventDefault();
+ }
+
+ this.trigger('update-swagger-ui', {
+ url: $('#input_baseUrl').val(),
+ apiKey: $('#input_apiKey').val()
+ });
+ },
+
+ update: function(url, apiKey, trigger){
+ if (trigger === undefined) {
+ trigger = false;
+ }
+
+ $('#input_baseUrl').val(url);
+
+ //$('#input_apiKey').val(apiKey);
+ if (trigger) {
+ this.trigger('update-swagger-ui', {url:url});
+ }
+ }
+});
+
+'use strict';
+
+SwaggerUi.Views.MainView = Backbone.View.extend({
+ apisSorter : {
+ alpha : function(a,b){ return a.name.localeCompare(b.name); }
+ },
+ operationsSorters : {
+ alpha : function(a,b){ return a.path.localeCompare(b.path); },
+ method : function(a,b){ return a.method.localeCompare(b.method); }
+ },
+ initialize: function(opts){
+ var sorterOption, sorterFn, key, value;
+ opts = opts || {};
+
+ this.router = opts.router;
+
+ // Sort APIs
+ if (opts.swaggerOptions.apisSorter) {
+ sorterOption = opts.swaggerOptions.apisSorter;
+ if (_.isFunction(sorterOption)) {
+ sorterFn = sorterOption;
+ } else {
+ sorterFn = this.apisSorter[sorterOption];
+ }
+ if (_.isFunction(sorterFn)) {
+ this.model.apisArray.sort(sorterFn);
+ }
+ }
+ // Sort operations of each API
+ if (opts.swaggerOptions.operationsSorter) {
+ sorterOption = opts.swaggerOptions.operationsSorter;
+ if (_.isFunction(sorterOption)) {
+ sorterFn = sorterOption;
+ } else {
+ sorterFn = this.operationsSorters[sorterOption];
+ }
+ if (_.isFunction(sorterFn)) {
+ for (key in this.model.apisArray) {
+ this.model.apisArray[key].operationsArray.sort(sorterFn);
+ }
+ }
+ }
+
+ // set up the UI for input
+ this.model.auths = [];
+
+ for (key in this.model.securityDefinitions) {
+ value = this.model.securityDefinitions[key];
+
+ this.model.auths.push({
+ name: key,
+ type: value.type,
+ value: value
+ });
+ }
+
+ if (this.model.swaggerVersion === '2.0') {
+ if ('validatorUrl' in opts.swaggerOptions) {
+
+ // Validator URL specified explicitly
+ this.model.validatorUrl = opts.swaggerOptions.validatorUrl;
+
+ } else if (this.model.url.indexOf('localhost') > 0) {
+
+ // Localhost override
+ this.model.validatorUrl = null;
+
+ } else {
+
+ // Default validator
+ this.model.validatorUrl = 'http://online.swagger.io/validator';
+ }
+ }
+ },
+
+ render: function(){
+ if (this.model.securityDefinitions) {
+ for (var name in this.model.securityDefinitions) {
+ var auth = this.model.securityDefinitions[name];
+ var button;
+
+ if (auth.type === 'apiKey' && $('#apikey_button').length === 0) {
+ button = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
+ $('.auth_main_container').append(button);
+ }
+
+ if (auth.type === 'basicAuth' && $('#basic_auth_button').length === 0) {
+ button = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
+ $('.auth_main_container').append(button);
+ }
+ }
+ }
+
+ // Render the outer container for resources
+ $(this.el).html(Handlebars.templates.main(this.model));
+
+ // Render each resource
+
+ var resources = {};
+ var counter = 0;
+ for (var i = 0; i < this.model.apisArray.length; i++) {
+ var resource = this.model.apisArray[i];
+ var id = resource.name;
+ while (typeof resources[id] !== 'undefined') {
+ id = id + '_' + counter;
+ counter += 1;
+ }
+ resource.id = id;
+ resources[id] = resource;
+ this.addResource(resource, this.model.auths);
+ }
+
+ $('.propWrap').hover(function onHover(){
+ $('.optionsWrapper', $(this)).show();
+ }, function offhover(){
+ $('.optionsWrapper', $(this)).hide();
+ });
+ return this;
+ },
+
+ addResource: function(resource, auths){
+ // Render a resource and add it to resources li
+ resource.id = resource.id.replace(/\s/g, '_');
+ var resourceView = new SwaggerUi.Views.ResourceView({
+ model: resource,
+ router: this.router,
+ tagName: 'li',
+ id: 'resource_' + resource.id,
+ className: 'resource',
+ auths: auths,
+ swaggerOptions: this.options.swaggerOptions
+ });
+ $('#resources').append(resourceView.render().el);
+ },
+
+ clear: function(){
+ $(this.el).html('');
+ }
+});
+
+'use strict';
+
+SwaggerUi.Views.OperationView = Backbone.View.extend({
+ invocationUrl: null,
+
+ events: {
+ 'submit .sandbox' : 'submitOperation',
+ 'click .submit' : 'submitOperation',
+ 'click .response_hider' : 'hideResponse',
+ 'click .toggleOperation' : 'toggleOperationContent',
+ 'mouseenter .api-ic' : 'mouseEnter',
+ 'mouseout .api-ic' : 'mouseExit',
+ },
+
+ initialize: function(opts) {
+ opts = opts || {};
+ this.router = opts.router;
+ this.auths = opts.auths;
+ this.parentId = this.model.parentId;
+ this.nickname = this.model.nickname;
+ this.model.encodedParentId = encodeURIComponent(this.parentId);
+ return this;
+ },
+
+ mouseEnter: function(e) {
+ var elem = $(this.el).find('.content');
+ var x = e.pageX;
+ var y = e.pageY;
+ var scX = $(window).scrollLeft();
+ var scY = $(window).scrollTop();
+ var scMaxX = scX + $(window).width();
+ var scMaxY = scY + $(window).height();
+ var wd = elem.width();
+ var hgh = elem.height();
+
+ if (x + wd > scMaxX) {
+ x = scMaxX - wd;
+ }
+
+ if (x < scX) {
+ x = scX;
+ }
+
+ if (y + hgh > scMaxY) {
+ y = scMaxY - hgh;
+ }
+
+ if (y < scY) {
+ y = scY;
+ }
+
+ var pos = {};
+ pos.top = y;
+ pos.left = x;
+ elem.css(pos);
+ $(e.currentTarget.parentNode).find('#api_information_panel').show();
+ },
+
+ mouseExit: function(e) {
+ $(e.currentTarget.parentNode).find('#api_information_panel').hide();
+ },
+
+ // Note: copied from CoffeeScript compiled file
+ // TODO: redactor
+ render: function() {
+ var a, auth, auths, code, contentTypeModel, isMethodSubmissionSupported, k, key, l, len, len1, len2, len3, len4, m, modelAuths, n, o, p, param, q, ref, ref1, ref2, ref3, ref4, ref5, responseContentTypeView, responseSignatureView, schema, schemaObj, scopeIndex, signatureModel, statusCode, successResponse, type, v, value;
+ isMethodSubmissionSupported = jQuery.inArray(this.model.method, this.model.supportedSubmitMethods()) >= 0;
+ if (!isMethodSubmissionSupported) {
+ this.model.isReadOnly = true;
+ }
+ this.model.description = this.model.description || this.model.notes;
+ this.model.oauth = null;
+ modelAuths = this.model.authorizations || this.model.security;
+ if (modelAuths) {
+ if (Array.isArray(modelAuths)) {
+ for (l = 0, len = modelAuths.length; l < len; l++) {
+ auths = modelAuths[l];
+ for (key in auths) {
+ auth = auths[key];
+ for (a in this.auths) {
+ auth = this.auths[a];
+ if (auth.type === 'oauth2') {
+ this.model.oauth = {};
+ this.model.oauth.scopes = [];
+ ref1 = auth.value.scopes;
+ for (k in ref1) {
+ v = ref1[k];
+ scopeIndex = auths[key].indexOf(k);
+ if (scopeIndex >= 0) {
+ o = {
+ scope: k,
+ description: v
+ };
+ this.model.oauth.scopes.push(o);
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ for (k in modelAuths) {
+ v = modelAuths[k];
+ if (k === 'oauth2') {
+ if (this.model.oauth === null) {
+ this.model.oauth = {};
+ }
+ if (this.model.oauth.scopes === void 0) {
+ this.model.oauth.scopes = [];
+ }
+ for (m = 0, len1 = v.length; m < len1; m++) {
+ o = v[m];
+ this.model.oauth.scopes.push(o);
+ }
+ }
+ }
+ }
+ }
+ if (typeof this.model.responses !== 'undefined') {
+ this.model.responseMessages = [];
+ ref2 = this.model.responses;
+ for (code in ref2) {
+ value = ref2[code];
+ schema = null;
+ schemaObj = this.model.responses[code].schema;
+ if (schemaObj && schemaObj.$ref) {
+ schema = schemaObj.$ref;
+ if (schema.indexOf('#/definitions/') === 0) {
+ schema = schema.substring('#/definitions/'.length);
+ }
+ }
+ this.model.responseMessages.push({
+ code: code,
+ message: value.description,
+ responseModel: schema
+ });
+ }
+ }
+ if (typeof this.model.responseMessages === 'undefined') {
+ this.model.responseMessages = [];
+ }
+ signatureModel = null;
+ if (this.model.successResponse) {
+ successResponse = this.model.successResponse;
+ for (key in successResponse) {
+ value = successResponse[key];
+ this.model.successCode = key;
+ if (typeof value === 'object' && typeof value.createJSONSample === 'function') {
+ signatureModel = {
+ sampleJSON: JSON.stringify(value.createJSONSample(), void 0, 2),
+ isParam: false,
+ signature: value.getMockSignature()
+ };
+ }
+ }
+ } else if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') {
+ signatureModel = {
+ sampleJSON: this.model.responseSampleJSON,
+ isParam: false,
+ signature: this.model.responseClassSignature
+ };
+ }
+ $(this.el).html(Handlebars.templates.operation(this.model));
+ if (signatureModel) {
+ responseSignatureView = new SwaggerUi.Views.SignatureView({
+ model: signatureModel,
+ router: this.router,
+ tagName: 'div'
+ });
+ $('.model-signature', $(this.el)).append(responseSignatureView.render().el);
+ } else {
+ this.model.responseClassSignature = 'string';
+ $('.model-signature', $(this.el)).html(this.model.type);
+ }
+ contentTypeModel = {
+ isParam: false
+ };
+ contentTypeModel.consumes = this.model.consumes;
+ contentTypeModel.produces = this.model.produces;
+ ref3 = this.model.parameters;
+ for (n = 0, len2 = ref3.length; n < len2; n++) {
+ param = ref3[n];
+ type = param.type || param.dataType || '';
+ if (typeof type === 'undefined') {
+ schema = param.schema;
+ if (schema && schema.$ref) {
+ ref = schema.$ref;
+ if (ref.indexOf('#/definitions/') === 0) {
+ type = ref.substring('#/definitions/'.length);
+ } else {
+ type = ref;
+ }
+ }
+ }
+ if (type && type.toLowerCase() === 'file') {
+ if (!contentTypeModel.consumes) {
+ contentTypeModel.consumes = 'multipart/form-data';
+ }
+ }
+ param.type = type;
+ }
+ responseContentTypeView = new SwaggerUi.Views.ResponseContentTypeView({
+ model: contentTypeModel,
+ router: this.router
+ });
+ $('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
+ ref4 = this.model.parameters;
+ for (p = 0, len3 = ref4.length; p < len3; p++) {
+ param = ref4[p];
+ this.addParameter(param, contentTypeModel.consumes);
+ }
+ ref5 = this.model.responseMessages;
+ for (q = 0, len4 = ref5.length; q < len4; q++) {
+ statusCode = ref5[q];
+ this.addStatusCode(statusCode);
+ }
+ return this;
+ },
+
+ addParameter: function(param, consumes) {
+ // Render a parameter
+ param.consumes = consumes;
+ var paramView = new SwaggerUi.Views.ParameterView({
+ model: param,
+ tagName: 'tr',
+ readOnly: this.model.isReadOnly
+ });
+ $('.operation-params', $(this.el)).append(paramView.render().el);
+ },
+
+ addStatusCode: function(statusCode) {
+ // Render status codes
+ var statusCodeView = new SwaggerUi.Views.StatusCodeView({
+ model: statusCode,
+ tagName: 'tr',
+ router: this.router
+ });
+ $('.operation-status', $(this.el)).append(statusCodeView.render().el);
+ },
+
+ // Note: copied from CoffeeScript compiled file
+ // TODO: redactor
+ submitOperation: function(e) {
+ var error_free, form, isFileUpload, l, len, len1, len2, m, map, n, o, opts, ref1, ref2, ref3, val;
+ if (e !== null) {
+ e.preventDefault();
+ }
+ form = $('.sandbox', $(this.el));
+ error_free = true;
+ form.find('input.required').each(function() {
+ $(this).removeClass('error');
+ if (jQuery.trim($(this).val()) === '') {
+ $(this).addClass('error');
+ $(this).wiggle({
+ callback: (function(_this) {
+ return function() {
+ $(_this).focus();
+ };
+ })(this)
+ });
+ error_free = false;
+ }
+ });
+ form.find('textarea.required').each(function() {
+ $(this).removeClass('error');
+ if (jQuery.trim($(this).val()) === '') {
+ $(this).addClass('error');
+ $(this).wiggle({
+ callback: (function(_this) {
+ return function() {
+ return $(_this).focus();
+ };
+ })(this)
+ });
+ error_free = false;
+ }
+ });
+ if (error_free) {
+ map = {};
+ opts = {
+ parent: this
+ };
+ isFileUpload = false;
+ ref1 = form.find('input');
+ for (l = 0, len = ref1.length; l < len; l++) {
+ o = ref1[l];
+ if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
+ map[o.name] = o.value;
+ }
+ if (o.type === 'file') {
+ map[o.name] = o.files[0];
+ isFileUpload = true;
+ }
+ }
+ ref2 = form.find('textarea');
+ for (m = 0, len1 = ref2.length; m < len1; m++) {
+ o = ref2[m];
+ if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
+ map[o.name] = o.value;
+ }
+ }
+ ref3 = form.find('select');
+ for (n = 0, len2 = ref3.length; n < len2; n++) {
+ o = ref3[n];
+ val = this.getSelectedValue(o);
+ if ((val !== null) && jQuery.trim(val).length > 0) {
+ map[o.name] = val;
+ }
+ }
+ opts.responseContentType = $('div select[name=responseContentType]', $(this.el)).val();
+ opts.requestContentType = $('div select[name=parameterContentType]', $(this.el)).val();
+ $('.response_throbber', $(this.el)).show();
+ if (isFileUpload) {
+ return this.handleFileUpload(map, form);
+ } else {
+ return this.model['do'](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
+ }
+ }
+ },
+
+ success: function(response, parent) {
+ parent.showCompleteStatus(response);
+ },
+
+ // Note: This is compiled code
+ // TODO: Refactor
+ handleFileUpload: function(map, form) {
+ var bodyParam, el, headerParams, l, len, len1, len2, len3, m, n, o, obj, p, param, params, ref1, ref2, ref3, ref4;
+ ref1 = form.serializeArray();
+ for (l = 0, len = ref1.length; l < len; l++) {
+ o = ref1[l];
+ if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
+ map[o.name] = o.value;
+ }
+ }
+ bodyParam = new FormData();
+ params = 0;
+ ref2 = this.model.parameters;
+ for (m = 0, len1 = ref2.length; m < len1; m++) {
+ param = ref2[m];
+ if (param.paramType === 'form' || param['in'] === 'formData') {
+ if (param.type.toLowerCase() !== 'file' && map[param.name] !== void 0) {
+ bodyParam.append(param.name, map[param.name]);
+ }
+ }
+ }
+ headerParams = {};
+ ref3 = this.model.parameters;
+ for (n = 0, len2 = ref3.length; n < len2; n++) {
+ param = ref3[n];
+ if (param.paramType === 'header') {
+ headerParams[param.name] = map[param.name];
+ }
+ }
+ ref4 = form.find('input[type~="file"]');
+ for (p = 0, len3 = ref4.length; p < len3; p++) {
+ el = ref4[p];
+ if (typeof el.files[0] !== 'undefined') {
+ bodyParam.append($(el).attr('name'), el.files[0]);
+ params += 1;
+ }
+ }
+ this.invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), delete headerParams['Content-Type'], this.model.urlify(map, false)) : this.model.urlify(map, true);
+ $('.request_url', $(this.el)).html('<pre></pre>');
+ $('.request_url pre', $(this.el)).text(this.invocationUrl);
+ obj = {
+ type: this.model.method,
+ url: this.invocationUrl,
+ headers: headerParams,
+ data: bodyParam,
+ dataType: 'json',
+ contentType: false,
+ processData: false,
+ error: (function(_this) {
+ return function(data) {
+ return _this.showErrorStatus(_this.wrap(data), _this);
+ };
+ })(this),
+ success: (function(_this) {
+ return function(data) {
+ return _this.showResponse(data, _this);
+ };
+ })(this),
+ complete: (function(_this) {
+ return function(data) {
+ return _this.showCompleteStatus(_this.wrap(data), _this);
+ };
+ })(this)
+ };
+ if (window.authorizations) {
+ window.authorizations.apply(obj);
+ }
+ jQuery.ajax(obj);
+ return false;
+ // end of file-upload nastiness
+ },
+ // wraps a jquery response as a shred response
+
+ wrap: function(data) {
+ var h, headerArray, headers, i, l, len, o;
+ headers = {};
+ headerArray = data.getAllResponseHeaders().split('\r');
+ for (l = 0, len = headerArray.length; l < len; l++) {
+ i = headerArray[l];
+ h = i.match(/^([^:]*?):(.*)$/);
+ if (!h) {
+ h = [];
+ }
+ h.shift();
+ if (h[0] !== void 0 && h[1] !== void 0) {
+ headers[h[0].trim()] = h[1].trim();
+ }
+ }
+ o = {};
+ o.content = {};
+ o.content.data = data.responseText;
+ o.headers = headers;
+ o.request = {};
+ o.request.url = this.invocationUrl;
+ o.status = data.status;
+ return o;
+ },
+
+ getSelectedValue: function(select) {
+ if (!select.multiple) {
+ return select.value;
+ } else {
+ var options = [];
+ for (var l = 0, len = select.options.length; l < len; l++) {
+ var opt = select.options[l];
+ if (opt.selected) {
+ options.push(opt.value);
+ }
+ }
+ if (options.length > 0) {
+ return options;
+ } else {
+ return null;
+ }
+ }
+ },
+
+ // handler for hide response link
+ hideResponse: function(e) {
+ if (e) { e.preventDefault(); }
+ $('.response', $(this.el)).slideUp();
+ $('.response_hider', $(this.el)).fadeOut();
+ },
+
+ // Show response from server
+ showResponse: function(response) {
+ var prettyJson = JSON.stringify(response, null, '\t').replace(/\n/g, '<br>');
+ $('.response_body', $(this.el)).html(_.escape(prettyJson));
+ },
+
+ // Show error from server
+ showErrorStatus: function(data, parent) {
+ parent.showStatus(data);
+ },
+
+ // show the status codes
+ showCompleteStatus: function(data, parent){
+ parent.showStatus(data);
+ },
+
+ // Adapted from http://stackoverflow.com/a/2893259/454004
+ // Note: directly ported from CoffeeScript
+ // TODO: Cleanup CoffeeScript artifacts
+ formatXml: function(xml) {
+ var contexp, fn, formatted, indent, l, lastType, len, lines, ln, pad, reg, transitions, wsexp;
+ reg = /(>)(<)(\/*)/g;
+ wsexp = /[ ]*(.*)[ ]+\n/g;
+ contexp = /(<.+>)(.+\n)/g;
+ xml = xml.replace(reg, '$1\n$2$3').replace(wsexp, '$1\n').replace(contexp, '$1\n$2');
+ pad = 0;
+ formatted = '';
+ lines = xml.split('\n');
+ indent = 0;
+ lastType = 'other';
+ transitions = {
+ 'single->single': 0,
+ 'single->closing': -1,
+ 'single->opening': 0,
+ 'single->other': 0,
+ 'closing->single': 0,
+ 'closing->closing': -1,
+ 'closing->opening': 0,
+ 'closing->other': 0,
+ 'opening->single': 1,
+ 'opening->closing': 0,
+ 'opening->opening': 1,
+ 'opening->other': 1,
+ 'other->single': 0,
+ 'other->closing': -1,
+ 'other->opening': 0,
+ 'other->other': 0
+ };
+ fn = function(ln) {
+ var fromTo, j, key, padding, type, types, value;
+ types = {
+ single: Boolean(ln.match(/<.+\/>/)),
+ closing: Boolean(ln.match(/<\/.+>/)),
+ opening: Boolean(ln.match(/<[^!?].*>/))
+ };
+ type = ((function() {
+ var results;
+ results = [];
+ for (key in types) {
+ value = types[key];
+ if (value) {
+ results.push(key);
+ }
+ }
+ return results;
+ })())[0];
+ type = type === void 0 ? 'other' : type;
+ fromTo = lastType + '->' + type;
+ lastType = type;
+ padding = '';
+ indent += transitions[fromTo];
+ padding = ((function() {
+ var m, ref1, results;
+ results = [];
+ for (j = m = 0, ref1 = indent; 0 <= ref1 ? m < ref1 : m > ref1; j = 0 <= ref1 ? ++m : --m) {
+ results.push(' ');
+ }
+ return results;
+ })()).join('');
+ if (fromTo === 'opening->closing') {
+ formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
+ } else {
+ formatted += padding + ln + '\n';
+ }
+ };
+ for (l = 0, len = lines.length; l < len; l++) {
+ ln = lines[l];
+ fn(ln);
+ }
+ return formatted;
+ },
+
+ // puts the response data in UI
+ showStatus: function(response) {
+ var url, content;
+ if (response.content === undefined) {
+ content = response.data;
+ url = response.url;
+ } else {
+ content = response.content.data;
+ url = response.request.url;
+ }
+ var headers = response.headers;
+
+ // if server is nice, and sends content-type back, we can use it
+ var contentType = null;
+ if (headers) {
+ contentType = headers['Content-Type'] || headers['content-type'];
+ if (contentType) {
+ contentType = contentType.split(';')[0].trim();
+ }
+ }
+ $('.response_body', $(this.el)).removeClass('json');
+ $('.response_body', $(this.el)).removeClass('xml');
+
+ var supportsAudioPlayback = function(contentType){
+ var audioElement = document.createElement('audio');
+ return !!(audioElement.canPlayType && audioElement.canPlayType(contentType).replace(/no/, ''));
+ };
+
+ var pre;
+ var code;
+ if (!content) {
+ code = $('<code />').text('no content');
+ pre = $('<pre class="json" />').append(code);
+
+ // JSON
+ } else if (contentType === 'application/json' || /\+json$/.test(contentType)) {
+ var json = null;
+ try {
+ json = JSON.stringify(JSON.parse(content), null, ' ');
+ } catch (_error) {
+ json = 'can\'t parse JSON. Raw result:\n\n' + content;
+ }
+ code = $('<code />').text(json);
+ pre = $('<pre class="json" />').append(code);
+
+ // XML
+ } else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) {
+ code = $('<code />').text(this.formatXml(content));
+ pre = $('<pre class="xml" />').append(code);
+
+ // HTML
+ } else if (contentType === 'text/html') {
+ code = $('<code />').html(_.escape(content));
+ pre = $('<pre class="xml" />').append(code);
+
+ // Image
+ } else if (/^image\//.test(contentType)) {
+ pre = $('<img>').attr('src', url);
+
+ // Audio
+ } else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) {
+ pre = $('<audio controls>').append($('<source>').attr('src', url).attr('type', contentType));
+
+ // Download
+ } else if (headers['Content-Disposition'].test(/attachment/) ||
+ headers['content-disposition'].test(/attachment/) ||
+ headers['Content-Description'].test(/File Transfer/) ||
+ headers['content-description'].test(/File Transfer/)) {
+
+ if ('Blob' in window) {
+ var type = contentType || 'text/html';
+ var blob = new Blob([content], {type: type});
+ var a = document.createElement('a');
+ var href = window.URL.createObjectURL(blob);
+ var fileName = response.url.substr(response.url.lastIndexOf('/') + 1);
+ var download = [type, fileName, href].join(':');
+
+ a.setAttribute('href', href);
+ a.setAttribute('download', download);
+ a.innerText = 'Download ' + fileName;
+
+ pre = $('<div/>').append(a);
+ } else {
+ pre = $('<pre class="json" />').append('Download headers detected but your browser does not support downloading binary via XHR (Blob).');
+ }
+
+ // Location header based redirect download
+ } else if(headers.location || headers.Location) {
+ window.location = response.url;
+
+ // Anything else (CORS)
+ } else {
+ code = $('<code />').text(content);
+ pre = $('<pre class="json" />').append(code);
+ }
+ var response_body = pre;
+ $('.request_url', $(this.el)).html('<pre></pre>');
+ $('.request_url pre', $(this.el)).text(url);
+ $('.response_code', $(this.el)).html('<pre>' + response.status + '</pre>');
+ $('.response_body', $(this.el)).html(response_body);
+ $('.response_headers', $(this.el)).html('<pre>' + _.escape(JSON.stringify(response.headers, null, ' ')).replace(/\n/g, '<br>') + '</pre>');
+ $('.response', $(this.el)).slideDown();
+ $('.response_hider', $(this.el)).show();
+ $('.response_throbber', $(this.el)).hide();
+ var response_body_el = $('.response_body', $(this.el))[0];
+
+ // only highlight the response if response is less than threshold, default state is highlight response
+ var opts = this.options.swaggerOptions;
+ if (opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold) {
+ return response_body_el;
+ } else {
+ return hljs.highlightBlock(response_body_el);
+ }
+ },
+
+ toggleOperationContent: function() {
+ var elem = $('#' + Docs.escapeResourceName(this.parentId + '_' + this.nickname + '_content'));
+ if (elem.is(':visible')){
+ Docs.collapseOperation(elem);
+ } else {
+ Docs.expandOperation(elem);
+ }
+ }
+});
+
+'use strict';
+
+SwaggerUi.Views.ParameterContentTypeView = Backbone.View.extend({
+ initialize: function () {},
+
+ render: function(){
+ $(this.el).html(Handlebars.templates.parameter_content_type(this.model));
+
+ $('label[for=parameterContentType]', $(this.el)).text('Parameter content type:');
+
+ return this;
+ }
+
+});
+'use strict';
+
+SwaggerUi.Views.ParameterView = Backbone.View.extend({
+ initialize: function(){
+ Handlebars.registerHelper('isArray', function(param, opts) {
+ if (param.type.toLowerCase() === 'array' || param.allowMultiple) {
+ opts.fn(this);
+ } else {
+ opts.inverse(this);
+ }
+ });
+ },
+
+ render: function() {
+ var type = this.model.type || this.model.dataType;
+
+ if (typeof type === 'undefined') {
+ var schema = this.model.schema;
+ if (schema && schema.$ref) {
+ var ref = schema.$ref;
+ if (ref.indexOf('#/definitions/') === 0) {
+ type = ref.substring('#/definitions/'.length);
+ } else {
+ type = ref;
+ }
+ }
+ }
+
+ this.model.type = type;
+ this.model.paramType = this.model.in || this.model.paramType;
+ this.model.isBody = this.model.paramType === 'body' || this.model.in === 'body';
+ this.model.isFile = type && type.toLowerCase() === 'file';
+ this.model.default = (this.model.default || this.model.defaultValue);
+
+ if (this.model.allowableValues) {
+ this.model.isList = true;
+ }
+
+ var template = this.template();
+ $(this.el).html(template(this.model));
+
+ var signatureModel = {
+ sampleJSON: this.model.sampleJSON,
+ isParam: true,
+ signature: this.model.signature
+ };
+
+ if (this.model.sampleJSON) {
+ var signatureView = new SwaggerUi.Views.SignatureView({model: signatureModel, tagName: 'div'});
+ $('.model-signature', $(this.el)).append(signatureView.render().el);
+ }
+ else {
+ $('.model-signature', $(this.el)).html(this.model.signature);
+ }
+
+ var isParam = false;
+
+ if (this.model.isBody) {
+ isParam = true;
+ }
+
+ var contentTypeModel = {
+ isParam: isParam
+ };
+
+ contentTypeModel.consumes = this.model.consumes;
+
+ if (isParam) {
+ var parameterContentTypeView = new SwaggerUi.Views.ParameterContentTypeView({model: contentTypeModel});
+ $('.parameter-content-type', $(this.el)).append(parameterContentTypeView.render().el);
+ }
+
+ else {
+ var responseContentTypeView = new SwaggerUi.Views.ResponseContentTypeView({model: contentTypeModel});
+ $('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
+ }
+
+ return this;
+ },
+
+ // Return an appropriate template based on if the parameter is a list, readonly, required
+ template: function(){
+ if (this.model.isList) {
+ return Handlebars.templates.param_list;
+ } else {
+ if (this.options.readOnly) {
+ if (this.model.required) {
+ return Handlebars.templates.param_readonly_required;
+ } else {
+ return Handlebars.templates.param_readonly;
+ }
+ } else {
+ if (this.model.required) {
+ return Handlebars.templates.param_required;
+ } else {
+ return Handlebars.templates.param;
+ }
+ }
+ }
+ }
+});
+'use strict';
+
+SwaggerUi.Views.ResourceView = Backbone.View.extend({
+ initialize: function(opts) {
+ opts = opts || {};
+ this.router = opts.router;
+ this.auths = opts.auths;
+ if ('' === this.model.description) {
+ this.model.description = null;
+ }
+ if (this.model.description) {
+ this.model.summary = this.model.description;
+ }
+ },
+
+ render: function(){
+ var methods = {};
+
+
+ $(this.el).html(Handlebars.templates.resource(this.model));
+
+ // Render each operation
+ for (var i = 0; i < this.model.operationsArray.length; i++) {
+ var operation = this.model.operationsArray[i];
+ var counter = 0;
+ var id = operation.nickname;
+
+ while (typeof methods[id] !== 'undefined') {
+ id = id + '_' + counter;
+ counter += 1;
+ }
+
+ methods[id] = operation;
+
+ operation.nickname = id;
+ operation.parentId = this.model.id;
+ this.addOperation(operation);
+ }
+
+ $('.toggleEndpointList', this.el).click(this.callDocs.bind(this, 'toggleEndpointListForResource'));
+ $('.collapseResource', this.el).click(this.callDocs.bind(this, 'collapseOperationsForResource'));
+ $('.expandResource', this.el).click(this.callDocs.bind(this, 'expandOperationsForResource'));
+
+ return this;
+ },
+
+ addOperation: function(operation) {
+
+ operation.number = this.number;
+
+ // Render an operation and add it to operations li
+ var operationView = new SwaggerUi.Views.OperationView({
+ model: operation,
+ router: this.router,
+ tagName: 'li',
+ className: 'endpoint',
+ swaggerOptions: this.options.swaggerOptions,
+ auths: this.auths
+ });
+
+ $('.endpoints', $(this.el)).append(operationView.render().el);
+
+ this.number++;
+
+ },
+ // Generic Event handler (`Docs` is global)
+
+
+ callDocs: function(fnName, e) {
+ e.preventDefault();
+ Docs[fnName](e.currentTarget.getAttribute('data-id'));
+ }
+});
+'use strict';
+
+SwaggerUi.Views.ResponseContentTypeView = Backbone.View.extend({
+ initialize: function(){},
+
+ render: function(){
+ $(this.el).html(Handlebars.templates.response_content_type(this.model));
+
+ $('label[for=responseContentType]', $(this.el)).text('Response Content Type');
+
+ return this;
+ }
+});
+'use strict';
+
+SwaggerUi.Views.SignatureView = Backbone.View.extend({
+ events: {
+ 'click a.description-link' : 'switchToDescription',
+ 'click a.snippet-link' : 'switchToSnippet',
+ 'mousedown .snippet' : 'snippetToTextArea'
+ },
+
+ initialize: function () {
+
+ },
+
+ render: function(){
+
+ $(this.el).html(Handlebars.templates.signature(this.model));
+
+ this.switchToSnippet();
+
+ this.isParam = this.model.isParam;
+
+ if (this.isParam) {
+ $('.notice', $(this.el)).text('Click to set as parameter value');
+ }
+
+ return this;
+ },
+
+ // handler for show signature
+ switchToDescription: function(e){
+ if (e) { e.preventDefault(); }
+
+ $('.snippet', $(this.el)).hide();
+ $('.description', $(this.el)).show();
+ $('.description-link', $(this.el)).addClass('selected');
+ $('.snippet-link', $(this.el)).removeClass('selected');
+ },
+
+ // handler for show sample
+ switchToSnippet: function(e){
+ if (e) { e.preventDefault(); }
+
+ $('.description', $(this.el)).hide();
+ $('.snippet', $(this.el)).show();
+ $('.snippet-link', $(this.el)).addClass('selected');
+ $('.description-link', $(this.el)).removeClass('selected');
+ },
+
+ // handler for snippet to text area
+ snippetToTextArea: function(e) {
+ if (this.isParam) {
+ if (e) { e.preventDefault(); }
+
+ var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
+ if ($.trim(textArea.val()) === '') {
+ textArea.val(this.model.sampleJSON);
+ }
+ }
+ }
+});
+'use strict';
+
+SwaggerUi.Views.StatusCodeView = Backbone.View.extend({
+ initialize: function (opts) {
+ this.options = opts || {};
+ this.router = this.options.router;
+ },
+
+ render: function(){
+ $(this.el).html(Handlebars.templates.status_code(this.model));
+
+ if (this.router.api.models.hasOwnProperty(this.model.responseModel)) {
+ var responseModel = {
+ sampleJSON: JSON.stringify(this.router.api.models[this.model.responseModel].createJSONSample(), null, 2),
+ isParam: false,
+ signature: this.router.api.models[this.model.responseModel].getMockSignature(),
+ };
+
+ var responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'});
+ $('.model-signature', this.$el).append(responseModelView.render().el);
+ } else {
+ $('.model-signature', this.$el).html('');
+ }
+ return this;
+ }
+});}).call(this);
diff --git a/catalog-be/src/main/resources/swagger/swagger-ui.min.js b/catalog-be/src/main/resources/swagger/swagger-ui.min.js
new file mode 100644
index 0000000000..0e21b8852c
--- /dev/null
+++ b/catalog-be/src/main/resources/swagger/swagger-ui.min.js
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR 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(){function e(){e.history=e.history||[],e.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])}this.Handlebars=this.Handlebars||{},this.Handlebars.templates=this.Handlebars.templates||{},this.Handlebars.templates.apikey_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return"<!--div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div-->\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>"+s((i=null!=(i=t.keyName||(null!=e?e.keyName:e))?i:a,typeof i===o?i.call(e,{name:"keyName",hash:{},data:r}):i))+'</div>\n <input placeholder="api_key" class="auth_input" id="input_apiKey_entry" name="apiKey" type="text"/>\n <div class=\'auth_submit\'><a class=\'auth_submit_button\' id="apply_api_key" href="#">apply</a></div>\n </div>\n</div>\n\n'},useData:!0}),this.Handlebars.templates.basic_auth_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(){return'<div class=\'auth_button\' id=\'basic_auth_button\'><img class=\'auth_icon\' src=\'images/password.jpeg\'></div>\n<div class=\'auth_container\' id=\'basic_auth_container\'>\n <div class=\'key_input_container\'>\n <div class="auth_label">Username</div>\n <input placeholder="username" class="auth_input" id="input_username" name="username" type="text"/>\n <div class="auth_label">Password</div>\n <input placeholder="password" class="auth_input" id="input_password" name="password" type="password"/>\n <div class=\'auth_submit\'><a class=\'auth_submit_button\' id="apply_basic_auth" href="#">apply</a></div>\n </div>\n</div>\n\n'},useData:!0}),this.Handlebars.templates.content_type=Handlebars.template({1:function(e,t,n,r){var i,o="";return i=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,r),inverse:this.noop,data:r}),null!=i&&(o+=i),o},2:function(e){var t,n=this.lambda,r=' <option value="';return t=n(e,e),null!=t&&(r+=t),r+='">',t=n(e,e),null!=t&&(r+=t),r+"</option>\n"},4:function(){return' <option value="application/json">application/json</option>\n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o='<label for="contentType"></label>\n<select name="contentType">\n';return i=t["if"].call(e,null!=e?e.produces:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(4,r),data:r}),null!=i&&(o+=i),o+"</select>\n"},useData:!0}),$(function(){$.fn.vAlign=function(){return this.each(function(){var e=$(this).height(),t=$(this).parent().height(),n=(t-e)/2;$(this).css("margin-top",n)})},$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(){var e=$(this).closest("form").innerWidth(),t=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10),n=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",e-t-n)})},$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent(),$("ul.downplayed li div.content p").vAlign(),$("form.sandbox").submit(function(){var e=!0;return $(this).find("input.required").each(function(){$(this).removeClass("error"),""===$(this).val()&&($(this).addClass("error"),$(this).wiggle(),e=!1)}),e})}),Function.prototype.bind&&console&&"object"==typeof console.log&&["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(e){console[e]=this.bind(console[e],console)},Function.prototype.call),window.Docs={shebang:function(){var e=$.param.fragment().split("/");switch(e.shift(),e.length){case 1:var t="resource_"+e[0];Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});break;case 2:Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});var n=e.join("_"),r=n+"_content";Docs.expandOperation($("#"+r)),$("#"+n).slideto({highlight:!1})}},toggleEndpointListForResource:function(e){var t=$("li#resource_"+Docs.escapeResourceName(e)+" ul.endpoints");t.is(":visible")?Docs.collapseEndpointListForResource(e):Docs.expandEndpointListForResource(e)},expandEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideDown();$("li#resource_"+e).addClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideDown()},collapseEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideUp();$("li#resource_"+e).removeClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideUp()},expandOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideDown():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideUp():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(e){return e.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(e){e.slideDown()},collapseOperation:function(e){e.slideUp()}},Handlebars.registerHelper("sanitize",function(e){return e=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,""),new Handlebars.SafeString(e)}),this.Handlebars.templates.main=Handlebars.template({1:function(e,t,n,r){var i,o=this.lambda,a=this.escapeExpression,s=' <div class="info_title">'+a(o(null!=(i=null!=e?e.info:e)?i.title:i,e))+'</div>\n <div class="info_description markdown">';return i=o(null!=(i=null!=e?e.info:e)?i.description:i,e),null!=i&&(s+=i),s+="</div>\n",i=t["if"].call(e,null!=e?e.externalDocs:e,{name:"if",hash:{},fn:this.program(2,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+=" ",i=t["if"].call(e,null!=(i=null!=e?e.info:e)?i.termsOfServiceUrl:i,{name:"if",hash:{},fn:this.program(4,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+="\n ",i=t["if"].call(e,null!=(i=null!=(i=null!=e?e.info:e)?i.contact:i)?i.name:i,{name:"if",hash:{},fn:this.program(6,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+="\n ",i=t["if"].call(e,null!=(i=null!=(i=null!=e?e.info:e)?i.contact:i)?i.url:i,{name:"if",hash:{},fn:this.program(8,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+="\n ",i=t["if"].call(e,null!=(i=null!=(i=null!=e?e.info:e)?i.contact:i)?i.email:i,{name:"if",hash:{},fn:this.program(10,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+="\n ",i=t["if"].call(e,null!=(i=null!=e?e.info:e)?i.license:i,{name:"if",hash:{},fn:this.program(12,r),inverse:this.noop,data:r}),null!=i&&(s+=i),s+"\n"},2:function(e){var t,n=this.lambda,r=this.escapeExpression;return" <h5>More documentations</h5>\n <p>"+r(n(null!=(t=null!=e?e.externalDocs:e)?t.description:t,e))+'</p>\n <a href="'+r(n(null!=(t=null!=e?e.externalDocs:e)?t.url:t,e))+'" target="_blank">'+r(n(null!=(t=null!=e?e.externalDocs:e)?t.url:t,e))+"</a>\n"},4:function(e){var t,n=this.lambda,r=this.escapeExpression;return'<div class="info_tos"><a href="'+r(n(null!=(t=null!=e?e.info:e)?t.termsOfServiceUrl:t,e))+'">Terms of service</a></div>'},6:function(e){var t,n=this.lambda,r=this.escapeExpression;return"<div class='info_name'>Created by "+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.name:t,e))+"</div>"},8:function(e){var t,n=this.lambda,r=this.escapeExpression;return"<div class='info_url'>See more at <a href=\""+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.url:t,e))+'">'+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.url:t,e))+"</a></div>"},10:function(e){var t,n=this.lambda,r=this.escapeExpression;return"<div class='info_email'><a href=\"mailto:"+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.email:t,e))+"?subject="+r(n(null!=(t=null!=e?e.info:e)?t.title:t,e))+'">Contact the developer</a></div>'},12:function(e){var t,n=this.lambda,r=this.escapeExpression;return"<div class='info_license'><a href='"+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.license:t)?t.url:t,e))+"'>"+r(n(null!=(t=null!=(t=null!=e?e.info:e)?t.license:t)?t.name:t,e))+"</a></div>"},14:function(e){var t,n=this.lambda,r=this.escapeExpression;return' , <span style="font-variant: small-caps">api version</span>: '+r(n(null!=(t=null!=e?e.info:e)?t.version:t,e))+"\n "},16:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return' <span style="float:right"><a href="'+s((i=null!=(i=t.validatorUrl||(null!=e?e.validatorUrl:e))?i:a,typeof i===o?i.call(e,{name:"validatorUrl",hash:{},data:r}):i))+"/debug?url="+s((i=null!=(i=t.url||(null!=e?e.url:e))?i:a,typeof i===o?i.call(e,{name:"url",hash:{},data:r}):i))+'"><img id="validator" src="'+s((i=null!=(i=t.validatorUrl||(null!=e?e.validatorUrl:e))?i:a,typeof i===o?i.call(e,{name:"validatorUrl",hash:{},data:r}):i))+"?url="+s((i=null!=(i=t.url||(null!=e?e.url:e))?i:a,typeof i===o?i.call(e,{name:"url",hash:{},data:r}):i))+'"></a>\n </span>\n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<div class='info' id='api_info'>\n";return i=t["if"].call(e,null!=e?e.info:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+="</div>\n<div class='container' id='resources_container'>\n <ul id='resources'></ul>\n\n <div class=\"footer\">\n <br>\n <br>\n <h4 style=\"color: #999\">[ <span style=\"font-variant: small-caps\">base url</span>: "+l((o=null!=(o=t.basePath||(null!=e?e.basePath:e))?o:s,typeof o===a?o.call(e,{name:"basePath",hash:{},data:r}):o))+"\n",i=t["if"].call(e,null!=(i=null!=e?e.info:e)?i.version:i,{name:"if",hash:{},fn:this.program(14,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+="]\n",i=t["if"].call(e,null!=e?e.validatorUrl:e,{name:"if",hash:{},fn:this.program(16,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+" </h4>\n </div>\n</div>\n"},useData:!0}),this.Handlebars.templates.operation=Handlebars.template({1:function(){return"deprecated"},3:function(){return" <h4>Warning: Deprecated</h4>\n"},5:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=' <h4>Implementation Notes</h4>\n <div class="markdown">';return o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(l+=i),l+"</div>\n"},7:function(){return' <div class="auth">\n <span class="api-ic ic-error"></span>'},9:function(e,t,n,r){var i,o=' <div id="api_information_panel" style="top: 526px; left: 776px; display: none;">\n';return i=t.each.call(e,e,{name:"each",hash:{},fn:this.program(10,r),inverse:this.noop,data:r}),null!=i&&(o+=i),o+" </div>\n"},10:function(e){var t,n=this.lambda,r=this.escapeExpression,i=" <div title='";return t=n(null!=e?e.description:e,e),null!=t&&(i+=t),i+"'>"+r(n(null!=e?e.scope:e,e))+"</div>\n"},12:function(){return"</div>"},14:function(){return' <div class=\'access\'>\n <span class="api-ic ic-off" title="click to authenticate"></span>\n </div>\n'},16:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <h4>Response Class (Status "+s((i=null!=(i=t.successCode||(null!=e?e.successCode:e))?i:a,typeof i===o?i.call(e,{name:"successCode",hash:{},data:r}):i))+')</h4>\n <p><span class="model-signature" /></p>\n <br/>\n <div class="response-content-type" />\n'},18:function(){return' <h4>Parameters</h4>\n <table class=\'fullwidth\'>\n <thead>\n <tr>\n <th style="width: 100px; max-width: 100px">Parameter</th>\n <th style="width: 310px; max-width: 310px">Value</th>\n <th style="width: 200px; max-width: 200px">Description</th>\n <th style="width: 100px; max-width: 100px">Parameter Type</th>\n <th style="width: 220px; max-width: 230px">Data Type</th>\n </tr>\n </thead>\n <tbody class="operation-params">\n\n </tbody>\n </table>\n'},20:function(){return" <div style='margin:0;padding:0;display:inline'></div>\n <h4>Response Messages</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n <th>Response Model</th>\n <th>Headers</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n\n </tbody>\n </table>\n"},22:function(){return""},24:function(){return" <div class='sandbox_header'>\n <input class='submit' name='commit' type='button' value='Try it out!' />\n <a href='#' class='response_hider' style='display:none'>Hide Response</a>\n <span class='response_throbber' style='display:none'></span>\n </div>\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a,s="function",l=t.helperMissing,u=this.escapeExpression,c=t.blockHelperMissing,p="\n <ul class='operations' >\n <li class='"+u((o=null!=(o=t.method||(null!=e?e.method:e))?o:l,typeof o===s?o.call(e,{name:"method",hash:{},data:r}):o))+" operation' id='"+u((o=null!=(o=t.parentId||(null!=e?e.parentId:e))?o:l,typeof o===s?o.call(e,{name:"parentId",hash:{},data:r}):o))+"_"+u((o=null!=(o=t.nickname||(null!=e?e.nickname:e))?o:l,typeof o===s?o.call(e,{name:"nickname",hash:{},data:r}):o))+"'>\n <div class='heading'>\n <h3>\n <span class='http_method'>\n <a href='#!/"+u((o=null!=(o=t.encodedParentId||(null!=e?e.encodedParentId:e))?o:l,typeof o===s?o.call(e,{name:"encodedParentId",hash:{},data:r}):o))+"/"+u((o=null!=(o=t.nickname||(null!=e?e.nickname:e))?o:l,typeof o===s?o.call(e,{name:"nickname",hash:{},data:r}):o))+'\' class="toggleOperation">'+u((o=null!=(o=t.method||(null!=e?e.method:e))?o:l,typeof o===s?o.call(e,{name:"method",hash:{},data:r}):o))+"</a>\n </span>\n <span class='path'>\n <a href='#!/"+u((o=null!=(o=t.encodedParentId||(null!=e?e.encodedParentId:e))?o:l,typeof o===s?o.call(e,{name:"encodedParentId",hash:{},data:r}):o))+"/"+u((o=null!=(o=t.nickname||(null!=e?e.nickname:e))?o:l,typeof o===s?o.call(e,{name:"nickname",hash:{},data:r}):o))+"' class=\"toggleOperation ";return i=t["if"].call(e,null!=e?e.deprecated:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.noop,data:r}),null!=i&&(p+=i),p+='">'+u((o=null!=(o=t.path||(null!=e?e.path:e))?o:l,typeof o===s?o.call(e,{name:"path",hash:{},data:r}):o))+"</a>\n </span>\n </h3>\n <ul class='options'>\n <li>\n <a href='#!/"+u((o=null!=(o=t.encodedParentId||(null!=e?e.encodedParentId:e))?o:l,typeof o===s?o.call(e,{name:"encodedParentId",hash:{},data:r}):o))+"/"+u((o=null!=(o=t.nickname||(null!=e?e.nickname:e))?o:l,typeof o===s?o.call(e,{name:"nickname",hash:{},data:r}):o))+'\' class="toggleOperation">',o=null!=(o=t.summary||(null!=e?e.summary:e))?o:l,i=typeof o===s?o.call(e,{name:"summary",hash:{},data:r}):o,null!=i&&(p+=i),p+="</a>\n </li>\n </ul>\n </div>\n <div class='content' id='"+u((o=null!=(o=t.parentId||(null!=e?e.parentId:e))?o:l,typeof o===s?o.call(e,{name:"parentId",hash:{},data:r}):o))+"_"+u((o=null!=(o=t.nickname||(null!=e?e.nickname:e))?o:l,typeof o===s?o.call(e,{name:"nickname",hash:{},data:r}):o))+"_content' style='display:none'>\n",i=t["if"].call(e,null!=e?e.deprecated:e,{name:"if",hash:{},fn:this.program(3,r),inverse:this.noop,data:r}),null!=i&&(p+=i),i=t["if"].call(e,null!=e?e.description:e,{name:"if",hash:{},fn:this.program(5,r),inverse:this.noop,data:r}),null!=i&&(p+=i),o=null!=(o=t.oauth||(null!=e?e.oauth:e))?o:l,a={name:"oauth",hash:{},fn:this.program(7,r),inverse:this.noop,data:r},i=typeof o===s?o.call(e,a):o,t.oauth||(i=c.call(e,i,a)),null!=i&&(p+=i),p+="\n",i=t.each.call(e,null!=e?e.oauth:e,{name:"each",hash:{},fn:this.program(9,r),inverse:this.noop,data:r}),null!=i&&(p+=i),p+=" ",o=null!=(o=t.oauth||(null!=e?e.oauth:e))?o:l,a={name:"oauth",hash:{},fn:this.program(12,r),inverse:this.noop,data:r},i=typeof o===s?o.call(e,a):o,t.oauth||(i=c.call(e,i,a)),null!=i&&(p+=i),p+="\n",o=null!=(o=t.oauth||(null!=e?e.oauth:e))?o:l,a={name:"oauth",hash:{},fn:this.program(14,r),inverse:this.noop,data:r},i=typeof o===s?o.call(e,a):o,t.oauth||(i=c.call(e,i,a)),null!=i&&(p+=i),i=t["if"].call(e,null!=e?e.type:e,{name:"if",hash:{},fn:this.program(16,r),inverse:this.noop,data:r}),null!=i&&(p+=i),p+=" <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n",i=t["if"].call(e,null!=e?e.parameters:e,{name:"if",hash:{},fn:this.program(18,r),inverse:this.noop,data:r}),null!=i&&(p+=i),i=t["if"].call(e,null!=e?e.responseMessages:e,{name:"if",hash:{},fn:this.program(20,r),inverse:this.noop,data:r}),null!=i&&(p+=i),i=t["if"].call(e,null!=e?e.isReadOnly:e,{name:"if",hash:{},fn:this.program(22,r),inverse:this.program(24,r),data:r}),null!=i&&(p+=i),p+" </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n"},useData:!0}),this.Handlebars.templates.param_list=Handlebars.template({1:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return"<td class='code required'>"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"</td>\n"},3:function(){return" multiple='multiple'"},5:function(){return""},7:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,r),inverse:this.program(8,r),data:r}),null!=i&&(o+=i),o},8:function(e,t,n,r){var i,o=t.helperMissing,a="";return i=(t.isArray||e&&e.isArray||o).call(e,e,{name:"isArray",hash:{},fn:this.program(5,r),inverse:this.program(9,r),data:r}),null!=i&&(a+=i),a},9:function(){return" <option selected=\"\" value=''></option>\n"},11:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e.isDefault:e,{name:"if",hash:{},fn:this.program(12,r),inverse:this.program(14,r),data:r}),null!=i&&(o+=i),o},12:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return' <option selected="" value=\''+s((i=null!=(i=t.value||(null!=e?e.value:e))?i:a,typeof i===o?i.call(e,{name:"value",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t.value||(null!=e?e.value:e))?i:a,typeof i===o?i.call(e,{name:"value",hash:{},data:r}):i))+" (default)</option>\n"},14:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <option value='"+s((i=null!=(i=t.value||(null!=e?e.value:e))?i:a,typeof i===o?i.call(e,{name:"value",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t.value||(null!=e?e.value:e))?i:a,typeof i===o?i.call(e,{name:"value",hash:{},data:r}):i))+"</option>\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="";return i=t["if"].call(e,null!=e?e.required:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+="<td class='code'>"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"</td>\n<td>\n <select ",i=(t.isArray||e&&e.isArray||s).call(e,e,{name:"isArray",hash:{},fn:this.program(3,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+=" class='parameter' name='"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"'>\n",i=t["if"].call(e,null!=e?e.required:e,{name:"if",hash:{},fn:this.program(5,r),inverse:this.program(7,r),data:r}),null!=i&&(u+=i),i=t.each.call(e,null!=(i=null!=e?e.allowableValues:e)?i.descriptiveValues:i,{name:"each",hash:{},fn:this.program(11,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+=' </select>\n</td>\n<td class="markdown">',o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(u+=i),u+="</td>\n<td>",o=null!=(o=t.paramType||(null!=e?e.paramType:e))?o:s,i=typeof o===a?o.call(e,{name:"paramType",hash:{},data:r}):o,null!=i&&(u+=i),u+'</td>\n<td><span class="model-signature"></span></td>'},useData:!0}),this.Handlebars.templates.param_readonly_required=Handlebars.template({1:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"</textarea>\n"},3:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,r),inverse:this.program(6,r),data:r}),null!=i&&(o+=i),o},4:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" "+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<td class='code required'>"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"</td>\n<td>\n";return i=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(3,r),data:r}),null!=i&&(u+=i),u+='</td>\n<td class="markdown">',o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(u+=i),u+="</td>\n<td>",o=null!=(o=t.paramType||(null!=e?e.paramType:e))?o:s,i=typeof o===a?o.call(e,{name:"paramType",hash:{},data:r}):o,null!=i&&(u+=i),u+'</td>\n<td><span class="model-signature"></span></td>\n'},useData:!0}),this.Handlebars.templates.param_readonly=Handlebars.template({1:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea' readonly='readonly' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"</textarea>\n"},3:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,r),inverse:this.program(6,r),data:r}),null!=i&&(o+=i),o},4:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" "+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<td class='code'>"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"</td>\n<td>\n";return i=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(3,r),data:r}),null!=i&&(u+=i),u+='</td>\n<td class="markdown">',o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(u+=i),u+="</td>\n<td>",o=null!=(o=t.paramType||(null!=e?e.paramType:e))?o:s,i=typeof o===a?o.call(e,{name:"paramType",hash:{},data:r}):o,null!=i&&(u+=i),u+'</td>\n<td><span class="model-signature"></span></td>\n'},useData:!0}),this.Handlebars.templates.param_required=Handlebars.template({1:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,r),inverse:this.program(4,r),data:r}),null!=i&&(o+=i),o},2:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return' <input type="file" name=\''+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'/>\n"},4:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,r),inverse:this.program(7,r),data:r}),null!=i&&(o+=i),o},5:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea required' placeholder='(required)' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+'</textarea>\n <br />\n <div class="parameter-content-type" />\n'},7:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea required' placeholder='(required)' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+'\'></textarea>\n <br />\n <div class="parameter-content-type" />\n'},9:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(10,r),inverse:this.program(12,r),data:r}),null!=i&&(o+=i),o},10:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <input class='parameter' class='required' type='file' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'/>\n"},12:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(13,r),inverse:this.program(15,r),data:r}),null!=i&&(o+=i),o},13:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <input class='parameter required' minlength='1' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"' placeholder='(required)' type='text' value='"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"'/>\n"},15:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <input class='parameter required' minlength='1' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"' placeholder='(required)' type='text' value=''/>\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<td class='code required'>"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"</td>\n<td>\n";return i=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(9,r),data:r}),null!=i&&(u+=i),u+='</td>\n<td>\n <strong><span class="markdown">',o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(u+=i),u+="</span></strong>\n</td>\n<td>",o=null!=(o=t.paramType||(null!=e?e.paramType:e))?o:s,i=typeof o===a?o.call(e,{name:"paramType",hash:{},data:r}):o,null!=i&&(u+=i),u+'</td>\n<td><span class="model-signature"></span></td>\n'},useData:!0}),this.Handlebars.templates.param=Handlebars.template({1:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,r),inverse:this.program(4,r),data:r}),null!=i&&(o+=i),o},2:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return' <input type="file" name=\''+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+'\'/>\n <div class="parameter-content-type" />\n'},4:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,r),inverse:this.program(7,r),data:r}),null!=i&&(o+=i),o},5:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"'>"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+'</textarea>\n <br />\n <div class="parameter-content-type" />\n'},7:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <textarea class='body-textarea' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+'\'></textarea>\n <br />\n <div class="parameter-content-type" />\n'},9:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,r),inverse:this.program(10,r),data:r}),null!=i&&(o+=i),o},10:function(e,t,n,r){var i,o="";return i=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(11,r),inverse:this.program(13,r),data:r}),null!=i&&(o+=i),o},11:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <input class='parameter' minlength='0' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"' placeholder='' type='text' value='"+s((i=null!=(i=t["default"]||(null!=e?e["default"]:e))?i:a,typeof i===o?i.call(e,{name:"default",hash:{},data:r}):i))+"'/>\n"},13:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <input class='parameter' minlength='0' name='"+s((i=null!=(i=t.name||(null!=e?e.name:e))?i:a,typeof i===o?i.call(e,{name:"name",hash:{},data:r}):i))+"' placeholder='' type='text' value=''/>\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<td class='code'>"+l((o=null!=(o=t.name||(null!=e?e.name:e))?o:s,typeof o===a?o.call(e,{name:"name",hash:{},data:r}):o))+"</td>\n<td>\n\n";return i=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(9,r),data:r}),null!=i&&(u+=i),u+='\n</td>\n<td class="markdown">',o=null!=(o=t.description||(null!=e?e.description:e))?o:s,i=typeof o===a?o.call(e,{name:"description",hash:{},data:r}):o,null!=i&&(u+=i),u+="</td>\n<td>",o=null!=(o=t.paramType||(null!=e?e.paramType:e))?o:s,i=typeof o===a?o.call(e,{name:"paramType",hash:{},data:r}):o,null!=i&&(u+=i),u+'</td>\n<td>\n <span class="model-signature"></span>\n</td>\n'},useData:!0}),this.Handlebars.templates.parameter_content_type=Handlebars.template({1:function(e,t,n,r){var i,o="";return i=t.each.call(e,null!=e?e.consumes:e,{name:"each",hash:{},fn:this.program(2,r),inverse:this.noop,data:r}),null!=i&&(o+=i),o},2:function(e){var t,n=this.lambda,r=' <option value="';return t=n(e,e),null!=t&&(r+=t),r+='">',t=n(e,e),null!=t&&(r+=t),r+"</option>\n"},4:function(){return' <option value="application/json">application/json</option>\n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o='<label for="parameterContentType"></label>\n<select name="parameterContentType">\n';return i=t["if"].call(e,null!=e?e.consumes:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(4,r),data:r}),null!=i&&(o+=i),o+"</select>\n"},useData:!0}),this.Handlebars.templates.resource=Handlebars.template({1:function(){return" : "},3:function(e,t,n,r){var i,o="function",a=t.helperMissing,s=this.escapeExpression;return" <li>\n <a href='"+s((i=null!=(i=t.url||(null!=e?e.url:e))?i:a,typeof i===o?i.call(e,{name:"url",hash:{},data:r}):i))+"'>Raw</a>\n </li>\n"
+},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a,s="function",l=t.helperMissing,u=this.escapeExpression,c=t.blockHelperMissing,p="<div class='heading'>\n <h2>\n <a href='#!/"+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'\' class="toggleEndpointList" data-id="'+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'">'+u((o=null!=(o=t.name||(null!=e?e.name:e))?o:l,typeof o===s?o.call(e,{name:"name",hash:{},data:r}):o))+"</a> ";return o=null!=(o=t.summary||(null!=e?e.summary:e))?o:l,a={name:"summary",hash:{},fn:this.program(1,r),inverse:this.noop,data:r},i=typeof o===s?o.call(e,a):o,t.summary||(i=c.call(e,i,a)),null!=i&&(p+=i),o=null!=(o=t.summary||(null!=e?e.summary:e))?o:l,i=typeof o===s?o.call(e,{name:"summary",hash:{},data:r}):o,null!=i&&(p+=i),p+="\n </h2>\n <ul class='options'>\n <li>\n <a href='#!/"+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+"' id='endpointListTogger_"+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'\' class="toggleEndpointList" data-id="'+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'">Show/Hide</a>\n </li>\n <li>\n <a href=\'#\' class="collapseResource" data-id="'+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'">\n List Operations\n </a>\n </li>\n <li>\n <a href=\'#\' class="expandResource" data-id="'+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+'">\n Expand Operations\n </a>\n </li>\n',i=t["if"].call(e,null!=e?e.url:e,{name:"if",hash:{},fn:this.program(3,r),inverse:this.noop,data:r}),null!=i&&(p+=i),p+" </ul>\n</div>\n<ul class='endpoints' id='"+u((o=null!=(o=t.id||(null!=e?e.id:e))?o:l,typeof o===s?o.call(e,{name:"id",hash:{},data:r}):o))+"_endpoint_list' style='display:none'>\n\n</ul>\n"},useData:!0}),this.Handlebars.templates.response_content_type=Handlebars.template({1:function(e,t,n,r){var i,o="";return i=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,r),inverse:this.noop,data:r}),null!=i&&(o+=i),o},2:function(e){var t,n=this.lambda,r=' <option value="';return t=n(e,e),null!=t&&(r+=t),r+='">',t=n(e,e),null!=t&&(r+=t),r+"</option>\n"},4:function(){return' <option value="application/json">application/json</option>\n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o='<label for="responseContentType"></label>\n<select name="responseContentType">\n';return i=t["if"].call(e,null!=e?e.produces:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(4,r),data:r}),null!=i&&(o+=i),o+"</select>\n"},useData:!0}),this.Handlebars.templates.signature=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u='<div>\n<ul class="signature-nav">\n <li><a class="description-link" href="#">Model</a></li>\n <li><a class="snippet-link" href="#">Model Schema</a></li>\n</ul>\n<div>\n\n<div class="signature-container">\n <div class="description">\n ';return o=null!=(o=t.signature||(null!=e?e.signature:e))?o:s,i=typeof o===a?o.call(e,{name:"signature",hash:{},data:r}):o,null!=i&&(u+=i),u+'\n </div>\n\n <div class="snippet">\n <pre><code>'+l((o=null!=(o=t.sampleJSON||(null!=e?e.sampleJSON:e))?o:s,typeof o===a?o.call(e,{name:"sampleJSON",hash:{},data:r}):o))+'</code></pre>\n <small class="notice"></small>\n </div>\n</div>\n\n'},useData:!0}),this.Handlebars.templates.status_code=Handlebars.template({1:function(e,t,n,r){var i=this.lambda,o=this.escapeExpression;return" <tr>\n <td>"+o(i(r&&r.key,e))+"</td>\n <td>"+o(i(null!=e?e.description:e,e))+"</td>\n <td>"+o(i(null!=e?e.type:e,e))+"</td>\n </tr>\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,o,a="function",s=t.helperMissing,l=this.escapeExpression,u="<td width='15%' class='code'>"+l((o=null!=(o=t.code||(null!=e?e.code:e))?o:s,typeof o===a?o.call(e,{name:"code",hash:{},data:r}):o))+"</td>\n<td>";return o=null!=(o=t.message||(null!=e?e.message:e))?o:s,i=typeof o===a?o.call(e,{name:"message",hash:{},data:r}):o,null!=i&&(u+=i),u+='</td>\n<td width=\'50%\'><span class="model-signature" /></td>\n<td class="headers">\n <table>\n <tbody>\n',i=t.each.call(e,null!=e?e.headers:e,{name:"each",hash:{},fn:this.program(1,r),inverse:this.noop,data:r}),null!=i&&(u+=i),u+" </tbody>\n </table>\n</td>"},useData:!0}),function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.SwaggerClient=e()}}(function(){var e;return function t(e,n,r){function i(a,s){if(!n[a]){if(!e[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(e,t){"use strict";var n=e("./lib/auth"),r=e("./lib/helpers"),i=e("./lib/client"),o=function(e,t){return r.log('This is deprecated, use "new SwaggerClient" instead.'),new i(e,t)};Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){for(var n=t||0,r=this.length;r>n;n++)if(this[n]===e)return n;return-1}),String.prototype.endsWith||(String.prototype.endsWith=function(e){return-1!==this.indexOf(e,this.length-e.length)}),t.exports=i,i.ApiKeyAuthorization=n.ApiKeyAuthorization,i.PasswordAuthorization=n.PasswordAuthorization,i.CookieAuthorization=n.CookieAuthorization,i.SwaggerApi=o,i.SwaggerClient=o},{"./lib/auth":2,"./lib/client":3,"./lib/helpers":4}],2:[function(e,t){"use strict";var n=e("btoa"),r=e("cookiejar"),i=t.exports.SwaggerAuthorizations=function(){this.authz={}};i.prototype.add=function(e,t){return this.authz[e]=t,t},i.prototype.remove=function(e){return delete this.authz[e]},i.prototype.apply=function(e,t){var n,r,i,o,a=null;if("undefined"==typeof t||0===Object.keys(t).length)for(n in this.authz)i=this.authz[n],o=i.apply(e,t),o===!0&&(a=!0);else if(Array.isArray(t))for(var s=0;s<t.length;s++){var l=t[s];for(r in l)for(n in this.authz)n===r&&(i=this.authz[n],o=i.apply(e,t),o===!0&&(a=!0))}else for(r in t)for(n in this.authz)n===r&&(i=this.authz[n],o=i.apply(e,t),o===!0&&(a=!0));return a};var o=t.exports.ApiKeyAuthorization=function(e,t,n){this.name=e,this.value=t,this.type=n};o.prototype.apply=function(e){return"query"===this.type?(e.url=e.url.indexOf("?")>0?e.url+"&"+this.name+"="+this.value:e.url+"?"+this.name+"="+this.value,!0):"header"===this.type?(e.headers[this.name]=this.value,!0):void 0};var a=t.exports.CookieAuthorization=function(e){this.cookie=e};a.prototype.apply=function(e){return e.cookieJar=e.cookieJar||new r,e.cookieJar.setCookie(this.cookie),!0};var s=t.exports.PasswordAuthorization=function(e,t,n){this.name=e,this.username=t,this.password=n};s.prototype.apply=function(e){return e.headers.Authorization="Basic "+n(this.username+":"+this.password),!0}},{btoa:16,cookiejar:17}],3:[function(e,t){"use strict";var n={bind:e("lodash-compat/function/bind"),cloneDeep:e("lodash-compat/lang/cloneDeep"),find:e("lodash-compat/collection/find"),forEach:e("lodash-compat/collection/forEach"),indexOf:e("lodash-compat/array/indexOf"),isArray:e("lodash-compat/lang/isArray"),isFunction:e("lodash-compat/lang/isFunction"),isPlainObject:e("lodash-compat/lang/isPlainObject"),isUndefined:e("lodash-compat/lang/isUndefined")},r=e("./auth"),i=e("./helpers"),o=e("./types/model"),a=e("./types/operation"),s=e("./types/operationGroup"),l=e("./resolver"),u=e("./http"),c=e("./spec-converter"),p=["authorizationScheme","authorizations","basePath","build","buildFrom1_1Spec","buildFrom1_2Spec","buildFromSpec","clientAuthorizations","convertInfo","debug","defaultErrorCallback","defaultSuccessCallback","fail","failure","finish","help","idFromOp","info","initialize","isBuilt","isValid","models","modelsArray","options","parseUri","progress","resourceCount","sampleModels","selfReflect","setConsolidatedModels","spec","supportedSubmitMethods","swaggerRequestHeaders","tagFromLabel","url","useJQuery"],h=["apis","asCurl","description","externalDocs","help","label","name","operation","operations","operationsArray","path","tag"],f=["delete","get","head","options","patch","post","put"],d=t.exports=function(e,t){return this.authorizationScheme=null,this.authorizations=null,this.basePath=null,this.debug=!1,this.info=null,this.isBuilt=!1,this.isValid=!1,this.modelsArray=[],this.resourceCount=0,this.url=null,this.useJQuery=!1,"undefined"!=typeof e?this.initialize(e,t):this};d.prototype.initialize=function(e,t){this.models={},this.sampleModels={},t=t||{},"string"==typeof e?this.url=e:"object"==typeof e&&(t=e,this.url=t.url),this.swaggerRequestHeaders=t.swaggerRequestHeaders||"application/json;charset=utf-8,*/*",this.defaultSuccessCallback=t.defaultSuccessCallback||null,this.defaultErrorCallback=t.defaultErrorCallback||null,"function"==typeof t.success&&(this.success=t.success),t.useJQuery&&(this.useJQuery=t.useJQuery),this.clientAuthorizations=t.authorizations?t.authorizations:new r.SwaggerAuthorizations,this.supportedSubmitMethods=t.supportedSubmitMethods||[],this.failure=t.failure||function(){},this.progress=t.progress||function(){},this.spec=n.cloneDeep(t.spec),this.options=t,"function"==typeof t.success&&(this.ready=!0,this.build())},d.prototype.build=function(e){if(this.isBuilt)return this;var t=this;this.progress("fetching resource list: "+this.url);var n={useJQuery:this.useJQuery,url:this.url,method:"get",headers:{accept:this.swaggerRequestHeaders},on:{error:function(e){return t.fail("http"!==t.url.substring(0,4)?"Please specify the protocol for "+t.url:0===e.status?"Can't read from server. It may not have the appropriate access-control-origin settings.":404===e.status?"Can't read swagger JSON from "+t.url:e.status+" : "+e.statusText+" "+t.url)},response:function(e){var n=e.obj||JSON.parse(e.data);if(t.swaggerVersion=n.swaggerVersion,n.swagger&&2===parseInt(n.swagger))t.swaggerVersion=n.swagger,(new l).resolve(n,t.buildFromSpec,t),t.isValid=!0;else{var r=new c;r.setDocumentationLocation(t.url),r.convert(n,function(e){(new l).resolve(e,t.buildFromSpec,t),t.isValid=!0})}}}};if(this.spec)setTimeout(function(){(new l).resolve(t.spec,t.buildFromSpec,t)},10);else{if(this.clientAuthorizations.apply(n),e)return n;(new u).execute(n)}return this},d.prototype.buildFromSpec=function(e){if(this.isBuilt)return this;this.apis={},this.apisArray=[],this.basePath=e.basePath||"",this.consumes=e.consumes,this.host=e.host||"",this.info=e.info||{},this.produces=e.produces,this.schemes=e.schemes||[],this.securityDefinitions=e.securityDefinitions,this.title=e.title||"",e.externalDocs&&(this.externalDocs=e.externalDocs),this.authSchemes=e.securityDefinitions;var t,r={};if(Array.isArray(e.tags))for(r={},t=0;t<e.tags.length;t++){var l=e.tags[t];r[l.name]=l}var u;"string"==typeof this.url&&(u=this.parseUri(this.url)),this.scheme="undefined"==typeof this.schemes||0===this.schemes.length?u.scheme||"http":this.schemes[0],("undefined"==typeof this.host||""===this.host)&&(this.host=u.host,u.port&&(this.host=this.host+":"+u.port)),this.definitions=e.definitions;var c;for(c in this.definitions){var d=new o(c,this.definitions[c],this.models);d&&(this.models[c]=d)}var m=this;return m.apis.help=n.bind(m.help,m),n.forEach(e.paths,function(e,t){n.isPlainObject(e)&&n.forEach(f,function(o){var l=e[o];if(!n.isUndefined(l)){if(!n.isPlainObject(l))return void i.log("The '"+o+"' operation for '"+t+"' path is not an Operation Object");var u=l.tags;(n.isUndefined(u)||!n.isArray(u)||0===u.length)&&(u=l.tags=["default"]);var c=m.idFromOp(t,o,l),f=new a(m,l.scheme,c,o,t,l,m.definitions,m.models,m.clientAuthorizations);n.forEach(u,function(e){var t=n.indexOf(p,e)>-1?"_"+e:e,o=n.indexOf(h,e)>-1?"_"+e:e,a=m[t];if(t!==e&&i.log("The '"+e+"' tag conflicts with a SwaggerClient function/property name. Use 'client."+t+"' or 'client.apis."+e+"' instead of 'client."+e+"'."),o!==e&&i.log("The '"+e+"' tag conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+o+"' instead of 'client.apis."+e+"'."),n.indexOf(h,c)>-1&&(i.log("The '"+c+"' operationId conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+o+"._"+c+"' instead of 'client.apis."+o+"."+c+"'."),c="_"+c,f.nickname=c),n.isUndefined(a)){a=m[t]=m.apis[o]={},a.operations={},a.label=o,a.apis={};var l=r[e];n.isUndefined(l)||(a.description=l.description,a.externalDocs=l.externalDocs),m[t].help=n.bind(m.help,a),m.apisArray.push(new s(e,a.description,a.externalDocs,f))}n.isFunction(a.help)||(a.help=n.bind(m.help,a)),m.apis[o][c]=a[c]=n.bind(f.execute,f),m.apis[o][c].help=a[c].help=n.bind(f.help,f),m.apis[o][c].asCurl=a[c].asCurl=n.bind(f.asCurl,f),a.apis[c]=a.operations[c]=f;var u=n.find(m.apisArray,function(t){return t.tag===e});u&&u.operationsArray.push(f)})}})}),this.isBuilt=!0,this.success&&(this.isValid=!0,this.isBuilt=!0,this.success()),this},d.prototype.parseUri=function(e){var t=/^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,n=t.exec(e);return{scheme:n[4].replace(":",""),host:n[11],port:n[12],path:n[15]}},d.prototype.help=function(e){var t="";return this instanceof d?n.forEach(this.apis,function(e,r){n.isPlainObject(e)&&(t+="operations for the '"+r+"' tag\n",n.forEach(e.operations,function(e,n){t+=" * "+n+": "+e.summary+"\n"}))}):(this instanceof s||n.isPlainObject(this))&&(t+="operations for the '"+this.label+"' tag\n",n.forEach(this.apis,function(e,n){t+=" * "+n+": "+e.summary+"\n"})),e?t:(i.log(t),t)},d.prototype.tagFromLabel=function(e){return e},d.prototype.idFromOp=function(e,t,n){n&&n.operationId||(n=n||{},n.operationId=t+"_"+e);var r=n.operationId.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g,"_")||e.substring(1)+"_"+t;return r=r.replace(/((_){2,})/g,"_"),r=r.replace(/^(_)*/g,""),r=r.replace(/([_])*$/g,"")},d.prototype.fail=function(e){throw this.failure(e),e}},{"./auth":2,"./helpers":4,"./http":5,"./resolver":6,"./spec-converter":7,"./types/model":8,"./types/operation":9,"./types/operationGroup":10,"lodash-compat/array/indexOf":19,"lodash-compat/collection/find":21,"lodash-compat/collection/forEach":22,"lodash-compat/function/bind":25,"lodash-compat/lang/cloneDeep":94,"lodash-compat/lang/isArray":96,"lodash-compat/lang/isFunction":97,"lodash-compat/lang/isPlainObject":100,"lodash-compat/lang/isUndefined":103}],4:[function(e,t){(function(e){"use strict";t.exports.__bind=function(e,t){return function(){return e.apply(t,arguments)}};var n=t.exports.log=function(){n.history=n.history||[],n.history.push(arguments),console&&"test"!==e.env.NODE_ENV&&console.log(Array.prototype.slice.call(arguments)[0])};t.exports.fail=function(e){n(e)},t.exports.optionHtml=function(e,t){return'<tr><td class="optionName">'+e+":</td><td>"+t+"</td></tr>"},t.exports.typeFromJsonSchema=function(e,t){var n;return"integer"===e&&"int32"===t?n="integer":"integer"===e&&"int64"===t?n="long":"integer"===e&&"undefined"==typeof t?n="long":"string"===e&&"date-time"===t?n="date-time":"string"===e&&"date"===t?n="date":"number"===e&&"float"===t?n="float":"number"===e&&"double"===t?n="double":"number"===e&&"undefined"==typeof t?n="double":"boolean"===e?n="boolean":"string"===e&&(n="string"),n};var r=t.exports.simpleRef=function(e){return"undefined"==typeof e?null:0===e.indexOf("#/definitions/")?e.substring("#/definitions/".length):e},i=t.exports.getStringSignature=function(e,t){var n="";return"undefined"!=typeof e.$ref?n+=r(e.$ref):"undefined"==typeof e.type?n+="object":"array"===e.type?t?n+=i(e.items||e.$ref||{}):(n+="Array[",n+=i(e.items||e.$ref||{}),n+="]"):n+="integer"===e.type&&"int32"===e.format?"integer":"integer"===e.type&&"int64"===e.format?"long":"integer"===e.type&&"undefined"==typeof e.format?"long":"string"===e.type&&"date-time"===e.format?"date-time":"string"===e.type&&"date"===e.format?"date":"string"===e.type&&"undefined"==typeof e.format?"string":"number"===e.type&&"float"===e.format?"float":"number"===e.type&&"double"===e.format?"double":"number"===e.type&&"undefined"==typeof e.format?"double":"boolean"===e.type?"boolean":e.$ref?r(e.$ref):e.type,n}}).call(this,e("_process"))},{_process:15}],5:[function(e,t){"use strict";var n=e("./helpers"),r=e("jquery"),i=e("superagent"),o=function(){},a=function(){},s=t.exports=function(){};s.prototype.execute=function(e,t){return this.useJQuery=e&&"boolean"==typeof e.useJQuery?e.useJQuery:this.isIE8(),e&&"object"==typeof e.body&&(e.body.type&&"formData"===e.body.type?(e.contentType=!1,e.processData=!1,delete e.headers["Content-Type"]):e.body=JSON.stringify(e.body)),this.useJQuery?new o(t).execute(e):new a(t).execute(e)},s.prototype.isIE8=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent){var t=navigator.userAgent.toLowerCase();if(-1!==t.indexOf("msie")){var n=parseInt(t.split("msie")[1]);8>=n&&(e=!0)}}return e},o.prototype.execute=function(e){var t=e.on,i=e;return e.type=e.method,e.cache=!1,delete e.useJQuery,e.data=e.body,delete e.body,e.complete=function(e){for(var r={},o=e.getAllResponseHeaders().split("\n"),a=0;a<o.length;a++){var s=o[a].trim();if(0!==s.length){var l=s.indexOf(":");if(-1!==l){var u=s.substring(0,l).trim(),c=s.substring(l+1).trim();r[u]=c}else r[s]=null}}var p={url:i.url,method:i.method,status:e.status,statusText:e.statusText,data:e.responseText,headers:r},h=r["content-type"]||r["Content-Type"]||null;if(h&&(0===h.indexOf("application/json")||h.indexOf("+json")>0))try{p.obj=e.responseJSON||JSON.parse(p.data)||{}}catch(f){n.log("unable to parse JSON content")}if(e.status>=200&&e.status<300)t.response(p);else{if(!(0===e.status||e.status>=400&&e.status<599))return t.response(p);t.error(p)}},r.support.cors=!0,r.ajax(e)},a.prototype.execute=function(e){var t=e.method.toLowerCase();"delete"===t&&(t="del");var n,r=e.headers||{},o=i[t](e.url);for(n in r)o.set(n,r[n]);e.body&&o.send(e.body),o.end(function(t,n){n=n||{status:0,headers:{error:"no response from server"}};var r,i={url:e.url,method:e.method,headers:n.headers};!t&&n.error&&(t=n.error),t&&e.on&&e.on.error?(i.obj=t,i.status=n?n.status:500,i.statusText=n?n.text:t.message,r=e.on.error):n&&e.on&&e.on.response&&(i.obj="undefined"!=typeof n.body?n.body:n.text,i.status=n.status,i.statusText=n.text,r=e.on.response),i.data=i.statusText,r&&r(i)})}},{"./helpers":4,jquery:18,superagent:111}],6:[function(e,t){"use strict";var n=e("./http"),r=t.exports=function(){};r.prototype.resolve=function(e,t,r){this.scope=r||this;var i,o,a,s,l,u=0,c={},p={},h={};for(o in e.definitions){var f=e.definitions[o];for(l in f.properties)s=f.properties[l],this.resolveTo(s,h)}for(o in e.paths){var d,m,g;a=e.paths[o];for(d in a)if("$ref"===d)this.resolveInline(e,a,h,p);else{m=a[d];var y,v=m.parameters;for(y in v){var b=v[y];"body"===b["in"]&&b.schema&&this.resolveTo(b.schema,h),b.$ref&&this.resolveInline(e,b,h,p)}for(g in m.responses){var w=m.responses[g];"object"==typeof w&&w.$ref&&this.resolveInline(e,w,h,p),w.schema&&this.resolveTo(w.schema,h)}}}var x={},A=0;for(o in h){var E=o.split("#");2===E.length?(i=E[0],a=E[1],Array.isArray(x[i])||(x[i]=[],A+=1),x[i].push(a)):(Array.isArray(x[o])||(x[o]=[],A+=1),x[o].push(null))}for(o in x){var j=this,C=x[o];i=o;var T={useJQuery:!1,url:i,method:"get",headers:{accept:this.scope.swaggerRequestHeaders||"application/json"},on:{error:function(){u+=1;var n;for(n=0;n<C.length;n++){var r=i+"#"+C[n];p[r]=null}u===A&&j.finish(e,h,c,p,t)},response:function(n){var r,a,s=n.obj;if(null===s||0===Object.keys(s).length)try{s=JSON.parse(n.data)}catch(l){s={}}for(u+=1,r=0;r<C.length;r++){var f=C[r];if(null==f)c[o]={name:o,obj:s};else{var d=s,m=f.split("/");for(a=0;a<m.length;a++){var g=m[a];if(-1!==g.indexOf("~1")&&(g=m[a].replace(/~0/g,"~").replace(/~1/g,"/"),"/"!==g.charAt(0)&&(g="/"+g)),"undefined"==typeof d)break;g.length>0&&(d=d[g])}var y=i+"#"+f,v=m[a-1];"undefined"!=typeof d?c[y]={name:v,obj:d}:p[y]=null}}u===A&&j.finish(e,h,c,p,t)}}};r&&r.clientAuthorizations&&r.clientAuthorizations.apply(T),(new n).execute(T)}0===Object.keys(x).length&&t.call(this.scope,e,p)},r.prototype.finish=function(e,t,n,r,i){var o;for(o in t){var a,s=t[o];for(a=0;a<s.length;a++){var l=n[s[a].obj.$ref];if(l)if(e.definitions||(e.definitions={}),"$ref"===s[a].resolveAs)e.definitions[l.name]=l.obj,s[a].obj.$ref="#/definitions/"+l.name;else if("inline"===s[a].resolveAs){var u,c=s[a].obj;delete c.$ref;for(u in l.obj)c[u]=l.obj[u]}}}i.call(this.scope,e,r)},r.prototype.resolveInline=function(e,t,n,r){var i=t.$ref;if(i){if(0===i.indexOf("http"))Array.isArray(n[i])?n[i].push({obj:t,resolveAs:"inline"}):n[i]=[{obj:t,resolveAs:"inline"}];else if(0===i.indexOf("#")){var o,a=i.substring(1),s=a.split("/"),l=e;for(o=0;o<s.length;o++){var u=s[o];u.length>0&&(l=l[u])}if(l){delete t.$ref;var c;for(c in l)t[c]=l[c]}else r[i]=null}}else"array"===t.type&&this.resolveTo(t.items,n)},r.prototype.resolveTo=function(e,t){var n=e.$ref;if(n)0===n.indexOf("http")&&(Array.isArray(t[n])?t[n].push({obj:e,resolveAs:"$ref"}):t[n]=[{obj:e,resolveAs:"$ref"}]);else if("array"===e.type){var r=e.items;this.resolveTo(r,t)}}},{"./http":5}],7:[function(e,t){"use strict";var n=(e("./client"),e("./http")),r=t.exports=function(){this.errors=[],this.warnings=[],this.modelMap={}};r.prototype.setDocumentationLocation=function(e){this.docLocation=e},r.prototype.convert=function(e,t){if(!e||!Array.isArray(e.apis))return this.finish(t,null);var n={swagger:"2.0"};n.originalVersion=e.swaggerVersion,this.apiInfo(e,n),this.securityDefinitions(e,n);var r,i=!1;for(r=0;r<e.apis.length;r++){var o=e.apis[r];Array.isArray(o.operations)&&(i=!0)}i?(this.declaration(e,n),this.finish(t,n)):this.resourceListing(e,n,t)},r.prototype.declaration=function(e,t){var n,r;if(e.apis){{e.basePath}if(0===e.basePath.indexOf("http://")){var i=e.basePath.substring("http://".length),o=i.indexOf("/");o>0?(t.host=i.substring(0,o),t.basePath=i.substring(o)):(t.host=i,t.basePath="/")}var a;if(e.authorizations&&(a=e.authorizations),e.consumes&&(t.consumes=e.consumes),e.produces&&(t.produces=e.produces),"object"==typeof e)for(n in e.models){var s=e.models[n],l=s.id||n;this.modelMap[l]=n}for(r=0;r<e.apis.length;r++){var u=e.apis[r],c=u.path,p=u.operations;this.operations(c,e.resourcePath,p,a,t)}var h=e.models;this.models(h,t)}},r.prototype.models=function(e,t){if("object"==typeof e){var n;t.definitions=t.definitions||{};for(n in e){var r,i=e[n],o=[],a={properties:{}};for(r in i.properties){var s=i.properties[r],l={};this.dataType(s,l),s.description&&(l.description=s.description),s["enum"]&&(l["enum"]=s["enum"]),"boolean"==typeof s.required&&s.required===!0&&o.push(r),"string"==typeof s.required&&"true"===s.required&&o.push(r),a.properties[r]=l}o.length>0&&(a["enum"]=o),t.definitions[n]=a}}},r.prototype.extractTag=function(e){var t=e||"default";return(0===t.indexOf("http:")||0===t.indexOf("https:"))&&(t=t.split(["/"]),t=t[t.length-1].substring()),t.replace("/","")},r.prototype.operations=function(e,t,n,r,i){if(Array.isArray(n)){var o;i.paths||(i.paths={});var a=i.paths[e]||{},s=this.extractTag(t);i.tags=i.tags||[];var l=!1;for(o=0;o<i.tags.length;o++){var u=i.tags[o];u.name===s&&(l=!0)}for(l||i.tags.push({name:s}),o=0;o<n.length;o++){var c=n[o],p=(c.method||c.httpMethod).toLowerCase(),h={tags:[s]},f=c.authorizations;if(f&&0===Object.keys(f).length&&(f=r),"undefined"!=typeof f)for(var d in f){h.security=h.security||[];var m=f[d];if(m){var g=[];for(var y in m)g.push(m[y].scope);var v={};v[d]=g,h.security.push(v)}else{var v={};v[d]=[],h.security.push(v)}}c.consumes?h.consumes=c.consumes:i.consumes&&(h.consumes=i.consumes),c.produces?h.produces=c.produces:i.produces&&(h.produces=i.produces),c.summary&&(h.summary=c.summary),c.notes&&(h.description=c.notes),c.nickname&&(h.operationId=c.nickname),c.deprecated&&(h.deprecated=c.deprecated),this.authorizations(f,i),this.parameters(h,c.parameters,i),this.responseMessages(h,c,i),a[p]=h}i.paths[e]=a}},r.prototype.responseMessages=function(e,t){if("object"==typeof t){var n={};this.dataType(t,n),n.schema||(n={schema:n}),e.responses=e.responses||{};var r=!1;if(Array.isArray(t.responseMessages)){var i,o=t.responseMessages;for(i=0;i<o.length;i++){var a=o[i],s={description:a.message};200===a.code&&(r=!0),e.responses[""+a.code]=s}}r?e.responses["default"]=n:e.responses[200]=n}},r.prototype.authorizations=function(e){},r.prototype.parameters=function(e,t){if(Array.isArray(t)){var n;for(n=0;n<t.length;n++){var r=t[n],i={};if(i.name=r.name,i.description=r.description,i.required=r.required,i["in"]=r.paramType,"body"===i["in"]&&(i.name="body"),"form"===i["in"]&&(i["in"]="formData"),r.allowMultiple===!0||"true"===r.allowMultiple){var o={};if(this.dataType(r,o),i.type="array",i.items=o,r.allowableValues){var a=r.allowableValues;"LIST"===a.valueType&&(i["enum"]=a.values)}}else this.dataType(r,i);e.parameters=e.parameters||[],e.parameters.push(i)}}},r.prototype.dataType=function(e,t){if("object"==typeof e){e.minimum&&(t.minimum=e.minimum),e.maximum&&(t.maximum=e.maximum),e.defaultValue&&(t["default"]=e.defaultValue);var n=this.toJsonSchema(e);n&&(t=t||{},n.type&&(t.type=n.type),n.format&&(t.format=n.format),n.$ref&&(t.schema={$ref:n.$ref}),n.items&&(t.items=n.items))}},r.prototype.toJsonSchema=function(e){if(!e)return"object";var t=e.type||e.dataType||e.responseClass||"",n=t.toLowerCase(),r=(e.format||"").toLowerCase();if(0===n.indexOf("list[")){var i=t.substring(5,t.length-1),o=this.toJsonSchema({type:i});return{type:"array",items:o}}if("int"===n||"integer"===n&&"int32"===r)return{type:"integer",format:"int32"};if("long"===n||"integer"===n&&"int64"===r)return{type:"integer",format:"int64"};if("integer"===n)return{type:"integer",format:"int64"};if("float"===n||"number"===n&&"float"===r)return{type:"number",format:"float"};if("double"===n||"number"===n&&"double"===r)return{type:"number",format:"double"};if("string"===n&&"date-time"===r||"date"===n)return{type:"string",format:"date-time"};if("string"===n)return{type:"string"};if("file"===n)return{type:"file"};if("boolean"===n)return{type:"boolean"};if("array"===n||"list"===n){if(e.items){var a=this.toJsonSchema(e.items);return{type:"array",items:a}}return{type:"array",items:{type:"object"}}}return e.$ref?{$ref:"#/definitions/"+this.modelMap[e.$ref]||e.$ref}:{$ref:"#/definitions/"+this.modelMap[e.type]||e.type}},r.prototype.resourceListing=function(e,t,r){var i,o=0,a=this,s=e.apis.length,l=t;for(0===s&&this.finish(r,t),i=0;s>i;i++){var u=e.apis[i],c=u.path,p=this.getAbsolutePath(e.swaggerVersion,this.docLocation,c);u.description&&(t.tags=t.tags||[],t.tags.push({name:this.extractTag(u.path),description:u.description||""}));var h={url:p,headers:{accept:"application/json"},on:{},method:"get"};h.on.response=function(e){o+=1,e.obj&&a.declaration(e.obj,l),o===s&&a.finish(r,l)},h.on.error=function(e){console.error(e),o+=1,o===s&&a.finish(r,l)},(new n).execute(h)}},r.prototype.getAbsolutePath=function(e,t,n){if("1.0"===e&&t.endsWith(".json")){var r=t.lastIndexOf("/");r>0&&(t=t.substring(0,r))}var i=t;return 0===n.indexOf("http://")||0===n.indexOf("https://")?i=n:(t.endsWith("/")&&(i=t.substring(0,t.length-1)),i+=n),i=i.replace("{format}","json")},r.prototype.securityDefinitions=function(e,t){if(e.authorizations){var n;for(n in e.authorizations){var r=!1,i={},o=e.authorizations[n];if("apiKey"===o.type)i.type="apiKey",i["in"]=o.passAs,i.name=o.keyname||n,r=!0;else if("oauth2"===o.type){var a,s=o.scopes||[],l={};for(a in s){var u=s[a];l[u.scope]=u.description}if(i.type="oauth2",a>0&&(i.scopes=l),o.grantTypes){if(o.grantTypes.implicit){var c=o.grantTypes.implicit;i.flow="implicit",i.authorizationUrl=c.loginEndpoint,r=!0}if(o.grantTypes.authorization_code&&!i.flow){var p=o.grantTypes.authorization_code;i.flow="accessCode",i.authorizationUrl=p.tokenRequestEndpoint.url,i.tokenUrl=p.tokenEndpoint.url,r=!0}}}r&&(t.securityDefinitions=t.securityDefinitions||{},t.securityDefinitions[n]=i)}}},r.prototype.apiInfo=function(e,t){if(e.info){var n=e.info;t.info={},n.contact&&(t.info.contact={},t.info.contact.email=n.contact),n.description&&(t.info.description=n.description),n.title&&(t.info.title=n.title),n.termsOfServiceUrl&&(t.info.termsOfService=n.termsOfServiceUrl),(n.license||n.licenseUrl)&&(t.license={},n.license&&(t.license.name=n.license),n.licenseUrl&&(t.license.url=n.licenseUrl))}else this.warnings.push("missing info section")},r.prototype.finish=function(e,t){e(t)}},{"./client":3,"./http":5}],8:[function(e,t){"use strict";var n={forEach:e("lodash-compat/collection/forEach"),indexOf:e("lodash-compat/array/indexOf"),isArray:e("lodash-compat/lang/isArray"),isPlainObject:e("lodash-compat/lang/isPlainObject"),isString:e("lodash-compat/lang/isString"),isUndefined:e("lodash-compat/lang/isUndefined"),keys:e("lodash-compat/object/keys"),map:e("lodash-compat/collection/map")},r=e("../helpers"),i=t.exports=function(e,t,n){return this.definition=t||{},this.isArray="array"===t.type,this.models=n||{},this.name=e||"Inline Model",this},o=function(e,t,o){for(var a='<span class="strong">',s="</span>",l={},u=[],c=0,p=function(e,t,a){var s,u=t;return e.$ref?(u=r.simpleRef(e.$ref),s=o[u]):n.isUndefined(t)&&(u="Inline Model "+ ++c,s=new i(u,e,o)),a!==!0&&(l[u]=n.isUndefined(s)?{}:s.definition),u},h=function(e){var t='<span class="propType">',i=e.type||"object";return e.$ref?t+=p(e,r.simpleRef(e.$ref)):"object"===i?t+=n.isUndefined(e.properties)?"object":p(e):"array"===i?(t+="Array[",n.isArray(e.items)?t+=n.map(e.items,p).join(","):n.isPlainObject(e.items)?t+=n.isUndefined(e.items.$ref)?n.isUndefined(e.items.type)||-1!==n.indexOf(["array","object"],e.items.type)?p(e.items):e.items.type:p(e.items,r.simpleRef(e.items.$ref)):(r.log("Array type's 'items' schema is not an array or an object, cannot process"),t+="object"),t+="]"):t+=e.type,t+="</span>"},f=function(e,t){var i="",o=e.type||"object",a="array"===o;switch(a&&(o=n.isPlainObject(e.items)&&!n.isUndefined(e.items.type)?e.items.type:"object"),e["default"]&&(i+=r.optionHtml("Default",e["default"])),o){case"string":e.minLength&&(i+=r.optionHtml("Min. Length",e.minLength)),e.maxLength&&(i+=r.optionHtml("Max. Length",e.maxLength)),e.pattern&&(i+=r.optionHtml("Reg. Exp.",e.pattern));break;case"integer":case"number":e.minimum&&(i+=r.optionHtml("Min. Value",e.minimum)),e.exclusiveMinimum&&(i+=r.optionHtml("Exclusive Min.","true")),e.maximum&&(i+=r.optionHtml("Max. Value",e.maximum)),e.exclusiveMaximum&&(i+=r.optionHtml("Exclusive Max.","true")),e.multipleOf&&(i+=r.optionHtml("Multiple Of",e.multipleOf))}if(a&&(e.minItems&&(i+=r.optionHtml("Min. Items",e.minItems)),e.maxItems&&(i+=r.optionHtml("Max. Items",e.maxItems)),e.uniqueItems&&(i+=r.optionHtml("Unique Items","true")),e.collectionFormat&&(i+=r.optionHtml("Coll. Format",e.collectionFormat))),n.isUndefined(e.items)&&n.isArray(e["enum"])){var s;s="number"===o||"integer"===o?e["enum"].join(", "):'"'+e["enum"].join('", "')+'"',i+=r.optionHtml("Enum",s)}return i.length>0&&(t='<span class="propWrap">'+t+'<table class="optionsWrapper"><tr><th colspan="2">'+o+"</th></tr>"+i+"</table></span>"),t},d=function(e,t){var i=e.type||"object",o="array"===e.type,l=a+t+" "+(o?"[":"{")+s;return t&&u.push(t),o?n.isArray(e.items)?l+="<div>"+n.map(e.items,function(e){var t=e.type||"object";return n.isUndefined(e.$ref)?n.indexOf(["array","object"],t)>-1?"object"===t&&n.isUndefined(e.properties)?"object":p(e):f(e,t):p(e,r.simpleRef(e.$ref))}).join(",</div><div>"):n.isPlainObject(e.items)?l+=n.isUndefined(e.items.$ref)?n.indexOf(["array","object"],e.items.type||"object")>-1?(n.isUndefined(e.items.type)||"object"===e.items.type)&&n.isUndefined(e.items.properties)?"<div>object</div>":"<div>"+p(e.items)+"</div>":"<div>"+f(e.items,e.items.type)+"</div>":"<div>"+p(e.items,r.simpleRef(e.items.$ref))+"</div>":(r.log("Array type's 'items' property is not an array or an object, cannot process"),l+="<div>object</div>"):e.$ref?l+="<div>"+p(e,t)+"</div>":"object"===i?(l+="<div>",n.isPlainObject(e.properties)&&(l+=n.map(e.properties,function(t,r){var i=n.indexOf(e.required||[],r)>-1,o='<span class="propName '+i+'">'+r+"</span> (";
+return o+=h(t),i||(o+=', <span class="propOptKey">optional</span>'),o+=")",n.isUndefined(t.description)||(o+=": "+t.description),t["enum"]&&(o+=' = <span class="propVals">[\''+t["enum"].join("' or '")+"']</span>"),f(t,o)}).join(",</div><div>")),l+="</div>"):l="<div>"+f(e,i)+"</div>",l+a+(o?"]":"}")+s},m=d(t,e);n.keys(l).length>0;)n.forEach(l,function(e,t){var r=n.indexOf(u,t)>-1;delete l[t],r||(u.push(t),m+="<br />"+d(e,t))});return m},a=function(e,t,i){var o,s,l=e.type||"object";return e.example?s=e.example:n.isUndefined(e.items)&&n.isArray(e["enum"])&&(s=e["enum"][0]),n.isUndefined(s)&&(e.$ref?(o=t[r.simpleRef(e.$ref)],n.isUndefined(o)||(n.isUndefined(i[o.name])?(i[o.name]=o,s=a(o.definition,t,i),delete i[o.name]):s="array"===o.type?[]:{})):e["default"]?s=e["default"]:"date-time"===l?s=(new Date).toISOString():"date"===l?s=(new Date).toISOString().split("T")[0]:"string"===l?s="string":"integer"===l?s=0:"long"===l?s=0:"float"===l?s=0:"double"===l?s=0:"boolean"===l?s=!0:"object"===l?(s={},n.forEach(e.properties,function(e,n){s[n]=a(e,t,i)})):"array"===l&&(s=[],n.isArray(e.items)?n.forEach(e.items,function(e){s.push(a(e,t,i))}):n.isPlainObject(e.items)?s.push(a(e.items,t,i)):n.isUndefined(e.items)?s.push({}):r.log("Array type's 'items' property is not an array or an object, cannot process"))),s};i.prototype.createJSONSample=i.prototype.getSampleValue=function(e){return e=e||{},e[this.name]=this,this.examples&&n.isPlainObject(this.examples)&&this.examples["application/json"]?(this.definition.example=this.examples["application/json"],n.isString(this.definition.example)&&(this.definition.example=JSON.parse(this.definition.example))):this.definition.example=this.examples,a(this.definition,this.models,e)},i.prototype.getMockSignature=function(){return o(this.name,this.definition,this.models)}},{"../helpers":4,"lodash-compat/array/indexOf":19,"lodash-compat/collection/forEach":22,"lodash-compat/collection/map":23,"lodash-compat/lang/isArray":96,"lodash-compat/lang/isPlainObject":100,"lodash-compat/lang/isString":101,"lodash-compat/lang/isUndefined":103,"lodash-compat/object/keys":104}],9:[function(e,t){"use strict";var n={isUndefined:e("lodash-compat/lang/isUndefined")},r=e("../helpers"),i=e("./model"),o=e("../http"),a=t.exports=function(e,t,n,r,o,a,s,l,u){var c=[];if(e=e||{},a=a||{},this.authorizations=a.security,this.basePath=e.basePath||"/",this.clientAuthorizations=u,this.consumes=a.consumes,this.deprecated=a.deprecated,this.description=a.description,this.host=e.host||"localhost",this.method=r||c.push("Operation "+n+" is missing method."),this.models=l||{},this.nickname=n||c.push("Operations must have a nickname."),this.operation=a,this.operations={},this.parameters=null!==a?a.parameters||[]:{},this.parent=e,this.path=o||c.push("Operation "+this.nickname+" is missing path."),this.produces=a.produces,this.responses=a.responses||{},this.scheme=t||e.scheme||"http",this.schemes=e.schemes,this.security=a.security,this.summary=a.summary||"",this.type=null,this.useJQuery=e.useJQuery,"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}var p,h;if(s){var f;for(f in this.definitions)h=new i(f,s[f],this.models),h&&(this.models[f]=h)}for(p=0;p<this.parameters.length;p++){var d=this.parameters[p];"array"===d.type&&(d.isList=!0,d.allowMultiple=!0);var m=this.getType(d);if(m&&"boolean"===m.toString().toLowerCase()&&(d.allowableValues={},d.isList=!0,d["enum"]=["true","false"]),"undefined"!=typeof d["enum"]){var g;for(d.allowableValues={},d.allowableValues.values=[],d.allowableValues.descriptiveValues=[],g=0;g<d["enum"].length;g++){var y=d["enum"][g],v=y===d["default"]?!0:!1;d.allowableValues.values.push(y),d.allowableValues.descriptiveValues.push({value:y,isDefault:v})}}"array"===d.type&&(m=[m],"undefined"==typeof d.allowableValues&&(delete d.isList,delete d.allowMultiple)),d.signature=this.getModelSignature(m,this.models).toString(),d.sampleJSON=this.getModelSampleJSON(m,this.models),d.responseClassSignature=d.signature}var b,w,x=this.responses;if(x[200]?(w=x[200],b="200"):x[201]?(w=x[201],b="201"):x[202]?(w=x[202],b="202"):x[203]?(w=x[203],b="203"):x[204]?(w=x[204],b="204"):x[205]?(w=x[205],b="205"):x[206]?(w=x[206],b="206"):x["default"]&&(w=x["default"],b="default"),w&&w.schema){var A,E=this.resolveModel(w.schema,s);delete x[b],E?(this.successResponse={},A=this.successResponse[b]=E):w.schema.type&&"object"!==w.schema.type&&"array"!==w.schema.type?(this.successResponse={},A=this.successResponse[b]=w.schema):(this.successResponse={},A=this.successResponse[b]=new i(void 0,w.schema||{},this.models)),A&&(w.description&&(A.description=w.description),w.examples&&(A.examples=w.examples),w.headers&&(A.headers=w.headers)),this.type=w}return c.length>0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(c),this};a.prototype.getType=function(e){var t,n=e.type,i=e.format,o=!1;"integer"===n&&"int32"===i?t="integer":"integer"===n&&"int64"===i?t="long":"integer"===n?t="integer":"string"===n?t="date-time"===i?"date-time":"date"===i?"date":"string":"number"===n&&"float"===i?t="float":"number"===n&&"double"===i?t="double":"number"===n?t="double":"boolean"===n?t="boolean":"array"===n&&(o=!0,e.items&&(t=this.getType(e.items))),e.$ref&&(t=e.$ref);var a=e.schema;if(a){var s=a.$ref;return s?(s=r.simpleRef(s),o?[s]:s):this.getType(a)}return o?[t]:t},a.prototype.resolveModel=function(e,t){if("undefined"!=typeof e.$ref){var r=e.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),t[r])return new i(r,t[r],this.models)}else if("object"===e.type||n.isUndefined(e.type))return new i(void 0,e,this.models);return null},a.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",n=0;n<this.parameters.length;n++){var i=this.parameters[n],o=i.signature;t+="\n * "+i.name+" ("+o+"): "+i.description}return"undefined"==typeof e&&r.log(t),t},a.prototype.getModelSignature=function(e,t){var n,r;return e instanceof Array?(r=!0,e=e[0]):"undefined"==typeof e&&(e="undefined"),n="string"===e?!0:r&&t[r]||t[e]?!1:!0,n?r?"Array["+e+"]":e.toString():r?"Array["+t[e].getMockSignature()+"]":t[e].getMockSignature()},a.prototype.supportHeaderParams=function(){return!0},a.prototype.supportedSubmitMethods=function(){return this.parent.supportedSubmitMethods},a.prototype.getHeaderParams=function(e){for(var t=this.setContentTypes(e,{}),n=0;n<this.parameters.length;n++){var r=this.parameters[n];if("undefined"!=typeof e[r.name]&&"header"===r["in"]){var i=e[r.name];Array.isArray(i)&&(i=i.toString()),t[r.name]=i}}return t},a.prototype.urlify=function(e){for(var t={},n=this.path,r="",i=0;i<this.parameters.length;i++){var o=this.parameters[i];if("undefined"!=typeof e[o.name])if("path"===o["in"]){var a=new RegExp("{"+o.name+"}","gi"),s=e[o.name];s=Array.isArray(s)?this.encodePathCollection(o.collectionFormat,o.name,s):this.encodePathParam(s),n=n.replace(a,s)}else if("query"===o["in"]&&"undefined"!=typeof e[o.name])if(r+=""===r?"?":"&","undefined"!=typeof o.collectionFormat){var l=e[o.name];r+=Array.isArray(l)?this.encodeQueryCollection(o.collectionFormat,o.name,l):this.encodeQueryParam(o.name)+"="+this.encodeQueryParam(e[o.name])}else r+=this.encodeQueryParam(o.name)+"="+this.encodeQueryParam(e[o.name]);else"formData"===o["in"]&&(t[o.name]=e[o.name])}var u=this.scheme+"://"+this.host;return"/"!==this.basePath&&(u+=this.basePath),u+n+r},a.prototype.getMissingParams=function(e){var t,n=[];for(t=0;t<this.parameters.length;t++){var r=this.parameters[t];r.required===!0&&"undefined"==typeof e[r.name]&&(n=r.name)}return n},a.prototype.getBody=function(e,t,n){for(var r,i,o,a={},s=0;s<this.parameters.length;s++){var l=this.parameters[s];"undefined"!=typeof t[l.name]&&("body"===l["in"]?r=t[l.name]:"formData"===l["in"]&&(a[l.name]=t[l.name]))}if("application/x-www-form-urlencoded"===e["Content-Type"]){var u="";for(i in a)o=a[i],"undefined"!=typeof o&&(""!==u&&(u+="&"),u+=encodeURIComponent(i)+"="+encodeURIComponent(o));r=u}else if(e["Content-Type"]&&e["Content-Type"].indexOf("multipart/form-data")>=0&&n.useJQuery){var c=new FormData;c.type="formData";for(i in a)o=t[i],"undefined"!=typeof o&&("file"===o.type&&o.value?(delete e["Content-Type"],c.append(i,o.value)):c.append(i,o));r=c}return r},a.prototype.getModelSampleJSON=function(e,t){var n,r,i;if(r=e instanceof Array,n=t[e]?!1:!0,i=n?void 0:t[e].createJSONSample()){if(i=r?[i]:i,"string"==typeof i)return i;if("object"==typeof i){var o=i;if(i instanceof Array&&i.length>0&&(o=i[0]),o.nodeName){var a=(new XMLSerializer).serializeToString(o);return this.formatXml(a)}return JSON.stringify(i,null,2)}return i}},a.prototype["do"]=function(e,t,n,r,i){return this.execute(e,t,n,r,i)},a.prototype.execute=function(e,t,n,i,a){var s,l,u=e||{},c={};"object"==typeof t&&(c=t,s=n,l=i),"function"==typeof t&&(s=t,l=n),s=s||r.log,l=l||r.log,c.useJQuery&&(this.useJQuery=c.useJQuery);var p=this.getMissingParams(u);if(p.length>0){var h="missing required params: "+p;return void r.fail(h)}var f,d=this.getHeaderParams(u),m=this.setContentTypes(u,c),g={};for(f in d)g[f]=d[f];for(f in m)g[f]=m[f];var y=this.getBody(g,u,c),v=this.urlify(u);if(v.indexOf(".{format}")>0&&g){var b=g.Accept||g.accept;b&&b.indexOf("json")>0?v=v.replace(".{format}",".json"):b&&b.indexOf("xml")>0&&(v=v.replace(".{format}",".xml"))}var w={url:v,method:this.method.toUpperCase(),body:y,useJQuery:this.useJQuery,headers:g,on:{response:function(e){return s(e,a)},error:function(e){return l(e,a)}}};return this.clientAuthorizations.apply(w,this.operation.security),c.mock===!0?w:void(new o).execute(w,c)},a.prototype.setContentTypes=function(e,t){var n,i,o="application/json",a=this.parameters,s=e.parameterContentType||"application/json",l=[],u=[],c={};for(i=0;i<a.length;i++){var p=a[i];if("formData"===p["in"])"file"===p.type?l.push(p):u.push(p);else if("header"===p["in"]&&t){var h=p.name,f=t[p.name];"undefined"!=typeof t[p.name]&&(c[h]=f)}else"body"===p["in"]&&"undefined"!=typeof e[p.name]&&(n=e[p.name])}return!n||"post"!==this.method&&"put"!==this.method&&"patch"!==this.method&&"delete"!==this.method?u.length>0?s=t.requestContentType?t.requestContentType:l.length>0?"multipart/form-data":"application/x-www-form-urlencoded":"DELETE"===this.type?n="{}":"DELETE"!==this.type&&(s=null):t.requestContentType&&(s=t.requestContentType),s&&this.consumes&&-1===this.consumes.indexOf(s)&&r.log("server doesn't consume "+s+", try "+JSON.stringify(this.consumes)),o=t.responseContentType?t.responseContentType:"application/json",o&&this.produces&&-1===this.produces.indexOf(o)&&r.log("server can't produce "+o),(s&&""!==n||"application/x-www-form-urlencoded"===s)&&(c["Content-Type"]=s),o&&(c.Accept=o),c},a.prototype.asCurl=function(e){var t=this.execute(e,{mock:!0});this.clientAuthorizations.apply(t);var n=[];if(n.push("-X "+this.method.toUpperCase()),t.headers){var r;for(r in t.headers)n.push('--header "'+r+": "+t.headers[r]+'"')}if(t.body){var i;i="object"==typeof t.body?JSON.stringify(t.body):t.body,n.push('-d "'+i.replace(/"/g,'\\"')+'"')}return"curl "+n.join(" ")+' "'+t.url+'"'},a.prototype.encodePathCollection=function(e,t,n){var r,i="",o="";for(o="ssv"===e?"%20":"tsv"===e?"\\t":"pipes"===e?"|":",",r=0;r<n.length;r++)0===r?i=this.encodeQueryParam(n[r]):i+=o+this.encodeQueryParam(n[r]);return i},a.prototype.encodeQueryCollection=function(e,t,n){var r,i="";if("default"===e||"multi"===e)for(r=0;r<n.length;r++)r>0&&(i+="&"),i+=this.encodeQueryParam(t)+"="+this.encodeQueryParam(n[r]);else{var o="";if("csv"===e)o=",";else if("ssv"===e)o="%20";else if("tsv"===e)o="\\t";else if("pipes"===e)o="|";else if("brackets"===e)for(r=0;r<n.length;r++)0!==r&&(i+="&"),i+=this.encodeQueryParam(t)+"[]="+this.encodeQueryParam(n[r]);if(""!==o)for(r=0;r<n.length;r++)0===r?i=this.encodeQueryParam(t)+"="+this.encodeQueryParam(n[r]):i+=o+this.encodeQueryParam(n[r])}return i},a.prototype.encodeQueryParam=function(e){return encodeURIComponent(e)},a.prototype.encodePathParam=function(e){var t,n,r,i;if(e=e.toString(),-1===e.indexOf("/"))return encodeURIComponent(e);for(n=e.split("/"),t=[],r=0,i=n.length;i>r;r++)t.push(encodeURIComponent(n[r]));return t.join("/")}},{"../helpers":4,"../http":5,"./model":8,"lodash-compat/lang/isUndefined":103}],10:[function(e,t){"use strict";var n=t.exports=function(e,t,n,r){this.description=t,this.externalDocs=n,this.name=e,this.operation=r,this.operationsArray=[],this.path=e,this.tag=e};n.prototype.sort=function(){}},{}],11:[function(e,t,n){function r(e,t){var n=this;if(!(n instanceof r))return new r(e,t);var i,o=typeof e;if("number"===o)i=+e;else if("string"===o)i=r.byteLength(e,t);else{if("object"!==o||null===e)throw new TypeError("must start with number, buffer, array or string");"Buffer"===e.type&&I(e.data)&&(e=e.data),i=+e.length}if(i>R)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+R.toString(16)+" bytes");0>i?i=0:i>>>=0,r.TYPED_ARRAY_SUPPORT?n=r._augment(new Uint8Array(i)):(n.length=i,n._isBuffer=!0);var a;if(r.TYPED_ARRAY_SUPPORT&&"number"==typeof e.byteLength)n._set(e);else if(T(e))if(r.isBuffer(e))for(a=0;i>a;a++)n[a]=e.readUInt8(a);else for(a=0;i>a;a++)n[a]=(e[a]%256+256)%256;else if("string"===o)n.write(e,0,t);else if("number"===o&&!r.TYPED_ARRAY_SUPPORT)for(a=0;i>a;a++)n[a]=0;return i>0&&i<=r.poolSize&&(n.parent=M),n}function i(e,t){if(!(this instanceof i))return new i(e,t);var n=new r(e,t);return delete n.parent,n}function o(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");r>o/2&&(r=o/2);for(var a=0;r>a;a++){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))throw new Error("Invalid hex string");e[n+a]=s}return a}function a(e,t,n,r){var i=D(_(t,e.length-n),e,n,r);return i}function s(e,t,n,r){var i=D(O(t),e,n,r);return i}function l(e,t,n,r){return s(e,t,n,r)}function u(e,t,n,r){var i=D($(t),e,n,r);return i}function c(e,t,n,r){var i=D(k(t,e.length-n),e,n,r);return i}function p(e,t,n){return N.fromByteArray(0===t&&n===e.length?e:e.slice(t,n))}function h(e,t,n){var r="",i="";n=Math.min(e.length,n);for(var o=t;n>o;o++)e[o]<=127?(r+=L(i)+String.fromCharCode(e[o]),i=""):i+="%"+e[o].toString(16);return r+L(i)}function f(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;n>i;i++)r+=String.fromCharCode(127&e[i]);return r}function d(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;n>i;i++)r+=String.fromCharCode(e[i]);return r}function m(e,t,n){var r=e.length;(!t||0>t)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var i="",o=t;n>o;o++)i+=S(e[o]);return i}function g(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function y(e,t,n){if(e%1!==0||0>e)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function v(e,t,n,i,o,a){if(!r.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>o||a>t)throw new RangeError("value is out of bounds");if(n+i>e.length)throw new RangeError("index out of range")}function b(e,t,n,r){0>t&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);o>i;i++)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function w(e,t,n,r){0>t&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);o>i;i++)e[n+i]=t>>>8*(r?i:3-i)&255}function x(e,t,n,r,i,o){if(t>i||o>t)throw new RangeError("value is out of bounds");if(n+r>e.length)throw new RangeError("index out of range");if(0>n)throw new RangeError("index out of range")}function A(e,t,n,r,i){return i||x(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),P.write(e,t,n,r,23,4),n+4}function E(e,t,n,r,i){return i||x(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),P.write(e,t,n,r,52,8),n+8}function j(e){if(e=C(e).replace(H,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function C(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function T(e){return I(e)||r.isBuffer(e)||e&&"object"==typeof e&&"number"==typeof e.length}function S(e){return 16>e?"0"+e.toString(16):e.toString(16)}function _(e,t){t=t||1/0;for(var n,r=e.length,i=null,o=[],a=0;r>a;a++){if(n=e.charCodeAt(a),n>55295&&57344>n){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(56320>n){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=i-55296<<10|n-56320|65536,i=null}else i&&((t-=3)>-1&&o.push(239,191,189),i=null);if(128>n){if((t-=1)<0)break;o.push(n)}else if(2048>n){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(65536>n){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(2097152>n))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function O(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}function k(e,t){for(var n,r,i,o=[],a=0;a<e.length&&!((t-=2)<0);a++)n=e.charCodeAt(a),r=n>>8,i=n%256,o.push(i),o.push(r);return o}function $(e){return N.toByteArray(j(e))}function D(e,t,n,r){for(var i=0;r>i&&!(i+n>=t.length||i>=e.length);i++)t[i+n]=e[i];return i}function L(e){try{return decodeURIComponent(e)}catch(t){return String.fromCharCode(65533)}}var N=e("base64-js"),P=e("ieee754"),I=e("is-array");n.Buffer=r,n.SlowBuffer=i,n.INSPECT_MAX_BYTES=50,r.poolSize=8192;var R=1073741823,M={};r.TYPED_ARRAY_SUPPORT=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(n){return!1}}(),r.isBuffer=function(e){return!(null==e||!e._isBuffer)},r.compare=function(e,t){if(!r.isBuffer(e)||!r.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,i=t.length,o=0,a=Math.min(n,i);a>o&&e[o]===t[o];o++);return o!==a&&(n=e[o],i=t[o]),i>n?-1:n>i?1:0},r.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},r.concat=function(e,t){if(!I(e))throw new TypeError("list argument must be an Array of Buffers.");if(0===e.length)return new r(0);if(1===e.length)return e[0];var n;if(void 0===t)for(t=0,n=0;n<e.length;n++)t+=e[n].length;var i=new r(t),o=0;for(n=0;n<e.length;n++){var a=e[n];a.copy(i,o),o+=a.length}return i},r.byteLength=function(e,t){var n;switch(e+="",t||"utf8"){case"ascii":case"binary":case"raw":n=e.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=2*e.length;break;case"hex":n=e.length>>>1;break;case"utf8":case"utf-8":n=_(e).length;break;case"base64":n=$(e).length;break;default:n=e.length}return n},r.prototype.length=void 0,r.prototype.parent=void 0,r.prototype.toString=function(e,t,n){var r=!1;if(t>>>=0,n=void 0===n||1/0===n?this.length:n>>>0,e||(e="utf8"),0>t&&(t=0),n>this.length&&(n=this.length),t>=n)return"";for(;;)switch(e){case"hex":return m(this,t,n);case"utf8":case"utf-8":return h(this,t,n);case"ascii":return f(this,t,n);case"binary":return d(this,t,n);case"base64":return p(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return g(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}},r.prototype.equals=function(e){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:0===r.compare(this,e)},r.prototype.inspect=function(){var e="",t=n.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},r.prototype.compare=function(e){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?0:r.compare(this,e)},r.prototype.indexOf=function(e,t){function n(e,t,n){for(var r=-1,i=0;n+i<e.length;i++)if(e[n+i]===t[-1===r?0:i-r]){if(-1===r&&(r=i),i-r+1===t.length)return n+r}else r=-1;return-1}if(t>2147483647?t=2147483647:-2147483648>t&&(t=-2147483648),t>>=0,0===this.length)return-1;if(t>=this.length)return-1;if(0>t&&(t=Math.max(this.length+t,0)),"string"==typeof e)return 0===e.length?-1:String.prototype.indexOf.call(this,e,t);if(r.isBuffer(e))return n(this,e,t);if("number"==typeof e)return r.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,e,t):n(this,[e],t);throw new TypeError("val must be string, number or Buffer")},r.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},r.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},r.prototype.write=function(e,t,n,r){if(isFinite(t))isFinite(n)||(r=n,n=void 0);else{var i=r;r=t,t=n,n=i}if(t=Number(t)||0,0>n||0>t||t>this.length)throw new RangeError("attempt to write outside buffer bounds");var p=this.length-t;n?(n=Number(n),n>p&&(n=p)):n=p,r=String(r||"utf8").toLowerCase();var h;switch(r){case"hex":h=o(this,e,t,n);break;case"utf8":case"utf-8":h=a(this,e,t,n);break;case"ascii":h=s(this,e,t,n);break;case"binary":h=l(this,e,t,n);break;case"base64":h=u(this,e,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":h=c(this,e,t,n);break;default:throw new TypeError("Unknown encoding: "+r)}return h},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),e>t&&(t=e);var i;if(r.TYPED_ARRAY_SUPPORT)i=r._augment(this.subarray(e,t));else{var o=t-e;i=new r(o,void 0);for(var a=0;o>a;a++)i[a]=this[a+e]}return i.length&&(i.parent=this.parent||this),i},r.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||y(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},r.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||y(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},r.prototype.readUInt8=function(e,t){return t||y(e,1,this.length),this[e]},r.prototype.readUInt16LE=function(e,t){return t||y(e,2,this.length),this[e]|this[e+1]<<8},r.prototype.readUInt16BE=function(e,t){return t||y(e,2,this.length),this[e]<<8|this[e+1]},r.prototype.readUInt32LE=function(e,t){return t||y(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},r.prototype.readUInt32BE=function(e,t){return t||y(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},r.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||y(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*t)),r},r.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||y(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},r.prototype.readInt8=function(e,t){return t||y(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},r.prototype.readInt16LE=function(e,t){t||y(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt16BE=function(e,t){t||y(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt32LE=function(e,t){return t||y(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},r.prototype.readInt32BE=function(e,t){return t||y(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},r.prototype.readFloatLE=function(e,t){return t||y(e,4,this.length),P.read(this,e,!0,23,4)},r.prototype.readFloatBE=function(e,t){return t||y(e,4,this.length),P.read(this,e,!1,23,4)},r.prototype.readDoubleLE=function(e,t){return t||y(e,8,this.length),P.read(this,e,!0,52,8)},r.prototype.readDoubleBE=function(e,t){return t||y(e,8,this.length),P.read(this,e,!1,52,8)},r.prototype.writeUIntLE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||v(this,e,t,n,Math.pow(2,8*n),0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i>>>0&255;return t+n},r.prototype.writeUIntBE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||v(this,e,t,n,Math.pow(2,8*n),0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o>>>0&255;return t+n},r.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,1,255,0),r.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=e,t+1},r.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,2,65535,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8):b(this,e,t,!0),t+2},r.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,2,65535,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e):b(this,e,t,!1),t+2},r.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,4,4294967295,0),r.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e):w(this,e,t,!0),t+4},r.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,4,4294967295,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e):w(this,e,t,!1),t+4},r.prototype.writeIntLE=function(e,t,n,r){e=+e,t>>>=0,r||v(this,e,t,n,Math.pow(2,8*n-1)-1,-Math.pow(2,8*n-1));var i=0,o=1,a=0>e?1:0;for(this[t]=255&e;++i<n&&(o*=256);)this[t+i]=(e/o>>0)-a&255;return t+n},r.prototype.writeIntBE=function(e,t,n,r){e=+e,t>>>=0,r||v(this,e,t,n,Math.pow(2,8*n-1)-1,-Math.pow(2,8*n-1));var i=n-1,o=1,a=0>e?1:0;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=(e/o>>0)-a&255;return t+n},r.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,1,127,-128),r.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),0>e&&(e=255+e+1),this[t]=e,t+1},r.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,2,32767,-32768),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8):b(this,e,t,!0),t+2},r.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,2,32767,-32768),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e):b(this,e,t,!1),t+2},r.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,4,2147483647,-2147483648),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):w(this,e,t,!0),t+4},r.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||v(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e):w(this,e,t,!1),t+4},r.prototype.writeFloatLE=function(e,t,n){return A(this,e,t,!0,n)},r.prototype.writeFloatBE=function(e,t,n){return A(this,e,t,!1,n)},r.prototype.writeDoubleLE=function(e,t,n){return E(this,e,t,!0,n)},r.prototype.writeDoubleBE=function(e,t,n){return E(this,e,t,!1,n)},r.prototype.copy=function(e,t,n,i){if(n||(n=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&n>i&&(i=n),i===n)return 0;if(0===e.length||0===this.length)return 0;if(0>t)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>i)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);var o=i-n;if(1e3>o||!r.TYPED_ARRAY_SUPPORT)for(var a=0;o>a;a++)e[a+t]=this[a+n];else e._set(this.subarray(n,n+o),t);return o},r.prototype.fill=function(e,t,n){if(e||(e=0),t||(t=0),n||(n=this.length),t>n)throw new RangeError("end < start");if(n!==t&&0!==this.length){if(0>t||t>=this.length)throw new RangeError("start out of bounds");if(0>n||n>this.length)throw new RangeError("end out of bounds");var r;if("number"==typeof e)for(r=t;n>r;r++)this[r]=e;else{var i=_(e.toString()),o=i.length;for(r=t;n>r;r++)this[r]=i[r%o]}return this}},r.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(r.TYPED_ARRAY_SUPPORT)return new r(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;n>t;t+=1)e[t]=this[t];return e.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var U=r.prototype;r._augment=function(e){return e.constructor=r,e._isBuffer=!0,e._set=e.set,e.get=U.get,e.set=U.set,e.write=U.write,e.toString=U.toString,e.toLocaleString=U.toString,e.toJSON=U.toJSON,e.equals=U.equals,e.compare=U.compare,e.indexOf=U.indexOf,e.copy=U.copy,e.slice=U.slice,e.readUIntLE=U.readUIntLE,e.readUIntBE=U.readUIntBE,e.readUInt8=U.readUInt8,e.readUInt16LE=U.readUInt16LE,e.readUInt16BE=U.readUInt16BE,e.readUInt32LE=U.readUInt32LE,e.readUInt32BE=U.readUInt32BE,e.readIntLE=U.readIntLE,e.readIntBE=U.readIntBE,e.readInt8=U.readInt8,e.readInt16LE=U.readInt16LE,e.readInt16BE=U.readInt16BE,e.readInt32LE=U.readInt32LE,e.readInt32BE=U.readInt32BE,e.readFloatLE=U.readFloatLE,e.readFloatBE=U.readFloatBE,e.readDoubleLE=U.readDoubleLE,e.readDoubleBE=U.readDoubleBE,e.writeUInt8=U.writeUInt8,e.writeUIntLE=U.writeUIntLE,e.writeUIntBE=U.writeUIntBE,e.writeUInt16LE=U.writeUInt16LE,e.writeUInt16BE=U.writeUInt16BE,e.writeUInt32LE=U.writeUInt32LE,e.writeUInt32BE=U.writeUInt32BE,e.writeIntLE=U.writeIntLE,e.writeIntBE=U.writeIntBE,e.writeInt8=U.writeInt8,e.writeInt16LE=U.writeInt16LE,e.writeInt16BE=U.writeInt16BE,e.writeInt32LE=U.writeInt32LE,e.writeInt32BE=U.writeInt32BE,e.writeFloatLE=U.writeFloatLE,e.writeFloatBE=U.writeFloatBE,e.writeDoubleLE=U.writeDoubleLE,e.writeDoubleBE=U.writeDoubleBE,e.fill=U.fill,e.inspect=U.inspect,e.toArrayBuffer=U.toArrayBuffer,e};var H=/[^+\/0-9A-z\-]/g},{"base64-js":12,ieee754:13,"is-array":14}],12:[function(e,t,n){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(e){"use strict";function t(e){var t=e.charCodeAt(0);return t===a||t===p?62:t===s||t===h?63:l>t?-1:l+10>t?t-l+26+26:c+26>t?t-c:u+26>t?t-u+26:void 0}function n(e){function n(e){u[p++]=e}var r,i,a,s,l,u;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;l="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,u=new o(3*e.length/4-l),a=l>0?e.length-4:e.length;var p=0;for(r=0,i=0;a>r;r+=4,i+=3)s=t(e.charAt(r))<<18|t(e.charAt(r+1))<<12|t(e.charAt(r+2))<<6|t(e.charAt(r+3)),n((16711680&s)>>16),n((65280&s)>>8),n(255&s);return 2===l?(s=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&s)):1===l&&(s=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(s>>8&255),n(255&s)),u}function i(e){function t(e){return r.charAt(e)}function n(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var i,o,a,s=e.length%3,l="";for(i=0,a=e.length-s;a>i;i+=3)o=(e[i]<<16)+(e[i+1]<<8)+e[i+2],l+=n(o);switch(s){case 1:o=e[e.length-1],l+=t(o>>2),l+=t(o<<4&63),l+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],l+=t(o>>10),l+=t(o>>4&63),l+=t(o<<2&63),l+="="}return l}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,a="+".charCodeAt(0),s="/".charCodeAt(0),l="0".charCodeAt(0),u="a".charCodeAt(0),c="A".charCodeAt(0),p="-".charCodeAt(0),h="_".charCodeAt(0);e.toByteArray=n,e.fromByteArray=i}("undefined"==typeof n?this.base64js={}:n)},{}],13:[function(e,t,n){n.read=function(e,t,n,r,i){var o,a,s=8*i-r-1,l=(1<<s)-1,u=l>>1,c=-7,p=n?i-1:0,h=n?-1:1,f=e[t+p];for(p+=h,o=f&(1<<-c)-1,f>>=-c,c+=s;c>0;o=256*o+e[t+p],p+=h,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+e[t+p],p+=h,c-=8);if(0===o)o=1-u;else{if(o===l)return a?0/0:1/0*(f?-1:1);a+=Math.pow(2,r),o-=u}return(f?-1:1)*a*Math.pow(2,o-r)},n.write=function(e,t,n,r,i,o){var a,s,l,u=8*o-i-1,c=(1<<u)-1,p=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,d=r?1:-1,m=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||1/0===t?(s=isNaN(t)?1:0,a=c):(a=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-a))<1&&(a--,l*=2),t+=a+p>=1?h/l:h*Math.pow(2,1-p),t*l>=2&&(a++,l/=2),a+p>=c?(s=0,a=c):a+p>=1?(s=(t*l-1)*Math.pow(2,i),a+=p):(s=t*Math.pow(2,p-1)*Math.pow(2,i),a=0));i>=8;e[n+f]=255&s,f+=d,s/=256,i-=8);for(a=a<<i|s,u+=i;u>0;e[n+f]=255&a,f+=d,a/=256,u-=8);e[n+f-d]|=128*m}},{}],14:[function(e,t){var n=Array.isArray,r=Object.prototype.toString;t.exports=n||function(e){return!!e&&"[object Array]"==r.call(e)}},{}],15:[function(e,t){function n(){if(!a){a=!0;for(var e,t=o.length;t;){e=o,o=[];for(var n=-1;++n<t;)e[n]();t=o.length}a=!1}}function r(){}var i=t.exports={},o=[],a=!1;i.nextTick=function(e){o.push(e),a||setTimeout(n,0)
+},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=r,i.addListener=r,i.once=r,i.off=r,i.removeListener=r,i.removeAllListeners=r,i.emit=r,i.binding=function(){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],16:[function(e,t){(function(e){!function(){"use strict";function n(t){var n;return n=t instanceof e?t:new e(t.toString(),"binary"),n.toString("base64")}t.exports=n}()}).call(this,e("buffer").Buffer)},{buffer:11}],17:[function(e,t,n){!function(){"use strict";function e(t,n,r,i){return this instanceof e?(this.domain=t||void 0,this.path=n||"/",this.secure=!!r,this.script=!!i,this):new e(t,n,r,i)}function t(e,n,r){return e instanceof t?e:this instanceof t?(this.name=null,this.value=null,this.expiration_date=1/0,this.path=String(r||"/"),this.explicit_path=!1,this.domain=n||null,this.explicit_domain=!1,this.secure=!1,this.noscript=!1,e&&this.parse(e,n,r),this):new t(e)}function r(){var e,n,i;return this instanceof r?(e=Object.create(null),this.setCookie=function(r,o,a){var s,l;if(r=new t(r,o,a),s=r.expiration_date<=Date.now(),void 0!==e[r.name]){for(n=e[r.name],l=0;l<n.length;l+=1)if(i=n[l],i.collidesWith(r))return s?(n.splice(l,1),0===n.length&&delete e[r.name],!1):(n[l]=r,r);return s?!1:(n.push(r),r)}return s?!1:(e[r.name]=[r],e[r.name])},this.getCookie=function(t,r){var i,o;if(n=e[t])for(o=0;o<n.length;o+=1)if(i=n[o],i.expiration_date<=Date.now())0===n.length&&delete e[i.name];else if(i.matches(r))return i},this.getCookies=function(t){var n,r,i=[];for(n in e)r=this.getCookie(n,t),r&&i.push(r);return i.toString=function(){return i.join(":")},i.toValueString=function(){return i.map(function(e){return e.toValueString()}).join(";")},i},this):new r}n.CookieAccessInfo=e,n.Cookie=t,t.prototype.toString=function(){var e=[this.name+"="+this.value];return 1/0!==this.expiration_date&&e.push("expires="+new Date(this.expiration_date).toGMTString()),this.domain&&e.push("domain="+this.domain),this.path&&e.push("path="+this.path),this.secure&&e.push("secure"),this.noscript&&e.push("httponly"),e.join("; ")},t.prototype.toValueString=function(){return this.name+"="+this.value};var i=/[:](?=\s*[a-zA-Z0-9_\-]+\s*[=])/g;t.prototype.parse=function(e,n,r){if(this instanceof t){var i,o=e.split(";").filter(function(e){return!!e}),a=o[0].match(/([^=]+)=([\s\S]*)/),s=a[1],l=a[2];for(this.name=s,this.value=l,i=1;i<o.length;i+=1)switch(a=o[i].match(/([^=]+)(?:=([\s\S]*))?/),s=a[1].trim().toLowerCase(),l=a[2],s){case"httponly":this.noscript=!0;break;case"expires":this.expiration_date=l?Number(Date.parse(l)):1/0;break;case"path":this.path=l?l.trim():"",this.explicit_path=!0;break;case"domain":this.domain=l?l.trim():"",this.explicit_domain=!!this.domain;break;case"secure":this.secure=!0}return this.explicit_path||(this.path=r||"/"),this.explicit_domain||(this.domain=n),this}return(new t).parse(e,n,r)},t.prototype.matches=function(e){return this.noscript&&e.script||this.secure&&!e.secure||!this.collidesWith(e)?!1:!0},t.prototype.collidesWith=function(e){if(this.path&&!e.path||this.domain&&!e.domain)return!1;if(this.path&&0!==e.path.indexOf(this.path))return!1;if(!this.explicit_path&&this.path!==e.path)return!1;var t=e.domain&&e.domain.replace(/^[\.]/,""),n=this.domain&&this.domain.replace(/^[\.]/,"");if(n===t)return!0;if(n){if(!this.explicit_domain)return!1;var r=t.indexOf(n);return-1===r||r!==t.length-n.length?!1:!0}return!0},n.CookieJar=r,r.prototype.setCookies=function(e,n,r){e=Array.isArray(e)?e:e.split(i);var o,a,s=[];for(e=e.map(t),o=0;o<e.length;o+=1)a=e[o],this.setCookie(a,n,r)&&s.push(a);return s}}()},{}],18:[function(t,n){!function(e,t){"object"==typeof n&&"object"==typeof n.exports?n.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(t,n){function r(e){var t=e.length,n=et.type(e);return"function"===n||et.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e}function i(e,t,n){if(et.isFunction(t))return et.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return et.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(lt.test(t))return et.filter(t,e,n);t=et.filter(t,e)}return et.grep(e,function(e){return J.call(t,e)>=0!==n})}function o(e,t){for(;(e=e[t])&&1!==e.nodeType;);return e}function a(e){var t=mt[e]={};return et.each(e.match(dt)||[],function(e,n){t[n]=!0}),t}function s(){G.removeEventListener("DOMContentLoaded",s,!1),t.removeEventListener("load",s,!1),et.ready()}function l(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=et.expando+l.uid++}function u(e,t,n){var r;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(xt,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:wt.test(n)?et.parseJSON(n):n}catch(i){}bt.set(e,t,n)}else n=void 0;return n}function c(){return!0}function p(){return!1}function h(){try{return G.activeElement}catch(e){}}function f(e,t){return et.nodeName(e,"table")&&et.nodeName(11!==t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function d(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function m(e){var t=Rt.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function g(e,t){for(var n=0,r=e.length;r>n;n++)vt.set(e[n],"globalEval",!t||vt.get(t[n],"globalEval"))}function y(e,t){var n,r,i,o,a,s,l,u;if(1===t.nodeType){if(vt.hasData(e)&&(o=vt.access(e),a=vt.set(t,o),u=o.events)){delete a.handle,a.events={};for(i in u)for(n=0,r=u[i].length;r>n;n++)et.event.add(t,i,u[i][n])}bt.hasData(e)&&(s=bt.access(e),l=et.extend({},s),bt.set(t,l))}}function v(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return void 0===t||t&&et.nodeName(e,t)?et.merge([e],n):n}function b(e,t){var n=t.nodeName.toLowerCase();"input"===n&&Ct.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}function w(e,n){var r,i=et(n.createElement(e)).appendTo(n.body),o=t.getDefaultComputedStyle&&(r=t.getDefaultComputedStyle(i[0]))?r.display:et.css(i[0],"display");return i.detach(),o}function x(e){var t=G,n=Ft[e];return n||(n=w(e,t),"none"!==n&&n||(Ht=(Ht||et("<iframe frameborder='0' width='0' height='0'/>")).appendTo(t.documentElement),t=Ht[0].contentDocument,t.write(),t.close(),n=w(e,t),Ht.detach()),Ft[e]=n),n}function A(e,t,n){var r,i,o,a,s=e.style;return n=n||zt(e),n&&(a=n.getPropertyValue(t)||n[t]),n&&(""!==a||et.contains(e.ownerDocument,e)||(a=et.style(e,t)),qt.test(a)&&Bt.test(t)&&(r=s.width,i=s.minWidth,o=s.maxWidth,s.minWidth=s.maxWidth=s.width=a,a=n.width,s.width=r,s.minWidth=i,s.maxWidth=o)),void 0!==a?a+"":a}function E(e,t){return{get:function(){return e()?void delete this.get:(this.get=t).apply(this,arguments)}}}function j(e,t){if(t in e)return t;for(var n=t[0].toUpperCase()+t.slice(1),r=t,i=Xt.length;i--;)if(t=Xt[i]+n,t in e)return t;return r}function C(e,t,n){var r=Wt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function T(e,t,n,r,i){for(var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;4>o;o+=2)"margin"===n&&(a+=et.css(e,n+Et[o],!0,i)),r?("content"===n&&(a-=et.css(e,"padding"+Et[o],!0,i)),"margin"!==n&&(a-=et.css(e,"border"+Et[o]+"Width",!0,i))):(a+=et.css(e,"padding"+Et[o],!0,i),"padding"!==n&&(a+=et.css(e,"border"+Et[o]+"Width",!0,i)));return a}function S(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=zt(e),a="border-box"===et.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=A(e,t,o),(0>i||null==i)&&(i=e.style[t]),qt.test(i))return i;r=a&&(K.boxSizingReliable()||i===e.style[t]),i=parseFloat(i)||0}return i+T(e,t,n||(a?"border":"content"),r,o)+"px"}function _(e,t){for(var n,r,i,o=[],a=0,s=e.length;s>a;a++)r=e[a],r.style&&(o[a]=vt.get(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&jt(r)&&(o[a]=vt.access(r,"olddisplay",x(r.nodeName)))):(i=jt(r),"none"===n&&i||vt.set(r,"olddisplay",i?n:et.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}function O(e,t,n,r,i){return new O.prototype.init(e,t,n,r,i)}function k(){return setTimeout(function(){Kt=void 0}),Kt=et.now()}function $(e,t){var n,r=0,i={height:e};for(t=t?1:0;4>r;r+=2-t)n=Et[r],i["margin"+n]=i["padding"+n]=e;return t&&(i.opacity=i.width=e),i}function D(e,t,n){for(var r,i=(rn[t]||[]).concat(rn["*"]),o=0,a=i.length;a>o;o++)if(r=i[o].call(n,t,e))return r}function L(e,t,n){var r,i,o,a,s,l,u,c,p=this,h={},f=e.style,d=e.nodeType&&jt(e),m=vt.get(e,"fxshow");n.queue||(s=et._queueHooks(e,"fx"),null==s.unqueued&&(s.unqueued=0,l=s.empty.fire,s.empty.fire=function(){s.unqueued||l()}),s.unqueued++,p.always(function(){p.always(function(){s.unqueued--,et.queue(e,"fx").length||s.empty.fire()})})),1===e.nodeType&&("height"in t||"width"in t)&&(n.overflow=[f.overflow,f.overflowX,f.overflowY],u=et.css(e,"display"),c="none"===u?vt.get(e,"olddisplay")||x(e.nodeName):u,"inline"===c&&"none"===et.css(e,"float")&&(f.display="inline-block")),n.overflow&&(f.overflow="hidden",p.always(function(){f.overflow=n.overflow[0],f.overflowX=n.overflow[1],f.overflowY=n.overflow[2]}));for(r in t)if(i=t[r],Zt.exec(i)){if(delete t[r],o=o||"toggle"===i,i===(d?"hide":"show")){if("show"!==i||!m||void 0===m[r])continue;d=!0}h[r]=m&&m[r]||et.style(e,r)}else u=void 0;if(et.isEmptyObject(h))"inline"===("none"===u?x(e.nodeName):u)&&(f.display=u);else{m?"hidden"in m&&(d=m.hidden):m=vt.access(e,"fxshow",{}),o&&(m.hidden=!d),d?et(e).show():p.done(function(){et(e).hide()}),p.done(function(){var t;vt.remove(e,"fxshow");for(t in h)et.style(e,t,h[t])});for(r in h)a=D(d?m[r]:0,r,p),r in m||(m[r]=a.start,d&&(a.end=a.start,a.start="width"===r||"height"===r?1:0))}}function N(e,t){var n,r,i,o,a;for(n in e)if(r=et.camelCase(n),i=t[r],o=e[n],et.isArray(o)&&(i=o[1],o=e[n]=o[0]),n!==r&&(e[r]=o,delete e[n]),a=et.cssHooks[r],a&&"expand"in a){o=a.expand(o),delete e[r];for(n in o)n in e||(e[n]=o[n],t[n]=i)}else t[r]=i}function P(e,t,n){var r,i,o=0,a=nn.length,s=et.Deferred().always(function(){delete l.elem}),l=function(){if(i)return!1;for(var t=Kt||k(),n=Math.max(0,u.startTime+u.duration-t),r=n/u.duration||0,o=1-r,a=0,l=u.tweens.length;l>a;a++)u.tweens[a].run(o);return s.notifyWith(e,[u,o,n]),1>o&&l?n:(s.resolveWith(e,[u]),!1)},u=s.promise({elem:e,props:et.extend({},t),opts:et.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:Kt||k(),duration:n.duration,tweens:[],createTween:function(t,n){var r=et.Tween(e,u.opts,t,n,u.opts.specialEasing[t]||u.opts.easing);return u.tweens.push(r),r},stop:function(t){var n=0,r=t?u.tweens.length:0;if(i)return this;for(i=!0;r>n;n++)u.tweens[n].run(1);return t?s.resolveWith(e,[u,t]):s.rejectWith(e,[u,t]),this}}),c=u.props;for(N(c,u.opts.specialEasing);a>o;o++)if(r=nn[o].call(u,e,c,u.opts))return r;return et.map(c,D,u),et.isFunction(u.opts.start)&&u.opts.start.call(e,u),et.fx.timer(et.extend(l,{elem:e,anim:u,queue:u.opts.queue})),u.progress(u.opts.progress).done(u.opts.done,u.opts.complete).fail(u.opts.fail).always(u.opts.always)}function I(e){return function(t,n){"string"!=typeof t&&(n=t,t="*");var r,i=0,o=t.toLowerCase().match(dt)||[];if(et.isFunction(n))for(;r=o[i++];)"+"===r[0]?(r=r.slice(1)||"*",(e[r]=e[r]||[]).unshift(n)):(e[r]=e[r]||[]).push(n)}}function R(e,t,n,r){function i(s){var l;return o[s]=!0,et.each(e[s]||[],function(e,s){var u=s(t,n,r);return"string"!=typeof u||a||o[u]?a?!(l=u):void 0:(t.dataTypes.unshift(u),i(u),!1)}),l}var o={},a=e===xn;return i(t.dataTypes[0])||!o["*"]&&i("*")}function M(e,t){var n,r,i=et.ajaxSettings.flatOptions||{};for(n in t)void 0!==t[n]&&((i[n]?e:r||(r={}))[n]=t[n]);return r&&et.extend(!0,e,r),e}function U(e,t,n){for(var r,i,o,a,s=e.contents,l=e.dataTypes;"*"===l[0];)l.shift(),void 0===r&&(r=e.mimeType||t.getResponseHeader("Content-Type"));if(r)for(i in s)if(s[i]&&s[i].test(r)){l.unshift(i);break}if(l[0]in n)o=l[0];else{for(i in n){if(!l[0]||e.converters[i+" "+l[0]]){o=i;break}a||(a=i)}o=o||a}return o?(o!==l[0]&&l.unshift(o),n[o]):void 0}function H(e,t,n,r){var i,o,a,s,l,u={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)u[a.toLowerCase()]=e.converters[a];for(o=c.shift();o;)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!l&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),l=o,o=c.shift())if("*"===o)o=l;else if("*"!==l&&l!==o){if(a=u[l+" "+o]||u["* "+o],!a)for(i in u)if(s=i.split(" "),s[1]===o&&(a=u[l+" "+s[0]]||u["* "+s[0]])){a===!0?a=u[i]:u[i]!==!0&&(o=s[0],c.unshift(s[1]));break}if(a!==!0)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(p){return{state:"parsererror",error:a?p:"No conversion from "+l+" to "+o}}}return{state:"success",data:t}}function F(e,t,n,r){var i;if(et.isArray(t))et.each(t,function(t,i){n||Tn.test(e)?r(e,i):F(e+"["+("object"==typeof i?t:"")+"]",i,n,r)});else if(n||"object"!==et.type(t))r(e,t);else for(i in t)F(e+"["+i+"]",t[i],n,r)}function B(e){return et.isWindow(e)?e:9===e.nodeType&&e.defaultView}var q=[],z=q.slice,V=q.concat,W=q.push,J=q.indexOf,Y={},Q=Y.toString,X=Y.hasOwnProperty,K={},G=t.document,Z="2.1.3",et=function(e,t){return new et.fn.init(e,t)},tt=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,nt=/^-ms-/,rt=/-([\da-z])/gi,it=function(e,t){return t.toUpperCase()};et.fn=et.prototype={jquery:Z,constructor:et,selector:"",length:0,toArray:function(){return z.call(this)},get:function(e){return null!=e?0>e?this[e+this.length]:this[e]:z.call(this)},pushStack:function(e){var t=et.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return et.each(this,e,t)},map:function(e){return this.pushStack(et.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(z.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:W,sort:q.sort,splice:q.splice},et.extend=et.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,l=arguments.length,u=!1;for("boolean"==typeof a&&(u=a,a=arguments[s]||{},s++),"object"==typeof a||et.isFunction(a)||(a={}),s===l&&(a=this,s--);l>s;s++)if(null!=(e=arguments[s]))for(t in e)n=a[t],r=e[t],a!==r&&(u&&r&&(et.isPlainObject(r)||(i=et.isArray(r)))?(i?(i=!1,o=n&&et.isArray(n)?n:[]):o=n&&et.isPlainObject(n)?n:{},a[t]=et.extend(u,o,r)):void 0!==r&&(a[t]=r));return a},et.extend({expando:"jQuery"+(Z+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isFunction:function(e){return"function"===et.type(e)},isArray:Array.isArray,isWindow:function(e){return null!=e&&e===e.window},isNumeric:function(e){return!et.isArray(e)&&e-parseFloat(e)+1>=0},isPlainObject:function(e){return"object"!==et.type(e)||e.nodeType||et.isWindow(e)?!1:e.constructor&&!X.call(e.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?Y[Q.call(e)]||"object":typeof e},globalEval:function(e){var t,n=eval;e=et.trim(e),e&&(1===e.indexOf("use strict")?(t=G.createElement("script"),t.text=e,G.head.appendChild(t).parentNode.removeChild(t)):n(e))},camelCase:function(e){return e.replace(nt,"ms-").replace(rt,it)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var i,o=0,a=e.length,s=r(e);if(n){if(s)for(;a>o&&(i=t.apply(e[o],n),i!==!1);o++);else for(o in e)if(i=t.apply(e[o],n),i===!1)break}else if(s)for(;a>o&&(i=t.call(e[o],o,e[o]),i!==!1);o++);else for(o in e)if(i=t.call(e[o],o,e[o]),i===!1)break;return e},trim:function(e){return null==e?"":(e+"").replace(tt,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(r(Object(e))?et.merge(n,"string"==typeof e?[e]:e):W.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:J.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;n>r;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r,i=[],o=0,a=e.length,s=!n;a>o;o++)r=!t(e[o],o),r!==s&&i.push(e[o]);return i},map:function(e,t,n){var i,o=0,a=e.length,s=r(e),l=[];if(s)for(;a>o;o++)i=t(e[o],o,n),null!=i&&l.push(i);else for(o in e)i=t(e[o],o,n),null!=i&&l.push(i);return V.apply([],l)},guid:1,proxy:function(e,t){var n,r,i;return"string"==typeof t&&(n=e[t],t=e,e=n),et.isFunction(e)?(r=z.call(arguments,2),i=function(){return e.apply(t||this,r.concat(z.call(arguments)))},i.guid=e.guid=e.guid||et.guid++,i):void 0},now:Date.now,support:K}),et.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){Y["[object "+t+"]"]=t.toLowerCase()});var ot=function(e){function t(e,t,n,r){var i,o,a,s,l,u,p,f,d,m;if((t?t.ownerDocument||t:H)!==D&&$(t),t=t||D,n=n||[],s=t.nodeType,"string"!=typeof e||!e||1!==s&&9!==s&&11!==s)return n;if(!r&&N){if(11!==s&&(i=vt.exec(e)))if(a=i[1]){if(9===s){if(o=t.getElementById(a),!o||!o.parentNode)return n;if(o.id===a)return n.push(o),n}else if(t.ownerDocument&&(o=t.ownerDocument.getElementById(a))&&M(t,o)&&o.id===a)return n.push(o),n}else{if(i[2])return G.apply(n,t.getElementsByTagName(e)),n;if((a=i[3])&&x.getElementsByClassName)return G.apply(n,t.getElementsByClassName(a)),n}if(x.qsa&&(!P||!P.test(e))){if(f=p=U,d=t,m=1!==s&&e,1===s&&"object"!==t.nodeName.toLowerCase()){for(u=C(e),(p=t.getAttribute("id"))?f=p.replace(wt,"\\$&"):t.setAttribute("id",f),f="[id='"+f+"'] ",l=u.length;l--;)u[l]=f+h(u[l]);d=bt.test(e)&&c(t.parentNode)||t,m=u.join(",")}if(m)try{return G.apply(n,d.querySelectorAll(m)),n}catch(g){}finally{p||t.removeAttribute("id")}}}return S(e.replace(lt,"$1"),t,n,r)}function n(){function e(n,r){return t.push(n+" ")>A.cacheLength&&delete e[t.shift()],e[n+" "]=r}var t=[];return e}function r(e){return e[U]=!0,e}function i(e){var t=D.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function o(e,t){for(var n=e.split("|"),r=e.length;r--;)A.attrHandle[n[r]]=t}function a(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||J)-(~e.sourceIndex||J);if(r)return r;if(n)for(;n=n.nextSibling;)if(n===t)return-1;return e?1:-1}function s(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function l(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function u(e){return r(function(t){return t=+t,r(function(n,r){for(var i,o=e([],n.length,t),a=o.length;a--;)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}function c(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}function p(){}function h(e){for(var t=0,n=e.length,r="";n>t;t++)r+=e[t].value;return r}function f(e,t,n){var r=t.dir,i=n&&"parentNode"===r,o=B++;return t.first?function(t,n,o){for(;t=t[r];)if(1===t.nodeType||i)return e(t,n,o)}:function(t,n,a){var s,l,u=[F,o];if(a){for(;t=t[r];)if((1===t.nodeType||i)&&e(t,n,a))return!0}else for(;t=t[r];)if(1===t.nodeType||i){if(l=t[U]||(t[U]={}),(s=l[r])&&s[0]===F&&s[1]===o)return u[2]=s[2];if(l[r]=u,u[2]=e(t,n,a))return!0}}}function d(e){return e.length>1?function(t,n,r){for(var i=e.length;i--;)if(!e[i](t,n,r))return!1;return!0}:e[0]}function m(e,n,r){for(var i=0,o=n.length;o>i;i++)t(e,n[i],r);return r}function g(e,t,n,r,i){for(var o,a=[],s=0,l=e.length,u=null!=t;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function y(e,t,n,i,o,a){return i&&!i[U]&&(i=y(i)),o&&!o[U]&&(o=y(o,a)),r(function(r,a,s,l){var u,c,p,h=[],f=[],d=a.length,y=r||m(t||"*",s.nodeType?[s]:s,[]),v=!e||!r&&t?y:g(y,h,e,s,l),b=n?o||(r?e:d||i)?[]:a:v;if(n&&n(v,b,s,l),i)for(u=g(b,f),i(u,[],s,l),c=u.length;c--;)(p=u[c])&&(b[f[c]]=!(v[f[c]]=p));if(r){if(o||e){if(o){for(u=[],c=b.length;c--;)(p=b[c])&&u.push(v[c]=p);o(null,b=[],u,l)}for(c=b.length;c--;)(p=b[c])&&(u=o?et(r,p):h[c])>-1&&(r[u]=!(a[u]=p))}}else b=g(b===a?b.splice(d,b.length):b),o?o(null,a,b,l):G.apply(a,b)})}function v(e){for(var t,n,r,i=e.length,o=A.relative[e[0].type],a=o||A.relative[" "],s=o?1:0,l=f(function(e){return e===t},a,!0),u=f(function(e){return et(t,e)>-1},a,!0),c=[function(e,n,r){var i=!o&&(r||n!==_)||((t=n).nodeType?l(e,n,r):u(e,n,r));return t=null,i}];i>s;s++)if(n=A.relative[e[s].type])c=[f(d(c),n)];else{if(n=A.filter[e[s].type].apply(null,e[s].matches),n[U]){for(r=++s;i>r&&!A.relative[e[r].type];r++);return y(s>1&&d(c),s>1&&h(e.slice(0,s-1).concat({value:" "===e[s-2].type?"*":""})).replace(lt,"$1"),n,r>s&&v(e.slice(s,r)),i>r&&v(e=e.slice(r)),i>r&&h(e))}c.push(n)}return d(c)}function b(e,n){var i=n.length>0,o=e.length>0,a=function(r,a,s,l,u){var c,p,h,f=0,d="0",m=r&&[],y=[],v=_,b=r||o&&A.find.TAG("*",u),w=F+=null==v?1:Math.random()||.1,x=b.length;for(u&&(_=a!==D&&a);d!==x&&null!=(c=b[d]);d++){if(o&&c){for(p=0;h=e[p++];)if(h(c,a,s)){l.push(c);break}u&&(F=w)}i&&((c=!h&&c)&&f--,r&&m.push(c))}if(f+=d,i&&d!==f){for(p=0;h=n[p++];)h(m,y,a,s);if(r){if(f>0)for(;d--;)m[d]||y[d]||(y[d]=X.call(l));y=g(y)}G.apply(l,y),u&&!r&&y.length>0&&f+n.length>1&&t.uniqueSort(l)}return u&&(F=w,_=v),m};return i?r(a):a}var w,x,A,E,j,C,T,S,_,O,k,$,D,L,N,P,I,R,M,U="sizzle"+1*new Date,H=e.document,F=0,B=0,q=n(),z=n(),V=n(),W=function(e,t){return e===t&&(k=!0),0},J=1<<31,Y={}.hasOwnProperty,Q=[],X=Q.pop,K=Q.push,G=Q.push,Z=Q.slice,et=function(e,t){for(var n=0,r=e.length;r>n;n++)if(e[n]===t)return n;return-1},tt="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",nt="[\\x20\\t\\r\\n\\f]",rt="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",it=rt.replace("w","w#"),ot="\\["+nt+"*("+rt+")(?:"+nt+"*([*^$|!~]?=)"+nt+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+it+"))|)"+nt+"*\\]",at=":("+rt+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+ot+")*)|.*)\\)|)",st=new RegExp(nt+"+","g"),lt=new RegExp("^"+nt+"+|((?:^|[^\\\\])(?:\\\\.)*)"+nt+"+$","g"),ut=new RegExp("^"+nt+"*,"+nt+"*"),ct=new RegExp("^"+nt+"*([>+~]|"+nt+")"+nt+"*"),pt=new RegExp("="+nt+"*([^\\]'\"]*?)"+nt+"*\\]","g"),ht=new RegExp(at),ft=new RegExp("^"+it+"$"),dt={ID:new RegExp("^#("+rt+")"),CLASS:new RegExp("^\\.("+rt+")"),TAG:new RegExp("^("+rt.replace("w","w*")+")"),ATTR:new RegExp("^"+ot),PSEUDO:new RegExp("^"+at),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+nt+"*(even|odd|(([+-]|)(\\d*)n|)"+nt+"*(?:([+-]|)"+nt+"*(\\d+)|))"+nt+"*\\)|)","i"),bool:new RegExp("^(?:"+tt+")$","i"),needsContext:new RegExp("^"+nt+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+nt+"*((?:-\\d)?\\d*)"+nt+"*\\)|)(?=[^-]|$)","i")},mt=/^(?:input|select|textarea|button)$/i,gt=/^h\d$/i,yt=/^[^{]+\{\s*\[native \w/,vt=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,bt=/[+~]/,wt=/'|\\/g,xt=new RegExp("\\\\([\\da-f]{1,6}"+nt+"?|("+nt+")|.)","ig"),At=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},Et=function(){$()};try{G.apply(Q=Z.call(H.childNodes),H.childNodes),Q[H.childNodes.length].nodeType}catch(jt){G={apply:Q.length?function(e,t){K.apply(e,Z.call(t))}:function(e,t){for(var n=e.length,r=0;e[n++]=t[r++];);e.length=n-1}}}x=t.support={},j=t.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},$=t.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:H;return r!==D&&9===r.nodeType&&r.documentElement?(D=r,L=r.documentElement,n=r.defaultView,n&&n!==n.top&&(n.addEventListener?n.addEventListener("unload",Et,!1):n.attachEvent&&n.attachEvent("onunload",Et)),N=!j(r),x.attributes=i(function(e){return e.className="i",!e.getAttribute("className")}),x.getElementsByTagName=i(function(e){return e.appendChild(r.createComment("")),!e.getElementsByTagName("*").length}),x.getElementsByClassName=yt.test(r.getElementsByClassName),x.getById=i(function(e){return L.appendChild(e).id=U,!r.getElementsByName||!r.getElementsByName(U).length}),x.getById?(A.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&N){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},A.filter.ID=function(e){var t=e.replace(xt,At);return function(e){return e.getAttribute("id")===t}}):(delete A.find.ID,A.filter.ID=function(e){var t=e.replace(xt,At);return function(e){var n="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return n&&n.value===t}}),A.find.TAG=x.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):x.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){for(;n=o[i++];)1===n.nodeType&&r.push(n);return r}return o},A.find.CLASS=x.getElementsByClassName&&function(e,t){return N?t.getElementsByClassName(e):void 0},I=[],P=[],(x.qsa=yt.test(r.querySelectorAll))&&(i(function(e){L.appendChild(e).innerHTML="<a id='"+U+"'></a><select id='"+U+"-\f]' msallowcapture=''><option selected=''></option></select>",e.querySelectorAll("[msallowcapture^='']").length&&P.push("[*^$]="+nt+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||P.push("\\["+nt+"*(?:value|"+tt+")"),e.querySelectorAll("[id~="+U+"-]").length||P.push("~="),e.querySelectorAll(":checked").length||P.push(":checked"),e.querySelectorAll("a#"+U+"+*").length||P.push(".#.+[+~]")}),i(function(e){var t=r.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&P.push("name"+nt+"*[*^$|!~]?="),e.querySelectorAll(":enabled").length||P.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),P.push(",.*:")})),(x.matchesSelector=yt.test(R=L.matches||L.webkitMatchesSelector||L.mozMatchesSelector||L.oMatchesSelector||L.msMatchesSelector))&&i(function(e){x.disconnectedMatch=R.call(e,"div"),R.call(e,"[s!='']:x"),I.push("!=",at)}),P=P.length&&new RegExp(P.join("|")),I=I.length&&new RegExp(I.join("|")),t=yt.test(L.compareDocumentPosition),M=t||yt.test(L.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)for(;t=t.parentNode;)if(t===e)return!0;return!1},W=t?function(e,t){if(e===t)return k=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n?n:(n=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1,1&n||!x.sortDetached&&t.compareDocumentPosition(e)===n?e===r||e.ownerDocument===H&&M(H,e)?-1:t===r||t.ownerDocument===H&&M(H,t)?1:O?et(O,e)-et(O,t):0:4&n?-1:1)}:function(e,t){if(e===t)return k=!0,0;var n,i=0,o=e.parentNode,s=t.parentNode,l=[e],u=[t];if(!o||!s)return e===r?-1:t===r?1:o?-1:s?1:O?et(O,e)-et(O,t):0;if(o===s)return a(e,t);for(n=e;n=n.parentNode;)l.unshift(n);for(n=t;n=n.parentNode;)u.unshift(n);for(;l[i]===u[i];)i++;return i?a(l[i],u[i]):l[i]===H?-1:u[i]===H?1:0},r):D},t.matches=function(e,n){return t(e,null,null,n)},t.matchesSelector=function(e,n){if((e.ownerDocument||e)!==D&&$(e),n=n.replace(pt,"='$1']"),!(!x.matchesSelector||!N||I&&I.test(n)||P&&P.test(n)))try{var r=R.call(e,n);if(r||x.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(i){}return t(n,D,null,[e]).length>0},t.contains=function(e,t){return(e.ownerDocument||e)!==D&&$(e),M(e,t)},t.attr=function(e,t){(e.ownerDocument||e)!==D&&$(e);var n=A.attrHandle[t.toLowerCase()],r=n&&Y.call(A.attrHandle,t.toLowerCase())?n(e,t,!N):void 0;return void 0!==r?r:x.attributes||!N?e.getAttribute(t):(r=e.getAttributeNode(t))&&r.specified?r.value:null},t.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},t.uniqueSort=function(e){var t,n=[],r=0,i=0;if(k=!x.detectDuplicates,O=!x.sortStable&&e.slice(0),e.sort(W),k){for(;t=e[i++];)t===e[i]&&(r=n.push(i));for(;r--;)e.splice(n[r],1)}return O=null,e},E=t.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=E(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r++];)n+=E(t);return n},A=t.selectors={cacheLength:50,createPseudo:r,match:dt,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(xt,At),e[3]=(e[3]||e[4]||e[5]||"").replace(xt,At),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||t.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&t.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return dt.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&ht.test(n)&&(t=C(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(xt,At).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=q[e+" "];return t||(t=new RegExp("(^|"+nt+")"+e+"("+nt+"|$)"))&&q(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(e,n,r){return function(i){var o=t.attr(i,e);return null==o?"!="===n:n?(o+="","="===n?o===r:"!="===n?o!==r:"^="===n?r&&0===o.indexOf(r):"*="===n?r&&o.indexOf(r)>-1:"$="===n?r&&o.slice(-r.length)===r:"~="===n?(" "+o.replace(st," ")+" ").indexOf(r)>-1:"|="===n?o===r||o.slice(0,r.length+1)===r+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,h,f,d,m=o!==a?"nextSibling":"previousSibling",g=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(g){if(o){for(;m;){for(p=t;p=p[m];)if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;d=m="only"===e&&!d&&"nextSibling"}return!0}if(d=[a?g.firstChild:g.lastChild],a&&v){for(c=g[U]||(g[U]={}),u=c[e]||[],f=u[0]===F&&u[1],h=u[0]===F&&u[2],p=f&&g.childNodes[f];p=++f&&p&&p[m]||(h=f=0)||d.pop();)if(1===p.nodeType&&++h&&p===t){c[e]=[F,f,h];break}}else if(v&&(u=(t[U]||(t[U]={}))[e])&&u[0]===F)h=u[1];else for(;(p=++f&&p&&p[m]||(h=f=0)||d.pop())&&((s?p.nodeName.toLowerCase()!==y:1!==p.nodeType)||!++h||(v&&((p[U]||(p[U]={}))[e]=[F,h]),p!==t)););return h-=i,h===r||h%r===0&&h/r>=0}}},PSEUDO:function(e,n){var i,o=A.pseudos[e]||A.setFilters[e.toLowerCase()]||t.error("unsupported pseudo: "+e);return o[U]?o(n):o.length>1?(i=[e,e,"",n],A.setFilters.hasOwnProperty(e.toLowerCase())?r(function(e,t){for(var r,i=o(e,n),a=i.length;a--;)r=et(e,i[a]),e[r]=!(t[r]=i[a])}):function(e){return o(e,0,i)}):o}},pseudos:{not:r(function(e){var t=[],n=[],i=T(e.replace(lt,"$1"));return i[U]?r(function(e,t,n,r){for(var o,a=i(e,null,r,[]),s=e.length;s--;)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,r,o){return t[0]=e,i(t,null,o,n),t[0]=null,!n.pop()}}),has:r(function(e){return function(n){return t(e,n).length>0}}),contains:r(function(e){return e=e.replace(xt,At),function(t){return(t.textContent||t.innerText||E(t)).indexOf(e)>-1}}),lang:r(function(e){return ft.test(e||"")||t.error("unsupported lang: "+e),e=e.replace(xt,At).toLowerCase(),function(t){var n;do if(n=N?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===L},focus:function(e){return e===D.activeElement&&(!D.hasFocus||D.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();
+return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!A.pseudos.empty(e)},header:function(e){return gt.test(e.nodeName)},input:function(e){return mt.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:u(function(){return[0]}),last:u(function(e,t){return[t-1]}),eq:u(function(e,t,n){return[0>n?n+t:n]}),even:u(function(e,t){for(var n=0;t>n;n+=2)e.push(n);return e}),odd:u(function(e,t){for(var n=1;t>n;n+=2)e.push(n);return e}),lt:u(function(e,t,n){for(var r=0>n?n+t:n;--r>=0;)e.push(r);return e}),gt:u(function(e,t,n){for(var r=0>n?n+t:n;++r<t;)e.push(r);return e})}},A.pseudos.nth=A.pseudos.eq;for(w in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})A.pseudos[w]=s(w);for(w in{submit:!0,reset:!0})A.pseudos[w]=l(w);return p.prototype=A.filters=A.pseudos,A.setFilters=new p,C=t.tokenize=function(e,n){var r,i,o,a,s,l,u,c=z[e+" "];if(c)return n?0:c.slice(0);for(s=e,l=[],u=A.preFilter;s;){(!r||(i=ut.exec(s)))&&(i&&(s=s.slice(i[0].length)||s),l.push(o=[])),r=!1,(i=ct.exec(s))&&(r=i.shift(),o.push({value:r,type:i[0].replace(lt," ")}),s=s.slice(r.length));for(a in A.filter)!(i=dt[a].exec(s))||u[a]&&!(i=u[a](i))||(r=i.shift(),o.push({value:r,type:a,matches:i}),s=s.slice(r.length));if(!r)break}return n?s.length:s?t.error(e):z(e,l).slice(0)},T=t.compile=function(e,t){var n,r=[],i=[],o=V[e+" "];if(!o){for(t||(t=C(e)),n=t.length;n--;)o=v(t[n]),o[U]?r.push(o):i.push(o);o=V(e,b(i,r)),o.selector=e}return o},S=t.select=function(e,t,n,r){var i,o,a,s,l,u="function"==typeof e&&e,p=!r&&C(e=u.selector||e);if(n=n||[],1===p.length){if(o=p[0]=p[0].slice(0),o.length>2&&"ID"===(a=o[0]).type&&x.getById&&9===t.nodeType&&N&&A.relative[o[1].type]){if(t=(A.find.ID(a.matches[0].replace(xt,At),t)||[])[0],!t)return n;u&&(t=t.parentNode),e=e.slice(o.shift().value.length)}for(i=dt.needsContext.test(e)?0:o.length;i--&&(a=o[i],!A.relative[s=a.type]);)if((l=A.find[s])&&(r=l(a.matches[0].replace(xt,At),bt.test(o[0].type)&&c(t.parentNode)||t))){if(o.splice(i,1),e=r.length&&h(o),!e)return G.apply(n,r),n;break}}return(u||T(e,p))(r,t,!N,n,bt.test(e)&&c(t.parentNode)||t),n},x.sortStable=U.split("").sort(W).join("")===U,x.detectDuplicates=!!k,$(),x.sortDetached=i(function(e){return 1&e.compareDocumentPosition(D.createElement("div"))}),i(function(e){return e.innerHTML="<a href='#'></a>","#"===e.firstChild.getAttribute("href")})||o("type|href|height|width",function(e,t,n){return n?void 0:e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),x.attributes&&i(function(e){return e.innerHTML="<input/>",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||o("value",function(e,t,n){return n||"input"!==e.nodeName.toLowerCase()?void 0:e.defaultValue}),i(function(e){return null==e.getAttribute("disabled")})||o(tt,function(e,t,n){var r;return n?void 0:e[t]===!0?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),t}(t);et.find=ot,et.expr=ot.selectors,et.expr[":"]=et.expr.pseudos,et.unique=ot.uniqueSort,et.text=ot.getText,et.isXMLDoc=ot.isXML,et.contains=ot.contains;var at=et.expr.match.needsContext,st=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,lt=/^.[^:#\[\.,]*$/;et.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?et.find.matchesSelector(r,e)?[r]:[]:et.find.matches(e,et.grep(t,function(e){return 1===e.nodeType}))},et.fn.extend({find:function(e){var t,n=this.length,r=[],i=this;if("string"!=typeof e)return this.pushStack(et(e).filter(function(){for(t=0;n>t;t++)if(et.contains(i[t],this))return!0}));for(t=0;n>t;t++)et.find(e,i[t],r);return r=this.pushStack(n>1?et.unique(r):r),r.selector=this.selector?this.selector+" "+e:e,r},filter:function(e){return this.pushStack(i(this,e||[],!1))},not:function(e){return this.pushStack(i(this,e||[],!0))},is:function(e){return!!i(this,"string"==typeof e&&at.test(e)?et(e):e||[],!1).length}});var ut,ct=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,pt=et.fn.init=function(e,t){var n,r;if(!e)return this;if("string"==typeof e){if(n="<"===e[0]&&">"===e[e.length-1]&&e.length>=3?[null,e,null]:ct.exec(e),!n||!n[1]&&t)return!t||t.jquery?(t||ut).find(e):this.constructor(t).find(e);if(n[1]){if(t=t instanceof et?t[0]:t,et.merge(this,et.parseHTML(n[1],t&&t.nodeType?t.ownerDocument||t:G,!0)),st.test(n[1])&&et.isPlainObject(t))for(n in t)et.isFunction(this[n])?this[n](t[n]):this.attr(n,t[n]);return this}return r=G.getElementById(n[2]),r&&r.parentNode&&(this.length=1,this[0]=r),this.context=G,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):et.isFunction(e)?"undefined"!=typeof ut.ready?ut.ready(e):e(et):(void 0!==e.selector&&(this.selector=e.selector,this.context=e.context),et.makeArray(e,this))};pt.prototype=et.fn,ut=et(G);var ht=/^(?:parents|prev(?:Until|All))/,ft={children:!0,contents:!0,next:!0,prev:!0};et.extend({dir:function(e,t,n){for(var r=[],i=void 0!==n;(e=e[t])&&9!==e.nodeType;)if(1===e.nodeType){if(i&&et(e).is(n))break;r.push(e)}return r},sibling:function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}}),et.fn.extend({has:function(e){var t=et(e,this),n=t.length;return this.filter(function(){for(var e=0;n>e;e++)if(et.contains(this,t[e]))return!0})},closest:function(e,t){for(var n,r=0,i=this.length,o=[],a=at.test(e)||"string"!=typeof e?et(e,t||this.context):0;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(n.nodeType<11&&(a?a.index(n)>-1:1===n.nodeType&&et.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(o.length>1?et.unique(o):o)},index:function(e){return e?"string"==typeof e?J.call(et(e),this[0]):J.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(et.unique(et.merge(this.get(),et(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),et.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return et.dir(e,"parentNode")},parentsUntil:function(e,t,n){return et.dir(e,"parentNode",n)},next:function(e){return o(e,"nextSibling")},prev:function(e){return o(e,"previousSibling")},nextAll:function(e){return et.dir(e,"nextSibling")},prevAll:function(e){return et.dir(e,"previousSibling")},nextUntil:function(e,t,n){return et.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return et.dir(e,"previousSibling",n)},siblings:function(e){return et.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return et.sibling(e.firstChild)},contents:function(e){return e.contentDocument||et.merge([],e.childNodes)}},function(e,t){et.fn[e]=function(n,r){var i=et.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=et.filter(r,i)),this.length>1&&(ft[e]||et.unique(i),ht.test(e)&&i.reverse()),this.pushStack(i)}});var dt=/\S+/g,mt={};et.Callbacks=function(e){e="string"==typeof e?mt[e]||a(e):et.extend({},e);var t,n,r,i,o,s,l=[],u=!e.once&&[],c=function(a){for(t=e.memory&&a,n=!0,s=i||0,i=0,o=l.length,r=!0;l&&o>s;s++)if(l[s].apply(a[0],a[1])===!1&&e.stopOnFalse){t=!1;break}r=!1,l&&(u?u.length&&c(u.shift()):t?l=[]:p.disable())},p={add:function(){if(l){var n=l.length;!function a(t){et.each(t,function(t,n){var r=et.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&a(n)})}(arguments),r?o=l.length:t&&(i=n,c(t))}return this},remove:function(){return l&&et.each(arguments,function(e,t){for(var n;(n=et.inArray(t,l,n))>-1;)l.splice(n,1),r&&(o>=n&&o--,s>=n&&s--)}),this},has:function(e){return e?et.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=t=void 0,this},disabled:function(){return!l},lock:function(){return u=void 0,t||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!l||n&&!u||(t=t||[],t=[e,t.slice?t.slice():t],r?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!n}};return p},et.extend({Deferred:function(e){var t=[["resolve","done",et.Callbacks("once memory"),"resolved"],["reject","fail",et.Callbacks("once memory"),"rejected"],["notify","progress",et.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return et.Deferred(function(n){et.each(t,function(t,o){var a=et.isFunction(e[t])&&e[t];i[o[1]](function(){var e=a&&a.apply(this,arguments);e&&et.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o[0]+"With"](this===r?n.promise():this,a?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?et.extend(e,r):r}},i={};return r.pipe=r.then,et.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t,n,r,i=0,o=z.call(arguments),a=o.length,s=1!==a||e&&et.isFunction(e.promise)?a:0,l=1===s?e:et.Deferred(),u=function(e,n,r){return function(i){n[e]=this,r[e]=arguments.length>1?z.call(arguments):i,r===t?l.notifyWith(n,r):--s||l.resolveWith(n,r)}};if(a>1)for(t=new Array(a),n=new Array(a),r=new Array(a);a>i;i++)o[i]&&et.isFunction(o[i].promise)?o[i].promise().done(u(i,r,o)).fail(l.reject).progress(u(i,n,t)):--s;return s||l.resolveWith(r,o),l.promise()}});var gt;et.fn.ready=function(e){return et.ready.promise().done(e),this},et.extend({isReady:!1,readyWait:1,holdReady:function(e){e?et.readyWait++:et.ready(!0)},ready:function(e){(e===!0?--et.readyWait:et.isReady)||(et.isReady=!0,e!==!0&&--et.readyWait>0||(gt.resolveWith(G,[et]),et.fn.triggerHandler&&(et(G).triggerHandler("ready"),et(G).off("ready"))))}}),et.ready.promise=function(e){return gt||(gt=et.Deferred(),"complete"===G.readyState?setTimeout(et.ready):(G.addEventListener("DOMContentLoaded",s,!1),t.addEventListener("load",s,!1))),gt.promise(e)},et.ready.promise();var yt=et.access=function(e,t,n,r,i,o,a){var s=0,l=e.length,u=null==n;if("object"===et.type(n)){i=!0;for(s in n)et.access(e,t,s,n[s],!0,o,a)}else if(void 0!==r&&(i=!0,et.isFunction(r)||(a=!0),u&&(a?(t.call(e,r),t=null):(u=t,t=function(e,t,n){return u.call(et(e),n)})),t))for(;l>s;s++)t(e[s],n,a?r:r.call(e[s],s,t(e[s],n)));return i?e:u?t.call(e):l?t(e[0],n):o};et.acceptData=function(e){return 1===e.nodeType||9===e.nodeType||!+e.nodeType},l.uid=1,l.accepts=et.acceptData,l.prototype={key:function(e){if(!l.accepts(e))return 0;var t={},n=e[this.expando];if(!n){n=l.uid++;try{t[this.expando]={value:n},Object.defineProperties(e,t)}catch(r){t[this.expando]=n,et.extend(e,t)}}return this.cache[n]||(this.cache[n]={}),n},set:function(e,t,n){var r,i=this.key(e),o=this.cache[i];if("string"==typeof t)o[t]=n;else if(et.isEmptyObject(o))et.extend(this.cache[i],t);else for(r in t)o[r]=t[r];return o},get:function(e,t){var n=this.cache[this.key(e)];return void 0===t?n:n[t]},access:function(e,t,n){var r;return void 0===t||t&&"string"==typeof t&&void 0===n?(r=this.get(e,t),void 0!==r?r:this.get(e,et.camelCase(t))):(this.set(e,t,n),void 0!==n?n:t)},remove:function(e,t){var n,r,i,o=this.key(e),a=this.cache[o];if(void 0===t)this.cache[o]={};else{et.isArray(t)?r=t.concat(t.map(et.camelCase)):(i=et.camelCase(t),t in a?r=[t,i]:(r=i,r=r in a?[r]:r.match(dt)||[])),n=r.length;for(;n--;)delete a[r[n]]}},hasData:function(e){return!et.isEmptyObject(this.cache[e[this.expando]]||{})},discard:function(e){e[this.expando]&&delete this.cache[e[this.expando]]}};var vt=new l,bt=new l,wt=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,xt=/([A-Z])/g;et.extend({hasData:function(e){return bt.hasData(e)||vt.hasData(e)},data:function(e,t,n){return bt.access(e,t,n)},removeData:function(e,t){bt.remove(e,t)},_data:function(e,t,n){return vt.access(e,t,n)},_removeData:function(e,t){vt.remove(e,t)}}),et.fn.extend({data:function(e,t){var n,r,i,o=this[0],a=o&&o.attributes;if(void 0===e){if(this.length&&(i=bt.get(o),1===o.nodeType&&!vt.get(o,"hasDataAttrs"))){for(n=a.length;n--;)a[n]&&(r=a[n].name,0===r.indexOf("data-")&&(r=et.camelCase(r.slice(5)),u(o,r,i[r])));vt.set(o,"hasDataAttrs",!0)}return i}return"object"==typeof e?this.each(function(){bt.set(this,e)}):yt(this,function(t){var n,r=et.camelCase(e);if(o&&void 0===t){if(n=bt.get(o,e),void 0!==n)return n;if(n=bt.get(o,r),void 0!==n)return n;if(n=u(o,r,void 0),void 0!==n)return n}else this.each(function(){var n=bt.get(this,r);bt.set(this,r,t),-1!==e.indexOf("-")&&void 0!==n&&bt.set(this,e,t)})},null,t,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){bt.remove(this,e)})}}),et.extend({queue:function(e,t,n){var r;return e?(t=(t||"fx")+"queue",r=vt.get(e,t),n&&(!r||et.isArray(n)?r=vt.access(e,t,et.makeArray(n)):r.push(n)),r||[]):void 0},dequeue:function(e,t){t=t||"fx";var n=et.queue(e,t),r=n.length,i=n.shift(),o=et._queueHooks(e,t),a=function(){et.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return vt.get(e,n)||vt.access(e,n,{empty:et.Callbacks("once memory").add(function(){vt.remove(e,[t+"queue",n])})})}}),et.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),arguments.length<n?et.queue(this[0],e):void 0===t?this:this.each(function(){var n=et.queue(this,e,t);et._queueHooks(this,e),"fx"===e&&"inprogress"!==n[0]&&et.dequeue(this,e)})},dequeue:function(e){return this.each(function(){et.dequeue(this,e)})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=et.Deferred(),o=this,a=this.length,s=function(){--r||i.resolveWith(o,[o])};for("string"!=typeof e&&(t=e,e=void 0),e=e||"fx";a--;)n=vt.get(o[a],e+"queueHooks"),n&&n.empty&&(r++,n.empty.add(s));return s(),i.promise(t)}});var At=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,Et=["Top","Right","Bottom","Left"],jt=function(e,t){return e=t||e,"none"===et.css(e,"display")||!et.contains(e.ownerDocument,e)},Ct=/^(?:checkbox|radio)$/i;!function(){var e=G.createDocumentFragment(),t=e.appendChild(G.createElement("div")),n=G.createElement("input");n.setAttribute("type","radio"),n.setAttribute("checked","checked"),n.setAttribute("name","t"),t.appendChild(n),K.checkClone=t.cloneNode(!0).cloneNode(!0).lastChild.checked,t.innerHTML="<textarea>x</textarea>",K.noCloneChecked=!!t.cloneNode(!0).lastChild.defaultValue}();var Tt="undefined";K.focusinBubbles="onfocusin"in t;var St=/^key/,_t=/^(?:mouse|pointer|contextmenu)|click/,Ot=/^(?:focusinfocus|focusoutblur)$/,kt=/^([^.]*)(?:\.(.+)|)$/;et.event={global:{},add:function(e,t,n,r,i){var o,a,s,l,u,c,p,h,f,d,m,g=vt.get(e);if(g)for(n.handler&&(o=n,n=o.handler,i=o.selector),n.guid||(n.guid=et.guid++),(l=g.events)||(l=g.events={}),(a=g.handle)||(a=g.handle=function(t){return typeof et!==Tt&&et.event.triggered!==t.type?et.event.dispatch.apply(e,arguments):void 0}),t=(t||"").match(dt)||[""],u=t.length;u--;)s=kt.exec(t[u])||[],f=m=s[1],d=(s[2]||"").split(".").sort(),f&&(p=et.event.special[f]||{},f=(i?p.delegateType:p.bindType)||f,p=et.event.special[f]||{},c=et.extend({type:f,origType:m,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&et.expr.match.needsContext.test(i),namespace:d.join(".")},o),(h=l[f])||(h=l[f]=[],h.delegateCount=0,p.setup&&p.setup.call(e,r,d,a)!==!1||e.addEventListener&&e.addEventListener(f,a,!1)),p.add&&(p.add.call(e,c),c.handler.guid||(c.handler.guid=n.guid)),i?h.splice(h.delegateCount++,0,c):h.push(c),et.event.global[f]=!0)},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,h,f,d,m,g=vt.hasData(e)&&vt.get(e);if(g&&(l=g.events)){for(t=(t||"").match(dt)||[""],u=t.length;u--;)if(s=kt.exec(t[u])||[],f=m=s[1],d=(s[2]||"").split(".").sort(),f){for(p=et.event.special[f]||{},f=(r?p.delegateType:p.bindType)||f,h=l[f]||[],s=s[2]&&new RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=h.length;o--;)c=h[o],!i&&m!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(h.splice(o,1),c.selector&&h.delegateCount--,p.remove&&p.remove.call(e,c));a&&!h.length&&(p.teardown&&p.teardown.call(e,d,g.handle)!==!1||et.removeEvent(e,f,g.handle),delete l[f])}else for(f in l)et.event.remove(e,f+t[u],n,r,!0);et.isEmptyObject(l)&&(delete g.handle,vt.remove(e,"events"))}},trigger:function(e,n,r,i){var o,a,s,l,u,c,p,h=[r||G],f=X.call(e,"type")?e.type:e,d=X.call(e,"namespace")?e.namespace.split("."):[];if(a=s=r=r||G,3!==r.nodeType&&8!==r.nodeType&&!Ot.test(f+et.event.triggered)&&(f.indexOf(".")>=0&&(d=f.split("."),f=d.shift(),d.sort()),u=f.indexOf(":")<0&&"on"+f,e=e[et.expando]?e:new et.Event(f,"object"==typeof e&&e),e.isTrigger=i?2:3,e.namespace=d.join("."),e.namespace_re=e.namespace?new RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,e.result=void 0,e.target||(e.target=r),n=null==n?[e]:et.makeArray(n,[e]),p=et.event.special[f]||{},i||!p.trigger||p.trigger.apply(r,n)!==!1)){if(!i&&!p.noBubble&&!et.isWindow(r)){for(l=p.delegateType||f,Ot.test(l+f)||(a=a.parentNode);a;a=a.parentNode)h.push(a),s=a;s===(r.ownerDocument||G)&&h.push(s.defaultView||s.parentWindow||t)}for(o=0;(a=h[o++])&&!e.isPropagationStopped();)e.type=o>1?l:p.bindType||f,c=(vt.get(a,"events")||{})[e.type]&&vt.get(a,"handle"),c&&c.apply(a,n),c=u&&a[u],c&&c.apply&&et.acceptData(a)&&(e.result=c.apply(a,n),e.result===!1&&e.preventDefault());return e.type=f,i||e.isDefaultPrevented()||p._default&&p._default.apply(h.pop(),n)!==!1||!et.acceptData(r)||u&&et.isFunction(r[f])&&!et.isWindow(r)&&(s=r[u],s&&(r[u]=null),et.event.triggered=f,r[f](),et.event.triggered=void 0,s&&(r[u]=s)),e.result}},dispatch:function(e){e=et.event.fix(e);var t,n,r,i,o,a=[],s=z.call(arguments),l=(vt.get(this,"events")||{})[e.type]||[],u=et.event.special[e.type]||{};if(s[0]=e,e.delegateTarget=this,!u.preDispatch||u.preDispatch.call(this,e)!==!1){for(a=et.event.handlers.call(this,e,l),t=0;(i=a[t++])&&!e.isPropagationStopped();)for(e.currentTarget=i.elem,n=0;(o=i.handlers[n++])&&!e.isImmediatePropagationStopped();)(!e.namespace_re||e.namespace_re.test(o.namespace))&&(e.handleObj=o,e.data=o.data,r=((et.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,s),void 0!==r&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()));return u.postDispatch&&u.postDispatch.call(this,e),e.result}},handlers:function(e,t){var n,r,i,o,a=[],s=t.delegateCount,l=e.target;if(s&&l.nodeType&&(!e.button||"click"!==e.type))for(;l!==this;l=l.parentNode||this)if(l.disabled!==!0||"click"!==e.type){for(r=[],n=0;s>n;n++)o=t[n],i=o.selector+" ",void 0===r[i]&&(r[i]=o.needsContext?et(i,this).index(l)>=0:et.find(i,this,null,[l]).length),r[i]&&r.push(o);r.length&&a.push({elem:l,handlers:r})}return s<t.length&&a.push({elem:this,handlers:t.slice(s)}),a},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(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,t){var n,r,i,o=t.button;return null==e.pageX&&null!=t.clientX&&(n=e.target.ownerDocument||G,r=n.documentElement,i=n.body,e.pageX=t.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)),e.which||void 0===o||(e.which=1&o?1:2&o?3:4&o?2:0),e}},fix:function(e){if(e[et.expando])return e;var t,n,r,i=e.type,o=e,a=this.fixHooks[i];for(a||(this.fixHooks[i]=a=_t.test(i)?this.mouseHooks:St.test(i)?this.keyHooks:{}),r=a.props?this.props.concat(a.props):this.props,e=new et.Event(o),t=r.length;t--;)n=r[t],e[n]=o[n];return e.target||(e.target=G),3===e.target.nodeType&&(e.target=e.target.parentNode),a.filter?a.filter(e,o):e},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==h()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===h()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&et.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(e){return et.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){void 0!==e.result&&e.originalEvent&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=et.extend(new et.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?et.event.trigger(i,null,t):et.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},et.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)},et.Event=function(e,t){return this instanceof et.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||void 0===e.defaultPrevented&&e.returnValue===!1?c:p):this.type=e,t&&et.extend(this,t),this.timeStamp=e&&e.timeStamp||et.now(),void(this[et.expando]=!0)):new et.Event(e,t)},et.Event.prototype={isDefaultPrevented:p,isPropagationStopped:p,isImmediatePropagationStopped:p,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=c,e&&e.preventDefault&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=c,e&&e.stopPropagation&&e.stopPropagation()},stopImmediatePropagation:function(){var e=this.originalEvent;this.isImmediatePropagationStopped=c,e&&e.stopImmediatePropagation&&e.stopImmediatePropagation(),this.stopPropagation()}},et.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(e,t){et.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!et.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),K.focusinBubbles||et.each({focus:"focusin",blur:"focusout"},function(e,t){var n=function(e){et.event.simulate(t,e.target,et.event.fix(e),!0)};et.event.special[t]={setup:function(){var r=this.ownerDocument||this,i=vt.access(r,t);i||r.addEventListener(e,n,!0),vt.access(r,t,(i||0)+1)},teardown:function(){var r=this.ownerDocument||this,i=vt.access(r,t)-1;i?vt.access(r,t,i):(r.removeEventListener(e,n,!0),vt.remove(r,t))}}}),et.fn.extend({on:function(e,t,n,r,i){var o,a;if("object"==typeof e){"string"!=typeof t&&(n=n||t,t=void 0);for(a in e)this.on(a,t,n,e[a],i);return this}if(null==n&&null==r?(r=t,n=t=void 0):null==r&&("string"==typeof t?(r=n,n=void 0):(r=n,n=t,t=void 0)),r===!1)r=p;else if(!r)return this;return 1===i&&(o=r,r=function(e){return et().off(e),o.apply(this,arguments)},r.guid=o.guid||(o.guid=et.guid++)),this.each(function(){et.event.add(this,e,r,n,t)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,et(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return(t===!1||"function"==typeof t)&&(n=t,t=void 0),n===!1&&(n=p),this.each(function(){et.event.remove(this,e,n,t)})},trigger:function(e,t){return this.each(function(){et.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];return n?et.event.trigger(e,t,n,!0):void 0}});var $t=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,Dt=/<([\w:]+)/,Lt=/<|&#?\w+;/,Nt=/<(?:script|style|link)/i,Pt=/checked\s*(?:[^=]|=\s*.checked.)/i,It=/^$|\/(?:java|ecma)script/i,Rt=/^true\/(.*)/,Mt=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,Ut={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};Ut.optgroup=Ut.option,Ut.tbody=Ut.tfoot=Ut.colgroup=Ut.caption=Ut.thead,Ut.th=Ut.td,et.extend({clone:function(e,t,n){var r,i,o,a,s=e.cloneNode(!0),l=et.contains(e.ownerDocument,e);if(!(K.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||et.isXMLDoc(e)))for(a=v(s),o=v(e),r=0,i=o.length;i>r;r++)b(o[r],a[r]);if(t)if(n)for(o=o||v(e),a=a||v(s),r=0,i=o.length;i>r;r++)y(o[r],a[r]);else y(e,s);return a=v(s,"script"),a.length>0&&g(a,!l&&v(e,"script")),s},buildFragment:function(e,t,n,r){for(var i,o,a,s,l,u,c=t.createDocumentFragment(),p=[],h=0,f=e.length;f>h;h++)if(i=e[h],i||0===i)if("object"===et.type(i))et.merge(p,i.nodeType?[i]:i);else if(Lt.test(i)){for(o=o||c.appendChild(t.createElement("div")),a=(Dt.exec(i)||["",""])[1].toLowerCase(),s=Ut[a]||Ut._default,o.innerHTML=s[1]+i.replace($t,"<$1></$2>")+s[2],u=s[0];u--;)o=o.lastChild;et.merge(p,o.childNodes),o=c.firstChild,o.textContent=""}else p.push(t.createTextNode(i));for(c.textContent="",h=0;i=p[h++];)if((!r||-1===et.inArray(i,r))&&(l=et.contains(i.ownerDocument,i),o=v(c.appendChild(i),"script"),l&&g(o),n))for(u=0;i=o[u++];)It.test(i.type||"")&&n.push(i);return c},cleanData:function(e){for(var t,n,r,i,o=et.event.special,a=0;void 0!==(n=e[a]);a++){if(et.acceptData(n)&&(i=n[vt.expando],i&&(t=vt.cache[i]))){if(t.events)for(r in t.events)o[r]?et.event.remove(n,r):et.removeEvent(n,r,t.handle);vt.cache[i]&&delete vt.cache[i]}delete bt.cache[n[bt.expando]]}}}),et.fn.extend({text:function(e){return yt(this,function(e){return void 0===e?et.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=e)})},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=f(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=f(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){for(var n,r=e?et.filter(e,this):this,i=0;null!=(n=r[i]);i++)t||1!==n.nodeType||et.cleanData(v(n)),n.parentNode&&(t&&et.contains(n.ownerDocument,n)&&g(v(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){for(var e,t=0;null!=(e=this[t]);t++)1===e.nodeType&&(et.cleanData(v(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return et.clone(this,e,t)})},html:function(e){return yt(this,function(e){var t=this[0]||{},n=0,r=this.length;if(void 0===e&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!Nt.test(e)&&!Ut[(Dt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace($t,"<$1></$2>");try{for(;r>n;n++)t=this[n]||{},1===t.nodeType&&(et.cleanData(v(t,!1)),t.innerHTML=e);t=0}catch(i){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=arguments[0];return this.domManip(arguments,function(t){e=this.parentNode,et.cleanData(v(this)),e&&e.replaceChild(t,this)}),e&&(e.length||e.nodeType)?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t){e=V.apply([],e);var n,r,i,o,a,s,l=0,u=this.length,c=this,p=u-1,h=e[0],f=et.isFunction(h);if(f||u>1&&"string"==typeof h&&!K.checkClone&&Pt.test(h))return this.each(function(n){var r=c.eq(n);f&&(e[0]=h.call(this,n,r.html())),r.domManip(e,t)});if(u&&(n=et.buildFragment(e,this[0].ownerDocument,!1,this),r=n.firstChild,1===n.childNodes.length&&(n=r),r)){for(i=et.map(v(n,"script"),d),o=i.length;u>l;l++)a=n,l!==p&&(a=et.clone(a,!0,!0),o&&et.merge(i,v(a,"script"))),t.call(this[l],a,l);if(o)for(s=i[i.length-1].ownerDocument,et.map(i,m),l=0;o>l;l++)a=i[l],It.test(a.type||"")&&!vt.access(a,"globalEval")&&et.contains(s,a)&&(a.src?et._evalUrl&&et._evalUrl(a.src):et.globalEval(a.textContent.replace(Mt,"")))}return this}}),et.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){et.fn[e]=function(e){for(var n,r=[],i=et(e),o=i.length-1,a=0;o>=a;a++)n=a===o?this:this.clone(!0),et(i[a])[t](n),W.apply(r,n.get());return this.pushStack(r)}});var Ht,Ft={},Bt=/^margin/,qt=new RegExp("^("+At+")(?!px)[a-z%]+$","i"),zt=function(e){return e.ownerDocument.defaultView.opener?e.ownerDocument.defaultView.getComputedStyle(e,null):t.getComputedStyle(e,null)};!function(){function e(){a.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",a.innerHTML="",i.appendChild(o);var e=t.getComputedStyle(a,null);n="1%"!==e.top,r="4px"===e.width,i.removeChild(o)}var n,r,i=G.documentElement,o=G.createElement("div"),a=G.createElement("div");a.style&&(a.style.backgroundClip="content-box",a.cloneNode(!0).style.backgroundClip="",K.clearCloneStyle="content-box"===a.style.backgroundClip,o.style.cssText="border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;position:absolute",o.appendChild(a),t.getComputedStyle&&et.extend(K,{pixelPosition:function(){return e(),n},boxSizingReliable:function(){return null==r&&e(),r},reliableMarginRight:function(){var e,n=a.appendChild(G.createElement("div"));return n.style.cssText=a.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",n.style.marginRight=n.style.width="0",a.style.width="1px",i.appendChild(o),e=!parseFloat(t.getComputedStyle(n,null).marginRight),i.removeChild(o),a.removeChild(n),e}}))}(),et.swap=function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i};var Vt=/^(none|table(?!-c[ea]).+)/,Wt=new RegExp("^("+At+")(.*)$","i"),Jt=new RegExp("^([+-])=("+At+")","i"),Yt={position:"absolute",visibility:"hidden",display:"block"},Qt={letterSpacing:"0",fontWeight:"400"},Xt=["Webkit","O","Moz","ms"];et.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=A(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,a,s=et.camelCase(t),l=e.style;return t=et.cssProps[s]||(et.cssProps[s]=j(l,s)),a=et.cssHooks[t]||et.cssHooks[s],void 0===n?a&&"get"in a&&void 0!==(i=a.get(e,!1,r))?i:l[t]:(o=typeof n,"string"===o&&(i=Jt.exec(n))&&(n=(i[1]+1)*i[2]+parseFloat(et.css(e,t)),o="number"),null!=n&&n===n&&("number"!==o||et.cssNumber[s]||(n+="px"),K.clearCloneStyle||""!==n||0!==t.indexOf("background")||(l[t]="inherit"),a&&"set"in a&&void 0===(n=a.set(e,n,r))||(l[t]=n)),void 0)}},css:function(e,t,n,r){var i,o,a,s=et.camelCase(t);return t=et.cssProps[s]||(et.cssProps[s]=j(e.style,s)),a=et.cssHooks[t]||et.cssHooks[s],a&&"get"in a&&(i=a.get(e,!0,n)),void 0===i&&(i=A(e,t,r)),"normal"===i&&t in Qt&&(i=Qt[t]),""===n||n?(o=parseFloat(i),n===!0||et.isNumeric(o)?o||0:i):i}}),et.each(["height","width"],function(e,t){et.cssHooks[t]={get:function(e,n,r){return n?Vt.test(et.css(e,"display"))&&0===e.offsetWidth?et.swap(e,Yt,function(){return S(e,t,r)}):S(e,t,r):void 0},set:function(e,n,r){var i=r&&zt(e);return C(e,n,r?T(e,t,r,"border-box"===et.css(e,"boxSizing",!1,i),i):0)}}}),et.cssHooks.marginRight=E(K.reliableMarginRight,function(e,t){return t?et.swap(e,{display:"inline-block"},A,[e,"marginRight"]):void 0}),et.each({margin:"",padding:"",border:"Width"},function(e,t){et.cssHooks[e+t]={expand:function(n){for(var r=0,i={},o="string"==typeof n?n.split(" "):[n];4>r;r++)i[e+Et[r]+t]=o[r]||o[r-2]||o[0];
+return i}},Bt.test(e)||(et.cssHooks[e+t].set=C)}),et.fn.extend({css:function(e,t){return yt(this,function(e,t,n){var r,i,o={},a=0;if(et.isArray(t)){for(r=zt(e),i=t.length;i>a;a++)o[t[a]]=et.css(e,t[a],!1,r);return o}return void 0!==n?et.style(e,t,n):et.css(e,t)},e,t,arguments.length>1)},show:function(){return _(this,!0)},hide:function(){return _(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){jt(this)?et(this).show():et(this).hide()})}}),et.Tween=O,O.prototype={constructor:O,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(et.cssNumber[n]?"":"px")},cur:function(){var e=O.propHooks[this.prop];return e&&e.get?e.get(this):O.propHooks._default.get(this)},run:function(e){var t,n=O.propHooks[this.prop];return this.pos=t=this.options.duration?et.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):O.propHooks._default.set(this),this}},O.prototype.init.prototype=O.prototype,O.propHooks={_default:{get:function(e){var t;return null==e.elem[e.prop]||e.elem.style&&null!=e.elem.style[e.prop]?(t=et.css(e.elem,e.prop,""),t&&"auto"!==t?t:0):e.elem[e.prop]},set:function(e){et.fx.step[e.prop]?et.fx.step[e.prop](e):e.elem.style&&(null!=e.elem.style[et.cssProps[e.prop]]||et.cssHooks[e.prop])?et.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},O.propHooks.scrollTop=O.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},et.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},et.fx=O.prototype.init,et.fx.step={};var Kt,Gt,Zt=/^(?:toggle|show|hide)$/,en=new RegExp("^(?:([+-])=|)("+At+")([a-z%]*)$","i"),tn=/queueHooks$/,nn=[L],rn={"*":[function(e,t){var n=this.createTween(e,t),r=n.cur(),i=en.exec(t),o=i&&i[3]||(et.cssNumber[e]?"":"px"),a=(et.cssNumber[e]||"px"!==o&&+r)&&en.exec(et.css(n.elem,e)),s=1,l=20;if(a&&a[3]!==o){o=o||a[3],i=i||[],a=+r||1;do s=s||".5",a/=s,et.style(n.elem,e,a+o);while(s!==(s=n.cur()/r)&&1!==s&&--l)}return i&&(a=n.start=+a||+r||0,n.unit=o,n.end=i[1]?a+(i[1]+1)*i[2]:+i[2]),n}]};et.Animation=et.extend(P,{tweener:function(e,t){et.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");for(var n,r=0,i=e.length;i>r;r++)n=e[r],rn[n]=rn[n]||[],rn[n].unshift(t)},prefilter:function(e,t){t?nn.unshift(e):nn.push(e)}}),et.speed=function(e,t,n){var r=e&&"object"==typeof e?et.extend({},e):{complete:n||!n&&t||et.isFunction(e)&&e,duration:e,easing:n&&t||t&&!et.isFunction(t)&&t};return r.duration=et.fx.off?0:"number"==typeof r.duration?r.duration:r.duration in et.fx.speeds?et.fx.speeds[r.duration]:et.fx.speeds._default,(null==r.queue||r.queue===!0)&&(r.queue="fx"),r.old=r.complete,r.complete=function(){et.isFunction(r.old)&&r.old.call(this),r.queue&&et.dequeue(this,r.queue)},r},et.fn.extend({fadeTo:function(e,t,n,r){return this.filter(jt).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=et.isEmptyObject(e),o=et.speed(t,n,r),a=function(){var t=P(this,et.extend({},e),o);(i||vt.get(this,"finish"))&&t.stop(!0)};return a.finish=a,i||o.queue===!1?this.each(a):this.queue(o.queue,a)},stop:function(e,t,n){var r=function(e){var t=e.stop;delete e.stop,t(n)};return"string"!=typeof e&&(n=t,t=e,e=void 0),t&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,i=null!=e&&e+"queueHooks",o=et.timers,a=vt.get(this);if(i)a[i]&&a[i].stop&&r(a[i]);else for(i in a)a[i]&&a[i].stop&&tn.test(i)&&r(a[i]);for(i=o.length;i--;)o[i].elem!==this||null!=e&&o[i].queue!==e||(o[i].anim.stop(n),t=!1,o.splice(i,1));(t||!n)&&et.dequeue(this,e)})},finish:function(e){return e!==!1&&(e=e||"fx"),this.each(function(){var t,n=vt.get(this),r=n[e+"queue"],i=n[e+"queueHooks"],o=et.timers,a=r?r.length:0;for(n.finish=!0,et.queue(this,e,[]),i&&i.stop&&i.stop.call(this,!0),t=o.length;t--;)o[t].elem===this&&o[t].queue===e&&(o[t].anim.stop(!0),o.splice(t,1));for(t=0;a>t;t++)r[t]&&r[t].finish&&r[t].finish.call(this);delete n.finish})}}),et.each(["toggle","show","hide"],function(e,t){var n=et.fn[t];et.fn[t]=function(e,r,i){return null==e||"boolean"==typeof e?n.apply(this,arguments):this.animate($(t,!0),e,r,i)}}),et.each({slideDown:$("show"),slideUp:$("hide"),slideToggle:$("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){et.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),et.timers=[],et.fx.tick=function(){var e,t=0,n=et.timers;for(Kt=et.now();t<n.length;t++)e=n[t],e()||n[t]!==e||n.splice(t--,1);n.length||et.fx.stop(),Kt=void 0},et.fx.timer=function(e){et.timers.push(e),e()?et.fx.start():et.timers.pop()},et.fx.interval=13,et.fx.start=function(){Gt||(Gt=setInterval(et.fx.tick,et.fx.interval))},et.fx.stop=function(){clearInterval(Gt),Gt=null},et.fx.speeds={slow:600,fast:200,_default:400},et.fn.delay=function(e,t){return e=et.fx?et.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},function(){var e=G.createElement("input"),t=G.createElement("select"),n=t.appendChild(G.createElement("option"));e.type="checkbox",K.checkOn=""!==e.value,K.optSelected=n.selected,t.disabled=!0,K.optDisabled=!n.disabled,e=G.createElement("input"),e.value="t",e.type="radio",K.radioValue="t"===e.value}();var on,an,sn=et.expr.attrHandle;et.fn.extend({attr:function(e,t){return yt(this,et.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){et.removeAttr(this,e)})}}),et.extend({attr:function(e,t,n){var r,i,o=e.nodeType;if(e&&3!==o&&8!==o&&2!==o)return typeof e.getAttribute===Tt?et.prop(e,t,n):(1===o&&et.isXMLDoc(e)||(t=t.toLowerCase(),r=et.attrHooks[t]||(et.expr.match.bool.test(t)?an:on)),void 0===n?r&&"get"in r&&null!==(i=r.get(e,t))?i:(i=et.find.attr(e,t),null==i?void 0:i):null!==n?r&&"set"in r&&void 0!==(i=r.set(e,n,t))?i:(e.setAttribute(t,n+""),n):void et.removeAttr(e,t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(dt);if(o&&1===e.nodeType)for(;n=o[i++];)r=et.propFix[n]||n,et.expr.match.bool.test(n)&&(e[r]=!1),e.removeAttribute(n)},attrHooks:{type:{set:function(e,t){if(!K.radioValue&&"radio"===t&&et.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}}}),an={set:function(e,t,n){return t===!1?et.removeAttr(e,n):e.setAttribute(n,n),n}},et.each(et.expr.match.bool.source.match(/\w+/g),function(e,t){var n=sn[t]||et.find.attr;sn[t]=function(e,t,r){var i,o;return r||(o=sn[t],sn[t]=i,i=null!=n(e,t,r)?t.toLowerCase():null,sn[t]=o),i}});var ln=/^(?:input|select|textarea|button)$/i;et.fn.extend({prop:function(e,t){return yt(this,et.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[et.propFix[e]||e]})}}),et.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(e,t,n){var r,i,o,a=e.nodeType;if(e&&3!==a&&8!==a&&2!==a)return o=1!==a||!et.isXMLDoc(e),o&&(t=et.propFix[t]||t,i=et.propHooks[t]),void 0!==n?i&&"set"in i&&void 0!==(r=i.set(e,n,t))?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){return e.hasAttribute("tabindex")||ln.test(e.nodeName)||e.href?e.tabIndex:-1}}}}),K.optSelected||(et.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null}}),et.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){et.propFix[this.toLowerCase()]=this});var un=/[\t\r\n\f]/g;et.fn.extend({addClass:function(e){var t,n,r,i,o,a,s="string"==typeof e&&e,l=0,u=this.length;if(et.isFunction(e))return this.each(function(t){et(this).addClass(e.call(this,t,this.className))});if(s)for(t=(e||"").match(dt)||[];u>l;l++)if(n=this[l],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(un," "):" ")){for(o=0;i=t[o++];)r.indexOf(" "+i+" ")<0&&(r+=i+" ");a=et.trim(r),n.className!==a&&(n.className=a)}return this},removeClass:function(e){var t,n,r,i,o,a,s=0===arguments.length||"string"==typeof e&&e,l=0,u=this.length;if(et.isFunction(e))return this.each(function(t){et(this).removeClass(e.call(this,t,this.className))});if(s)for(t=(e||"").match(dt)||[];u>l;l++)if(n=this[l],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(un," "):"")){for(o=0;i=t[o++];)for(;r.indexOf(" "+i+" ")>=0;)r=r.replace(" "+i+" "," ");a=e?et.trim(r):"",n.className!==a&&(n.className=a)}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):this.each(et.isFunction(e)?function(n){et(this).toggleClass(e.call(this,n,this.className,t),t)}:function(){if("string"===n)for(var t,r=0,i=et(this),o=e.match(dt)||[];t=o[r++];)i.hasClass(t)?i.removeClass(t):i.addClass(t);else(n===Tt||"boolean"===n)&&(this.className&&vt.set(this,"__className__",this.className),this.className=this.className||e===!1?"":vt.get(this,"__className__")||"")})},hasClass:function(e){for(var t=" "+e+" ",n=0,r=this.length;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(un," ").indexOf(t)>=0)return!0;return!1}});var cn=/\r/g;et.fn.extend({val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=et.isFunction(e),this.each(function(n){var i;1===this.nodeType&&(i=r?e.call(this,n,et(this).val()):e,null==i?i="":"number"==typeof i?i+="":et.isArray(i)&&(i=et.map(i,function(e){return null==e?"":e+""})),t=et.valHooks[this.type]||et.valHooks[this.nodeName.toLowerCase()],t&&"set"in t&&void 0!==t.set(this,i,"value")||(this.value=i))});if(i)return t=et.valHooks[i.type]||et.valHooks[i.nodeName.toLowerCase()],t&&"get"in t&&void 0!==(n=t.get(i,"value"))?n:(n=i.value,"string"==typeof n?n.replace(cn,""):null==n?"":n)}}}),et.extend({valHooks:{option:{get:function(e){var t=et.find.attr(e,"value");return null!=t?t:et.trim(et.text(e))}},select:{get:function(e){for(var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(K.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&et.nodeName(n.parentNode,"optgroup"))){if(t=et(n).val(),o)return t;a.push(t)}return a},set:function(e,t){for(var n,r,i=e.options,o=et.makeArray(t),a=i.length;a--;)r=i[a],(r.selected=et.inArray(r.value,o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}}}),et.each(["radio","checkbox"],function(){et.valHooks[this]={set:function(e,t){return et.isArray(t)?e.checked=et.inArray(et(e).val(),t)>=0:void 0}},K.checkOn||(et.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})}),et.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(e,t){et.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),et.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}});var pn=et.now(),hn=/\?/;et.parseJSON=function(e){return JSON.parse(e+"")},et.parseXML=function(e){var t,n;if(!e||"string"!=typeof e)return null;try{n=new DOMParser,t=n.parseFromString(e,"text/xml")}catch(r){t=void 0}return(!t||t.getElementsByTagName("parsererror").length)&&et.error("Invalid XML: "+e),t};var fn=/#.*$/,dn=/([?&])_=[^&]*/,mn=/^(.*?):[ \t]*([^\r\n]*)$/gm,gn=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,yn=/^(?:GET|HEAD)$/,vn=/^\/\//,bn=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,wn={},xn={},An="*/".concat("*"),En=t.location.href,jn=bn.exec(En.toLowerCase())||[];et.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:En,type:"GET",isLocal:gn.test(jn[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":An,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":et.parseJSON,"text xml":et.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?M(M(e,et.ajaxSettings),t):M(et.ajaxSettings,e)},ajaxPrefilter:I(wn),ajaxTransport:I(xn),ajax:function(e,t){function n(e,t,n,a){var l,c,y,v,w,A=t;2!==b&&(b=2,s&&clearTimeout(s),r=void 0,o=a||"",x.readyState=e>0?4:0,l=e>=200&&300>e||304===e,n&&(v=U(p,x,n)),v=H(p,v,x,l),l?(p.ifModified&&(w=x.getResponseHeader("Last-Modified"),w&&(et.lastModified[i]=w),w=x.getResponseHeader("etag"),w&&(et.etag[i]=w)),204===e||"HEAD"===p.type?A="nocontent":304===e?A="notmodified":(A=v.state,c=v.data,y=v.error,l=!y)):(y=A,(e||!A)&&(A="error",0>e&&(e=0))),x.status=e,x.statusText=(t||A)+"",l?d.resolveWith(h,[c,A,x]):d.rejectWith(h,[x,A,y]),x.statusCode(g),g=void 0,u&&f.trigger(l?"ajaxSuccess":"ajaxError",[x,p,l?c:y]),m.fireWith(h,[x,A]),u&&(f.trigger("ajaxComplete",[x,p]),--et.active||et.event.trigger("ajaxStop")))}"object"==typeof e&&(t=e,e=void 0),t=t||{};var r,i,o,a,s,l,u,c,p=et.ajaxSetup({},t),h=p.context||p,f=p.context&&(h.nodeType||h.jquery)?et(h):et.event,d=et.Deferred(),m=et.Callbacks("once memory"),g=p.statusCode||{},y={},v={},b=0,w="canceled",x={readyState:0,getResponseHeader:function(e){var t;if(2===b){if(!a)for(a={};t=mn.exec(o);)a[t[1].toLowerCase()]=t[2];t=a[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return 2===b?o:null},setRequestHeader:function(e,t){var n=e.toLowerCase();return b||(e=v[n]=v[n]||e,y[e]=t),this},overrideMimeType:function(e){return b||(p.mimeType=e),this},statusCode:function(e){var t;if(e)if(2>b)for(t in e)g[t]=[g[t],e[t]];else x.always(e[x.status]);return this},abort:function(e){var t=e||w;return r&&r.abort(t),n(0,t),this}};if(d.promise(x).complete=m.add,x.success=x.done,x.error=x.fail,p.url=((e||p.url||En)+"").replace(fn,"").replace(vn,jn[1]+"//"),p.type=t.method||t.type||p.method||p.type,p.dataTypes=et.trim(p.dataType||"*").toLowerCase().match(dt)||[""],null==p.crossDomain&&(l=bn.exec(p.url.toLowerCase()),p.crossDomain=!(!l||l[1]===jn[1]&&l[2]===jn[2]&&(l[3]||("http:"===l[1]?"80":"443"))===(jn[3]||("http:"===jn[1]?"80":"443")))),p.data&&p.processData&&"string"!=typeof p.data&&(p.data=et.param(p.data,p.traditional)),R(wn,p,t,x),2===b)return x;u=et.event&&p.global,u&&0===et.active++&&et.event.trigger("ajaxStart"),p.type=p.type.toUpperCase(),p.hasContent=!yn.test(p.type),i=p.url,p.hasContent||(p.data&&(i=p.url+=(hn.test(i)?"&":"?")+p.data,delete p.data),p.cache===!1&&(p.url=dn.test(i)?i.replace(dn,"$1_="+pn++):i+(hn.test(i)?"&":"?")+"_="+pn++)),p.ifModified&&(et.lastModified[i]&&x.setRequestHeader("If-Modified-Since",et.lastModified[i]),et.etag[i]&&x.setRequestHeader("If-None-Match",et.etag[i])),(p.data&&p.hasContent&&p.contentType!==!1||t.contentType)&&x.setRequestHeader("Content-Type",p.contentType),x.setRequestHeader("Accept",p.dataTypes[0]&&p.accepts[p.dataTypes[0]]?p.accepts[p.dataTypes[0]]+("*"!==p.dataTypes[0]?", "+An+"; q=0.01":""):p.accepts["*"]);for(c in p.headers)x.setRequestHeader(c,p.headers[c]);if(p.beforeSend&&(p.beforeSend.call(h,x,p)===!1||2===b))return x.abort();w="abort";for(c in{success:1,error:1,complete:1})x[c](p[c]);if(r=R(xn,p,t,x)){x.readyState=1,u&&f.trigger("ajaxSend",[x,p]),p.async&&p.timeout>0&&(s=setTimeout(function(){x.abort("timeout")},p.timeout));try{b=1,r.send(y,n)}catch(A){if(!(2>b))throw A;n(-1,A)}}else n(-1,"No Transport");return x},getJSON:function(e,t,n){return et.get(e,t,n,"json")},getScript:function(e,t){return et.get(e,void 0,t,"script")}}),et.each(["get","post"],function(e,t){et[t]=function(e,n,r,i){return et.isFunction(n)&&(i=i||r,r=n,n=void 0),et.ajax({url:e,type:t,dataType:i,data:n,success:r})}}),et._evalUrl=function(e){return et.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},et.fn.extend({wrapAll:function(e){var t;return et.isFunction(e)?this.each(function(t){et(this).wrapAll(e.call(this,t))}):(this[0]&&(t=et(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){for(var e=this;e.firstElementChild;)e=e.firstElementChild;return e}).append(this)),this)},wrapInner:function(e){return this.each(et.isFunction(e)?function(t){et(this).wrapInner(e.call(this,t))}:function(){var t=et(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=et.isFunction(e);return this.each(function(n){et(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){et.nodeName(this,"body")||et(this).replaceWith(this.childNodes)}).end()}}),et.expr.filters.hidden=function(e){return e.offsetWidth<=0&&e.offsetHeight<=0},et.expr.filters.visible=function(e){return!et.expr.filters.hidden(e)};var Cn=/%20/g,Tn=/\[\]$/,Sn=/\r?\n/g,_n=/^(?:submit|button|image|reset|file)$/i,On=/^(?:input|select|textarea|keygen)/i;et.param=function(e,t){var n,r=[],i=function(e,t){t=et.isFunction(t)?t():null==t?"":t,r[r.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};if(void 0===t&&(t=et.ajaxSettings&&et.ajaxSettings.traditional),et.isArray(e)||e.jquery&&!et.isPlainObject(e))et.each(e,function(){i(this.name,this.value)});else for(n in e)F(n,e[n],t,i);return r.join("&").replace(Cn,"+")},et.fn.extend({serialize:function(){return et.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=et.prop(this,"elements");return e?et.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!et(this).is(":disabled")&&On.test(this.nodeName)&&!_n.test(e)&&(this.checked||!Ct.test(e))}).map(function(e,t){var n=et(this).val();return null==n?null:et.isArray(n)?et.map(n,function(e){return{name:t.name,value:e.replace(Sn,"\r\n")}}):{name:t.name,value:n.replace(Sn,"\r\n")}}).get()}}),et.ajaxSettings.xhr=function(){try{return new XMLHttpRequest}catch(e){}};var kn=0,$n={},Dn={0:200,1223:204},Ln=et.ajaxSettings.xhr();t.attachEvent&&t.attachEvent("onunload",function(){for(var e in $n)$n[e]()}),K.cors=!!Ln&&"withCredentials"in Ln,K.ajax=Ln=!!Ln,et.ajaxTransport(function(e){var t;return K.cors||Ln&&!e.crossDomain?{send:function(n,r){var i,o=e.xhr(),a=++kn;if(o.open(e.type,e.url,e.async,e.username,e.password),e.xhrFields)for(i in e.xhrFields)o[i]=e.xhrFields[i];e.mimeType&&o.overrideMimeType&&o.overrideMimeType(e.mimeType),e.crossDomain||n["X-Requested-With"]||(n["X-Requested-With"]="XMLHttpRequest");for(i in n)o.setRequestHeader(i,n[i]);t=function(e){return function(){t&&(delete $n[a],t=o.onload=o.onerror=null,"abort"===e?o.abort():"error"===e?r(o.status,o.statusText):r(Dn[o.status]||o.status,o.statusText,"string"==typeof o.responseText?{text:o.responseText}:void 0,o.getAllResponseHeaders()))}},o.onload=t(),o.onerror=t("error"),t=$n[a]=t("abort");try{o.send(e.hasContent&&e.data||null)}catch(s){if(t)throw s}},abort:function(){t&&t()}}:void 0}),et.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(e){return et.globalEval(e),e}}}),et.ajaxPrefilter("script",function(e){void 0===e.cache&&(e.cache=!1),e.crossDomain&&(e.type="GET")}),et.ajaxTransport("script",function(e){if(e.crossDomain){var t,n;return{send:function(r,i){t=et("<script>").prop({async:!0,charset:e.scriptCharset,src:e.url}).on("load error",n=function(e){t.remove(),n=null,e&&i("error"===e.type?404:200,e.type)}),G.head.appendChild(t[0])},abort:function(){n&&n()}}}});var Nn=[],Pn=/(=)\?(?=&|$)|\?\?/;et.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Nn.pop()||et.expando+"_"+pn++;return this[e]=!0,e}}),et.ajaxPrefilter("json jsonp",function(e,n,r){var i,o,a,s=e.jsonp!==!1&&(Pn.test(e.url)?"url":"string"==typeof e.data&&!(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Pn.test(e.data)&&"data");return s||"jsonp"===e.dataTypes[0]?(i=e.jsonpCallback=et.isFunction(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,s?e[s]=e[s].replace(Pn,"$1"+i):e.jsonp!==!1&&(e.url+=(hn.test(e.url)?"&":"?")+e.jsonp+"="+i),e.converters["script json"]=function(){return a||et.error(i+" was not called"),a[0]},e.dataTypes[0]="json",o=t[i],t[i]=function(){a=arguments},r.always(function(){t[i]=o,e[i]&&(e.jsonpCallback=n.jsonpCallback,Nn.push(i)),a&&et.isFunction(o)&&o(a[0]),a=o=void 0}),"script"):void 0}),et.parseHTML=function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||G;var r=st.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=et.buildFragment([e],t,i),i&&i.length&&et(i).remove(),et.merge([],r.childNodes))};var In=et.fn.load;et.fn.load=function(e,t,n){if("string"!=typeof e&&In)return In.apply(this,arguments);var r,i,o,a=this,s=e.indexOf(" ");return s>=0&&(r=et.trim(e.slice(s)),e=e.slice(0,s)),et.isFunction(t)?(n=t,t=void 0):t&&"object"==typeof t&&(i="POST"),a.length>0&&et.ajax({url:e,type:i,dataType:"html",data:t}).done(function(e){o=arguments,a.html(r?et("<div>").append(et.parseHTML(e)).find(r):e)}).complete(n&&function(e,t){a.each(n,o||[e.responseText,t,e])}),this},et.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){et.fn[t]=function(e){return this.on(t,e)}}),et.expr.filters.animated=function(e){return et.grep(et.timers,function(t){return e===t.elem}).length};var Rn=t.document.documentElement;et.offset={setOffset:function(e,t,n){var r,i,o,a,s,l,u,c=et.css(e,"position"),p=et(e),h={};"static"===c&&(e.style.position="relative"),s=p.offset(),o=et.css(e,"top"),l=et.css(e,"left"),u=("absolute"===c||"fixed"===c)&&(o+l).indexOf("auto")>-1,u?(r=p.position(),a=r.top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(l)||0),et.isFunction(t)&&(t=t.call(e,n,s)),null!=t.top&&(h.top=t.top-s.top+a),null!=t.left&&(h.left=t.left-s.left+i),"using"in t?t.using.call(e,h):p.css(h)}},et.fn.extend({offset:function(e){if(arguments.length)return void 0===e?this:this.each(function(t){et.offset.setOffset(this,e,t)});var t,n,r=this[0],i={top:0,left:0},o=r&&r.ownerDocument;if(o)return t=o.documentElement,et.contains(t,r)?(typeof r.getBoundingClientRect!==Tt&&(i=r.getBoundingClientRect()),n=B(o),{top:i.top+n.pageYOffset-t.clientTop,left:i.left+n.pageXOffset-t.clientLeft}):i},position:function(){if(this[0]){var e,t,n=this[0],r={top:0,left:0};return"fixed"===et.css(n,"position")?t=n.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),et.nodeName(e[0],"html")||(r=e.offset()),r.top+=et.css(e[0],"borderTopWidth",!0),r.left+=et.css(e[0],"borderLeftWidth",!0)),{top:t.top-r.top-et.css(n,"marginTop",!0),left:t.left-r.left-et.css(n,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){for(var e=this.offsetParent||Rn;e&&!et.nodeName(e,"html")&&"static"===et.css(e,"position");)e=e.offsetParent;return e||Rn})}}),et.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r="pageYOffset"===n;et.fn[e]=function(i){return yt(this,function(e,i,o){var a=B(e);return void 0===o?a?a[n]:e[i]:void(a?a.scrollTo(r?t.pageXOffset:o,r?o:t.pageYOffset):e[i]=o)},e,i,arguments.length,null)}}),et.each(["top","left"],function(e,t){et.cssHooks[t]=E(K.pixelPosition,function(e,n){return n?(n=A(e,t),qt.test(n)?et(e).position()[t]+"px":n):void 0})}),et.each({Height:"height",Width:"width"},function(e,t){et.each({padding:"inner"+e,content:t,"":"outer"+e},function(n,r){et.fn[r]=function(r,i){var o=arguments.length&&(n||"boolean"!=typeof r),a=n||(r===!0||i===!0?"margin":"border");return yt(this,function(t,n,r){var i;return et.isWindow(t)?t.document.documentElement["client"+e]:9===t.nodeType?(i=t.documentElement,Math.max(t.body["scroll"+e],i["scroll"+e],t.body["offset"+e],i["offset"+e],i["client"+e])):void 0===r?et.css(t,n,a):et.style(t,n,r,a)},t,o?r:void 0,o,null)}})}),et.fn.size=function(){return this.length},et.fn.andSelf=et.fn.addBack,"function"==typeof e&&e.amd&&e("jquery",[],function(){return et});var Mn=t.jQuery,Un=t.$;return et.noConflict=function(e){return t.$===et&&(t.$=Un),e&&t.jQuery===et&&(t.jQuery=Mn),et},typeof n===Tt&&(t.jQuery=t.$=et),et})},{}],19:[function(e,t){function n(e,t,n){var a=e?e.length:0;if(!a)return-1;if("number"==typeof n)n=0>n?o(a+n,0):n;else if(n){var s=i(e,t),l=e[s];return(t===t?t===l:l!==l)?s:-1}return r(e,t,n||0)}var r=e("../internal/baseIndexOf"),i=e("../internal/binaryIndex"),o=Math.max;t.exports=n},{"../internal/baseIndexOf":42,"../internal/binaryIndex":54}],20:[function(e,t){function n(e){if(s(e)&&!a(e)&&!(e instanceof r)){if(e instanceof i)return e;if(c.call(e,"__chain__")&&c.call(e,"__wrapped__"))return l(e)}return new i(e)}var r=e("../internal/LazyWrapper"),i=e("../internal/LodashWrapper"),o=e("../internal/baseLodash"),a=e("../lang/isArray"),s=e("../internal/isObjectLike"),l=e("../internal/wrapperClone"),u=Object.prototype,c=u.hasOwnProperty;n.prototype=o.prototype,t.exports=n},{"../internal/LazyWrapper":27,"../internal/LodashWrapper":28,"../internal/baseLodash":47,"../internal/isObjectLike":82,"../internal/wrapperClone":93,"../lang/isArray":96}],21:[function(e,t){var n=e("../internal/baseEach"),r=e("../internal/createFind"),i=r(n);t.exports=i},{"../internal/baseEach":36,"../internal/createFind":64}],22:[function(e,t){var n=e("../internal/arrayEach"),r=e("../internal/baseEach"),i=e("../internal/createForEach"),o=i(n,r);t.exports=o},{"../internal/arrayEach":30,"../internal/baseEach":36,"../internal/createForEach":65}],23:[function(e,t){function n(e,t,n){var s=a(e)?r:o;return t=i(t,n,3),s(e,t)}var r=e("../internal/arrayMap"),i=e("../internal/baseCallback"),o=e("../internal/baseMap"),a=e("../lang/isArray");t.exports=n},{"../internal/arrayMap":31,"../internal/baseCallback":32,"../internal/baseMap":48,"../lang/isArray":96}],24:[function(e,t){var n=e("../lang/isNative"),r=n(r=Date.now)&&r,i=r||function(){return(new Date).getTime()};t.exports=i},{"../lang/isNative":98}],25:[function(e,t){var n=e("../internal/createWrapper"),r=e("../internal/replaceHolders"),i=e("./restParam"),o=1,a=32,s=i(function(e,t,i){var l=o;if(i.length){var u=r(i,s.placeholder);l|=a}return n(e,l,t,i,u)});s.placeholder={},t.exports=s},{"../internal/createWrapper":68,"../internal/replaceHolders":88,"./restParam":26}],26:[function(e,t){function n(e,t){if("function"!=typeof e)throw new TypeError(r);return t=i("undefined"==typeof t?e.length-1:+t||0,0),function(){for(var n=arguments,r=-1,o=i(n.length-t,0),a=Array(o);++r<o;)a[r]=n[t+r];switch(t){case 0:return e.call(this,a);case 1:return e.call(this,n[0],a);case 2:return e.call(this,n[0],n[1],a)}var s=Array(t+1);for(r=-1;++r<t;)s[r]=n[r];return s[t]=a,e.apply(this,s)}}var r="Expected a function",i=Math.max;t.exports=n},{}],27:[function(e,t){function n(e){this.__wrapped__=e,this.__actions__=null,this.__dir__=1,this.__dropCount__=0,this.__filtered__=!1,this.__iteratees__=null,this.__takeCount__=o,this.__views__=null}var r=e("./baseCreate"),i=e("./baseLodash"),o=Number.POSITIVE_INFINITY;n.prototype=r(i.prototype),n.prototype.constructor=n,t.exports=n},{"./baseCreate":35,"./baseLodash":47}],28:[function(e,t){function n(e,t,n){this.__wrapped__=e,this.__actions__=n||[],this.__chain__=!!t}var r=e("./baseCreate"),i=e("./baseLodash");n.prototype=r(i.prototype),n.prototype.constructor=n,t.exports=n},{"./baseCreate":35,"./baseLodash":47}],29:[function(e,t){function n(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}t.exports=n},{}],30:[function(e,t){function n(e,t){for(var n=-1,r=e.length;++n<r&&t(e[n],n,e)!==!1;);return e}t.exports=n},{}],31:[function(e,t){function n(e,t){for(var n=-1,r=e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}t.exports=n},{}],32:[function(e,t){function n(e,t,n){var l=typeof e;return"function"==l?"undefined"==typeof t?e:a(e,t,n):null==e?s:"object"==l?r(e):"undefined"==typeof t?o(e+""):i(e+"",t)}var r=e("./baseMatches"),i=e("./baseMatchesProperty"),o=e("./baseProperty"),a=e("./bindCallback"),s=e("../utility/identity");t.exports=n},{"../utility/identity":109,"./baseMatches":49,"./baseMatchesProperty":50,"./baseProperty":51,"./bindCallback":56}],33:[function(e,t){function n(e,t,m,g,y,v,w){var x;if(m&&(x=y?m(e,g,y):m(e)),"undefined"!=typeof x)return x;if(!h(e))return e;var E=c(e);if(E){if(x=s(e),!t)return r(e,x)}else{var j=U.call(e),C=j==b;if(j!=A&&j!=d&&(!C||y))return R[j]?l(e,j,t):y?e:{};if(p(e))return y?e:{};if(x=u(C?{}:e),!t)return o(e,x,f(e))}v||(v=[]),w||(w=[]);for(var T=v.length;T--;)if(v[T]==e)return w[T];return v.push(e),w.push(x),(E?i:a)(e,function(r,i){x[i]=n(r,t,m,i,e,v,w)}),x}var r=e("./arrayCopy"),i=e("./arrayEach"),o=e("./baseCopy"),a=e("./baseForOwn"),s=e("./initCloneArray"),l=e("./initCloneByTag"),u=e("./initCloneObject"),c=e("../lang/isArray"),p=e("./isHostObject"),h=e("../lang/isObject"),f=e("../object/keys"),d="[object Arguments]",m="[object Array]",g="[object Boolean]",y="[object Date]",v="[object Error]",b="[object Function]",w="[object Map]",x="[object Number]",A="[object Object]",E="[object RegExp]",j="[object Set]",C="[object String]",T="[object WeakMap]",S="[object ArrayBuffer]",_="[object Float32Array]",O="[object Float64Array]",k="[object Int8Array]",$="[object Int16Array]",D="[object Int32Array]",L="[object Uint8Array]",N="[object Uint8ClampedArray]",P="[object Uint16Array]",I="[object Uint32Array]",R={};R[d]=R[m]=R[S]=R[g]=R[y]=R[_]=R[O]=R[k]=R[$]=R[D]=R[x]=R[A]=R[E]=R[C]=R[L]=R[N]=R[P]=R[I]=!0,R[v]=R[b]=R[w]=R[j]=R[T]=!1;var M=Object.prototype,U=M.toString;t.exports=n},{"../lang/isArray":96,"../lang/isObject":99,"../object/keys":104,"./arrayCopy":29,"./arrayEach":30,"./baseCopy":34,"./baseForOwn":41,"./initCloneArray":75,"./initCloneByTag":76,"./initCloneObject":77,"./isHostObject":78}],34:[function(e,t){function n(e,t,n){n||(n=t,t={});for(var r=-1,i=n.length;++r<i;){var o=n[r];t[o]=e[o]}return t}t.exports=n},{}],35:[function(e,t){(function(n){var r=e("../lang/isObject"),i=function(){function e(){}return function(t){if(r(t)){e.prototype=t;var i=new e;e.prototype=null}return i||n.Object()}}();t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../lang/isObject":99}],36:[function(e,t){var n=e("./baseForOwn"),r=e("./createBaseEach"),i=r(n);t.exports=i},{"./baseForOwn":41,"./createBaseEach":60}],37:[function(e,t){function n(e,t,n,r){var i;return n(e,function(e,n,o){return t(e,n,o)?(i=r?n:e,!1):void 0}),i}t.exports=n},{}],38:[function(e,t){function n(e,t,n){for(var r=e.length,i=n?r:-1;n?i--:++i<r;)if(t(e[i],i,e))return i;return-1}t.exports=n},{}],39:[function(e,t){var n=e("./createBaseFor"),r=n();t.exports=r},{"./createBaseFor":61}],40:[function(e,t){function n(e,t){return r(e,t,i)}var r=e("./baseFor"),i=e("../object/keysIn");t.exports=n},{"../object/keysIn":105,"./baseFor":39}],41:[function(e,t){function n(e,t){return r(e,t,i)}var r=e("./baseFor"),i=e("../object/keys");t.exports=n},{"../object/keys":104,"./baseFor":39}],42:[function(e,t){function n(e,t,n){if(t!==t)return r(e,n);for(var i=n-1,o=e.length;++i<o;)if(e[i]===t)return i;return-1}var r=e("./indexOfNaN");t.exports=n},{"./indexOfNaN":74}],43:[function(e,t){function n(e,t,i,o,a,s){if(e===t)return 0!==e||1/e==1/t;var l=typeof e,u=typeof t;return"function"!=l&&"object"!=l&&"function"!=u&&"object"!=u||null==e||null==t?e!==e&&t!==t:r(e,t,n,i,o,a,s)}var r=e("./baseIsEqualDeep");t.exports=n},{"./baseIsEqualDeep":44}],44:[function(e,t){function n(e,t,n,f,g,y,v){var b=a(e),w=a(t),x=c,A=c;b||(x=m.call(e),x==u?x=h:x!=h&&(b=l(e))),w||(A=m.call(t),A==u?A=h:A!=h&&(w=l(t)));var E=(x==h||g&&x==p)&&!s(e),j=(A==h||g&&A==p)&&!s(t),C=x==A;if(C&&!b&&!E)return i(e,t,x);if(g){if(!(C||E&&j))return!1}else{var T=E&&d.call(e,"__wrapped__"),S=j&&d.call(t,"__wrapped__");if(T||S)return n(T?e.value():e,S?t.value():t,f,g,y,v);
+if(!C)return!1}y||(y=[]),v||(v=[]);for(var _=y.length;_--;)if(y[_]==e)return v[_]==t;y.push(e),v.push(t);var O=(b?r:o)(e,t,n,f,g,y,v);return y.pop(),v.pop(),O}var r=e("./equalArrays"),i=e("./equalByTag"),o=e("./equalObjects"),a=e("../lang/isArray"),s=e("./isHostObject"),l=e("../lang/isTypedArray"),u="[object Arguments]",c="[object Array]",p="[object Function]",h="[object Object]",f=Object.prototype,d=f.hasOwnProperty,m=f.toString;t.exports=n},{"../lang/isArray":96,"../lang/isTypedArray":102,"./equalArrays":69,"./equalByTag":70,"./equalObjects":71,"./isHostObject":78}],45:[function(e,t){function n(e){return"function"==typeof e||!1}t.exports=n},{}],46:[function(e,t){function n(e,t,n,i,o){for(var a=-1,s=t.length,l=!o;++a<s;)if(l&&i[a]?n[a]!==e[t[a]]:!(t[a]in e))return!1;for(a=-1;++a<s;){var u=t[a],c=e[u],p=n[a];if(l&&i[a])var h="undefined"!=typeof c||u in e;else h=o?o(c,p,u):void 0,"undefined"==typeof h&&(h=r(p,c,o,!0));if(!h)return!1}return!0}var r=e("./baseIsEqual");t.exports=n},{"./baseIsEqual":43}],47:[function(e,t){function n(){}t.exports=n},{}],48:[function(e,t){function n(e,t){var n=[];return r(e,function(e,r,i){n.push(t(e,r,i))}),n}var r=e("./baseEach");t.exports=n},{"./baseEach":36}],49:[function(e,t){function n(e){var t=a(e),n=t.length;if(!n)return i(!0);if(1==n){var l=t[0],u=e[l];if(o(u))return function(e){return null!=e&&e[l]===u&&("undefined"!=typeof u||l in s(e))}}for(var c=Array(n),p=Array(n);n--;)u=e[t[n]],c[n]=u,p[n]=o(u);return function(e){return null!=e&&r(s(e),t,c,p)}}var r=e("./baseIsMatch"),i=e("../utility/constant"),o=e("./isStrictComparable"),a=e("../object/keys"),s=e("./toObject");t.exports=n},{"../object/keys":104,"../utility/constant":108,"./baseIsMatch":46,"./isStrictComparable":83,"./toObject":92}],50:[function(e,t){function n(e,t){return i(t)?function(n){return null!=n&&n[e]===t&&("undefined"!=typeof t||e in o(n))}:function(n){return null!=n&&r(t,n[e],null,!0)}}var r=e("./baseIsEqual"),i=e("./isStrictComparable"),o=e("./toObject");t.exports=n},{"./baseIsEqual":43,"./isStrictComparable":83,"./toObject":92}],51:[function(e,t){function n(e){return function(t){return null==t?void 0:t[e]}}t.exports=n},{}],52:[function(e,t){var n=e("../utility/identity"),r=e("./metaMap"),i=r?function(e,t){return r.set(e,t),e}:n;t.exports=i},{"../utility/identity":109,"./metaMap":85}],53:[function(e,t){function n(e){return"string"==typeof e?e:null==e?"":e+""}t.exports=n},{}],54:[function(e,t){function n(e,t,n){var o=0,s=e?e.length:o;if("number"==typeof t&&t===t&&a>=s){for(;s>o;){var l=o+s>>>1,u=e[l];(n?t>=u:t>u)?o=l+1:s=l}return s}return r(e,t,i,n)}var r=e("./binaryIndexBy"),i=e("../utility/identity"),o=Math.pow(2,32)-1,a=o>>>1;t.exports=n},{"../utility/identity":109,"./binaryIndexBy":55}],55:[function(e,t){function n(e,t,n,o){t=n(t);for(var s=0,l=e?e.length:0,u=t!==t,c="undefined"==typeof t;l>s;){var p=r((s+l)/2),h=n(e[p]),f=h===h;if(u)var d=f||o;else d=c?f&&(o||"undefined"!=typeof h):o?t>=h:t>h;d?s=p+1:l=p}return i(l,a)}var r=Math.floor,i=Math.min,o=Math.pow(2,32)-1,a=o-1;t.exports=n},{}],56:[function(e,t){function n(e,t,n){if("function"!=typeof e)return r;if("undefined"==typeof t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 3:return function(n,r,i){return e.call(t,n,r,i)};case 4:return function(n,r,i,o){return e.call(t,n,r,i,o)};case 5:return function(n,r,i,o,a){return e.call(t,n,r,i,o,a)}}return function(){return e.apply(t,arguments)}}var r=e("../utility/identity");t.exports=n},{"../utility/identity":109}],57:[function(e,t){(function(n){function r(e){return s.call(e,0)}var i=e("../utility/constant"),o=e("../lang/isNative"),a=o(a=n.ArrayBuffer)&&a,s=o(s=a&&new a(0).slice)&&s,l=Math.floor,u=o(u=n.Uint8Array)&&u,c=function(){try{var e=o(e=n.Float64Array)&&e,t=new e(new a(10),0,1)&&e}catch(r){}return t}(),p=c?c.BYTES_PER_ELEMENT:0;s||(r=a&&u?function(e){var t=e.byteLength,n=c?l(t/p):0,r=n*p,i=new a(t);if(n){var o=new c(i,0,n);o.set(new c(e,0,n))}return t!=r&&(o=new u(i,r),o.set(new u(e,r))),i}:i(null)),t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../lang/isNative":98,"../utility/constant":108}],58:[function(e,t){function n(e,t,n){for(var i=n.length,o=-1,a=r(e.length-i,0),s=-1,l=t.length,u=Array(a+l);++s<l;)u[s]=t[s];for(;++o<i;)u[n[o]]=e[o];for(;a--;)u[s++]=e[o++];return u}var r=Math.max;t.exports=n},{}],59:[function(e,t){function n(e,t,n){for(var i=-1,o=n.length,a=-1,s=r(e.length-o,0),l=-1,u=t.length,c=Array(s+u);++a<s;)c[a]=e[a];for(var p=a;++l<u;)c[p+l]=t[l];for(;++i<o;)c[p+n[i]]=e[a++];return c}var r=Math.max;t.exports=n},{}],60:[function(e,t){function n(e,t){return function(n,o){var a=n?n.length:0;if(!r(a))return e(n,o);for(var s=t?a:-1,l=i(n);(t?s--:++s<a)&&o(l[s],s,l)!==!1;);return n}}var r=e("./isLength"),i=e("./toObject");t.exports=n},{"./isLength":81,"./toObject":92}],61:[function(e,t){function n(e){return function(t,n,i){for(var o=r(t),a=i(t),s=a.length,l=e?s:-1;e?l--:++l<s;){var u=a[l];if(n(o[u],u,o)===!1)break}return t}}var r=e("./toObject");t.exports=n},{"./toObject":92}],62:[function(e,t){(function(n){function r(e,t){function r(){var i=this&&this!==n&&this instanceof r?o:e;return i.apply(t,arguments)}var o=i(e);return r}var i=e("./createCtorWrapper");t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./createCtorWrapper":63}],63:[function(e,t){function n(e){return function(){var t=r(e.prototype),n=e.apply(t,arguments);return i(n)?n:t}}var r=e("./baseCreate"),i=e("../lang/isObject");t.exports=n},{"../lang/isObject":99,"./baseCreate":35}],64:[function(e,t){function n(e,t){return function(n,s,l){if(s=r(s,l,3),a(n)){var u=o(n,s,t);return u>-1?n[u]:void 0}return i(n,s,e)}}var r=e("./baseCallback"),i=e("./baseFind"),o=e("./baseFindIndex"),a=e("../lang/isArray");t.exports=n},{"../lang/isArray":96,"./baseCallback":32,"./baseFind":37,"./baseFindIndex":38}],65:[function(e,t){function n(e,t){return function(n,o,a){return"function"==typeof o&&"undefined"==typeof a&&i(n)?e(n,o):t(n,r(o,a,3))}}var r=e("./bindCallback"),i=e("../lang/isArray");t.exports=n},{"../lang/isArray":96,"./bindCallback":56}],66:[function(e,t){(function(n){function r(e,t,x,A,E,j,C,T,S,_){function O(){for(var d=arguments.length,m=d,g=Array(d);m--;)g[m]=arguments[m];if(A&&(g=o(g,A,E)),j&&(g=a(g,j,C)),L||P){var b=O.placeholder,M=c(g,b);if(d-=M.length,_>d){var U=T?i(T):null,H=w(_-d,0),F=L?M:null,B=L?null:M,q=L?g:null,z=L?null:g;t|=L?y:v,t&=~(L?v:y),N||(t&=~(h|f));var V=[e,t,x,q,F,z,B,U,S,H],W=r.apply(void 0,V);return l(e)&&p(W,V),W.placeholder=b,W}}var J=$?x:this;D&&(e=J[R]),T&&(g=u(g,T)),k&&S<g.length&&(g.length=S);var Y=this&&this!==n&&this instanceof O?I||s(e):e;return Y.apply(J,g)}var k=t&b,$=t&h,D=t&f,L=t&m,N=t&d,P=t&g,I=!D&&s(e),R=e;return O}var i=e("./arrayCopy"),o=e("./composeArgs"),a=e("./composeArgsRight"),s=e("./createCtorWrapper"),l=e("./isLaziable"),u=e("./reorder"),c=e("./replaceHolders"),p=e("./setData"),h=1,f=2,d=4,m=8,g=16,y=32,v=64,b=128,w=Math.max;t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./arrayCopy":29,"./composeArgs":58,"./composeArgsRight":59,"./createCtorWrapper":63,"./isLaziable":80,"./reorder":87,"./replaceHolders":88,"./setData":89}],67:[function(e,t){(function(n){function r(e,t,r,a){function s(){for(var t=-1,i=arguments.length,o=-1,c=a.length,p=Array(i+c);++o<c;)p[o]=a[o];for(;i--;)p[o++]=arguments[++t];var h=this&&this!==n&&this instanceof s?u:e;return h.apply(l?r:this,p)}var l=t&o,u=i(e);return s}var i=e("./createCtorWrapper"),o=1;t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./createCtorWrapper":63}],68:[function(e,t){function n(e,t,n,g,y,v,b,w){var x=t&p;if(!x&&"function"!=typeof e)throw new TypeError(d);var A=g?g.length:0;if(A||(t&=~(h|f),g=y=null),A-=y?y.length:0,t&f){var E=g,j=y;g=y=null}var C=x?null:s(e),T=[e,t,n,g,y,E,j,v,b,w];if(C&&(l(T,C),t=T[1],w=T[9]),T[9]=null==w?x?0:e.length:m(w-A,0)||0,t==c)var S=i(T[0],T[2]);else S=t!=h&&t!=(c|h)||T[4].length?o.apply(void 0,T):a.apply(void 0,T);var _=C?r:u;return _(S,T)}var r=e("./baseSetData"),i=e("./createBindWrapper"),o=e("./createHybridWrapper"),a=e("./createPartialWrapper"),s=e("./getData"),l=e("./mergeData"),u=e("./setData"),c=1,p=2,h=32,f=64,d="Expected a function",m=Math.max;t.exports=n},{"./baseSetData":52,"./createBindWrapper":62,"./createHybridWrapper":66,"./createPartialWrapper":67,"./getData":72,"./mergeData":84,"./setData":89}],69:[function(e,t){function n(e,t,n,r,i,o,a){var s=-1,l=e.length,u=t.length,c=!0;if(l!=u&&!(i&&u>l))return!1;for(;c&&++s<l;){var p=e[s],h=t[s];if(c=void 0,r&&(c=i?r(h,p,s):r(p,h,s)),"undefined"==typeof c)if(i)for(var f=u;f--&&(h=t[f],!(c=p&&p===h||n(p,h,r,i,o,a))););else c=p&&p===h||n(p,h,r,i,o,a)}return!!c}t.exports=n},{}],70:[function(e,t){function n(e,t,n){switch(n){case r:case i:return+e==+t;case o:return e.name==t.name&&e.message==t.message;case a:return e!=+e?t!=+t:0==e?1/e==1/t:e==+t;case s:case l:return e==t+""}return!1}var r="[object Boolean]",i="[object Date]",o="[object Error]",a="[object Number]",s="[object RegExp]",l="[object String]";t.exports=n},{}],71:[function(e,t){function n(e,t,n,i,a,s,l){var u=r(e),c=u.length,p=r(t),h=p.length;if(c!=h&&!a)return!1;for(var f=a,d=-1;++d<c;){var m=u[d],g=a?m in t:o.call(t,m);if(g){var y=e[m],v=t[m];g=void 0,i&&(g=a?i(v,y,m):i(y,v,m)),"undefined"==typeof g&&(g=y&&y===v||n(y,v,i,a,s,l))}if(!g)return!1;f||(f="constructor"==m)}if(!f){var b=e.constructor,w=t.constructor;if(b!=w&&"constructor"in e&&"constructor"in t&&!("function"==typeof b&&b instanceof b&&"function"==typeof w&&w instanceof w))return!1}return!0}var r=e("../object/keys"),i=Object.prototype,o=i.hasOwnProperty;t.exports=n},{"../object/keys":104}],72:[function(e,t){var n=e("./metaMap"),r=e("../utility/noop"),i=n?function(e){return n.get(e)}:r;t.exports=i},{"../utility/noop":110,"./metaMap":85}],73:[function(e,t){var n=e("./baseProperty"),r=e("../utility/constant"),i=e("./realNames"),o=e("../support"),a=function(){return o.funcNames?"constant"==r.name?n("name"):function(e){for(var t=e.name,n=i[t],r=n?n.length:0;r--;){var o=n[r],a=o.func;if(null==a||a==e)return o.name}return t}:r("")}();t.exports=a},{"../support":107,"../utility/constant":108,"./baseProperty":51,"./realNames":86}],74:[function(e,t){function n(e,t,n){for(var r=e.length,i=t+(n?0:-1);n?i--:++i<r;){var o=e[i];if(o!==o)return i}return-1}t.exports=n},{}],75:[function(e,t){function n(e){var t=e.length,n=new e.constructor(t);return t&&"string"==typeof e[0]&&i.call(e,"index")&&(n.index=e.index,n.input=e.input),n}var r=Object.prototype,i=r.hasOwnProperty;t.exports=n},{}],76:[function(e,t){(function(n){function r(e,t,n){var r=e.constructor;switch(t){case c:return i(e);case o:case a:return new r(+e);case p:case h:case f:case d:case m:case g:case y:case v:case b:r instanceof r&&(r=x[t]);var A=e.buffer;return new r(n?i(A):A,e.byteOffset,e.length);case s:case u:return new r(e);case l:var E=new r(e.source,w.exec(e));E.lastIndex=e.lastIndex}return E}var i=e("./bufferClone"),o="[object Boolean]",a="[object Date]",s="[object Number]",l="[object RegExp]",u="[object String]",c="[object ArrayBuffer]",p="[object Float32Array]",h="[object Float64Array]",f="[object Int8Array]",d="[object Int16Array]",m="[object Int32Array]",g="[object Uint8Array]",y="[object Uint8ClampedArray]",v="[object Uint16Array]",b="[object Uint32Array]",w=/\w*$/,x={};x[p]=n.Float32Array,x[h]=n.Float64Array,x[f]=n.Int8Array,x[d]=n.Int16Array,x[m]=n.Int32Array,x[g]=n.Uint8Array,x[y]=n.Uint8ClampedArray,x[v]=n.Uint16Array,x[b]=n.Uint32Array,t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./bufferClone":57}],77:[function(e,t){function n(e){var t=e.constructor;return"function"==typeof t&&t instanceof t||(t=Object),new t}t.exports=n},{}],78:[function(e,t){var n=function(){try{Object({toString:0}+"")}catch(e){return function(){return!1}}return function(e){return"function"!=typeof e.toString&&"string"==typeof(e+"")}}();t.exports=n},{}],79:[function(e,t){function n(e,t){return e=+e,t=null==t?r:t,e>-1&&e%1==0&&t>e}var r=Math.pow(2,53)-1;t.exports=n},{}],80:[function(e,t){function n(e){var t=i(e);return!!t&&e===o[t]&&t in r.prototype}var r=e("./LazyWrapper"),i=e("./getFuncName"),o=e("../chain/lodash");t.exports=n},{"../chain/lodash":20,"./LazyWrapper":27,"./getFuncName":73}],81:[function(e,t){function n(e){return"number"==typeof e&&e>-1&&e%1==0&&r>=e}var r=Math.pow(2,53)-1;t.exports=n},{}],82:[function(e,t){function n(e){return!!e&&"object"==typeof e}t.exports=n},{}],83:[function(e,t){function n(e){return e===e&&(0===e?1/e>0:!r(e))}var r=e("../lang/isObject");t.exports=n},{"../lang/isObject":99}],84:[function(e,t){function n(e,t){var n=e[1],d=t[1],m=n|d,g=c>m,y=d==c&&n==u||d==c&&n==p&&e[7].length<=t[8]||d==(c|p)&&n==u;if(!g&&!y)return e;d&s&&(e[2]=t[2],m|=n&s?0:l);var v=t[3];if(v){var b=e[3];e[3]=b?i(b,v,t[4]):r(v),e[4]=b?a(e[3],h):r(t[4])}return v=t[5],v&&(b=e[5],e[5]=b?o(b,v,t[6]):r(v),e[6]=b?a(e[5],h):r(t[6])),v=t[7],v&&(e[7]=r(v)),d&c&&(e[8]=null==e[8]?t[8]:f(e[8],t[8])),null==e[9]&&(e[9]=t[9]),e[0]=t[0],e[1]=m,e}var r=e("./arrayCopy"),i=e("./composeArgs"),o=e("./composeArgsRight"),a=e("./replaceHolders"),s=1,l=4,u=8,c=128,p=256,h="__lodash_placeholder__",f=Math.min;t.exports=n},{"./arrayCopy":29,"./composeArgs":58,"./composeArgsRight":59,"./replaceHolders":88}],85:[function(e,t){(function(n){var r=e("../lang/isNative"),i=r(i=n.WeakMap)&&i,o=i&&new i;t.exports=o}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../lang/isNative":98}],86:[function(e,t){var n={};t.exports=n},{}],87:[function(e,t){function n(e,t){for(var n=e.length,a=o(t.length,n),s=r(e);a--;){var l=t[a];e[a]=i(l,n)?s[l]:void 0}return e}var r=e("./arrayCopy"),i=e("./isIndex"),o=Math.min;t.exports=n},{"./arrayCopy":29,"./isIndex":79}],88:[function(e,t){function n(e,t){for(var n=-1,i=e.length,o=-1,a=[];++n<i;)e[n]===t&&(e[n]=r,a[++o]=n);return a}var r="__lodash_placeholder__";t.exports=n},{}],89:[function(e,t){var n=e("./baseSetData"),r=e("../date/now"),i=150,o=16,a=function(){var e=0,t=0;return function(a,s){var l=r(),u=o-(l-t);if(t=l,u>0){if(++e>=i)return a}else e=0;return n(a,s)}}();t.exports=a},{"../date/now":24,"./baseSetData":52}],90:[function(e,t){function n(e){var t;if(!a(e)||p.call(e)!=l||o(e)||!c.call(e,"constructor")&&(t=e.constructor,"function"==typeof t&&!(t instanceof t))||!s.argsTag&&i(e))return!1;var n;return s.ownLast?(r(e,function(e,t,r){return n=c.call(r,t),!1}),n!==!1):(r(e,function(e,t){n=t}),"undefined"==typeof n||c.call(e,n))}var r=e("./baseForIn"),i=e("../lang/isArguments"),o=e("./isHostObject"),a=e("./isObjectLike"),s=e("../support"),l="[object Object]",u=Object.prototype,c=u.hasOwnProperty,p=u.toString;t.exports=n},{"../lang/isArguments":95,"../support":107,"./baseForIn":40,"./isHostObject":78,"./isObjectLike":82}],91:[function(e,t){function n(e){for(var t=l(e),n=t.length,c=n&&e.length,h=c&&a(c)&&(i(e)||u.nonEnumStrings&&s(e)||u.nonEnumArgs&&r(e)),f=-1,d=[];++f<n;){var m=t[f];(h&&o(m,c)||p.call(e,m))&&d.push(m)}return d}var r=e("../lang/isArguments"),i=e("../lang/isArray"),o=e("./isIndex"),a=e("./isLength"),s=e("../lang/isString"),l=e("../object/keysIn"),u=e("../support"),c=Object.prototype,p=c.hasOwnProperty;t.exports=n},{"../lang/isArguments":95,"../lang/isArray":96,"../lang/isString":101,"../object/keysIn":105,"../support":107,"./isIndex":79,"./isLength":81}],92:[function(e,t){function n(e){if(o.unindexedChars&&i(e)){for(var t=-1,n=e.length,a=Object(e);++t<n;)a[t]=e.charAt(t);return a}return r(e)?e:Object(e)}var r=e("../lang/isObject"),i=e("../lang/isString"),o=e("../support");t.exports=n},{"../lang/isObject":99,"../lang/isString":101,"../support":107}],93:[function(e,t){function n(e){return e instanceof r?e.clone():new i(e.__wrapped__,e.__chain__,o(e.__actions__))}var r=e("./LazyWrapper"),i=e("./LodashWrapper"),o=e("./arrayCopy");t.exports=n},{"./LazyWrapper":27,"./LodashWrapper":28,"./arrayCopy":29}],94:[function(e,t){function n(e,t,n){return t="function"==typeof t&&i(t,n,1),r(e,!0,t)}var r=e("../internal/baseClone"),i=e("../internal/bindCallback");t.exports=n},{"../internal/baseClone":33,"../internal/bindCallback":56}],95:[function(e,t){function n(e){var t=i(e)?e.length:void 0;return r(t)&&u.call(e)==a}var r=e("../internal/isLength"),i=e("../internal/isObjectLike"),o=e("../support"),a="[object Arguments]",s=Object.prototype,l=s.hasOwnProperty,u=s.toString,c=s.propertyIsEnumerable;o.argsTag||(n=function(e){var t=i(e)?e.length:void 0;return r(t)&&l.call(e,"callee")&&!c.call(e,"callee")}),t.exports=n},{"../internal/isLength":81,"../internal/isObjectLike":82,"../support":107}],96:[function(e,t){var n=e("../internal/isLength"),r=e("./isNative"),i=e("../internal/isObjectLike"),o="[object Array]",a=Object.prototype,s=a.toString,l=r(l=Array.isArray)&&l,u=l||function(e){return i(e)&&n(e.length)&&s.call(e)==o};t.exports=u},{"../internal/isLength":81,"../internal/isObjectLike":82,"./isNative":98}],97:[function(e,t){(function(n){var r=e("../internal/baseIsFunction"),i=e("./isNative"),o="[object Function]",a=Object.prototype,s=a.toString,l=i(l=n.Uint8Array)&&l,u=r(/x/)||l&&!r(l)?function(e){return s.call(e)==o}:r;t.exports=u}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../internal/baseIsFunction":45,"./isNative":98}],98:[function(e,t){function n(e){return null==e?!1:c.call(e)==a?p.test(u.call(e)):o(e)&&(i(e)?p:s).test(e)}var r=e("../string/escapeRegExp"),i=e("../internal/isHostObject"),o=e("../internal/isObjectLike"),a="[object Function]",s=/^\[object .+?Constructor\]$/,l=Object.prototype,u=Function.prototype.toString,c=l.toString,p=RegExp("^"+r(c).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=n},{"../internal/isHostObject":78,"../internal/isObjectLike":82,"../string/escapeRegExp":106}],99:[function(e,t){function n(e){var t=typeof e;return"function"==t||!!e&&"object"==t}t.exports=n},{}],100:[function(e,t){var n=e("./isArguments"),r=e("./isNative"),i=e("../internal/shimIsPlainObject"),o=e("../support"),a="[object Object]",s=Object.prototype,l=s.toString,u=r(u=Object.getPrototypeOf)&&u,c=u?function(e){if(!e||l.call(e)!=a||!o.argsTag&&n(e))return!1;var t=e.valueOf,s=r(t)&&(s=u(t))&&u(s);return s?e==s||u(e)==s:i(e)}:i;t.exports=c},{"../internal/shimIsPlainObject":90,"../support":107,"./isArguments":95,"./isNative":98}],101:[function(e,t){function n(e){return"string"==typeof e||r(e)&&a.call(e)==i}var r=e("../internal/isObjectLike"),i="[object String]",o=Object.prototype,a=o.toString;t.exports=n},{"../internal/isObjectLike":82}],102:[function(e,t){function n(e){return i(e)&&r(e.length)&&!!_[k.call(e)]}var r=e("../internal/isLength"),i=e("../internal/isObjectLike"),o="[object Arguments]",a="[object Array]",s="[object Boolean]",l="[object Date]",u="[object Error]",c="[object Function]",p="[object Map]",h="[object Number]",f="[object Object]",d="[object RegExp]",m="[object Set]",g="[object String]",y="[object WeakMap]",v="[object ArrayBuffer]",b="[object Float32Array]",w="[object Float64Array]",x="[object Int8Array]",A="[object Int16Array]",E="[object Int32Array]",j="[object Uint8Array]",C="[object Uint8ClampedArray]",T="[object Uint16Array]",S="[object Uint32Array]",_={};_[b]=_[w]=_[x]=_[A]=_[E]=_[j]=_[C]=_[T]=_[S]=!0,_[o]=_[a]=_[v]=_[s]=_[l]=_[u]=_[c]=_[p]=_[h]=_[f]=_[d]=_[m]=_[g]=_[y]=!1;var O=Object.prototype,k=O.toString;t.exports=n},{"../internal/isLength":81,"../internal/isObjectLike":82}],103:[function(e,t){function n(e){return"undefined"==typeof e}t.exports=n},{}],104:[function(e,t){var n=e("../internal/isLength"),r=e("../lang/isNative"),i=e("../lang/isObject"),o=e("../internal/shimKeys"),a=e("../support"),s=r(s=Object.keys)&&s,l=s?function(e){if(e)var t=e.constructor,r=e.length;return"function"==typeof t&&t.prototype===e||("function"==typeof e?a.enumPrototypes:r&&n(r))?o(e):i(e)?s(e):[]}:o;t.exports=l},{"../internal/isLength":81,"../internal/shimKeys":91,"../lang/isNative":98,"../lang/isObject":99,"../support":107}],105:[function(e,t){function n(e){if(null==e)return[];u(e)||(e=Object(e));var t=e.length;t=t&&l(t)&&(o(e)||p.nonEnumStrings&&c(e)||p.nonEnumArgs&&i(e))&&t||0;for(var n=e.constructor,r=-1,h=a(n)&&n.prototype||E,f=h===e,d=Array(t),g=t>0,y=p.enumErrorProps&&(e===A||e instanceof Error),b=p.enumPrototypes&&a(e);++r<t;)d[r]=r+"";for(var _ in e)b&&"prototype"==_||y&&("message"==_||"name"==_)||g&&s(_,t)||"constructor"==_&&(f||!C.call(e,_))||d.push(_);if(p.nonEnumShadows&&e!==E){var O=e===j?w:e===A?m:T.call(e),k=S[O]||S[v];for(O==v&&(h=E),t=x.length;t--;){_=x[t];var $=k[_];f&&$||($?!C.call(e,_):e[_]===h[_])||d.push(_)}}return d}var r=e("../internal/arrayEach"),i=e("../lang/isArguments"),o=e("../lang/isArray"),a=e("../lang/isFunction"),s=e("../internal/isIndex"),l=e("../internal/isLength"),u=e("../lang/isObject"),c=e("../lang/isString"),p=e("../support"),h="[object Array]",f="[object Boolean]",d="[object Date]",m="[object Error]",g="[object Function]",y="[object Number]",v="[object Object]",b="[object RegExp]",w="[object String]",x=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],A=Error.prototype,E=Object.prototype,j=String.prototype,C=E.hasOwnProperty,T=E.toString,S={};S[h]=S[d]=S[y]={constructor:!0,toLocaleString:!0,toString:!0,valueOf:!0},S[f]=S[w]={constructor:!0,toString:!0,valueOf:!0},S[m]=S[g]=S[b]={constructor:!0,toString:!0},S[v]={constructor:!0},r(x,function(e){for(var t in S)if(C.call(S,t)){var n=S[t];n[e]=C.call(n,e)}}),t.exports=n},{"../internal/arrayEach":30,"../internal/isIndex":79,"../internal/isLength":81,"../lang/isArguments":95,"../lang/isArray":96,"../lang/isFunction":97,"../lang/isObject":99,"../lang/isString":101,"../support":107}],106:[function(e,t){function n(e){return e=r(e),e&&o.test(e)?e.replace(i,"\\$&"):e}var r=e("../internal/baseToString"),i=/[.*+?^${}()|[\]\/\\]/g,o=RegExp(i.source);t.exports=n},{"../internal/baseToString":53}],107:[function(e,t){(function(e){var n="[object Arguments]",r="[object Object]",i=Array.prototype,o=Error.prototype,a=Object.prototype,s=(s=e.window)&&s.document,l=a.toString,u=a.propertyIsEnumerable,c=i.splice,p={};!function(){var e=function(){this.x=1},t={0:1,length:1},i=[];e.prototype={valueOf:1,y:1};for(var a in new e)i.push(a);p.argsTag=l.call(arguments)==n,p.enumErrorProps=u.call(o,"message")||u.call(o,"name"),p.enumPrototypes=u.call(e,"prototype"),p.funcDecomp=/\bthis\b/.test(function(){return this}),p.funcNames="string"==typeof Function.name,p.nodeTag=l.call(s)!=r,p.nonEnumStrings=!u.call("x",0),p.nonEnumShadows=!/valueOf/.test(i),p.ownLast="x"!=i[0],p.spliceObjects=(c.call(t,0,1),!t[0]),p.unindexedChars="x"[0]+Object("x")[0]!="xx";try{p.dom=11===s.createDocumentFragment().nodeType}catch(h){p.dom=!1}try{p.nonEnumArgs=!u.call(arguments,1)}catch(h){p.nonEnumArgs=!0}}(0,0),t.exports=p}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],108:[function(e,t){function n(e){return function(){return e}}t.exports=n},{}],109:[function(e,t){function n(e){return e}t.exports=n},{}],110:[function(e,t){function n(){}t.exports=n},{}],111:[function(e,t){function n(){}function r(e){var t={}.toString.call(e);switch(t){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function i(){if(g.XMLHttpRequest&&("file:"!=g.location.protocol||!g.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}return!1}function o(e){return e===Object(e)}function a(e){if(!o(e))return e;var t=[];for(var n in e)null!=e[n]&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.join("&")}function s(e){for(var t,n,r={},i=e.split("&"),o=0,a=i.length;a>o;++o)n=i[o],t=n.split("="),r[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return r}function l(e){var t,n,r,i,o=e.split(/\r?\n/),a={};o.pop();for(var s=0,l=o.length;l>s;++s)n=o[s],t=n.indexOf(":"),r=n.slice(0,t).toLowerCase(),i=y(n.slice(t+1)),a[r]=i;return a}function u(e){return e.split(/ *; */).shift()}function c(e){return m(e.split(/ *; */),function(e,t){var n=t.split(/ *= */),r=n.shift(),i=n.shift();return r&&i&&(e[r]=i),e},{})}function p(e,t){t=t||{},this.req=e,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method?this.xhr.responseText:null,this.setStatusProperties(this.xhr.status),this.header=this.headers=l(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text):null}function h(e,t){var n=this;d.call(this),this._query=this._query||[],this.method=e,this.url=t,this.header={},this._header={},this.on("end",function(){var e=null,t=null;try{t=new p(n)}catch(r){e=new Error("Parser is unable to parse the response"),e.parse=!0,e.original=r}n.callback(e,t)})}function f(e,t){return"function"==typeof t?new h("GET",e).end(t):1==arguments.length?new h("GET",e):new h(e,t)}var d=e("emitter"),m=e("reduce"),g="undefined"==typeof window?this:window,y="".trim?function(e){return e.trim()}:function(e){return e.replace(/(^\s*|\s*$)/g,"")};f.serializeObject=a,f.parseString=s,f.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},f.serialize={"application/x-www-form-urlencoded":a,"application/json":JSON.stringify},f.parse={"application/x-www-form-urlencoded":s,"application/json":JSON.parse},p.prototype.get=function(e){return this.header[e.toLowerCase()]},p.prototype.setHeaderProperties=function(){var e=this.header["content-type"]||"";this.type=u(e);var t=c(e);for(var n in t)this[n]=t[n]},p.prototype.parseBody=function(e){var t=f.parse[this.type];return t&&e&&e.length?t(e):null},p.prototype.setStatusProperties=function(e){var t=e/100|0;this.status=e,this.statusType=t,this.info=1==t,this.ok=2==t,this.clientError=4==t,this.serverError=5==t,this.error=4==t||5==t?this.toError():!1,this.accepted=202==e,this.noContent=204==e||1223==e,this.badRequest=400==e,this.unauthorized=401==e,this.notAcceptable=406==e,this.notFound=404==e,this.forbidden=403==e},p.prototype.toError=function(){var e=this.req,t=e.method,n=e.url,r="cannot "+t+" "+n+" ("+this.status+")",i=new Error(r);return i.status=this.status,i.method=t,i.url=n,i},f.Response=p,d(h.prototype),h.prototype.use=function(e){return e(this),this},h.prototype.timeout=function(e){return this._timeout=e,this},h.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},h.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},h.prototype.set=function(e,t){if(o(e)){for(var n in e)this.set(n,e[n]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},h.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},h.prototype.getHeader=function(e){return this._header[e.toLowerCase()]},h.prototype.type=function(e){return this.set("Content-Type",f.types[e]||e),this},h.prototype.accept=function(e){return this.set("Accept",f.types[e]||e),this},h.prototype.auth=function(e,t){var n=btoa(e+":"+t);return this.set("Authorization","Basic "+n),this},h.prototype.query=function(e){return"string"!=typeof e&&(e=a(e)),e&&this._query.push(e),this},h.prototype.field=function(e,t){return this._formData||(this._formData=new FormData),this._formData.append(e,t),this},h.prototype.attach=function(e,t,n){return this._formData||(this._formData=new FormData),this._formData.append(e,t,n),this},h.prototype.send=function(e){var t=o(e),n=this.getHeader("Content-Type");if(t&&o(this._data))for(var r in e)this._data[r]=e[r];else"string"==typeof e?(n||this.type("form"),n=this.getHeader("Content-Type"),this._data="application/x-www-form-urlencoded"==n?this._data?this._data+"&"+e:e:(this._data||"")+e):this._data=e;return t?(n||this.type("json"),this):this},h.prototype.callback=function(e,t){var n=this._callback;return this.clearTimeout(),2==n.length?n(e,t):e?this.emit("error",e):void n(t)},h.prototype.crossDomainError=function(){var e=new Error("Origin is not allowed by Access-Control-Allow-Origin");e.crossDomain=!0,this.callback(e)},h.prototype.timeoutError=function(){var e=this._timeout,t=new Error("timeout of "+e+"ms exceeded");t.timeout=e,this.callback(t)},h.prototype.withCredentials=function(){return this._withCredentials=!0,this},h.prototype.end=function(e){var t=this,o=this.xhr=i(),a=this._query.join("&"),s=this._timeout,l=this._formData||this._data;if(this._callback=e||n,o.onreadystatechange=function(){return 4==o.readyState?0==o.status?t.aborted?t.timeoutError():t.crossDomainError():void t.emit("end"):void 0},o.upload&&(o.upload.onprogress=function(e){e.percent=e.loaded/e.total*100,t.emit("progress",e)}),s&&!this._timer&&(this._timer=setTimeout(function(){t.abort()},s)),a&&(a=f.serializeObject(a),this.url+=~this.url.indexOf("?")?"&"+a:"?"+a),o.open(this.method,this.url,!0),this._withCredentials&&(o.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof l&&!r(l)){var u=f.serialize[this.getHeader("Content-Type")];u&&(l=u(l))}for(var c in this.header)null!=this.header[c]&&o.setRequestHeader(c,this.header[c]);return this.emit("request",this),o.send(l),this},f.Request=h,f.get=function(e,t,n){var r=f("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},f.head=function(e,t,n){var r=f("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},f.del=function(e,t){var n=f("DELETE",e);return t&&n.end(t),n},f.patch=function(e,t,n){var r=f("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},f.post=function(e,t,n){var r=f("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},f.put=function(e,t,n){var r=f("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},t.exports=f},{emitter:112,reduce:113}],112:[function(e,t){function n(e){return e?r(e):void 0}function r(e){for(var t in n.prototype)e[t]=n.prototype[t];return e}t.exports=n,n.prototype.on=n.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks[e]=this._callbacks[e]||[]).push(t),this},n.prototype.once=function(e,t){function n(){r.off(e,n),t.apply(this,arguments)}var r=this;return this._callbacks=this._callbacks||{},n.fn=t,this.on(e,n),this},n.prototype.off=n.prototype.removeListener=n.prototype.removeAllListeners=n.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n=this._callbacks[e];if(!n)return this;if(1==arguments.length)return delete this._callbacks[e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return this},n.prototype.emit=function(e){this._callbacks=this._callbacks||{};var t=[].slice.call(arguments,1),n=this._callbacks[e];if(n){n=n.slice(0);for(var r=0,i=n.length;i>r;++r)n[r].apply(this,t)}return this},n.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks[e]||[]},n.prototype.hasListeners=function(e){return!!this.listeners(e).length}},{}],113:[function(e,t){t.exports=function(e,t,n){for(var r=0,i=e.length,o=3==arguments.length?n:e[r++];i>r;)o=t.call(null,o,e[r],++r,e);return o}},{}]},{},[1])(1)}),window.SwaggerUi=Backbone.Router.extend({dom_id:"swagger_ui",options:null,api:null,headerView:null,mainView:null,initialize:function(e){e=e||{},e.dom_id&&(this.dom_id=e.dom_id,delete e.dom_id),e.supportedSubmitMethods||(e.supportedSubmitMethods=["get","put","post","delete","head","options","patch"]),"string"==typeof e.oauth2RedirectUrl&&(window.oAuthRedirectUrl=e.redirectUrl),$("#"+this.dom_id).length||$("body").append('<div id="'+this.dom_id+'"></div>'),this.options=e,marked.setOptions({gfm:!0});
+var t=this;this.options.success=function(){return t.render()},this.options.progress=function(e){return t.showMessage(e)},this.options.failure=function(e){return t.onLoadFailure(e)},this.headerView=new SwaggerUi.Views.HeaderView({el:$("#header")}),this.headerView.on("update-swagger-ui",function(e){return t.updateSwaggerUi(e)})},setOption:function(e,t){this.options[e]=t},getOption:function(e){return this.options[e]},updateSwaggerUi:function(e){this.options.url=e.url,this.load()},load:function(){this.mainView&&this.mainView.clear();var e=this.options.url;e&&0!==e.indexOf("http")&&(e=this.buildUrl(window.location.href.toString(),e)),this.options.url=e,this.headerView.update(e),this.api=new SwaggerClient(this.options)},collapseAll:function(){Docs.collapseEndpointListForResource("")},listAll:function(){Docs.collapseOperationsForResource("")},expandAll:function(){Docs.expandOperationsForResource("")},render:function(){switch(this.showMessage("Finished Loading Resource Information. Rendering Swagger UI..."),this.mainView=new SwaggerUi.Views.MainView({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options,router:this}).render(),this.showMessage(),this.options.docExpansion){case"full":this.expandAll();break;case"list":this.listAll()}this.renderGFM(),this.options.onComplete&&this.options.onComplete(this.api,this),setTimeout(Docs.shebang.bind(this),100)},buildUrl:function(e,t){if(0===t.indexOf("/")){var n=e.split("/");return e=n[0]+"//"+n[2],e+t}var r=e.length;return e.indexOf("?")>-1&&(r=Math.min(r,e.indexOf("?"))),e.indexOf("#")>-1&&(r=Math.min(r,e.indexOf("#"))),e=e.substring(0,r),-1!==e.indexOf("/",e.length-1)?e+t:e+"/"+t},showMessage:function(e){void 0===e&&(e=""),$("#message-bar").removeClass("message-fail"),$("#message-bar").addClass("message-success"),$("#message-bar").html(e)},onLoadFailure:function(e){void 0===e&&(e=""),$("#message-bar").removeClass("message-success"),$("#message-bar").addClass("message-fail");var t=$("#message-bar").html(e);return this.options.onFailure&&this.options.onFailure(e),t},renderGFM:function(){$(".markdown").each(function(){$(this).html(marked($(this).html()))})}}),window.SwaggerUi.Views={},function(){function e(e){"console"in window&&"function"==typeof window.console.warn&&console.warn(e)}window.authorizations={add:function(){if(e("Using window.authorizations is deprecated. Please use SwaggerUi.api.clientAuthorizations.add()."),"undefined"==typeof window.swaggerUi)throw new TypeError("window.swaggerUi is not defined");window.swaggerUi instanceof SwaggerUi&&window.swaggerUi.api.clientAuthorizations.add.apply(window.swaggerUi.api.clientAuthorizations,arguments)}},window.ApiKeyAuthorization=function(){e("window.ApiKeyAuthorization is deprecated. Please use SwaggerClient.ApiKeyAuthorization."),SwaggerClient.ApiKeyAuthorization.apply(window,arguments)},window.PasswordAuthorization=function(){e("window.PasswordAuthorization is deprecated. Please use SwaggerClient.PasswordAuthorization."),SwaggerClient.PasswordAuthorization.apply(window,arguments)}}(),function(e,t){"function"==typeof define&&define.amd?define(["b"],function(n){return e.SwaggerUi=t(n)}):"object"==typeof exports?module.exports=t(require("b")):e.SwaggerUi=t(e.b)}(this,function(){return SwaggerUi}),SwaggerUi.Views.ApiKeyButton=Backbone.View.extend({events:{"click #apikey_button":"toggleApiKeyContainer","click #apply_api_key":"applyApiKey"},initialize:function(e){this.options=e||{},this.router=this.options.router},render:function(){var e=this.template();return $(this.el).html(e(this.model)),this},applyApiKey:function(){var e=new SwaggerClient.ApiKeyAuthorization(this.model.name,$("#input_apiKey_entry").val(),this.model["in"]);this.router.api.clientAuthorizations.add(this.model.name,e),this.router.load(),$("#apikey_container").show()},toggleApiKeyContainer:function(){if($("#apikey_container").length){var e=$("#apikey_container").first();e.is(":visible")?e.hide():($(".auth_container").hide(),e.show())}},template:function(){return Handlebars.templates.apikey_button_view}}),SwaggerUi.Views.BasicAuthButton=Backbone.View.extend({initialize:function(e){this.options=e||{},this.router=this.options.router},render:function(){var e=this.template();return $(this.el).html(e(this.model)),this},events:{"click #basic_auth_button":"togglePasswordContainer","click #apply_basic_auth":"applyPassword"},applyPassword:function(){var e=$(".input_username").val(),t=$(".input_password").val(),n=new SwaggerClient.PasswordAuthorization("basic",e,t);this.router.api.clientAuthorizations.add(this.model.type,n),this.router.load(),$("#basic_auth_container").hide()},togglePasswordContainer:function(){if($("#basic_auth_container").length){var e=$("#basic_auth_container").show();e.is(":visible")?e.slideUp():($(".auth_container").hide(),e.show())}},template:function(){return Handlebars.templates.basic_auth_button_view}}),SwaggerUi.Views.ContentTypeView=Backbone.View.extend({initialize:function(){},render:function(){return $(this.el).html(Handlebars.templates.content_type(this.model)),$("label[for=contentType]",$(this.el)).text("Response Content Type"),this}}),SwaggerUi.Views.HeaderView=Backbone.View.extend({events:{"click #show-pet-store-icon":"showPetStore","click #show-wordnik-dev-icon":"showWordnikDev","click #explore":"showCustom","keyup #input_baseUrl":"showCustomOnKeyup","keyup #input_apiKey":"showCustomOnKeyup"},initialize:function(){},showPetStore:function(){this.trigger("update-swagger-ui",{url:"http://petstore.swagger.io/v2/swagger.json"})},showWordnikDev:function(){this.trigger("update-swagger-ui",{url:"http://api.wordnik.com/v4/resources.json"})},showCustomOnKeyup:function(e){13===e.keyCode&&this.showCustom()},showCustom:function(e){e&&e.preventDefault(),this.trigger("update-swagger-ui",{url:$("#input_baseUrl").val(),apiKey:$("#input_apiKey").val()})},update:function(e,t,n){void 0===n&&(n=!1),$("#input_baseUrl").val(e),n&&this.trigger("update-swagger-ui",{url:e})}}),SwaggerUi.Views.MainView=Backbone.View.extend({apisSorter:{alpha:function(e,t){return e.name.localeCompare(t.name)}},operationsSorters:{alpha:function(e,t){return e.path.localeCompare(t.path)},method:function(e,t){return e.method.localeCompare(t.method)}},initialize:function(e){var t,n,r,i;if(e=e||{},this.router=e.router,e.swaggerOptions.apisSorter&&(t=e.swaggerOptions.apisSorter,n=_.isFunction(t)?t:this.apisSorter[t],_.isFunction(n)&&this.model.apisArray.sort(n)),e.swaggerOptions.operationsSorter&&(t=e.swaggerOptions.operationsSorter,n=_.isFunction(t)?t:this.operationsSorters[t],_.isFunction(n)))for(r in this.model.apisArray)this.model.apisArray[r].operationsArray.sort(n);this.model.auths=[];for(r in this.model.securityDefinitions)i=this.model.securityDefinitions[r],this.model.auths.push({name:r,type:i.type,value:i});"2.0"===this.model.swaggerVersion&&(this.model.validatorUrl="validatorUrl"in e.swaggerOptions?e.swaggerOptions.validatorUrl:this.model.url.indexOf("localhost")>0?null:"http://online.swagger.io/validator")},render:function(){if(this.model.securityDefinitions)for(var e in this.model.securityDefinitions){var t,n=this.model.securityDefinitions[e];"apiKey"===n.type&&0===$("#apikey_button").length&&(t=new SwaggerUi.Views.ApiKeyButton({model:n,router:this.router}).render().el,$(".auth_main_container").append(t)),"basicAuth"===n.type&&0===$("#basic_auth_button").length&&(t=new SwaggerUi.Views.BasicAuthButton({model:n,router:this.router}).render().el,$(".auth_main_container").append(t))}$(this.el).html(Handlebars.templates.main(this.model));for(var r={},i=0,o=0;o<this.model.apisArray.length;o++){for(var a=this.model.apisArray[o],s=a.name;"undefined"!=typeof r[s];)s=s+"_"+i,i+=1;a.id=s,r[s]=a,this.addResource(a,this.model.auths)}return $(".propWrap").hover(function(){$(".optionsWrapper",$(this)).show()},function(){$(".optionsWrapper",$(this)).hide()}),this},addResource:function(e,t){e.id=e.id.replace(/\s/g,"_");var n=new SwaggerUi.Views.ResourceView({model:e,router:this.router,tagName:"li",id:"resource_"+e.id,className:"resource",auths:t,swaggerOptions:this.options.swaggerOptions});$("#resources").append(n.render().el)},clear:function(){$(this.el).html("")}}),SwaggerUi.Views.OperationView=Backbone.View.extend({invocationUrl:null,events:{"submit .sandbox":"submitOperation","click .submit":"submitOperation","click .response_hider":"hideResponse","click .toggleOperation":"toggleOperationContent","mouseenter .api-ic":"mouseEnter","mouseout .api-ic":"mouseExit"},initialize:function(e){return e=e||{},this.router=e.router,this.auths=e.auths,this.parentId=this.model.parentId,this.nickname=this.model.nickname,this.model.encodedParentId=encodeURIComponent(this.parentId),this},mouseEnter:function(e){var t=$(this.el).find(".content"),n=e.pageX,r=e.pageY,i=$(window).scrollLeft(),o=$(window).scrollTop(),a=i+$(window).width(),s=o+$(window).height(),l=t.width(),u=t.height();n+l>a&&(n=a-l),i>n&&(n=i),r+u>s&&(r=s-u),o>r&&(r=o);var c={};c.top=r,c.left=n,t.css(c),$(e.currentTarget.parentNode).find("#api_information_panel").show()},mouseExit:function(e){$(e.currentTarget.parentNode).find("#api_information_panel").hide()},render:function(){var e,t,n,r,i,o,a,s,l,u,c,p,h,f,d,m,g,y,v,b,w,x,A,E,j,C,T,S,_,O,k,D,L,N,P,I,R,M;if(o=jQuery.inArray(this.model.method,this.model.supportedSubmitMethods())>=0,o||(this.model.isReadOnly=!0),this.model.description=this.model.description||this.model.notes,this.model.oauth=null,m=this.model.authorizations||this.model.security)if(Array.isArray(m))for(l=0,u=m.length;u>l;l++){n=m[l];for(s in n){t=n[s];for(e in this.auths)if(t=this.auths[e],"oauth2"===t.type){this.model.oauth={},this.model.oauth.scopes=[],A=t.value.scopes;for(a in A)R=A[a],D=n[s].indexOf(a),D>=0&&(y={scope:a,description:R},this.model.oauth.scopes.push(y))}}}else for(a in m)if(R=m[a],"oauth2"===a)for(null===this.model.oauth&&(this.model.oauth={}),void 0===this.model.oauth.scopes&&(this.model.oauth.scopes=[]),d=0,c=R.length;c>d;d++)y=R[d],this.model.oauth.scopes.push(y);if("undefined"!=typeof this.model.responses){this.model.responseMessages=[],E=this.model.responses;for(r in E)M=E[r],O=null,k=this.model.responses[r].schema,k&&k.$ref&&(O=k.$ref,0===O.indexOf("#/definitions/")&&(O=O.substring("#/definitions/".length))),this.model.responseMessages.push({code:r,message:M.description,responseModel:O})}if("undefined"==typeof this.model.responseMessages&&(this.model.responseMessages=[]),L=null,this.model.successResponse){P=this.model.successResponse;for(s in P)M=P[s],this.model.successCode=s,"object"==typeof M&&"function"==typeof M.createJSONSample&&(L={sampleJSON:JSON.stringify(M.createJSONSample(),void 0,2),isParam:!1,signature:M.getMockSignature()})}else this.model.responseClassSignature&&"string"!==this.model.responseClassSignature&&(L={sampleJSON:this.model.responseSampleJSON,isParam:!1,signature:this.model.responseClassSignature});for($(this.el).html(Handlebars.templates.operation(this.model)),L?(_=new SwaggerUi.Views.SignatureView({model:L,router:this.router,tagName:"div"}),$(".model-signature",$(this.el)).append(_.render().el)):(this.model.responseClassSignature="string",$(".model-signature",$(this.el)).html(this.model.type)),i={isParam:!1},i.consumes=this.model.consumes,i.produces=this.model.produces,j=this.model.parameters,g=0,p=j.length;p>g;g++)b=j[g],I=b.type||b.dataType||"","undefined"==typeof I&&(O=b.schema,O&&O.$ref&&(x=O.$ref,I=0===x.indexOf("#/definitions/")?x.substring("#/definitions/".length):x)),I&&"file"===I.toLowerCase()&&(i.consumes||(i.consumes="multipart/form-data")),b.type=I;for(S=new SwaggerUi.Views.ResponseContentTypeView({model:i,router:this.router}),$(".response-content-type",$(this.el)).append(S.render().el),C=this.model.parameters,v=0,h=C.length;h>v;v++)b=C[v],this.addParameter(b,i.consumes);for(T=this.model.responseMessages,w=0,f=T.length;f>w;w++)N=T[w],this.addStatusCode(N);return this},addParameter:function(e,t){e.consumes=t;var n=new SwaggerUi.Views.ParameterView({model:e,tagName:"tr",readOnly:this.model.isReadOnly});$(".operation-params",$(this.el)).append(n.render().el)},addStatusCode:function(e){var t=new SwaggerUi.Views.StatusCodeView({model:e,tagName:"tr",router:this.router});$(".operation-status",$(this.el)).append(t.render().el)},submitOperation:function(e){var t,n,r,i,o,a,s,l,u,c,p,h,f,d,m,g;if(null!==e&&e.preventDefault(),n=$(".sandbox",$(this.el)),t=!0,n.find("input.required").each(function(){$(this).removeClass("error"),""===jQuery.trim($(this).val())&&($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){$(e).focus()}}(this)}),t=!1)}),n.find("textarea.required").each(function(){$(this).removeClass("error"),""===jQuery.trim($(this).val())&&($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){return $(e).focus()}}(this)}),t=!1)}),t){for(u={},h={parent:this},r=!1,f=n.find("input"),i=0,o=f.length;o>i;i++)p=f[i],null!==p.value&&jQuery.trim(p.value).length>0&&(u[p.name]=p.value),"file"===p.type&&(u[p.name]=p.files[0],r=!0);for(d=n.find("textarea"),l=0,a=d.length;a>l;l++)p=d[l],null!==p.value&&jQuery.trim(p.value).length>0&&(u[p.name]=p.value);for(m=n.find("select"),c=0,s=m.length;s>c;c++)p=m[c],g=this.getSelectedValue(p),null!==g&&jQuery.trim(g).length>0&&(u[p.name]=g);return h.responseContentType=$("div select[name=responseContentType]",$(this.el)).val(),h.requestContentType=$("div select[name=parameterContentType]",$(this.el)).val(),$(".response_throbber",$(this.el)).show(),r?this.handleFileUpload(u,n):this.model["do"](u,h,this.showCompleteStatus,this.showErrorStatus,this)}},success:function(e,t){t.showCompleteStatus(e)},handleFileUpload:function(e,t){var n,r,i,o,a,s,l,u,c,p,h,f,d,m,g,y,v,b,w;for(y=t.serializeArray(),o=0,a=y.length;a>o;o++)h=y[o],null!==h.value&&jQuery.trim(h.value).length>0&&(e[h.name]=h.value);for(n=new FormData,g=0,v=this.model.parameters,c=0,s=v.length;s>c;c++)m=v[c],("form"===m.paramType||"formData"===m["in"])&&"file"!==m.type.toLowerCase()&&void 0!==e[m.name]&&n.append(m.name,e[m.name]);for(i={},b=this.model.parameters,p=0,l=b.length;l>p;p++)m=b[p],"header"===m.paramType&&(i[m.name]=e[m.name]);for(w=t.find('input[type~="file"]'),d=0,u=w.length;u>d;d++)r=w[d],"undefined"!=typeof r.files[0]&&(n.append($(r).attr("name"),r.files[0]),g+=1);return this.invocationUrl=this.model.supportHeaderParams()?(i=this.model.getHeaderParams(e),delete i["Content-Type"],this.model.urlify(e,!1)):this.model.urlify(e,!0),$(".request_url",$(this.el)).html("<pre></pre>"),$(".request_url pre",$(this.el)).text(this.invocationUrl),f={type:this.model.method,url:this.invocationUrl,headers:i,data:n,dataType:"json",contentType:!1,processData:!1,error:function(e){return function(t){return e.showErrorStatus(e.wrap(t),e)}}(this),success:function(e){return function(t){return e.showResponse(t,e)}}(this),complete:function(e){return function(t){return e.showCompleteStatus(e.wrap(t),e)}}(this)},window.authorizations&&window.authorizations.apply(f),jQuery.ajax(f),!1},wrap:function(e){var t,n,r,i,o,a,s;for(r={},n=e.getAllResponseHeaders().split("\r"),o=0,a=n.length;a>o;o++)i=n[o],t=i.match(/^([^:]*?):(.*)$/),t||(t=[]),t.shift(),void 0!==t[0]&&void 0!==t[1]&&(r[t[0].trim()]=t[1].trim());return s={},s.content={},s.content.data=e.responseText,s.headers=r,s.request={},s.request.url=this.invocationUrl,s.status=e.status,s},getSelectedValue:function(e){if(e.multiple){for(var t=[],n=0,r=e.options.length;r>n;n++){var i=e.options[n];i.selected&&t.push(i.value)}return t.length>0?t:null}return e.value},hideResponse:function(e){e&&e.preventDefault(),$(".response",$(this.el)).slideUp(),$(".response_hider",$(this.el)).fadeOut()},showResponse:function(e){var t=JSON.stringify(e,null," ").replace(/\n/g,"<br>");$(".response_body",$(this.el)).html(_.escape(t))},showErrorStatus:function(e,t){t.showStatus(e)},showCompleteStatus:function(e,t){t.showStatus(e)},formatXml:function(e){var t,n,r,i,o,a,s,l,u,c,p,h,f;for(p=/(>)(<)(\/*)/g,f=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(p,"$1\n$2$3").replace(f,"$1\n").replace(t,"$1\n$2"),c=0,r="",l=e.split("\n"),i=0,a="other",h={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},n=function(e){var t,n,o,s,l,u,c;u={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},l=function(){var e;e=[];for(o in u)c=u[o],c&&e.push(o);return e}()[0],l=void 0===l?"other":l,t=a+"->"+l,a=l,s="",i+=h[t],s=function(){var e,t,r;for(r=[],n=e=0,t=i;t>=0?t>e:e>t;n=t>=0?++e:--e)r.push(" ");return r}().join(""),"opening->closing"===t?r=r.substr(0,r.length-1)+e+"\n":r+=s+e+"\n"},o=0,s=l.length;s>o;o++)u=l[o],n(u);return r},showStatus:function(e){var t,n;void 0===e.content?(n=e.data,t=e.url):(n=e.content.data,t=e.request.url);var r=e.headers,i=null;r&&(i=r["Content-Type"]||r["content-type"],i&&(i=i.split(";")[0].trim())),$(".response_body",$(this.el)).removeClass("json"),$(".response_body",$(this.el)).removeClass("xml");var o,a,s=function(e){var t=document.createElement("audio");return!(!t.canPlayType||!t.canPlayType(e).replace(/no/,""))};if(n)if("application/json"===i||/\+json$/.test(i)){var l=null;try{l=JSON.stringify(JSON.parse(n),null," ")}catch(u){l="can't parse JSON. Raw result:\n\n"+n}a=$("<code />").text(l),o=$('<pre class="json" />').append(a)}else if("application/xml"===i||/\+xml$/.test(i))a=$("<code />").text(this.formatXml(n)),o=$('<pre class="xml" />').append(a);else if("text/html"===i)a=$("<code />").html(_.escape(n)),o=$('<pre class="xml" />').append(a);else if(/^image\//.test(i))o=$("<img>").attr("src",t);else if(/^audio\//.test(i)&&s(i))o=$("<audio controls>").append($("<source>").attr("src",t).attr("type",i));else if(r["Content-Disposition"].test(/attachment/)||r["content-disposition"].test(/attachment/)||r["Content-Description"].test(/File Transfer/)||r["content-description"].test(/File Transfer/))if("Blob"in window){var c=i||"text/html",p=new Blob([n],{type:c}),h=document.createElement("a"),f=window.URL.createObjectURL(p),d=e.url.substr(e.url.lastIndexOf("/")+1),m=[c,d,f].join(":");h.setAttribute("href",f),h.setAttribute("download",m),h.innerText="Download "+d,o=$("<div/>").append(h)}else o=$('<pre class="json" />').append("Download headers detected but your browser does not support downloading binary via XHR (Blob).");else r.location||r.Location?window.location=e.url:(a=$("<code />").text(n),o=$('<pre class="json" />').append(a));else a=$("<code />").text("no content"),o=$('<pre class="json" />').append(a);var g=o;$(".request_url",$(this.el)).html("<pre></pre>"),$(".request_url pre",$(this.el)).text(t),$(".response_code",$(this.el)).html("<pre>"+e.status+"</pre>"),$(".response_body",$(this.el)).html(g),$(".response_headers",$(this.el)).html("<pre>"+_.escape(JSON.stringify(e.headers,null," ")).replace(/\n/g,"<br>")+"</pre>"),$(".response",$(this.el)).slideDown(),$(".response_hider",$(this.el)).show(),$(".response_throbber",$(this.el)).hide();var y=$(".response_body",$(this.el))[0],v=this.options.swaggerOptions;return v.highlightSizeThreshold&&e.data.length>v.highlightSizeThreshold?y:hljs.highlightBlock(y)},toggleOperationContent:function(){var e=$("#"+Docs.escapeResourceName(this.parentId+"_"+this.nickname+"_content"));e.is(":visible")?Docs.collapseOperation(e):Docs.expandOperation(e)}}),SwaggerUi.Views.ParameterContentTypeView=Backbone.View.extend({initialize:function(){},render:function(){return $(this.el).html(Handlebars.templates.parameter_content_type(this.model)),$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:"),this}}),SwaggerUi.Views.ParameterView=Backbone.View.extend({initialize:function(){Handlebars.registerHelper("isArray",function(e,t){"array"===e.type.toLowerCase()||e.allowMultiple?t.fn(this):t.inverse(this)})},render:function(){var e=this.model.type||this.model.dataType;if("undefined"==typeof e){var t=this.model.schema;if(t&&t.$ref){var n=t.$ref;e=0===n.indexOf("#/definitions/")?n.substring("#/definitions/".length):n}}this.model.type=e,this.model.paramType=this.model["in"]||this.model.paramType,this.model.isBody="body"===this.model.paramType||"body"===this.model["in"],this.model.isFile=e&&"file"===e.toLowerCase(),this.model["default"]=this.model["default"]||this.model.defaultValue,this.model.allowableValues&&(this.model.isList=!0);var r=this.template();$(this.el).html(r(this.model));var i={sampleJSON:this.model.sampleJSON,isParam:!0,signature:this.model.signature};if(this.model.sampleJSON){var o=new SwaggerUi.Views.SignatureView({model:i,tagName:"div"});$(".model-signature",$(this.el)).append(o.render().el)}else $(".model-signature",$(this.el)).html(this.model.signature);var a=!1;this.model.isBody&&(a=!0);var s={isParam:a};if(s.consumes=this.model.consumes,a){var l=new SwaggerUi.Views.ParameterContentTypeView({model:s});$(".parameter-content-type",$(this.el)).append(l.render().el)}else{var u=new SwaggerUi.Views.ResponseContentTypeView({model:s});$(".response-content-type",$(this.el)).append(u.render().el)}return this},template:function(){return this.model.isList?Handlebars.templates.param_list:this.options.readOnly?this.model.required?Handlebars.templates.param_readonly_required:Handlebars.templates.param_readonly:this.model.required?Handlebars.templates.param_required:Handlebars.templates.param}}),SwaggerUi.Views.ResourceView=Backbone.View.extend({initialize:function(e){e=e||{},this.router=e.router,this.auths=e.auths,""===this.model.description&&(this.model.description=null),this.model.description&&(this.model.summary=this.model.description)},render:function(){var e={};$(this.el).html(Handlebars.templates.resource(this.model));for(var t=0;t<this.model.operationsArray.length;t++){for(var n=this.model.operationsArray[t],r=0,i=n.nickname;"undefined"!=typeof e[i];)i=i+"_"+r,r+=1;e[i]=n,n.nickname=i,n.parentId=this.model.id,this.addOperation(n)}return $(".toggleEndpointList",this.el).click(this.callDocs.bind(this,"toggleEndpointListForResource")),$(".collapseResource",this.el).click(this.callDocs.bind(this,"collapseOperationsForResource")),$(".expandResource",this.el).click(this.callDocs.bind(this,"expandOperationsForResource")),this},addOperation:function(e){e.number=this.number;var t=new SwaggerUi.Views.OperationView({model:e,router:this.router,tagName:"li",className:"endpoint",swaggerOptions:this.options.swaggerOptions,auths:this.auths});$(".endpoints",$(this.el)).append(t.render().el),this.number++},callDocs:function(e,t){t.preventDefault(),Docs[e](t.currentTarget.getAttribute("data-id"))}}),SwaggerUi.Views.ResponseContentTypeView=Backbone.View.extend({initialize:function(){},render:function(){return $(this.el).html(Handlebars.templates.response_content_type(this.model)),$("label[for=responseContentType]",$(this.el)).text("Response Content Type"),this}}),SwaggerUi.Views.SignatureView=Backbone.View.extend({events:{"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"},initialize:function(){},render:function(){return $(this.el).html(Handlebars.templates.signature(this.model)),this.switchToSnippet(),this.isParam=this.model.isParam,this.isParam&&$(".notice",$(this.el)).text("Click to set as parameter value"),this},switchToDescription:function(e){e&&e.preventDefault(),$(".snippet",$(this.el)).hide(),$(".description",$(this.el)).show(),$(".description-link",$(this.el)).addClass("selected"),$(".snippet-link",$(this.el)).removeClass("selected")},switchToSnippet:function(e){e&&e.preventDefault(),$(".description",$(this.el)).hide(),$(".snippet",$(this.el)).show(),$(".snippet-link",$(this.el)).addClass("selected"),$(".description-link",$(this.el)).removeClass("selected")},snippetToTextArea:function(e){if(this.isParam){e&&e.preventDefault();var t=$("textarea",$(this.el.parentNode.parentNode.parentNode));""===$.trim(t.val())&&t.val(this.model.sampleJSON)}}}),SwaggerUi.Views.StatusCodeView=Backbone.View.extend({initialize:function(e){this.options=e||{},this.router=this.options.router},render:function(){if($(this.el).html(Handlebars.templates.status_code(this.model)),this.router.api.models.hasOwnProperty(this.model.responseModel)){var e={sampleJSON:JSON.stringify(this.router.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:!1,signature:this.router.api.models[this.model.responseModel].getMockSignature()},t=new SwaggerUi.Views.SignatureView({model:e,tagName:"div"});$(".model-signature",this.$el).append(t.render().el)}else $(".model-signature",this.$el).html("");return this}})}).call(this);
diff --git a/catalog-be/src/main/webapp/META-INF/MANIFEST.MF b/catalog-be/src/main/webapp/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..b00130fad6
--- /dev/null
+++ b/catalog-be/src/main/webapp/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Implementation-Title: catalog-be
+Implementation-Version: APPLICATION_VERSION
+Implementation-Vendor-Id: org.openecomp.sdc
+Built-By: esofer
+Build-Jdk: 1.7.0_45
+Created-By: Apache Maven 3.2.1
+Archiver-Version: Plexus Archiver
+
diff --git a/catalog-be/src/main/webapp/WEB-INF/jetty-web.xml b/catalog-be/src/main/webapp/WEB-INF/jetty-web.xml
new file mode 100644
index 0000000000..2e287bcc90
--- /dev/null
+++ b/catalog-be/src/main/webapp/WEB-INF/jetty-web.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Configure PUBLIC
+ "-//Mort Bay Consulting//DTD Configure//EN"
+ "http://www.eclipse.org/jetty/configure_9_0.dtd">
+
+<Configure class="org.eclipse.jetty.webapp.WebAppContext">
+ <Set name="contextPath">/</Set>
+</Configure>
diff --git a/catalog-be/src/main/webapp/WEB-INF/web.xml b/catalog-be/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..814a58a4fe
--- /dev/null
+++ b/catalog-be/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>com.wordnik.swagger.jaxrs.json, org.openecomp.sdc.be.servlets</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>com.wordnik.swagger.jersey.listing.ApiListingResourceJSON;org.glassfish.jersey.media.multipart.MultiPartFeature,org.openecomp.sdc.be.filters.BeServletFilter, org.openecomp.sdc.be.filters.ComponentsAvailabilityFilter</param-value>
+ <!-- <param-value>com.wordnik.swagger.jersey.listing.ApiListingResourceJSON;org.glassfish.jersey.media.multipart.MultiPartFeature,org.openecomp.sdc.be.filters.BeServletFilter</param-value> -->
+ </init-param>
+
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>EsGateway</servlet-name>
+ <servlet-class>org.openecomp.sdc.be.monitoring.EsGateway</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>EsGateway</servlet-name>
+ <url-pattern>/sdc2/esGateway/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>jerseyDistribution</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.openecomp.sdc.be.distribution.servlet, org.openecomp.sdc.be.externalapi.servlet</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+<!-- <param-value>com.wordnik.swagger.jersey.listing.ApiListingResourceJSON;org.glassfish.jersey.media.multipart.MultiPartFeature,org.openecomp.sdc.be.filters.BeServletFilter,org.openecomp.sdc.be.filters.BasicAuthenticationFilter, org.openecomp.sdc.be.filters.ComponentsAvailabilityFilter</param-value> -->
+
+ <!-- Closed till the feature done and basic authentication defined with M Lando -->
+ <param-value>com.wordnik.swagger.jersey.listing.ApiListingResourceJSON;org.glassfish.jersey.media.multipart.MultiPartFeature,org.openecomp.sdc.be.filters.BeServletFilter,org.openecomp.sdc.be.filters.BasicAuthenticationFilter</param-value>
+ </init-param>
+
+ <load-on-startup>1</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jerseyDistribution</servlet-name>
+ <url-pattern>/asdc/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>Jersey2Config</servlet-name>
+ <servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
+ <init-param>
+ <param-name>api.version</param-name>
+ <param-value>1.0.0</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.api.basepath</param-name>
+ <param-value>http://behost:8080/sdc2/rest</param-value>
+ </init-param>
+
+ <load-on-startup>2</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <!-- ECOMP Portal -->
+ <servlet>
+ <servlet-name>ViewStatusMessages</servlet-name>
+ <servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ViewStatusMessages</servlet-name>
+ <url-pattern>/lbClassicStatus</url-pattern>
+ </servlet-mapping>
+
+ <filter>
+ <filter-name>GzipFilter</filter-name>
+ <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
+ <async-supported>true</async-supported>
+ <init-param>
+ <param-name>methods</param-name>
+ <param-value>GET,POST</param-value>
+ </init-param>
+ <init-param>
+ <param-name>mimeTypes</param-name>
+ <param-value>text/html,text/plain,text/css,application/javascript,application/json</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>GzipFilter</filter-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ </filter-mapping>
+
+
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath:application-context.xml</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>org.openecomp.sdc.be.listen.BEAppContextListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+
+
+
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+</web-app>
diff --git a/catalog-be/src/main/webapp/index.html b/catalog-be/src/main/webapp/index.html
new file mode 100644
index 0000000000..4b26987758
--- /dev/null
+++ b/catalog-be/src/main/webapp/index.html
@@ -0,0 +1,7 @@
+<html>
+
+<body>
+ <h1>Hello Catalog Server</h1>
+</body>
+
+</html> \ No newline at end of file
diff --git a/catalog-be/src/main/webapp/index.jsp b/catalog-be/src/main/webapp/index.jsp
new file mode 100644
index 0000000000..c38169bb95
--- /dev/null
+++ b/catalog-be/src/main/webapp/index.jsp
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/AuditingMockManager.java b/catalog-be/src/test/java/org/openecomp/sdc/AuditingMockManager.java
new file mode 100644
index 0000000000..272f0d6a1d
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/AuditingMockManager.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc;
+
+import java.util.EnumMap;
+
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditingMockManager implements IAuditingManager {
+
+ private static Logger log = LoggerFactory.getLogger(AuditingMockManager.class.getName());
+
+ public AuditingMockManager(String string) {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void auditEvent(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
+ AuditingActionEnum actionEnum = AuditingActionEnum.getActionByName((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_ACTION));
+ log.debug("call was made to auditEvent with event type {}", actionEnum.getName());
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java
new file mode 100644
index 0000000000..28b60559aa
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java
@@ -0,0 +1,266 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.Category;
+import org.openecomp.sdc.be.model.PropertyScope;
+import org.openecomp.sdc.be.model.Tag;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.CategoryData;
+
+import fj.data.Either;
+
+public class ElementOperationMock implements IElementOperation {
+
+ CategoryDefinition resourceCategory;
+ CategoryDefinition serviceCategory;
+ CategoryDefinition productCategory;
+
+ Category oldService;
+
+ public ElementOperationMock() {
+ resourceCategory = new CategoryDefinition();
+ resourceCategory.setName("Network Layer 2-3");
+ SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition();
+ subCategoryDefinition.setName("Router");
+ SubCategoryDefinition subCategoryDefinition1 = new SubCategoryDefinition();
+ subCategoryDefinition1.setName("Gateway");
+
+ resourceCategory.addSubCategory(subCategoryDefinition);
+ resourceCategory.addSubCategory(subCategoryDefinition1);
+
+ serviceCategory = new CategoryDefinition();
+ serviceCategory.setName("Mobility");
+ oldService = new Category();
+ oldService.setName("Mobility");
+
+ productCategory = new CategoryDefinition();
+ productCategory.setName("Network Layer 2-31");
+ SubCategoryDefinition subCategoryDefinition11 = new SubCategoryDefinition();
+ subCategoryDefinition11.setName("Router1");
+ GroupingDefinition group = new GroupingDefinition();
+ group.setName("group1");
+ subCategoryDefinition11.addGrouping(group);
+ productCategory.addSubCategory(subCategoryDefinition11);
+
+ }
+
+ @Override
+ public Either<List<CategoryDefinition>, ActionStatus> getAllResourceCategories() {
+
+ List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
+ categories.add(resourceCategory);
+ return Either.left(categories);
+
+ }
+
+ @Override
+ public Either<List<CategoryDefinition>, ActionStatus> getAllServiceCategories() {
+
+ List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
+ categories.add(serviceCategory);
+ return Either.left(categories);
+
+ }
+
+ /*
+ * @Override public Either<Category, ActionStatus> getCategory(String name) { if (name.equals(resourceCategory.getName())){ return Either.left(resourceCategory); } else { return Either.right(ActionStatus.CATEGORY_NOT_FOUND); } }
+ */
+
+ @Override
+ public Either<List<Tag>, ActionStatus> getAllTags() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<List<PropertyScope>, ActionStatus> getAllPropertyScopes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Map<String, Object>, ActionStatus> getAllDeploymentArtifactTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public <T extends GraphNode> Either<CategoryData, StorageOperationStatus> getCategoryData(String name, NodeTypeEnum type, Class<T> clazz) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Integer, ActionStatus> getDefaultHeatTimeout() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> deleteCategory(NodeTypeEnum nodeType, String categoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Boolean, ActionStatus> isCategoryUniqueForType(NodeTypeEnum nodeType, String normalizedName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction) {
+
+ List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
+ switch (nodeType) {
+ case ResourceNewCategory:
+ categories.add(resourceCategory);
+ break;
+ case ProductCategory:
+ categories.add(productCategory);
+ break;
+ case ServiceNewCategory:
+ categories.add(serviceCategory);
+ break;
+ default:
+ break;
+ }
+ return Either.left(categories);
+ }
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> getSubCategoryUniqueForType(NodeTypeEnum nodeType, String normalizedName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Boolean, ActionStatus> isSubCategoryUniqueForCategory(NodeTypeEnum nodeType, String subCategoryNormName, String parentCategoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> deleteSubCategory(NodeTypeEnum nodeType, String subCategoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<GroupingDefinition, ActionStatus> createGrouping(String subCategoryId, GroupingDefinition grouping, NodeTypeEnum nodeType) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<GroupingDefinition, ActionStatus> deleteGrouping(NodeTypeEnum nodeType, String groupingId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> getSubCategory(NodeTypeEnum nodeType, String subCategoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Boolean, ActionStatus> isGroupingUniqueForSubCategory(NodeTypeEnum nodeType, String groupingNormName, String parentSubCategoryId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<GroupingDefinition, ActionStatus> getGroupingUniqueForType(NodeTypeEnum nodeType, String groupingNormalizedName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<Map<String, String>, ActionStatus> getResourceTypesMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public <T extends GraphNode> Either<org.openecomp.sdc.be.resources.data.category.CategoryData, StorageOperationStatus> getNewCategoryData(String name, NodeTypeEnum type, Class<T> clazz) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<List<CategoryDefinition>, ActionStatus> getAllProductCategories() {
+ List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
+ categories.add(productCategory);
+ return Either.left(categories);
+ }
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ErrorConfigurationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/ErrorConfigurationTest.java
new file mode 100644
index 0000000000..5b86b9cc69
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/ErrorConfigurationTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.config.ErrorConfiguration;
+import org.openecomp.sdc.be.config.ErrorInfo;
+import org.openecomp.sdc.common.api.BasicConfiguration;
+import org.openecomp.sdc.common.api.ConfigurationListener;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.FileChangeCallback;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ErrorConfigurationTest {
+ ConfigurationSource configurationSource = null;
+ private static Logger log = LoggerFactory.getLogger(ErrorConfigurationTest.class.getName());
+
+ @Before
+ public void setup() {
+
+ ExternalConfiguration.setAppName("catalog-be");
+ ExternalConfiguration.setConfigDir("src/test/resources/config");
+ ExternalConfiguration.listenForChanges();
+
+ configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), ExternalConfiguration.getConfigDir() + File.separator + ExternalConfiguration.getAppName());
+
+ }
+
+ @Test
+ public void testReadConfigurationFile() {
+
+ ConfigurationListener configurationListener = new ConfigurationListener(ErrorConfiguration.class, new FileChangeCallback() {
+
+ public void reconfigure(BasicConfiguration obj) {
+ // TODO Auto-generated method stub
+ log.debug("In reconfigure of {}", obj);
+ }
+
+ });
+
+ ErrorConfiguration testConfiguration = configurationSource.getAndWatchConfiguration(ErrorConfiguration.class, configurationListener);
+
+ assertTrue(testConfiguration != null);
+ ErrorInfo errorInfo = testConfiguration.getErrorInfo("USER_NOT_FOUND");
+ assertTrue(errorInfo != null);
+ log.debug("{}", testConfiguration);
+ log.debug("{}", errorInfo);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/TestExternalConfiguration.java b/catalog-be/src/test/java/org/openecomp/sdc/TestExternalConfiguration.java
new file mode 100644
index 0000000000..d19ae9c872
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/TestExternalConfiguration.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc;
+
+import java.io.IOException;
+
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.common.api.BasicConfiguration;
+import org.openecomp.sdc.common.api.ConfigurationListener;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.FileChangeCallback;
+import org.openecomp.sdc.common.impl.ConfigFileChangeListener;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+public class TestExternalConfiguration<T extends Object> {
+
+ public static void main(String[] args) throws IOException {
+
+ ExternalConfiguration.setAppName("catalog-server");
+ ExternalConfiguration.setConfigDir("C:\\Users\\esofer\\workspaceLuna\\catalog-server\\src\\test\\resources\\config");
+ ExternalConfiguration.listenForChanges();
+
+ ConfigurationListener configurationListener = new ConfigurationListener(Configuration.class, new FileChangeCallback() {
+
+ @Override
+ public void reconfigure(BasicConfiguration obj) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ ConfigurationSource configurationSource1 = new FSConfigurationSource(new ConfigFileChangeListener(), ExternalConfiguration.getConfigDir());
+ configurationSource1.getAndWatchConfiguration(Configuration.class, configurationListener);
+
+ try {
+ Thread.currentThread().sleep(100 * 1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ZipUtil.java b/catalog-be/src/test/java/org/openecomp/sdc/ZipUtil.java
new file mode 100644
index 0000000000..a651b77f9a
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/ZipUtil.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+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.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+
+public class ZipUtil {
+
+ public static void main(String[] args) {
+
+ String zipFileName = "/src/test/resources/config/config.zip";
+
+ zipFileName = "C:\\Git_work\\D2-SDnC\\catalog-be\\src\\test\\resources\\config\\config.zip";
+ zipFileName = "src/test/resources/config/config.zip";
+
+ Path path = Paths.get(zipFileName);
+
+ try {
+ byte[] zipAsBytes = Files.readAllBytes(path);
+ // encode to base
+
+ byte[] decodedMd5 = Base64.encodeBase64(zipAsBytes);
+ String decodedStr = new String(decodedMd5);
+
+ zipAsBytes = Base64.decodeBase64(decodedStr.getBytes());
+
+ // String str = new String(zipAsBytes);
+
+ // readZip(str.getBytes());
+ readZip(zipAsBytes);
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ private static Map<String, byte[]> readZip(byte[] zipAsBytes) {
+
+ Map<String, byte[]> fileNameToByteArray = new HashMap<String, byte[]>();
+
+ byte[] buffer = new byte[1024];
+ ZipInputStream zis = null;
+ try {
+
+ zis = new ZipInputStream(new ByteArrayInputStream(zipAsBytes));
+ // get the zipped file list entry
+ ZipEntry ze = zis.getNextEntry();
+
+ while (ze != null) {
+
+ String fileName = ze.getName();
+
+ if (false == ze.isDirectory()) {
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ try {
+ int len;
+ while ((len = zis.read(buffer)) > 0) {
+ os.write(buffer, 0, len);
+ }
+
+ // aClass.outputStreamMethod(os);
+ String aString = new String(os.toByteArray(), "UTF-8");
+
+ fileNameToByteArray.put(fileName, os.toByteArray());
+
+ } finally {
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+ ze = zis.getNextEntry();
+
+ }
+
+ zis.closeEntry();
+ zis.close();
+
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ return null;
+ } finally {
+ if (zis != null) {
+ try {
+ zis.closeEntry();
+ zis.close();
+ } catch (IOException e) {
+ // TODO: add log
+ }
+
+ }
+ }
+
+ return fileNameToByteArray;
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/AuditingManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/AuditingManagerTest.java
new file mode 100644
index 0000000000..dff0e3c729
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/AuditingManagerTest.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import static org.mockito.Mockito.when;
+
+import java.util.EnumMap;
+import java.util.UUID;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+
+public class AuditingManagerTest extends BaseConfDependentTest{
+
+ @InjectMocks
+ private AuditingManager auditingManager = Mockito.spy(AuditingManager.class);
+ public static final AuditingDao auditingDao = Mockito.mock(AuditingDao.class);
+
+ public AuditingManagerTest() {
+ }
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ when(auditingDao.addRecord(Mockito.anyMap(), Mockito.anyString())).thenReturn(ActionStatus.OK);
+
+ }
+
+ @Test
+ public void testNormalizeEmptyStringValuesAndUuid() {
+ EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<>(AuditingFieldsKeysEnum.class);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, "Create");
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DESC, null);
+ auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, " null ");
+
+ String randomUUID = UUID.randomUUID().toString();
+ ThreadLocalsHolder.setUuid(randomUUID);
+
+ auditingManager.auditEvent(auditingFields);
+ // Checking normalization
+ Assert.assertEquals(auditingFields.get(AuditingFieldsKeysEnum.AUDIT_DESC), Constants.EMPTY_STRING);
+ Assert.assertEquals(auditingFields.get(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT), Constants.EMPTY_STRING);
+ Assert.assertEquals(auditingFields.get(AuditingFieldsKeysEnum.AUDIT_REQUEST_ID), randomUUID);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseConfDependentTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseConfDependentTest.java
new file mode 100644
index 0000000000..ad5471e852
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseConfDependentTest.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import java.io.File;
+
+import org.junit.BeforeClass;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+public class BaseConfDependentTest {
+ protected static ConfigurationManager configurationManager;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+
+ ExternalConfiguration.setAppName("catalog-be");
+ ExternalConfiguration.setConfigDir("src/test/resources/config");
+ ExternalConfiguration.listenForChanges();
+
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), ExternalConfiguration.getConfigDir() + File.separator + ExternalConfiguration.getAppName());
+
+ configurationManager = new ConfigurationManager(configurationSource);
+
+ configurationManager.getConfiguration().setTitanInMemoryGraph(true);
+
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ComponentBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ComponentBusinessLogicTest.java
new file mode 100644
index 0000000000..8f3234bc39
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ComponentBusinessLogicTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class ComponentBusinessLogicTest {
+ ComponentBusinessLogic businessLogic = new ComponentBusinessLogic() {
+
+ @Override
+ public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ComponentInstanceBusinessLogic getComponentInstanceBL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+ @Test
+ public void testGetRequirementsAndCapabilities() {
+ // businessLogic.getRequirementsAndCapabilities(componentId,
+ // componentTypeEnum);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java
new file mode 100644
index 0000000000..6af338ebcf
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/HealthCheckBusinessLogicTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.HealthCheckBusinessLogic;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class HealthCheckBusinessLogicTest {
+
+ HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
+
+ @Test
+ public void checkStausUpdated() {
+
+ boolean statusChanged = healthCheckBusinessLogic.anyStatusChanged(null, null);
+ assertFalse("check false", statusChanged);
+
+ List<HealthCheckInfo> checkInfosLeft = new ArrayList<HealthCheckInfo>();
+ List<HealthCheckInfo> checkInfosRight = new ArrayList<HealthCheckInfo>();
+
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertFalse("check false", statusChanged);
+
+ HealthCheckInfo checkInfoTitanUp = new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.UP, null, null);
+ HealthCheckInfo checkInfoTitanDown = new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, null);
+
+ HealthCheckInfo checkInfoEsUp = new HealthCheckInfo(HealthCheckComponent.ES, HealthCheckStatus.UP, null, null);
+ HealthCheckInfo checkInfoEsDown = new HealthCheckInfo(HealthCheckComponent.ES, HealthCheckStatus.DOWN, null, null);
+
+ /*
+ * HealthCheckInfo checkInfoUebUp = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.UP, null, null); HealthCheckInfo checkInfoUebDown = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, null);
+ */
+
+ checkInfosLeft.add(checkInfoTitanUp);
+ checkInfosLeft.add(checkInfoEsUp);
+
+ checkInfosRight.add(checkInfoTitanUp);
+ checkInfosRight.add(checkInfoEsUp);
+
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertFalse("check false", statusChanged);
+
+ checkInfosRight.remove(checkInfoTitanUp);
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertTrue("check true", statusChanged);
+
+ checkInfosRight.add(checkInfoTitanDown);
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertTrue("check true", statusChanged);
+
+ checkInfosRight.remove(checkInfoTitanDown);
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertTrue("check true", statusChanged);
+
+ checkInfosRight.add(checkInfoTitanUp);
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
+ assertFalse("check false", statusChanged);
+
+ statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, null);
+ assertTrue("check true", statusChanged);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
new file mode 100644
index 0000000000..aea29a6419
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.junit.Before;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+import junit.framework.Assert;
+
+public class PropertyBusinessLogicTest {
+
+ private static Logger log = LoggerFactory.getLogger(PropertyBusinessLogicTest.class.getName());
+ final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
+ final IResourceOperation resourceOperation = Mockito.mock(IResourceOperation.class);
+ WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ PropertyBusinessLogic bl = new PropertyBusinessLogic();
+ User user = null;
+ Resource resourceResponse = null;
+ ResourceBusinessLogic blResource = new ResourceBusinessLogic();
+ PropertyBusinessLogic spy = null;
+ String resourceId = "resourceforproperty.0.1";
+
+ public PropertyBusinessLogicTest() {
+
+ }
+
+ @Before
+ public void setup() {
+
+ ExternalConfiguration.setAppName("catalog-be");
+
+ // Init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ Either<User, ActionStatus> eitherGetUser = Either.left(user);
+ when(mockUserAdmin.getUser("jh003", false)).thenReturn(eitherGetUser);
+
+ // Servlet Context attributes
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(servletContext.getAttribute(Constants.RESOURCE_OPERATION_MANAGER)).thenReturn(resourceOperation);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
+
+ // Resource Operation mock methods
+ // getCount
+ Either<Integer, StorageOperationStatus> eitherCount = Either.left(0);
+ when(resourceOperation.getNumberOfResourcesByName("MyResourceName".toLowerCase())).thenReturn(eitherCount);
+ Either<Integer, StorageOperationStatus> eitherCountExist = Either.left(1);
+ when(resourceOperation.getNumberOfResourcesByName("alreadyExist".toLowerCase())).thenReturn(eitherCountExist);
+ Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
+ when(resourceOperation.getNumberOfResourcesByName("Root".toLowerCase())).thenReturn(eitherCountRoot);
+
+ Either<Resource, StorageOperationStatus> eitherGetResource = Either.left(createResourceObject(true));
+ when(resourceOperation.getResource(resourceId)).thenReturn(eitherGetResource);
+
+ // // createResource
+ // resourceResponse = createResourceObject(true);
+ // Either<Resource, StorageOperationStatus> eitherCreate =
+ // Either.left(resourceResponse);
+ // when(resourceOperation.createResource(Mockito.any(Resource.class))).thenReturn(eitherCreate);
+
+ // BL object
+ // bl = PropertyBusinessLogic.getInstance(servletContext);
+ // PropertyBusinessLogic spy = PowerMockito.spy(bl);
+ // when(spy, method(PropertyBusinessLogic.class, "getResource",
+ // String.class)).withArguments(resource).thenReturn(true);
+
+ }
+
+ private Resource createResourceObject(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName("MyResourceName");
+ resource.addCategory("Generic", "VoIP");
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("yavivi");
+ resource.setIcon("MyIcon.jpg");
+
+ if (afterCreate) {
+ resource.setName(resource.getName().toLowerCase());
+ resource.setVersion("0.1");
+ ;
+ resource.setUniqueId(resourceId);
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug(gson.toJson(resource));
+ return resource;
+ }
+
+ // @Test
+ public void testHappyScenario() {
+
+ String propertyName = "disk_size";
+ PropertyDefinition newPropertyDefinition = createPropertyObject(propertyName, resourceId);
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> either = bl.createProperty(resourceId, propertyName, newPropertyDefinition, user.getUserId());
+
+ if (either.isRight()) {
+ Assert.assertFalse(true);
+ }
+ Assert.assertEquals(newPropertyDefinition, either.left().value());
+ }
+
+ private PropertyDefinition createPropertyObject(String propertyName, String resourceId) {
+ PropertyDefinition pd = new PropertyDefinition();
+ List<PropertyConstraint> constraints = new ArrayList<PropertyConstraint>();
+ pd.setConstraints(null);
+ pd.setDefaultValue("100");
+ pd.setDescription("Size of thasdasdasdasde local disk, in Gigabytes (GB), available to applications running on the Compute node");
+ pd.setPassword(false);
+ pd.setRequired(true);
+ pd.setType("Integer");
+ pd.setUniqueId(resourceId + "." + propertyName);
+ return pd;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
new file mode 100644
index 0000000000..eee5c4dd32
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -0,0 +1,369 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtilsTest;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.PolicyException;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+
+import fj.data.Either;
+
+public class ResourceImportManagerTest {
+
+ private static ConfigurationManager configurationManager;
+ static ResourceImportManager importManager;
+ static IAuditingManager auditingManager = Mockito.mock(IAuditingManager.class);
+ static ResponseFormatManager responseFormatManager = Mockito.mock(ResponseFormatManager.class);
+ static ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
+ static ResourceOperation resourceOperation = Mockito.mock(ResourceOperation.class);
+ static UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
+ static Logger log = Mockito.spy(Logger.class);
+
+ @BeforeClass
+ public static void beforeClass() throws IOException {
+ importManager = new ResourceImportManager();
+ importManager.setAuditingManager(auditingManager);
+ when(resourceOperation.getLatestByToscaResourceName(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(Either.left(null));
+ importManager.setResponseFormatManager(responseFormatManager);
+ importManager.setResourceBusinessLogic(resourceBusinessLogic);
+ importManager.setResourceOperation(resourceOperation);
+ ResourceImportManager.setLog(log);
+
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+
+ Configuration configuration = new Configuration();
+ configuration.setTitanInMemoryGraph(true);
+ configurationManager.setConfiguration(configuration);
+ }
+
+ @Before
+ public void beforeTest() {
+ Mockito.reset(auditingManager, responseFormatManager, resourceBusinessLogic, userAdmin, log);
+ }
+
+ @Test
+ public void testBasicResourceCreation() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ user.setRole("ADMIN");
+ user.setFirstName("Jhon");
+ user.setLastName("Doh");
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(eitherUser);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-blockStorage.yml");
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertTrue(createResource.isLeft());
+ Resource resource = createResource.left().value().left;
+
+ testSetConstantMetaData(resource);
+ testSetMetaDataFromJson(resource, resourceMD);
+
+ testSetDerivedFrom(resource);
+ testSetProperties(resource);
+
+ Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(Mockito.eq(user), Mockito.eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true));
+ }
+
+ @Test
+ public void testResourceCreationFailed() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(eitherUser);
+ ResponseFormat dummyResponseFormat = createGeneralErrorInfo();
+
+ when(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(dummyResponseFormat);
+ setResourceBusinessLogicMock();
+
+ String jsonContent = "this is an invalid yml!";
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertTrue(createResource.isRight());
+ ResponseFormat errorInfoFromTest = createResource.right().value();
+ assertTrue(errorInfoFromTest.getStatus().equals(dummyResponseFormat.getStatus()));
+ assertTrue(errorInfoFromTest.getMessageId().equals(dummyResponseFormat.getMessageId()));
+ assertTrue(errorInfoFromTest.getFormattedMessage().equals(dummyResponseFormat.getFormattedMessage()));
+ Mockito.verify(log).debug(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Exception.class));
+ // Mockito.verify(log).error(Mockito.anyString(), Mockito.anyString(),
+ // Mockito.anyString());
+
+ Mockito.verify(resourceBusinessLogic, Mockito.times(0)).createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.eq(user), Mockito.eq(true), Mockito.eq(false), Mockito.eq(true));
+
+ Mockito.verify(resourceBusinessLogic, Mockito.times(0)).propagateStateToCertified(Mockito.eq(user), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true));
+
+ }
+
+ @Test
+ public void testResourceCreationWithCapabilities() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(eitherUser);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertTrue(createResource.isLeft());
+ Resource resource = createResource.left().value().left;
+ testSetCapabilities(resource);
+
+ Mockito.verify(resourceBusinessLogic, Mockito.times(1)).propagateStateToCertified(Mockito.eq(user), Mockito.eq(resource), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true));
+ Mockito.verify(resourceBusinessLogic, Mockito.times(1)).createOrUpdateResourceByImport(resource, user, true, false, true);
+
+ }
+
+ @Test
+ public void testResourceCreationWithRequirments() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(eitherUser);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-port.yml");
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertTrue(createResource.isLeft());
+ testSetRequirments(createResource.left().value().left);
+
+ }
+
+ private void setResourceBusinessLogicMock() {
+ when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin);
+ when(resourceBusinessLogic.createOrUpdateResourceByImport(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean()))
+ .thenAnswer(new Answer<Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat>>() {
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ return Either.left(new ImmutablePair<Resource, ActionStatus>((Resource) args[0], ActionStatus.CREATED));
+
+ }
+ });
+ when(resourceBusinessLogic.propagateStateToCertified(Mockito.any(User.class), Mockito.any(Resource.class), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.eq(false), Mockito.eq(true)))
+ .thenAnswer(new Answer<Either<Resource, ResponseFormat>>() {
+ public Either<Resource, ResponseFormat> answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ return Either.left((Resource) args[1]);
+
+ }
+ });
+ when(resourceBusinessLogic.createResourceByDao(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), Mockito.anyBoolean())).thenAnswer(new Answer<Either<Resource, ResponseFormat>>() {
+ public Either<Resource, ResponseFormat> answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ return Either.left((Resource) args[0]);
+
+ }
+ });
+ when(resourceBusinessLogic.validateResourceBeforeCreate(Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(AuditingActionEnum.class), Mockito.eq(false))).thenAnswer(new Answer<Either<Resource, ResponseFormat>>() {
+ public Either<Resource, ResponseFormat> answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ return Either.left((Resource) args[0]);
+
+ }
+ });
+
+ Either<Boolean, ResponseFormat> either = Either.left(true);
+ when(resourceBusinessLogic.validatePropertiesDefaultValues(Mockito.any(Resource.class))).thenReturn(either);
+ }
+
+ public ResponseFormat createGeneralErrorInfo() {
+ ResponseFormat responseFormat = new ResponseFormat(500);
+ responseFormat.setPolicyException(new PolicyException("POL5000", "Error: Internal Server Error. Please try again later", null));
+ return responseFormat;
+ }
+
+ private UploadResourceInfo createDummyResourceMD() {
+ UploadResourceInfo resourceMD = new UploadResourceInfo();
+ resourceMD.setName("tosca.nodes.BlockStorage");
+ resourceMD.addSubCategory("Generic", "Infrastructure");
+ resourceMD.setContactId("ya107f");
+ resourceMD.setResourceIconPath("defaulticon");
+ resourceMD.setTags(Arrays.asList(new String[] { "BlockStorage" }));
+ resourceMD.setDescription("Represents a server-local block storage device (i.e., not shared) offering evenly sized blocks of data from which raw storage volumes can be created.");
+ return resourceMD;
+ }
+
+ private void testSetProperties(Resource resource) {
+ List<PropertyDefinition> propertiesList = resource.getProperties();
+
+ Map<String, PropertyDefinition> properties = new HashMap<String, PropertyDefinition>();
+ for (PropertyDefinition propertyDefinition : propertiesList) {
+ properties.put(propertyDefinition.getName(), propertyDefinition);
+ }
+
+ assertTrue(properties.size() == 3);
+ assertTrue(properties.containsKey("size"));
+ PropertyDefinition propertyDefinition = properties.get("size");
+ assertTrue(propertyDefinition.getType().equals("scalar-unit.size"));
+ assertTrue(propertyDefinition.getConstraints().size() == 1);
+ PropertyConstraint propertyConstraint = propertyDefinition.getConstraints().get(0);
+ assertTrue(propertyConstraint instanceof GreaterOrEqualConstraint);
+
+ assertTrue(properties.containsKey("volume_id"));
+ propertyDefinition = properties.get("volume_id");
+ assertTrue(propertyDefinition.getType().equals("string"));
+ assertTrue(propertyDefinition.isRequired() == false);
+
+ assertTrue(properties.containsKey("snapshot_id"));
+ propertyDefinition = properties.get("snapshot_id");
+ assertTrue(propertyDefinition.getType().equals("string"));
+ assertTrue(propertyDefinition.isRequired() == false);
+
+ }
+
+ private void testSetCapabilities(Resource resource) {
+ Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
+ assertTrue(capabilities.size() == 3);
+ assertTrue(capabilities.containsKey("tosca.capabilities.Endpoint"));
+ List<CapabilityDefinition> capabilityList = capabilities.get("tosca.capabilities.Endpoint");
+ CapabilityDefinition capability = capabilityList.get(0);
+ assertTrue(capability.getType().equals("tosca.capabilities.Endpoint"));
+ assertTrue(capability.getName().equals("data_endpoint"));
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.Endpoint.Admin"));
+ capabilityList = capabilities.get("tosca.capabilities.Endpoint.Admin");
+ capability = capabilityList.get(0);
+ assertTrue(capability.getType().equals("tosca.capabilities.Endpoint.Admin"));
+ assertTrue(capability.getName().equals("admin_endpoint"));
+
+ assertTrue(capabilities.containsKey("tosca.capabilities.Container"));
+ capabilityList = capabilities.get("tosca.capabilities.Container");
+ capability = capabilityList.get(0);
+ assertTrue(capability.getType().equals("tosca.capabilities.Container"));
+ assertTrue(capability.getName().equals("host"));
+
+ List<String> validSourceTypes = capability.getValidSourceTypes();
+ assertTrue(validSourceTypes.size() == 1);
+ assertTrue(validSourceTypes.get(0).equals("tosca.nodes.WebApplication"));
+
+ }
+
+ private void testSetRequirments(Resource resource) {
+ Map<String, List<RequirementDefinition>> requirements = resource.getRequirements();
+ assertTrue(requirements.size() == 2);
+
+ assertTrue(requirements.containsKey("tosca.capabilities.network.Linkable"));
+ List<RequirementDefinition> requirementList = requirements.get("tosca.capabilities.network.Linkable");
+ RequirementDefinition requirement = requirementList.get(0);
+ assertTrue(requirement.getCapability().equals("tosca.capabilities.network.Linkable"));
+ assertTrue(requirement.getRelationship().equals("tosca.relationships.network.LinksTo"));
+ assertTrue(requirement.getName().equals("link"));
+
+ assertTrue(requirements.containsKey("tosca.capabilities.network.Bindable"));
+ requirementList = requirements.get("tosca.capabilities.network.Bindable");
+ requirement = requirementList.get(0);
+ assertTrue(requirement.getCapability().equals("tosca.capabilities.network.Bindable"));
+ assertTrue(requirement.getRelationship().equals("tosca.relationships.network.BindsTo"));
+ assertTrue(requirement.getName().equals("binding"));
+
+ }
+
+ private void testSetDerivedFrom(Resource resource) {
+ assertTrue(resource.getDerivedFrom().size() == 1);
+ assertTrue(resource.getDerivedFrom().get(0).equals("tosca.nodes.Root"));
+
+ }
+
+ private void testSetMetaDataFromJson(Resource resource, UploadResourceInfo resourceMD) {
+
+ // assertTrue( resource.getCategory().equals(resourceMD.getCategory())
+ // );
+ assertTrue(resource.getDescription().equals(resourceMD.getDescription()));
+ assertTrue(resource.getIcon().equals(resourceMD.getResourceIconPath()));
+ assertTrue(resource.getName().equals(resourceMD.getName()));
+ assertTrue(resource.getContactId().equals(resourceMD.getContactId()));
+ assertTrue(resource.getCreatorUserId().equals(resourceMD.getContactId()));
+
+ // assertTrue( resource.isAbstract() ==
+ // Constants.ABSTRACT_CATEGORY.equals(resourceMD.getCategory()));
+
+ assertTrue(resourceMD.getTags().size() == resource.getTags().size());
+ for (String tag : resource.getTags()) {
+ assertTrue(resourceMD.getTags().contains(tag));
+ }
+
+ }
+
+ private void testSetConstantMetaData(Resource resource) {
+ assertTrue(resource.getVersion().equals(ImportUtils.Constants.FIRST_CERTIFIED_VERSION_VERSION));
+ assertTrue(resource.getLifecycleState() == ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE);
+ assertTrue(resource.isHighestVersion() == ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
+ assertTrue(resource.getVendorName().equals(ImportUtils.Constants.VENDOR_NAME));
+ assertTrue(resource.getVendorRelease().equals(ImportUtils.Constants.VENDOR_RELEASE));
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceTestUtils.java
new file mode 100644
index 0000000000..9a8f1c5ad8
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceTestUtils.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+
+public class ResourceTestUtils {
+
+ public static Resource prepareResource(int resourceIndex) {
+ Resource r = new Resource();
+ r.setName("resource_" + resourceIndex);
+ r.setDescription("description");
+ r.setVendorName("vendor name");
+ r.setVendorRelease("vendor release");
+ r.setContactId("as123y");
+ r.addCategory("Generic", "Infrastructure");
+ List<String> arr = new ArrayList<String>();
+ arr.add("tosca.nodes.Root");
+ r.setDerivedFrom(arr);
+ List<String> arr1 = new ArrayList<String>();
+ arr1.add(r.getName());
+ r.setTags(arr1);
+ r.setIcon("borderElement");
+ return r;
+ }
+
+ public static Resource prepareResource(int resourceIndex, ResourceTypeEnum resourceType) {
+ Resource r = new Resource();
+ r.setName("resource_" + resourceIndex);
+ r.setToscaResourceName("resource_" + resourceIndex);
+ r.setDescription("description");
+ r.setVendorName("vendor name");
+ r.setVendorRelease("vendor release");
+ r.setContactId("as123y");
+ r.setResourceType(resourceType);
+ r.addCategory("Generic", "Infrastructure");
+ List<String> arr = new ArrayList<String>();
+ arr.add("tosca.nodes.Root");
+ r.setDerivedFrom(arr);
+ List<String> arr1 = new ArrayList<String>();
+ arr1.add(r.getName());
+ r.setTags(arr1);
+ r.setIcon("borderElement");
+ return r;
+ }
+
+ public static Service prepareService(int serviceIndex) {
+ Service service = new Service();
+ service.setName("service_" + serviceIndex);
+ service.setDescription("desc");
+ service.setIcon("icon-service-red1");
+ List<String> tags = new ArrayList<String>();
+ tags.add(service.getName());
+ service.setTags(tags);
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName("Mobility");
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ service.setCategories(categories);
+ service.setContactId("as123y");
+ service.setProjectCode("123456");
+
+ return service;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceBusinessLogicTest.java
new file mode 100644
index 0000000000..fd83af016a
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceBusinessLogicTest.java
@@ -0,0 +1,931 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.ElementOperationMock;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
+import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class ServiceBusinessLogicTest {
+
+ private static Logger log = LoggerFactory.getLogger(ServiceBusinessLogicTest.class.getName());
+ private static final String SERVICE_CATEGORY = "Mobility";
+ final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ IAuditingManager iAuditingManager = null;
+ UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ final ServiceOperation serviceOperation = Mockito.mock(ServiceOperation.class);
+ WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ ServiceBusinessLogic bl = new ServiceBusinessLogic();
+ ResponseFormatManager responseManager = null;
+ IElementOperation mockElementDao;
+ AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
+ ComponentsUtils componentsUtils = new ComponentsUtils();
+ AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
+ ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
+ GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ TitanGenericDao mockTitanDao = Mockito.mock(TitanGenericDao.class);
+
+ CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
+
+ User user = null;
+ Service serviceResponse = null;
+ private static final String CERTIFIED_VERSION = "1.0";
+ private static final String UNCERTIFIED_VERSION = "0.2";
+ private static final String COMPONNET_ID = "myUniqueId";
+ private static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<AuditingFieldsKeysEnum, Object>();
+ private static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<AuditingFieldsKeysEnum, Object>();
+ private static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<AuditingFieldsKeysEnum, Object>();
+
+ public ServiceBusinessLogicTest() {
+
+ }
+
+ @Before
+ public void setup() {
+
+ ExternalConfiguration.setAppName("catalog-be");
+
+ // Init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+
+ // Elements
+ mockElementDao = new ElementOperationMock();
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh0003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ Either<User, ActionStatus> eitherGetUser = Either.left(user);
+ when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
+
+ // Servlet Context attributes
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ when(servletContext.getAttribute(Constants.SERVICE_OPERATION_MANAGER)).thenReturn(serviceOperation);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
+ when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
+ when(graphLockOperation.lockComponent(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Service))).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.lockComponentByName(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Service))).thenReturn(StorageOperationStatus.OK);
+
+ // artifact bussinesslogic
+ ArtifactDefinition artifactDef = new ArtifactDefinition();
+ when(artifactBl.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+
+ // createService
+ serviceResponse = createServiceObject(true);
+ Either<Service, StorageOperationStatus> eitherCreate = Either.left(serviceResponse);
+ when(serviceOperation.createService(Mockito.any(Service.class))).thenReturn(eitherCreate);
+ Either<Boolean, StorageOperationStatus> eitherCount = Either.left(true);
+ when(serviceOperation.validateServiceNameExists("Service")).thenReturn(eitherCount);
+ Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(false);
+ when(serviceOperation.validateServiceNameExists("alreadyExist")).thenReturn(eitherCountExist);
+
+ when(serviceOperation.validateComponentNameExists("alreadyExist")).thenReturn(eitherCountExist);
+ when(serviceOperation.validateComponentNameExists("Service")).thenReturn(eitherCount);
+
+ bl = new ServiceBusinessLogic();
+ bl.setElementDao(mockElementDao);
+ bl.setUserAdmin(mockUserAdmin);
+ bl.setServiceOperation(serviceOperation);
+ bl.setArtifactBl(artifactBl);
+ bl.setGraphLockOperation(graphLockOperation);
+ bl.setTitanGenericDao(mockTitanDao);
+
+ componentsUtils.Init();
+ componentsUtils.setAuditingManager(auditingManager);
+ bl.setComponentsUtils(componentsUtils);
+ bl.setCassandraAuditingDao(auditingDao);
+ bl.setCacheManagerOperation(cacheManager);
+
+ mockAuditingDaoLogic();
+
+ responseManager = ResponseFormatManager.getInstance();
+
+ }
+
+ @Test
+ public void testGetComponentAuditRecordsCertifiedVersion() {
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(CERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ assertTrue(componentAuditRecords.isLeft());
+ int size = componentAuditRecords.left().value().size();
+ assertTrue(size == 3);
+ }
+
+ @Test
+ public void testGetComponentAuditRecordsUnCertifiedVersion() {
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(UNCERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ assertTrue(componentAuditRecords.isLeft());
+ int size = componentAuditRecords.left().value().size();
+ assertTrue(size == 1);
+ }
+
+ @Test
+ public void testHappyScenario() {
+ Service service = createServiceObject(false);
+ Either<Service, ResponseFormat> createResponse = bl.createService(service, user);
+
+ if (createResponse.isRight()) {
+ assertEquals(new Integer(200), createResponse.right().value().getStatus());
+ }
+ assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
+ }
+
+ private void assertEqualsServiceObject(Service origService, Service newService) {
+ assertEquals(origService.getContactId(), newService.getContactId());
+ assertEquals(origService.getCategories(), newService.getCategories());
+ assertEquals(origService.getCreatorUserId(), newService.getCreatorUserId());
+ assertEquals(origService.getCreatorFullName(), newService.getCreatorFullName());
+ assertEquals(origService.getDescription(), newService.getDescription());
+ assertEquals(origService.getIcon(), newService.getIcon());
+ assertEquals(origService.getLastUpdaterUserId(), newService.getLastUpdaterUserId());
+ assertEquals(origService.getLastUpdaterFullName(), newService.getLastUpdaterFullName());
+ assertEquals(origService.getName(), newService.getName());
+ assertEquals(origService.getName(), newService.getName());
+ assertEquals(origService.getUniqueId(), newService.getUniqueId());
+ assertEquals(origService.getVersion(), newService.getVersion());
+ assertEquals(origService.getArtifacts(), newService.getArtifacts());
+ assertEquals(origService.getCreationDate(), newService.getCreationDate());
+ assertEquals(origService.getLastUpdateDate(), newService.getLastUpdateDate());
+ assertEquals(origService.getLifecycleState(), newService.getLifecycleState());
+ assertEquals(origService.getTags(), newService.getTags());
+ }
+
+ private void assertResponse(Either<Service, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
+ ResponseFormat actualResponse = createResponse.right().value();
+ assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
+ assertEquals("assert error description", expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
+ }
+
+ /* CREATE validations - start ***********************/
+ // Service name - start
+
+ @Test
+ public void testFailedServiceValidations() {
+ testServiceNameAlreadyExists();
+ testServiceNameEmpty();
+ // testServiceNameExceedsLimit();
+ testServiceNameWrongFormat();
+ testServiceDescriptionEmpty();
+ testServiceDescriptionMissing();
+ testServiceDescExceedsLimitCreate();
+ testServiceDescNotEnglish();
+ testServiceIconEmpty();
+ testServiceIconMissing();
+ testResourceIconInvalid();
+ testResourceIconExceedsLimit();
+ // testTagsExceedsLimitCreate();
+ // testTagsSingleExcessLimit();
+ testTagsNoServiceName();
+ testInvalidTag();
+ testServiceTagNotExist();
+ testServiceTagEmpty();
+ // 1610OS Support - Because of changes in the validation in the ui these tests will fail. need to fix them
+ //testContactIdTooLong();
+ //testContactIdWrongFormatCreate();
+ testResourceContactIdMissing();
+ testServiceCategoryExist();
+ testServiceBadCategoryCreate();
+ // 1610OS Support - Because of changes in the validation in the ui these tests will fail. need to fix them
+ //testInvalidProjectCode();
+ //testProjectCodeTooLong();
+ //testProjectCodeTooShort();
+ testMissingProjectCode();
+ }
+
+ private void testServiceNameAlreadyExists() {
+ String serviceName = "alreadyExist";
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ // 51 chars, the limit is 50
+ serviceExccedsNameLimit.setName(serviceName);
+ List<String> tgs = new ArrayList<String>();
+ tgs.add(serviceName);
+ serviceExccedsNameLimit.setTags(tgs);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.SERVICE.getValue(), serviceName);
+ }
+
+ private void testServiceNameEmpty() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ serviceExccedsNameLimit.setName(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testServiceNameExceedsLimit() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ // 51 chars, the limit is 50
+ String tooLongServiceName = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxdsafefegesse";
+ serviceExccedsNameLimit.setName(tooLongServiceName);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ }
+
+ private void testServiceNameWrongFormat() {
+ Service service = createServiceObject(false);
+ // contains :
+ String nameWrongFormat = "ljg\fd";
+ service.setName(nameWrongFormat);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(service, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ // Service name - end
+ // Service description - start
+ private void testServiceDescriptionEmpty() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setDescription("");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testServiceDescriptionMissing() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setDescription(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testServiceDescExceedsLimitCreate() {
+ Service serviceExccedsDescLimit = createServiceObject(false);
+ // 1025 chars, the limit is 1024
+ String tooLongServiceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+
+ serviceExccedsDescLimit.setDescription(tooLongServiceDesc);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsDescLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ }
+
+ private void testServiceDescNotEnglish() {
+ Service notEnglish = createServiceObject(false);
+ // Not english
+ String tooLongServiceDesc = "\uC2B5";
+ notEnglish.setDescription(tooLongServiceDesc);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(notEnglish, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ // Service description - stop
+ // Service icon - start
+ private void testServiceIconEmpty() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setIcon("");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testServiceIconMissing() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setIcon(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testResourceIconInvalid() {
+ Service resourceExist = createServiceObject(false);
+ resourceExist.setIcon("kjk3453^&");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(resourceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testResourceIconExceedsLimit() {
+ Service resourceExist = createServiceObject(false);
+ resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(resourceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ }
+
+ // Service icon - stop
+ // Service tags - start
+ private void testTagsExceedsLimitCreate() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
+ String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
+ String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
+ String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
+ String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
+ String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
+ String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
+ String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
+ String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
+ String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
+ String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
+ String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
+ String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
+ String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
+ String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
+ String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
+ String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
+
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ tagsList.add(tag3);
+ tagsList.add(tag4);
+ tagsList.add(tag5);
+ tagsList.add(tag6);
+ tagsList.add(tag7);
+ tagsList.add(tag8);
+ tagsList.add(tag9);
+ tagsList.add(tag10);
+ tagsList.add(tag11);
+ tagsList.add(tag12);
+ tagsList.add(tag13);
+ tagsList.add(tag14);
+ tagsList.add(tag15);
+ tagsList.add(tag16);
+ tagsList.add(tag17);
+ tagsList.add(tag18);
+ tagsList.add(tag19);
+ tagsList.add(tag20);
+ tagsList.add(tag21);
+ tagsList.add(serviceExccedsNameLimit.getName());
+
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+
+ }
+
+ private void testTagsSingleExcessLimit() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9a";
+ String tag2 = serviceExccedsNameLimit.getName();
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
+
+ }
+
+ private void testTagsNoServiceName() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ String tag1 = "afzs2qLBb";
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+
+ }
+
+ private void testInvalidTag() {
+ Service serviceExccedsNameLimit = createServiceObject(false);
+ String tag1 = "afzs2qLBb%#%";
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExccedsNameLimit, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Service", "tag" });
+
+ }
+
+ private void testServiceTagNotExist() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setTags(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+
+ private void testServiceTagEmpty() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setTags(new ArrayList<String>());
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+
+ // Service tags - stop
+ // Service contactId - start
+ private void testContactIdTooLong() {
+ Service serviceContactId = createServiceObject(false);
+ // 7 chars instead of 6
+ String contactIdTooLong = "yrt1234";
+ serviceContactId.setContactId(contactIdTooLong);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceContactId, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testContactIdWrongFormatCreate() {
+ Service serviceContactId = createServiceObject(false);
+ // 3 letters and 3 digits
+ String contactIdTooLong = "yrt134";
+ serviceContactId.setContactId(contactIdTooLong);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceContactId, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ private void testResourceContactIdMissing() {
+ Service resourceExist = createServiceObject(false);
+ resourceExist.setContactId(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(resourceExist, user);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ // Service contactId - stop
+ // Service category - start
+ private void testServiceCategoryExist() {
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setCategories(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ public void markDistributionAsDeployedTestAlreadyDeployed() {
+ String notifyAction = "DNotify";
+ String requestAction = "DRequest";
+ String resultAction = "DResult";
+ String did = "123456";
+
+ setupBeforeDeploy(notifyAction, requestAction, did);
+ List<DistributionDeployEvent> resultList = new ArrayList<DistributionDeployEvent>();
+ Map<String, Object> params = new HashMap<String, Object>();
+ DistributionDeployEvent event = new DistributionDeployEvent();
+
+ event.setAction(resultAction);
+ event.setDid(did);
+ event.setStatus("200");
+ // ESTimeBasedEvent deployEvent = new ESTimeBasedEvent();
+ // deployEvent.setFields(params);
+ resultList.add(event);
+ Either<List<DistributionDeployEvent>, ActionStatus> eventList = Either.left(resultList);
+
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq(resultAction), Mockito.anyString())).thenReturn(eventList);
+
+ Either<Service, ResponseFormat> markDeployed = bl.markDistributionAsDeployed(did, did, user);
+ assertTrue(markDeployed.isLeft());
+
+ Mockito.verify(auditingDao, Mockito.times(0)).getDistributionRequest(did, requestAction);
+
+ }
+
+ @Test
+ public void markDistributionAsDeployedTestSuccess() {
+ String notifyAction = "DNotify";
+ String requestAction = "DRequest";
+ String did = "123456";
+
+ setupBeforeDeploy(notifyAction, requestAction, did);
+
+ Either<Service, ResponseFormat> markDeployed = bl.markDistributionAsDeployed(did, did, user);
+ assertTrue(markDeployed.isLeft());
+
+ }
+
+ @Test
+ public void markDistributionAsDeployedTestNotDistributed() {
+ String notifyAction = "DNotify";
+ String requestAction = "DRequest";
+ String did = "123456";
+
+ setupBeforeDeploy(notifyAction, requestAction, did);
+ List<ResourceAdminEvent> emptyList = new ArrayList<ResourceAdminEvent>();
+ Either<List<ResourceAdminEvent>, ActionStatus> emptyEventList = Either.left(emptyList);
+ Mockito.when(auditingDao.getDistributionRequest(Mockito.anyString(), Mockito.eq(requestAction))).thenReturn(emptyEventList);
+
+ Either<Service, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND);
+ Mockito.when(serviceOperation.getService(did)).thenReturn(notFound);
+
+ Either<Service, ResponseFormat> markDeployed = bl.markDistributionAsDeployed(did, did, user);
+ assertTrue(markDeployed.isRight());
+ assertEquals(404, markDeployed.right().value().getStatus().intValue());
+
+ }
+
+ private void testServiceBadCategoryCreate() {
+
+ Service serviceExist = createServiceObject(false);
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName("koko");
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ serviceExist.setCategories(categories);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ }
+
+ // Service category - stop
+ private void testInvalidProjectCode() {
+
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setProjectCode("koko");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.INVALID_PROJECT_CODE);
+ }
+
+ private void testProjectCodeTooLong() {
+
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setProjectCode("5555555555555");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.INVALID_PROJECT_CODE);
+ }
+
+ private void testProjectCodeTooShort() {
+
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setProjectCode("555");
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.INVALID_PROJECT_CODE);
+ }
+
+ private void testMissingProjectCode() {
+
+ Service serviceExist = createServiceObject(false);
+ serviceExist.setProjectCode(null);
+
+ Either<Service, ResponseFormat> createResponse = bl.createService(serviceExist, user);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_PROJECT_CODE);
+ }
+
+ @Test
+ public void testDeleteMarkedServicesNoServices() {
+ List<String> ids = new ArrayList<String>();
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
+ when(serviceOperation.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ assertTrue(deleteMarkedResources.left().value().isEmpty());
+
+ Mockito.verify(artifactBl, Mockito.times(0)).deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList());
+
+ }
+
+ @Test
+ public void testDeleteMarkedServices() {
+ List<String> ids = new ArrayList<String>();
+ String resourceInUse = "123";
+ ids.add(resourceInUse);
+ String resourceFree = "456";
+ ids.add(resourceFree);
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
+ when(serviceOperation.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
+
+ Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
+ Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
+
+ List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
+ Either<List<ArtifactDefinition>, StorageOperationStatus> getArtifactsResponse = Either.left(artifacts);
+ when(serviceOperation.getComponentArtifactsForDelete(resourceFree, NodeTypeEnum.Service, true)).thenReturn(getArtifactsResponse);
+
+ when(serviceOperation.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
+ when(serviceOperation.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
+
+ Either<Component, StorageOperationStatus> eitherDelete = Either.left(new Resource());
+ when(serviceOperation.deleteComponent(resourceFree, true)).thenReturn(eitherDelete);
+
+ when(artifactBl.deleteAllComponentArtifactsIfNotOnGraph(artifacts)).thenReturn(StorageOperationStatus.OK);
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ List<String> resourceIdList = deleteMarkedResources.left().value();
+ assertFalse(resourceIdList.isEmpty());
+ assertTrue(resourceIdList.contains(resourceFree));
+ assertFalse(resourceIdList.contains(resourceInUse));
+
+ Mockito.verify(artifactBl, Mockito.times(1)).deleteAllComponentArtifactsIfNotOnGraph(artifacts);
+ }
+
+ private Service createServiceObject(boolean afterCreate) {
+ Service service = new Service();
+ service.setName("Service");
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName(SERVICE_CATEGORY);
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ service.setCategories(categories);
+
+ service.setDescription("description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add(service.getName());
+ service.setTags(tgs);
+ // service.setVendorName("Motorola");
+ // service.setVendorRelease("1.0.0");
+ // service.setContactId("ya5467");
+ service.setIcon("MyIcon");
+ // service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setContactId("aa1234");
+ service.setProjectCode("12345");
+
+ if (afterCreate) {
+ service.setVersion("0.1");
+ service.setUniqueId(service.getName() + ":" + service.getVersion());
+ service.setCreatorUserId(user.getUserId());
+ service.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug("{}", gson.toJson(service));
+ return service;
+ }
+
+ private void mockAuditingDaoLogic() {
+ FILTER_MAP_CERTIFIED_VERSION.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+ FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+ FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+
+ FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, UNCERTIFIED_VERSION);
+ FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, UNCERTIFIED_VERSION);
+
+ final ResourceAdminEvent createResourceAudit = new ResourceAdminEvent();
+ createResourceAudit.setModifier("Carlos Santana(cs0008)");
+ createResourceAudit.setCurrState("NOT_CERTIFIED_CHECKOUT");
+ createResourceAudit.setCurrVersion("0.1");
+ createResourceAudit.setServiceInstanceId("82eddd99-0bd9-4742-ab0a-1bdb5e262a05");
+ createResourceAudit.setRequestId("3e65cea1-7403-4bc7-b461-e2544d83799f");
+ createResourceAudit.setDesc("OK");
+ createResourceAudit.setResourceType("Resource");
+ createResourceAudit.setStatus("201");
+ createResourceAudit.setPrevVersion("");
+ createResourceAudit.setAction("Create");
+ // fields.put("TIMESTAMP", "2015-11-22 09:19:12.977");
+ createResourceAudit.setPrevState("");
+ createResourceAudit.setResourceName("MyTestResource");
+ // createResourceAudit.setFields(fields);
+
+ final ResourceAdminEvent checkInResourceAudit = new ResourceAdminEvent();
+ checkInResourceAudit.setModifier("Carlos Santana(cs0008)");
+ checkInResourceAudit.setCurrState("NOT_CERTIFIED_CHECKIN");
+ checkInResourceAudit.setCurrVersion("0.1");
+ checkInResourceAudit.setServiceInstanceId("82eddd99-0bd9-4742-ab0a-1bdb5e262a05");
+ checkInResourceAudit.setRequestId("ffacbf5d-eeb1-43c6-a310-37fe7e1cc091");
+ checkInResourceAudit.setDesc("OK");
+ checkInResourceAudit.setComment("Stam");
+ checkInResourceAudit.setResourceType("Resource");
+ checkInResourceAudit.setStatus("200");
+ checkInResourceAudit.setPrevVersion("0.1");
+ checkInResourceAudit.setAction("Checkin");
+ // fields.put("TIMESTAMP", "2015-11-22 09:25:03.797");
+ checkInResourceAudit.setPrevState("NOT_CERTIFIED_CHECKOUT");
+ checkInResourceAudit.setResourceName("MyTestResource");
+
+ final ResourceAdminEvent checkOutResourceAudit = new ResourceAdminEvent();
+ checkOutResourceAudit.setModifier("Carlos Santana(cs0008)");
+ checkOutResourceAudit.setCurrState("NOT_CERTIFIED_CHECKOUT");
+ checkOutResourceAudit.setCurrVersion("0.2");
+ checkOutResourceAudit.setServiceInstanceId("82eddd99-0bd9-4742-ab0a-1bdb5e262a05");
+ checkOutResourceAudit.setRequestId("7add5078-4c16-4d74-9691-cc150e3c96b8");
+ checkOutResourceAudit.setDesc("OK");
+ checkOutResourceAudit.setComment("");
+ checkOutResourceAudit.setResourceType("Resource");
+ checkOutResourceAudit.setStatus("200");
+ checkOutResourceAudit.setPrevVersion("0.1");
+ checkOutResourceAudit.setAction("Checkout");
+ // fields.put("TIMESTAMP", "2015-11-22 09:39:41.024");
+ checkOutResourceAudit.setPrevState("NOT_CERTIFIED_CHECKIN");
+ checkOutResourceAudit.setResourceName("MyTestResource");
+ // checkOutResourceAudit.setFields(fields);
+
+ // Mockito.doAnswer(new Answer<Either<List<ESTimeBasedEvent>,
+ // ActionStatus> >() {
+ // public Either<List<ESTimeBasedEvent>, ActionStatus>
+ // answer(InvocationOnMock invocation) {
+ // final Either<List<ESTimeBasedEvent>, ActionStatus> either;
+ // final List<ESTimeBasedEvent> list;
+ // Object[] args = invocation.getArguments();
+ // Map<AuditingFieldsKeysEnum, Object> filterMap =
+ // (Map<AuditingFieldsKeysEnum, Object>) args[0];
+ // if( filterMap.equals(FILTER_MAP_CERTIFIED_VERSION) ){
+ // list = new
+ // ArrayList<ESTimeBasedEvent>(){{add(createResourceAudit);add(checkInResourceAudit);add(checkOutResourceAudit);}};
+ // either = Either.left(list);
+ //
+ // }
+ // else if( filterMap.equals(FILTER_MAP_UNCERTIFIED_VERSION_PREV) ){
+ // list = new ArrayList<ESTimeBasedEvent>();
+ // either = Either.left(list);
+ // }
+ // else if( filterMap.equals(FILTER_MAP_UNCERTIFIED_VERSION_CURR) ){
+ // list = new
+ // ArrayList<ESTimeBasedEvent>(){{/*add(createResourceAudit);add(checkInResourceAudit);*/add(checkOutResourceAudit);}};
+ // either = Either.left(list);
+ // }
+ // else{
+ // either = null;
+ // }
+ // return either;
+ // }
+ // }).when(auditingDao).getFilteredResourceAdminAuditingEvents(Mockito.anyMap());
+ //
+ //
+ List<ResourceAdminEvent> list = new ArrayList<ResourceAdminEvent>() {
+ {
+ add(createResourceAudit);
+ add(checkInResourceAudit);
+ add(checkOutResourceAudit);
+ }
+ };
+ Either<List<ResourceAdminEvent>, ActionStatus> result = Either.left(list);
+ Mockito.when(auditingDao.getByServiceInstanceId(Mockito.anyString())).thenReturn(result);
+
+ List<ResourceAdminEvent> listPrev = new ArrayList<ResourceAdminEvent>();
+ Either<List<ResourceAdminEvent>, ActionStatus> resultPrev = Either.left(listPrev);
+ Mockito.when(auditingDao.getAuditByServiceIdAndPrevVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(resultPrev);
+
+ List<ResourceAdminEvent> listCurr = new ArrayList<ResourceAdminEvent>() {
+ {
+ add(checkOutResourceAudit);
+ }
+ };
+ Either<List<ResourceAdminEvent>, ActionStatus> resultCurr = Either.left(listCurr);
+ Mockito.when(auditingDao.getAuditByServiceIdAndCurrVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(resultCurr);
+
+ }
+
+ private void setupBeforeDeploy(String notifyAction, String requestAction, String did) {
+
+ DistributionNotificationEvent notifyEvent = new DistributionNotificationEvent();
+ notifyEvent.setAction(notifyAction);
+ notifyEvent.setDid(did);
+ notifyEvent.setStatus("200");
+
+ ResourceAdminEvent requestEvent = new ResourceAdminEvent();
+ requestEvent.setAction(requestAction);
+ requestEvent.setDid(did);
+ requestEvent.setStatus("200");
+
+ ArrayList<DistributionNotificationEvent> arrayList = new ArrayList<DistributionNotificationEvent>();
+ List<DistributionNotificationEvent> notifyResults = arrayList;
+ notifyResults.add(notifyEvent);
+ Either<List<DistributionNotificationEvent>, ActionStatus> eitherNotify = Either.left(notifyResults);
+
+ Mockito.when(auditingDao.getDistributionNotify(Mockito.anyString(), Mockito.eq(notifyAction))).thenReturn(eitherNotify);
+
+ List<ResourceAdminEvent> requestResults = new ArrayList<ResourceAdminEvent>();
+ requestResults.add(requestEvent);
+ Either<List<ResourceAdminEvent>, ActionStatus> eitherRequest = Either.left(requestResults);
+ Mockito.when(auditingDao.getDistributionRequest(Mockito.anyString(), Mockito.eq(requestAction))).thenReturn(eitherRequest);
+
+ Either<Service, StorageOperationStatus> eitherService = Either.left(createServiceObject(true));
+ Mockito.when(serviceOperation.getService(Mockito.anyString())).thenReturn(eitherService);
+
+ List<DistributionDeployEvent> emptyList = new ArrayList<DistributionDeployEvent>();
+ Either<List<DistributionDeployEvent>, ActionStatus> emptyEventList = Either.left(emptyList);
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq("DResult"), Mockito.anyString())).thenReturn(emptyEventList);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineConfigTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineConfigTest.java
new file mode 100644
index 0000000000..7ad93226c7
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineConfigTest.java
@@ -0,0 +1,168 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.ComponentArtifactTypesConfig;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.CreateTopicConfig;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionStatusTopicConfig;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+public class DistributionEngineConfigTest {
+
+ @Before
+ public void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+ ExternalConfiguration.setConfigDir("src/test/resources/config");
+ ExternalConfiguration.listenForChanges();
+
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), ExternalConfiguration.getConfigDir() + File.separator + ExternalConfiguration.getAppName());
+
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ }
+
+ @Test
+ public void validateMissingEnvironments() {
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+
+ String uebPublicKey = "uebPublicKey";
+ String uebSecretKey = "uebSecretKey";
+
+ DistributionEngine distributionEngine = new DistributionEngine();
+
+ List<String> environments = new ArrayList<String>();
+ environments.add("PROD");
+ deConfiguration.setEnvironments(environments);
+
+ List<String> servers = new ArrayList<String>();
+ servers.add("server1:80");
+ servers.add("server2:8080");
+
+ CreateTopicConfig createTopic = new CreateTopicConfig();
+ createTopic.setPartitionCount(1);
+ createTopic.setReplicationCount(1);
+ deConfiguration.setCreateTopic(createTopic);
+
+ ComponentArtifactTypesConfig distribNotifResourceArtifactTypes = new ComponentArtifactTypesConfig();
+ deConfiguration.setDistribNotifResourceArtifactTypes(distribNotifResourceArtifactTypes);
+
+ ComponentArtifactTypesConfig distribNotifServiceArtifactTypes = new ComponentArtifactTypesConfig();
+ deConfiguration.setDistribNotifServiceArtifactTypes(distribNotifServiceArtifactTypes);
+
+ deConfiguration.setDistributionNotifTopicName("distributionNotifTopicName");
+ deConfiguration.setDistributionStatusTopicName("statusTopic");
+
+ DistributionStatusTopicConfig distributionStatusTopic = new DistributionStatusTopicConfig();
+ distributionStatusTopic.setConsumerGroup("asdc-group");
+ distributionStatusTopic.setConsumerId("asdc-id");
+ distributionStatusTopic.setFetchTimeSec(20);
+ distributionStatusTopic.setPollingIntervalSec(20);
+ deConfiguration.setDistributionStatusTopic(distributionStatusTopic);
+
+ deConfiguration.setUebServers(servers);
+ deConfiguration.setUebPublicKey(uebPublicKey);
+ deConfiguration.setUebSecretKey(uebSecretKey);
+ deConfiguration.setInitMaxIntervalSec(8);
+ deConfiguration.setInitRetryIntervalSec(3);
+
+ boolean isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setUebServers(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setUebServers(servers);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setEnvironments(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setEnvironments(environments);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setUebPublicKey(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setUebPublicKey(uebPublicKey);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setUebSecretKey(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setUebSecretKey(uebPublicKey);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setDistributionNotifTopicName(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setDistributionNotifTopicName(uebPublicKey);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setDistributionStatusTopicName(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setDistributionStatusTopicName(uebPublicKey);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setInitMaxIntervalSec(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setInitMaxIntervalSec(8);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ deConfiguration.setInitRetryIntervalSec(null);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertFalse("check empty configuration", isValid);
+
+ deConfiguration.setInitRetryIntervalSec(8);
+ isValid = distributionEngine.validateConfiguration(deConfiguration);
+ assertTrue("check empty configuration", isValid);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineHealthCheckTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineHealthCheckTest.java
new file mode 100644
index 0000000000..b3a254f531
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineHealthCheckTest.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.components.BaseConfDependentTest;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaHandler;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
+import org.openecomp.sdc.be.components.distribution.engine.UebHealthCheckCall;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DistributionEngineHealthCheckTest extends BaseConfDependentTest {
+
+ @Mock
+ private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
+
+ DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
+
+ Gson gson = new Gson();
+
+ Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
+
+ //
+ // @Test
+ // public void validateDownWhenEnvAreDown() {
+ //
+ // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ // envNamePerStatus.put("PROD1", new AtomicBoolean(false));
+ // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
+ //
+ // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
+ //
+ // HealthCheckInfo healthCheckInfo =
+ // distributionEngineClusterHealth.getHealthCheckInfo();
+ // assertEquals("verify down", HealthCheckStatus.DOWN,
+ // healthCheckInfo.getHealthCheckStatus());
+ // assertEquals("verify DE component", HealthCheckComponent.DE,
+ // healthCheckInfo.getHealthCheckComponent());
+ //
+ // }
+
+ @Test
+ public void validateUpWhenQuerySucceed() {
+
+ // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ // envNamePerStatus.put("PROD1", new AtomicBoolean(true));
+ // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
+ //
+ // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus,
+ // false);
+
+ CambriaErrorResponse cambriaOkResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
+ CambriaErrorResponse cambriaNotErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, 403);
+
+ List<String> uebServers = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getUebServers();
+ if (uebServers.size() >= 2) {
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
+ }
+
+ UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
+ healthCheckCall1.setCambriaHandler(cambriaHandler);
+ Boolean call1 = healthCheckCall1.call();
+ assertTrue("check response okay", call1);
+
+ UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
+ healthCheckCall2.setCambriaHandler(cambriaHandler);
+
+ Boolean call2 = healthCheckCall2.call();
+ assertTrue("check response okay", call2);
+
+ if (uebServers.size() >= 2) {
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
+ }
+ healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
+ healthCheckCall1.setCambriaHandler(cambriaHandler);
+
+ call1 = healthCheckCall1.call();
+ assertFalse("check response okay", call1);
+
+ healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
+ healthCheckCall2.setCambriaHandler(cambriaHandler);
+
+ call2 = healthCheckCall2.call();
+ assertTrue("check response okay", call2);
+
+ if (uebServers.size() >= 2) {
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
+ when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaNotErrorResponse);
+ }
+ healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
+ healthCheckCall1.setCambriaHandler(cambriaHandler);
+
+ call1 = healthCheckCall1.call();
+ assertFalse("check response okay", call1);
+
+ healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
+ healthCheckCall2.setCambriaHandler(cambriaHandler);
+
+ call2 = healthCheckCall2.call();
+ assertTrue("check response okay", call2);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTaskTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTaskTest.java
new file mode 100644
index 0000000000..de7b84fa82
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineInitTaskTest.java
@@ -0,0 +1,269 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaHandler;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration.CreateTopicConfig;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+import fj.data.Either;
+
+public class DistributionEngineInitTaskTest {
+
+ @Mock
+ private ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+
+ @Mock
+ private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
+
+ // public static final IAuditingDao iAuditingDao =
+ // Mockito.mock(AuditingDao.class);
+
+ @Before
+ public void setup() {
+ // ExternalConfiguration.setAppName("distribEngine1");
+ ExternalConfiguration.setAppName("catalog-be");
+ ExternalConfiguration.setConfigDir("src/test/resources/config");
+ ExternalConfiguration.listenForChanges();
+
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), ExternalConfiguration.getConfigDir() + File.separator + ExternalConfiguration.getAppName());
+
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ }
+
+ @Test
+ public void checkIncrement() {
+
+ String envName = "PrOD";
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+ int retry = 2;
+ int maxRetry = 40;
+ deConfiguration.setInitRetryIntervalSec(retry);
+ deConfiguration.setInitMaxIntervalSec(maxRetry);
+ DistributionEngineInitTask initTask = new DistributionEngineInitTask(0l, deConfiguration, envName, new AtomicBoolean(false), componentsUtils, null);
+
+ for (int i = 1; i < 5; i++) {
+ initTask.incrementRetryInterval();
+ assertEquals("check next retry interval", initTask.getCurrentRetryInterval(), retry * (long) Math.pow(2, i));
+ }
+
+ initTask.incrementRetryInterval();
+ assertEquals("check next retry interval reach max retry interval", initTask.getCurrentRetryInterval(), maxRetry);
+
+ }
+
+ @Test
+ public void testInitFlowScenarioSuccess() {
+
+ String notifTopic = "notif";
+ String statusTopic = "status";
+
+ List<String> uebServers = new ArrayList<>();
+ uebServers.add("server1");
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.NOT_FOUND);
+ Either<Set<String>, CambriaErrorResponse> right = Either.right(cambriaErrorResponse);
+ when(cambriaHandler.getTopics(Mockito.any(List.class))).thenReturn(right);
+
+ String envName = "PrOD";
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+ deConfiguration.setUebServers(uebServers);
+ int retry = 2;
+ int maxRetry = 40;
+ deConfiguration.setInitRetryIntervalSec(retry);
+ deConfiguration.setInitMaxIntervalSec(maxRetry);
+ deConfiguration.setDistributionNotifTopicName(notifTopic);
+ deConfiguration.setDistributionStatusTopicName(statusTopic);
+ CreateTopicConfig createTopic = new CreateTopicConfig();
+ createTopic.setPartitionCount(1);
+ createTopic.setReplicationCount(1);
+ deConfiguration.setCreateTopic(createTopic);
+
+ cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK);
+
+ String realNotifTopic = notifTopic + "-" + envName.toUpperCase();
+ String realStatusTopic = statusTopic + "-" + envName.toUpperCase();
+ when(cambriaHandler.createTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(realNotifTopic), Mockito.eq(1), Mockito.eq(1))).thenReturn(cambriaErrorResponse);
+ when(cambriaHandler.createTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(realStatusTopic), Mockito.eq(1), Mockito.eq(1))).thenReturn(cambriaErrorResponse);
+
+ cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK);
+ when(cambriaHandler.registerToTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(SubscriberTypeEnum.class)))
+ .thenReturn(cambriaErrorResponse);
+
+ DistributionEngineInitTask initTask = new DistributionEngineInitTask(0l, deConfiguration, envName, new AtomicBoolean(false), componentsUtils, null);
+ initTask.setCambriaHandler(cambriaHandler);
+
+ boolean initFlow = initTask.initFlow();
+ assertTrue("check init flow succeed", initFlow);
+
+ }
+
+ @Test
+ public void testInitFlowScenarioSuccessTopicsAlreadyExists() {
+
+ String envName = "PrOD";
+ String notifTopic = "notif";
+ String statusTopic = "status";
+
+ String realNotifTopic = notifTopic + "-" + envName.toUpperCase();
+ String realStatusTopic = statusTopic + "-" + envName.toUpperCase();
+
+ Set<String> topics = new HashSet<String>();
+ topics.add(realNotifTopic);
+ topics.add(realStatusTopic);
+
+ List<String> uebServers = new ArrayList<>();
+ uebServers.add("server1");
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.NOT_FOUND);
+ Either<Set<String>, CambriaErrorResponse> left = Either.left(topics);
+
+ when(cambriaHandler.getTopics(Mockito.any(List.class))).thenReturn(left);
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+ deConfiguration.setUebServers(uebServers);
+ int retry = 2;
+ int maxRetry = 40;
+ deConfiguration.setInitRetryIntervalSec(retry);
+ deConfiguration.setInitMaxIntervalSec(maxRetry);
+ deConfiguration.setDistributionNotifTopicName(notifTopic);
+ deConfiguration.setDistributionStatusTopicName(statusTopic);
+ CreateTopicConfig createTopic = new CreateTopicConfig();
+ createTopic.setPartitionCount(1);
+ createTopic.setReplicationCount(1);
+ deConfiguration.setCreateTopic(createTopic);
+
+ cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK);
+ when(cambriaHandler.registerToTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(SubscriberTypeEnum.class)))
+ .thenReturn(cambriaErrorResponse);
+
+ DistributionEngineInitTask initTask = new DistributionEngineInitTask(0l, deConfiguration, envName, new AtomicBoolean(false), componentsUtils, null);
+ initTask.setCambriaHandler(cambriaHandler);
+
+ try {
+ boolean initFlow = initTask.initFlow();
+ assertTrue("check init flow succeed", initFlow);
+ } catch (Exception e) {
+ assertTrue("Should not throw exception", false);
+ }
+
+ }
+
+ @Test
+ public void testInitFlowScenarioFailToRegister() {
+
+ String notifTopic = "notif";
+ String statusTopic = "status";
+
+ List<String> uebServers = new ArrayList<>();
+ uebServers.add("server1");
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.NOT_FOUND);
+ Either<Set<String>, CambriaErrorResponse> right = Either.right(cambriaErrorResponse);
+ when(cambriaHandler.getTopics(Mockito.any(List.class))).thenReturn(right);
+
+ String envName = "PrOD";
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+ deConfiguration.setUebServers(uebServers);
+ int retry = 2;
+ int maxRetry = 40;
+ deConfiguration.setInitRetryIntervalSec(retry);
+ deConfiguration.setInitMaxIntervalSec(maxRetry);
+ deConfiguration.setDistributionNotifTopicName(notifTopic);
+ deConfiguration.setDistributionStatusTopicName(statusTopic);
+ CreateTopicConfig createTopic = new CreateTopicConfig();
+ createTopic.setPartitionCount(1);
+ createTopic.setReplicationCount(1);
+ deConfiguration.setCreateTopic(createTopic);
+
+ cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.OK);
+
+ String realNotifTopic = notifTopic + "-" + envName.toUpperCase();
+ String realStatusTopic = statusTopic + "-" + envName.toUpperCase();
+ when(cambriaHandler.createTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(realNotifTopic), Mockito.eq(1), Mockito.eq(1))).thenReturn(cambriaErrorResponse);
+ when(cambriaHandler.createTopic(Mockito.any(Collection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(realStatusTopic), Mockito.eq(1), Mockito.eq(1))).thenReturn(cambriaErrorResponse);
+
+ when(cambriaHandler.registerToTopic(Mockito.any(Collection.class), Mockito.eq(realNotifTopic), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(SubscriberTypeEnum.class)))
+ .thenReturn(new CambriaErrorResponse(CambriaOperationStatus.OK));
+
+ when(cambriaHandler.registerToTopic(Mockito.any(Collection.class), Mockito.eq(realStatusTopic), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(SubscriberTypeEnum.class)))
+ .thenReturn(new CambriaErrorResponse(CambriaOperationStatus.CONNNECTION_ERROR));
+
+ DistributionEngineInitTask initTask = new DistributionEngineInitTask(0l, deConfiguration, envName, new AtomicBoolean(false), componentsUtils, null);
+ initTask.setCambriaHandler(cambriaHandler);
+
+ boolean initFlow = initTask.initFlow();
+ assertFalse("check init flow failed", initFlow);
+
+ }
+
+ @Test
+ public void testInitFlowScenario1GetTopicsFailed() {
+
+ List<String> uebServers = new ArrayList<>();
+ uebServers.add("server1");
+ CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.CONNNECTION_ERROR);
+ Either<Set<String>, CambriaErrorResponse> right = Either.right(cambriaErrorResponse);
+ when(cambriaHandler.getTopics(Mockito.any(List.class))).thenReturn(right);
+
+ String envName = "PrOD";
+
+ DistributionEngineConfiguration deConfiguration = new DistributionEngineConfiguration();
+ deConfiguration.setUebServers(uebServers);
+ int retry = 2;
+ int maxRetry = 40;
+ deConfiguration.setInitRetryIntervalSec(retry);
+ deConfiguration.setInitMaxIntervalSec(maxRetry);
+ DistributionEngineInitTask initTask = new DistributionEngineInitTask(0l, deConfiguration, envName, new AtomicBoolean(false), componentsUtils, null);
+ initTask.setCambriaHandler(cambriaHandler);
+
+ boolean initFlow = initTask.initFlow();
+ assertFalse("check init flow failed", initFlow);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
new file mode 100644
index 0000000000..0905b8cd19
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
@@ -0,0 +1,234 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+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.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+
+import fj.data.Either;
+
+public class ArtifactBusinessLogicTest {
+
+ static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+ static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+
+ @InjectMocks
+ static ArtifactsBusinessLogic artifactBL = new ArtifactsBusinessLogic();
+
+ public static final ArtifactOperation artifactOperation = Mockito.mock(ArtifactOperation.class);
+ public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+ public static final IInterfaceLifecycleOperation lifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
+ public static final IUserAdminOperation userOperation = Mockito.mock(IUserAdminOperation.class);
+ public static final IElementOperation elementOperation = Mockito.mock(IElementOperation.class);
+ // public static final InformationDeployedArtifactsBusinessLogic
+ // informationDeployedArtifactsBusinessLogic =
+ // Mockito.mock(InformationDeployedArtifactsBusinessLogic.class);
+
+ public static final Resource resource = Mockito.mock(Resource.class);
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ @BeforeClass
+ public static void setup() {
+
+ Either<ArtifactDefinition, StorageOperationStatus> NotFoundResult = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(artifactOperation.getArtifactById(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(NotFoundResult);
+
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> NotFoundResult2 = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(artifactOperation.getArtifacts(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Service), Mockito.anyBoolean())).thenReturn(NotFoundResult2);
+ when(artifactOperation.getArtifacts(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource), Mockito.anyBoolean())).thenReturn(NotFoundResult2);
+
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> notFoundInterfaces = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(lifecycleOperation.getAllInterfacesOfResource(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(notFoundInterfaces);
+
+ User userJH = new User("John", "Doh", "jh0003", "jh0003@gmail.com", "ADMIN", System.currentTimeMillis());
+ Either<User, ActionStatus> getUserResult = Either.left(userJH);
+
+ when(userOperation.getUserData("jh0003", false)).thenReturn(getUserResult);
+
+ Either<List<ArtifactType>, ActionStatus> getType = Either.left(getAllTypes());
+ when(elementOperation.getAllArtifactTypes()).thenReturn(getType);
+
+ when(resource.getResourceType()).thenReturn(ResourceTypeEnum.VFC);
+ // when(informationDeployedArtifactsBusinessLogic.getAllDeployableArtifacts(Mockito.any(Resource.class))).thenReturn(new
+ // ArrayList<ArtifactDefinition>());
+ }
+
+ private static List<ArtifactType> getAllTypes() {
+ List<ArtifactType> artifactTypes = new ArrayList<ArtifactType>();
+ List<String> artifactTypesList = ConfigurationManager.getConfigurationManager().getConfiguration().getArtifactTypes();
+ for (String artifactType : artifactTypesList) {
+ ArtifactType artifactT = new ArtifactType();
+ artifactT.setName(artifactType);
+ artifactTypes.add(artifactT);
+ }
+ return artifactTypes;
+ }
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testValidJson() {
+ ArtifactDefinition ad = createArtifactDef();
+
+ String jsonArtifact = gson.toJson(ad);
+
+ ArtifactDefinition afterConvert = RepresentationUtils.convertJsonToArtifactDefinition(jsonArtifact, ArtifactDefinition.class);
+ assertEquals(ad, afterConvert);
+ }
+
+ private ArtifactDefinition createArtifactDef() {
+ ArtifactDefinition ad = new ArtifactDefinition();
+ ad.setArtifactName("artifact1.yaml");
+ ad.setArtifactLabel("label1");
+ ad.setDescription("description");
+ ad.setArtifactType(ArtifactTypeEnum.HEAT.getType());
+ ad.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ ad.setCreationDate(System.currentTimeMillis());
+ ad.setMandatory(false);
+ ad.setTimeout(15);
+ return ad;
+ }
+
+ @Test
+ public void testInvalidStringGroupType() {
+ ArtifactDefinition ad = new ArtifactDefinition();
+ ad.setArtifactName("artifact1");
+ ad.setCreationDate(System.currentTimeMillis());
+ ad.setMandatory(false);
+ ad.setTimeout(15);
+
+ JsonElement jsonArtifact = gson.toJsonTree(ad);
+ jsonArtifact.getAsJsonObject().addProperty("artifactGroupType", "www");
+
+ ArtifactDefinition afterConvert = RepresentationUtils.convertJsonToArtifactDefinition(jsonArtifact.toString(), ArtifactDefinition.class);
+ assertNull(afterConvert);
+ }
+
+ @Test
+ public void testInvalidNumberGroupType() {
+ ArtifactDefinition ad = new ArtifactDefinition();
+ ad.setArtifactName("artifact1");
+ ad.setCreationDate(System.currentTimeMillis());
+ ad.setMandatory(false);
+ ad.setTimeout(15);
+
+ JsonElement jsonArtifact = gson.toJsonTree(ad);
+ jsonArtifact.getAsJsonObject().addProperty("artifactGroupType", 123);
+
+ ArtifactDefinition afterConvert = RepresentationUtils.convertJsonToArtifactDefinition(jsonArtifact.toString(), ArtifactDefinition.class);
+ assertNull(afterConvert);
+ }
+
+ @Test
+ public void testInvalidGroupTypeWithSpace() {
+ ArtifactDefinition ad = new ArtifactDefinition();
+ ad.setArtifactName("artifact1");
+ ad.setCreationDate(System.currentTimeMillis());
+ ad.setMandatory(false);
+ ad.setTimeout(15);
+
+ JsonElement jsonArtifact = gson.toJsonTree(ad);
+ jsonArtifact.getAsJsonObject().addProperty("artifactGroupType", " DEPLOYMENT");
+
+ ArtifactDefinition afterConvert = RepresentationUtils.convertJsonToArtifactDefinition(jsonArtifact.toString(), ArtifactDefinition.class);
+ assertNull(afterConvert);
+ }
+
+ @Test
+ public void testInvalidTimeoutWithSpace() {
+ ArtifactDefinition ad = new ArtifactDefinition();
+ ad.setArtifactName("artifact1");
+ ad.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ ad.setCreationDate(System.currentTimeMillis());
+ ad.setMandatory(false);
+
+ JsonElement jsonArtifact = gson.toJsonTree(ad);
+ jsonArtifact.getAsJsonObject().addProperty("timeout", " 15");
+
+ ArtifactDefinition afterConvert = RepresentationUtils.convertJsonToArtifactDefinition(jsonArtifact.toString(), ArtifactDefinition.class);
+ assertNull(afterConvert);
+ }
+
+ // @Test
+ // public void convertAndValidateDeploymentArtifactNonHeatSuccess(){
+ // ArtifactDefinition createArtifactDef = createArtifactDef();
+ // createArtifactDef.setArtifactType(ArtifactTypeEnum.YANG_XML.getType());
+ //
+ // Either<ArtifactDefinition, ResponseFormat> validateResult = artifactBL
+ // .convertAndValidate(resource, "resourceId",
+ // gson.toJson(createArtifactDef), "jh0003", null, null, true,
+ // null, NodeTypeEnum.Resource);
+ //
+ // assertTrue(validateResult.isLeft());
+ // ArtifactDefinition validatedArtifact = validateResult.left().value();
+ //
+ // assertEquals(createArtifactDef.getArtifactGroupType(),
+ // validatedArtifact.getArtifactGroupType());
+ // assertEquals(new Integer(0), validatedArtifact.getTimeout());
+ // assertFalse(validatedArtifact.getMandatory());
+ // assertFalse(validatedArtifact.getServiceApi());
+ //
+ // }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
new file mode 100644
index 0000000000..776fe8864e
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
+import org.openecomp.sdc.be.components.impl.CommonImportManager;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
+import org.openecomp.sdc.common.util.CapabilityTypeNameEnum;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class CapabilityTypeImportManagerTest {
+ @InjectMocks
+ private CapabilityTypeImportManager manager = new CapabilityTypeImportManager();
+ public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class);
+ public static final CapabilityTypeOperation capabilityTypeOperation = Mockito.mock(CapabilityTypeOperation.class);
+ public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+
+ @BeforeClass
+ public static void beforeClass() {
+ when(capabilityTypeOperation.addCapabilityType(Mockito.any(CapabilityTypeDefinition.class))).thenAnswer(new Answer<Either<CapabilityTypeDefinition, StorageOperationStatus>>() {
+ public Either<CapabilityTypeDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ Either<CapabilityTypeDefinition, StorageOperationStatus> ans = Either.left((CapabilityTypeDefinition) args[0]);
+ return ans;
+ }
+
+ });
+ when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
+ }
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testCreateCapabilityTypes() throws IOException {
+ String ymlContent = getCapabilityTypesYml();
+ Either<List<CapabilityTypeDefinition>, ResponseFormat> createCapabilityTypes = manager.createCapabilityTypes(ymlContent);
+ assertTrue(createCapabilityTypes.isLeft());
+
+ List<CapabilityTypeDefinition> capabilityTypesList = createCapabilityTypes.left().value();
+ assertTrue(capabilityTypesList.size() == 14);
+ Map<String, CapabilityTypeDefinition> capibilityTypeMap = new HashMap<>();
+ for (CapabilityTypeDefinition capType : capabilityTypesList) {
+ capibilityTypeMap.put(capType.getType(), capType);
+ }
+ assertTrue(capabilityTypesList.size() == 14);
+
+ for (CapabilityTypeNameEnum curr : CapabilityTypeNameEnum.values()) {
+ assertTrue(capibilityTypeMap.containsKey(curr.getCapabilityName()));
+ }
+
+ }
+
+ private String getCapabilityTypesYml() throws IOException {
+ Path filePath = Paths.get("src/test/resources/types/capabilityTypes.yml");
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String ymlContent = new String(fileContent);
+ return ymlContent;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
new file mode 100644
index 0000000000..05fc6a2948
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
+import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+
+import fj.data.Either;
+
+public class CategoriesImportManagerTest {
+ @InjectMocks
+ static CategoriesImportManager importManager = new CategoriesImportManager();
+ public static final IElementOperation elementOperation = Mockito.mock(IElementOperation.class);
+ public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+
+ static Logger log = Mockito.spy(Logger.class);
+
+ private static SubCategoryDefinition subcategory;
+
+ @BeforeClass
+ public static void beforeClass() throws IOException {
+ InterfaceLifecycleTypeImportManager.setLog(log);
+
+ subcategory = new SubCategoryDefinition();
+ subcategory.setUniqueId("123");
+
+ when(elementOperation.createCategory(Mockito.any(CategoryDefinition.class), Mockito.any(NodeTypeEnum.class))).thenAnswer(new Answer<Either<CategoryDefinition, ActionStatus>>() {
+ public Either<CategoryDefinition, ActionStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ Either<CategoryDefinition, ActionStatus> ans = Either.left((CategoryDefinition) args[0]);
+ return ans;
+ }
+
+ });
+ when(elementOperation.createSubCategory(Mockito.any(String.class), Mockito.any(SubCategoryDefinition.class), Mockito.any(NodeTypeEnum.class))).thenAnswer(new Answer<Either<SubCategoryDefinition, ActionStatus>>() {
+ public Either<SubCategoryDefinition, ActionStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ // subcategory.setName(((SubCategoryDefinition)args[0]).getName());
+ Either<SubCategoryDefinition, ActionStatus> ans = Either.left(subcategory);
+ return ans;
+ }
+
+ });
+
+ // when(Mockito.any(SubCategoryDefinition.class).getUniqueId()).thenReturn("123");
+ }
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void importCategoriesTest() throws IOException {
+ String ymlContent = getYmlContent();
+ Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
+ assertTrue(createCapabilityTypes.isLeft());
+
+ }
+
+ private String getYmlContent() throws IOException {
+ Path filePath = Paths.get("src/test/resources/types/categoryTypes.yml");
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String ymlContent = new String(fileContent);
+ return ymlContent;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogicTest.java
new file mode 100644
index 0000000000..135caf2c82
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogicTest.java
@@ -0,0 +1,155 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.unittests.utils.FactoryUtils;
+
+public class CompositionBusinessLogicTest {
+ CompositionBusinessLogic compBl = new CompositionBusinessLogic();
+
+ @Test
+ public void testBuildSpiralPatternPositioningForComponentInstances() {
+ int instancesNum = 10;
+ Resource createVF = FactoryUtils.createVF();
+ for (int i = 0; i < instancesNum; i++) {
+ FactoryUtils.addComponentInstanceToVF(createVF, FactoryUtils.createResourceInstance());
+ }
+ Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstances = compBl.buildSpiralPatternPositioningForComponentInstances(createVF);
+ assertTrue(componentInstances.size() == instancesNum);
+ // Verify Spiral Pattern
+ ImmutablePair<Double, Double> key;
+ key = new ImmutablePair<>(0D, 0D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(-1D, 0D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(-1D, 1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(0D, 1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(1D, 1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(1D, 0D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(1D, -1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(0D, -1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(-1D, -1D);
+ assertTrue(componentInstances.containsKey(key));
+ key = new ImmutablePair<>(-2D, -1D);
+ assertTrue(componentInstances.containsKey(key));
+ }
+
+ @Test
+ public void testGetCpsConnectedToVFC() {
+ List<ComponentInstance> allComponentInstances = new ArrayList<>();
+ Resource createVF = FactoryUtils.createVF();
+ ComponentInstance vfc = populateVfWithVfcAndCps(allComponentInstances, createVF);
+
+ Map<ComponentInstance, List<ComponentInstance>> cpsConnectedToVFC = compBl.getCpsConnectedToVFC(allComponentInstances, createVF);
+ assertTrue(cpsConnectedToVFC.size() == 1);
+ assertTrue(cpsConnectedToVFC.containsKey(vfc));
+ Set<ComponentInstance> cps = cpsConnectedToVFC.get(vfc).stream().collect(Collectors.toSet());
+ assertTrue(cps.size() == 3);
+ cps.stream().forEach(e -> assertTrue(e.getOriginType() == OriginTypeEnum.CP));
+
+ }
+
+ @Test
+ public void testBuildCirclePatternForCps() {
+ List<ComponentInstance> allComponentInstances = new ArrayList<>();
+ Resource createVF = FactoryUtils.createVF();
+ ComponentInstance vfcInstance = populateVfWithVfcAndCps(allComponentInstances, createVF);
+ Map<ComponentInstance, List<ComponentInstance>> cpsConnectedToVFC = compBl.getCpsConnectedToVFC(allComponentInstances, createVF);
+
+ Map<ImmutablePair<Double, Double>, ComponentInstance> componentInstLocations = new HashMap<>();
+ componentInstLocations.put(new ImmutablePair<Double, Double>(0D, 0D), vfcInstance);
+ compBl.buildCirclePatternForCps(componentInstLocations, cpsConnectedToVFC);
+ assertTrue(componentInstLocations.size() == 4);
+
+ Set<ImmutablePair<Double, Double>> cpsLocations = componentInstLocations.entrySet().stream().filter(entry -> entry.getValue().getOriginType() == OriginTypeEnum.CP).map(e -> e.getKey()).collect(Collectors.toSet());
+ // Verify that all cps are located at different positions
+ assertTrue(cpsLocations.size() == 3);
+ Set<Double> distances = cpsLocations.stream().map(cpLocation -> Math.sqrt(Math.pow(cpLocation.left, 2) + Math.pow(cpLocation.right, 2))).collect(Collectors.toSet());
+ // Verify that all cps are at the same distance from center
+ assertTrue(distances.size() == 1);
+
+ }
+
+ /**
+ * Adds 4 instances to the vf.<br>
+ * vfc instance and 3 cps instances.<br>
+ * the cp instances are connected to the vfc instance.<br>
+ *
+ * @param allComponentInstances
+ * @param createVF
+ * @return vfc instance
+ */
+ private ComponentInstance populateVfWithVfcAndCps(List<ComponentInstance> allComponentInstances, Resource createVF) {
+ ComponentInstance vfc = FactoryUtils.createResourceInstance();
+ vfc.setOriginType(OriginTypeEnum.VFC);
+ FactoryUtils.addComponentInstanceToVF(createVF, vfc);
+ allComponentInstances.add(vfc);
+
+ connectCpToVfc(allComponentInstances, createVF, vfc);
+ connectCpToVfc(allComponentInstances, createVF, vfc);
+ connectCpToVfc(allComponentInstances, createVF, vfc);
+ return vfc;
+ }
+
+ private void connectCpToVfc(List<ComponentInstance> allComponentInstances, Resource createVF, ComponentInstance vfc) {
+ List<RequirementCapabilityRelDef> allRelations;
+ if (createVF.getComponentInstancesRelations() != null) {
+ allRelations = createVF.getComponentInstancesRelations();
+ } else {
+ allRelations = new ArrayList<>();
+ createVF.setComponentInstancesRelations(allRelations);
+ }
+ ComponentInstance cp1 = FactoryUtils.createResourceInstance();
+ cp1.setOriginType(OriginTypeEnum.CP);
+ addVfcCpRelation(vfc, cp1, allRelations);
+ FactoryUtils.addComponentInstanceToVF(createVF, cp1);
+ allComponentInstances.add(cp1);
+ }
+
+ private void addVfcCpRelation(ComponentInstance vfc, ComponentInstance cp, List<RequirementCapabilityRelDef> allRelations) {
+ RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
+ rel.setToNode(vfc.getComponentUid());
+ rel.setFromNode(cp.getComponentUid());
+ allRelations.add(rel);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CsarValidationUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CsarValidationUtilsTest.java
new file mode 100644
index 0000000000..84c8286f14
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CsarValidationUtilsTest.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.Arrays;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
+
+public class CsarValidationUtilsTest {
+ private String[] invalidExtensions = { null, ".bla", ".yaml", ".yml", ".txt", ".zip" };
+ private String[] validExtensions = { ".csar", ".cSAr", ".Csar", ".CSAR" };
+
+ @Test
+ public void testIsCsarPayloadName() {
+ Arrays.stream(invalidExtensions).forEach(e -> Assert.assertFalse(CsarValidationUtils.isCsarPayloadName(e)));
+ Arrays.stream(validExtensions).forEach(e -> Assert.assertTrue(CsarValidationUtils.isCsarPayloadName(e)));
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java
new file mode 100644
index 0000000000..6dd19cce57
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java
@@ -0,0 +1,509 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Function;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.AttributeDefinition;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.yaml.snakeyaml.Yaml;
+
+import fj.data.Either;
+
+public class ImportUtilsTest {
+ @Test
+ public void testStringTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "stringTestTag", ToscaElementTypeEnum.STRING, new ArrayList<>());
+ assertTrue(toscaElements.isLeft());
+ List<Object> list = toscaElements.left().value();
+ assertTrue(list.size() == 4);
+ int count = 1;
+ for (Object element : list) {
+ assertTrue(element instanceof String);
+ String value = (String) element;
+ assertTrue(value.equals("stringVal" + count));
+ count++;
+ }
+ }
+
+ @Test
+ public void testBooleanTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "required", ToscaElementTypeEnum.BOOLEAN, new ArrayList<>());
+ assertTrue(toscaElements.isLeft());
+ List<Object> list = toscaElements.left().value();
+ assertTrue(list.size() == 3);
+ int count = 1;
+ for (Object element : list) {
+ assertTrue(element instanceof Boolean);
+ Boolean value = (Boolean) element;
+ if (count == 1 || count == 3) {
+ assertFalse(value);
+ } else if (count == 2) {
+ assertTrue(value);
+ }
+
+ count++;
+ }
+ }
+
+ @Test
+ public void testListTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "listTestTag", ToscaElementTypeEnum.LIST, new ArrayList<>());
+ assertTrue(toscaElements.isLeft());
+ List<Object> list = toscaElements.left().value();
+ assertTrue(list.size() == 3);
+ int count = 1;
+ for (Object element : list) {
+ assertTrue(element instanceof List);
+
+ if (count == 1) {
+ verifyListElement1(element);
+ } else if (count == 2) {
+ verifyListElement2(element);
+ }
+
+ else if (count == 3) {
+ verifyListElement3(element);
+ }
+ count++;
+ }
+ }
+
+ @Test
+ public void testAllTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "allTestTag", ToscaElementTypeEnum.ALL, new ArrayList<>());
+ assertTrue(toscaElements.isLeft());
+ List<Object> list = toscaElements.left().value();
+ assertTrue(list.size() == 5);
+ int count = 1;
+ for (Object element : list) {
+ if (count == 1) {
+ assertTrue(element instanceof String);
+ assertTrue(element.equals("tosca.nodes.Root"));
+ } else if (count == 2) {
+ assertTrue(element instanceof Map);
+ Map<String, Object> mapElement = (Map<String, Object>) element;
+ assertTrue(mapElement.size() == 2);
+ Iterator<Entry<String, Object>> elementEntries = mapElement.entrySet().iterator();
+ Entry<String, Object> elementEntry = elementEntries.next();
+ assertTrue(elementEntry.getKey().equals("mapTestTag"));
+ assertTrue(elementEntry.getValue().equals("string"));
+
+ elementEntry = elementEntries.next();
+ assertTrue(elementEntry.getKey().equals("required"));
+ assertTrue(elementEntry.getValue() instanceof Boolean);
+ assertTrue((Boolean) elementEntry.getValue());
+ }
+
+ else if (count == 3) {
+ assertTrue(element instanceof String);
+ assertTrue(element.equals("1 MB"));
+ }
+
+ else if (count == 4) {
+ assertTrue(element instanceof List);
+ List<Object> listElement = (List<Object>) element;
+ assertTrue(listElement.size() == 2);
+
+ assertTrue(listElement.get(0) instanceof Map);
+ Map<String, Object> innerElement = (Map<String, Object>) listElement.get(0);
+ assertTrue(innerElement.size() == 1);
+ Entry<String, Object> innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("greater_or_equal"));
+ assertTrue(innerEntry.getValue().equals("1 MB"));
+
+ assertTrue(listElement.get(1) instanceof Map);
+ innerElement = (Map<String, Object>) listElement.get(1);
+ assertTrue(innerElement.size() == 1);
+ innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("stringTestTag"));
+ assertTrue(innerEntry.getValue().equals("stringVal3"));
+ } else if (count == 5) {
+ assertTrue(element instanceof Boolean);
+ assertFalse((Boolean) element);
+ }
+ count++;
+ }
+ }
+
+ @Test
+ public void testMapTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "mapTestTag", ToscaElementTypeEnum.MAP, new ArrayList<>());
+ assertTrue(toscaElements.isLeft());
+ List<Object> list = toscaElements.left().value();
+ assertTrue(list.size() == 2);
+ int count = 1;
+ for (Object element : list) {
+ assertTrue(element instanceof Map);
+
+ if (count == 1) {
+ Map<String, Object> mapElement = (Map<String, Object>) element;
+ assertTrue(mapElement.size() == 2);
+ Iterator<Entry<String, Object>> iterator = mapElement.entrySet().iterator();
+ Entry<String, Object> inerElementEntry = iterator.next();
+ assertTrue(inerElementEntry.getKey().equals("stringTestTag"));
+ assertTrue(inerElementEntry.getValue().equals("stringVal1"));
+
+ inerElementEntry = iterator.next();
+ assertTrue(inerElementEntry.getKey().equals("listTestTag"));
+ assertTrue(inerElementEntry.getValue() instanceof List);
+ List<Object> innerValue = (List<Object>) inerElementEntry.getValue();
+
+ assertTrue(innerValue.size() == 3);
+
+ } else if (count == 2) {
+ Map<String, Object> mapElement = (Map<String, Object>) element;
+ assertTrue(mapElement.size() == 2);
+ Iterator<Entry<String, Object>> entryItr = mapElement.entrySet().iterator();
+ Entry<String, Object> inerElementEntry = entryItr.next();
+ assertTrue(inerElementEntry.getKey().equals("type"));
+ assertTrue(inerElementEntry.getValue().equals("tosca.capabilities.Attachment"));
+ inerElementEntry = entryItr.next();
+ assertTrue(inerElementEntry.getKey().equals("allTestTag"));
+ assertTrue(inerElementEntry.getValue() instanceof Boolean);
+ }
+
+ count++;
+ }
+ }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithString() {
+
+ testCreateFullHeatParameterModule("string", "default value");
+
+ }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithNumber() {
+
+ testCreateFullHeatParameterModule("number", "777");
+ testCreateFullHeatParameterModule("number", "777.23");
+
+ }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithBoolean() {
+
+ testCreateFullHeatParameterModule("boolean", "true");
+ testCreateFullHeatParameterModule("boolean", "on");
+ testCreateFullHeatParameterModule("boolean", "n");
+
+ }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithList() {
+
+ testCreateFullHeatParameterModule("comma_delimited_list", "[one, two]");
+
+ }
+
+ // @Test
+ // public void testCreateFullHeatParameterModuleWithInvalidType(){
+ //
+ // String name = "fullParameter";
+ // String description = "description_text";
+ //
+ // Map<String, Object> parametersMap = new HashMap<String, Object>();
+ // Map<String, Object> firstParam = createParameterMap("aaa", "aaa",
+ // name, description);
+ // parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(),
+ // firstParam);
+ //
+ // Either<List<HeatParameterDefinition>,ResultStatusEnum> heatParameters =
+ // ImportUtils.getHeatParameters(parametersMap);
+ // assertTrue(heatParameters.isRight());
+ // assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE,
+ // heatParameters.right().value());
+ //
+ // }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithMissingType() {
+
+ String name = "fullParameter";
+ String description = "description_text";
+
+ Map<String, Object> parametersMap = new HashMap<String, Object>();
+ Map<String, Object> firstParam = createParameterMap(null, "aaa", name, description);
+ parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
+
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ assertTrue(heatParameters.isRight());
+ assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE, heatParameters.right().value());
+
+ }
+
+ @Test
+ public void testCreateFullHeatParameterModuleWithMissingFields() {
+
+ String name = "fullParameter";
+
+ Map<String, Object> parametersMap = new HashMap<String, Object>();
+ String type = "number";
+ String defValue = "defvalue";
+ // default value cannot be empty in heat in case tag exists
+ Map<String, Object> firstParam = createParameterMap(type, defValue, name, null);
+ parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
+
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ assertTrue(heatParameters.isLeft());
+ List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
+ assertFalse(parameterDefList.isEmpty());
+ HeatParameterDefinition parameterDefinition = parameterDefList.get(0);
+
+ assertParameter(parameterDefinition, name, type, null, defValue);
+
+ }
+
+ @Test
+ public void testGetAttributesFromYml() throws IOException {
+
+ Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaWithAttribute.yml");
+ Either<Map<String, AttributeDefinition>, ResultStatusEnum> actualAttributes = ImportUtils.getAttributes(toscaJson);
+ assertTrue(actualAttributes.isLeft());
+ Map<String, Map<String, Object>> expectedAttributes = getElements(toscaJson, ToscaTagNamesEnum.ATTRIBUTES);
+ compareAttributes(expectedAttributes, actualAttributes.left().value());
+
+ }
+
+ @Test
+ public void testGetPropertiesFromYml() throws IOException {
+
+ Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaProperties.yml");
+ Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualProperties = ImportUtils.getProperties(toscaJson);
+ assertTrue(actualProperties.isLeft());
+ Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, ToscaTagNamesEnum.PROPERTIES);
+ compareProperties(expectedProperties, actualProperties.left().value());
+
+ }
+
+ private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, AttributeDefinition> actual) {
+
+ Map<String, Object> singleExpectedAttribute;
+ AttributeDefinition actualAttribute, expectedAttributeModel;
+ // attributes of resource
+ for (Map.Entry<String, Map<String, Object>> expectedAttribute : expected.entrySet()) {
+
+ singleExpectedAttribute = expectedAttribute.getValue();
+ assertNotNull(singleExpectedAttribute);
+ actualAttribute = actual.get(expectedAttribute.getKey());
+ assertNotNull(actualAttribute);
+ actualAttribute.setName(expectedAttribute.getKey().toString());
+ expectedAttributeModel = ImportUtils.createModuleAttribute(singleExpectedAttribute);
+ expectedAttributeModel.setName(expectedAttribute.getKey().toString());
+
+ assertEquals(expectedAttributeModel.getDefaultValue(), actualAttribute.getDefaultValue());
+ assertEquals(expectedAttributeModel.getDescription(), actualAttribute.getDescription());
+ assertEquals(expectedAttributeModel.getName(), actualAttribute.getName());
+ assertEquals(expectedAttributeModel.getStatus(), actualAttribute.getStatus());
+ assertEquals(expectedAttributeModel.getType(), actualAttribute.getType());
+
+ compareSchemas(expectedAttributeModel.getSchema(), actualAttribute.getSchema());
+
+ }
+
+ }
+
+ private void compareProperties(Map<String, Map<String, Object>> expected, Map<String, PropertyDefinition> actual) {
+
+ Map<String, Object> singleExpectedProperty;
+ PropertyDefinition actualProperty, expectedPropertyModel;
+ // attributes of resource
+ for (Map.Entry<String, Map<String, Object>> expectedProperty : expected.entrySet()) {
+
+ singleExpectedProperty = expectedProperty.getValue();
+ assertNotNull(singleExpectedProperty);
+ actualProperty = actual.get(expectedProperty.getKey());
+ assertNotNull(actualProperty);
+ actualProperty.setName(expectedProperty.getKey().toString());
+ expectedPropertyModel = ImportUtils.createModuleProperty(singleExpectedProperty);
+ expectedPropertyModel.setName(expectedProperty.getKey().toString());
+
+ assertEquals(expectedPropertyModel.getDefaultValue(), actualProperty.getDefaultValue());
+ assertEquals(expectedPropertyModel.getDescription(), actualProperty.getDescription());
+ assertEquals(expectedPropertyModel.getName(), actualProperty.getName());
+ assertEquals(expectedPropertyModel.getStatus(), actualProperty.getStatus());
+ assertEquals(expectedPropertyModel.getType(), actualProperty.getType());
+
+ compareSchemas(expectedPropertyModel.getSchema(), actualProperty.getSchema());
+
+ }
+
+ }
+
+ private void compareSchemas(SchemaDefinition expected, SchemaDefinition actual) {
+
+ if (expected == null && actual == null) {
+ return;
+ }
+ PropertyDataDefinition actualPropertySchema = actual.getProperty();
+ PropertyDataDefinition expectedPropertySchema = expected.getProperty();
+ assertNotNull(actualPropertySchema);
+ assertNotNull(expectedPropertySchema);
+ assertEquals(expectedPropertySchema.getDescription(), actualPropertySchema.getDescription());
+ assertEquals(expectedPropertySchema.getType(), actualPropertySchema.getType());
+
+ }
+
+ private <T> Map<String, T> getElements(Map<String, Object> toscaJson, ToscaTagNamesEnum elementType) {
+
+ Either<Map<String, T>, ResultStatusEnum> toscaExpectedElements = ImportUtils.findFirstToscaMapElement(toscaJson, elementType);
+ assertTrue(toscaExpectedElements.isLeft());
+
+ return toscaExpectedElements.left().value();
+
+ }
+
+ private void testCreateFullHeatParameterModule(String type, Object defaultVal) {
+
+ String name = "fullParameter";
+ String description = "description_text";
+
+ Map<String, Object> parametersMap = new HashMap<String, Object>();
+ Map<String, Object> firstParam = createParameterMap(type, defaultVal, name, description);
+ parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
+
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ assertTrue(heatParameters.isLeft());
+ List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
+ assertFalse(parameterDefList.isEmpty());
+ HeatParameterDefinition parameterDefinition = parameterDefList.get(0);
+
+ assertParameter(parameterDefinition, name, type, description, defaultVal);
+
+ }
+
+ private Map<String, Object> createParameterMap(String type, Object defaultVal, String name, String description) {
+ Map<String, Object> firstParam = new HashMap<String, Object>();
+ Map<String, Object> valuesMap = new HashMap<String, Object>();
+
+ valuesMap.put(ToscaTagNamesEnum.TYPE.getElementName(), type);
+ valuesMap.put(ToscaTagNamesEnum.DESCRIPTION.getElementName(), description);
+ valuesMap.put(ToscaTagNamesEnum.DEFAULT_VALUE.getElementName(), defaultVal);
+
+ firstParam.put(name, valuesMap);
+ return firstParam;
+ }
+
+ private void assertParameter(HeatParameterDefinition parameterDefinition, String name, String type, String description, Object defaultVal) {
+ assertEquals(name, parameterDefinition.getName());
+ assertEquals(description, parameterDefinition.getDescription());
+ assertEquals(type, parameterDefinition.getType());
+ assertEquals(String.valueOf(defaultVal), parameterDefinition.getDefaultValue());
+ assertEquals(String.valueOf(defaultVal), parameterDefinition.getCurrentValue());
+ }
+
+ private void verifyListElement3(Object element) {
+ List<Object> listElement = (List<Object>) element;
+ assertTrue(listElement.size() == 2);
+
+ Map<String, String> innerElement = (Map<String, String>) listElement.get(0);
+ assertTrue(innerElement.size() == 1);
+ Entry<String, String> innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("testTag1"));
+ assertTrue(innerEntry.getValue().equals("1 MB"));
+
+ innerElement = (Map<String, String>) listElement.get(1);
+ assertTrue(innerElement.size() == 1);
+ innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("type"));
+ assertTrue(innerEntry.getValue().equals("stringVal2"));
+ }
+
+ private void verifyListElement2(Object element) {
+ List<Object> listElement = (List<Object>) element;
+ assertTrue(listElement.size() == 2);
+
+ Map<String, Object> innerElement = (Map<String, Object>) listElement.get(0);
+ assertTrue(innerElement.size() == 1);
+ Entry<String, Object> innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("testTag1"));
+ assertTrue(innerEntry.getValue().equals("1 MB"));
+
+ assertTrue(listElement.get(1) instanceof Map);
+ innerElement = (Map<String, Object>) listElement.get(1);
+ assertTrue(innerElement.size() == 1);
+ innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("listTestTag"));
+ assertTrue(innerEntry.getValue() instanceof List);
+ }
+
+ private void verifyListElement1(Object element) {
+ List<Object> listElement = (List<Object>) element;
+ assertTrue(listElement.size() == 3);
+
+ Map<String, String> innerElement = (Map<String, String>) listElement.get(0);
+ assertTrue(innerElement.size() == 1);
+ Entry<String, String> innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("listTestTag"));
+ assertTrue(innerEntry.getValue().equals("1 MB"));
+
+ innerElement = (Map<String, String>) listElement.get(1);
+ assertTrue(innerElement.size() == 1);
+ innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("listTestTag"));
+ assertTrue(innerEntry.getValue().equals("2 MB"));
+
+ innerElement = (Map<String, String>) listElement.get(2);
+ assertTrue(innerElement.size() == 1);
+ innerEntry = innerElement.entrySet().iterator().next();
+ assertTrue(innerEntry.getKey().equals("stringTestTag"));
+ assertTrue(innerEntry.getValue().equals("stringVal2"));
+ }
+
+ public static String loadFileNameToJsonString(String fileName) throws IOException {
+ String sourceDir = "src/test/resources/normativeTypes";
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir, fileName);
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String content = new String(fileContent);
+ return content;
+ }
+
+ private static Object loadJsonFromFile(String fileName) throws IOException {
+ String content = loadFileNameToJsonString(fileName);
+ Object load = new Yaml().load(content);
+ return load;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
new file mode 100644
index 0000000000..6ba74ec133
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.components.impl.CommonImportManager;
+import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+
+import fj.data.Either;
+
+public class InterfaceLifecycleTypeImportManagerTest {
+
+ @InjectMocks
+ private InterfaceLifecycleTypeImportManager importManager = new InterfaceLifecycleTypeImportManager();
+ public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class);
+ public static final IInterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
+ public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+
+ static Logger log = Mockito.spy(Logger.class);
+
+ @BeforeClass
+ public static void beforeClass() throws IOException {
+ InterfaceLifecycleTypeImportManager.setLog(log);
+ when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
+ public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ Either<InterfaceDefinition, StorageOperationStatus> ans = Either.left((InterfaceDefinition) args[0]);
+ return ans;
+ }
+
+ });
+ when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
+ }
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void importLiecycleTest() throws IOException {
+ String ymlContent = getYmlContent();
+ Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes = importManager.createLifecycleTypes(ymlContent);
+ assertTrue(createCapabilityTypes.isLeft());
+
+ }
+
+ private String getYmlContent() throws IOException {
+ Path filePath = Paths.get("src/test/resources/types/interfaceLifecycleTypes.yml");
+ byte[] fileContent = Files.readAllBytes(filePath);
+ String ymlContent = new String(fileContent);
+ return ymlContent;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
new file mode 100644
index 0000000000..5a503dc97c
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -0,0 +1,1423 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.ElementOperationMock;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.auditing.impl.AuditingLogFormatUtil;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class ResourceBusinessLogicTest {
+
+ private static Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class.getName());
+ public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
+ public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
+ public static final String RESOURCE_SUBCATEGORY = "Router";
+
+ public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
+ public static final String UPDATED_SUBCATEGORY = "Gateway";
+
+ public static final String RESOURCE_NAME = "My-Resource_Name with space";
+
+ final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ IAuditingManager iAuditingManager = null;
+ IElementOperation mockElementDao;
+ TitanGenericDao mockTitanDao = Mockito.mock(TitanGenericDao.class);
+ UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ final ResourceOperation resourceOperation = Mockito.mock(ResourceOperation.class);
+ final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
+ final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
+ final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
+ final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ AuditingLogFormatUtil auditingLogFormatter = Mockito.mock(AuditingLogFormatUtil.class);
+ @InjectMocks
+ ResourceBusinessLogic bl = new ResourceBusinessLogic();
+ ResponseFormatManager responseManager = null;
+ AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
+ GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ User user = null;
+ Resource resourceResponse = null;
+ ComponentsUtils componentsUtils = new ComponentsUtils();
+ ArtifactsBusinessLogic artifactManager = Mockito.mock(ArtifactsBusinessLogic.class);
+ CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
+
+ CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
+
+ public ResourceBusinessLogicTest() {
+
+ }
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.reset(propertyOperation);
+
+ ExternalConfiguration.setAppName("catalog-be");
+
+ // Init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+
+ // Elements
+ mockElementDao = new ElementOperationMock();
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh0003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ Either<User, ActionStatus> eitherGetUser = Either.left(user);
+ when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
+
+ // Servlet Context attributes
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ // when(servletContext.getAttribute(Constants.AUDITING_MANAGER)).thenReturn(iAuditingManager);
+ when(servletContext.getAttribute(Constants.RESOURCE_OPERATION_MANAGER)).thenReturn(resourceOperation);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
+ when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
+
+ // Resource Operation mock methods
+ // getCount
+ /*
+ * Either<Integer, StorageOperationStatus> eitherCount = Either.left(0); when(resourceOperation.getNumberOfResourcesByName("MyResourceName")). thenReturn(eitherCount); Either<Integer, StorageOperationStatus> eitherCountExist = Either.left(1);
+ * when(resourceOperation.getNumberOfResourcesByName("alreadyExist")). thenReturn(eitherCountExist);
+ */
+ Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
+ when(resourceOperation.getNumberOfResourcesByName("Root".toLowerCase())).thenReturn(eitherCountRoot);
+ Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(false);
+ when(resourceOperation.validateResourceNameExists(ValidationUtils.normaliseComponentName("Root"), ResourceTypeEnum.VFC)).thenReturn(eitherFalse);
+
+ Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(false);
+ when(resourceOperation.validateResourceNameExists("alreadyExists", ResourceTypeEnum.VFC)).thenReturn(eitherCountExist);
+ Either<Boolean, StorageOperationStatus> eitherCount = Either.left(true);
+ when(resourceOperation.validateResourceNameExists(RESOURCE_NAME, ResourceTypeEnum.VFC)).thenReturn(eitherCount);
+
+ Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(false);
+ when(resourceOperation.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
+ Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(true);
+ when(resourceOperation.validateToscaResourceNameExists(ValidationUtils.normaliseComponentName("kuku"))).thenReturn(validateDerivedNotExists);
+
+ when(graphLockOperation.lockComponent(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.lockComponentByName(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
+
+ ArtifactDefinition artifactDef = new ArtifactDefinition();
+ artifactDef.setUniqueId("123.123");
+ Either<ArtifactDefinition, StorageOperationStatus> returnEither = Either.left(artifactDef);
+ when(artifactManager.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+
+ when(artifactManager.addHeatEnvArtifact(Mockito.any(ArtifactDefinition.class), Mockito.any(ArtifactDefinition.class), Mockito.anyString(), Mockito.any(NodeTypeEnum.class), Mockito.anyBoolean())).thenReturn(returnEither);
+
+ // createResource
+ resourceResponse = createResourceObject(true);
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
+ Either<List<ResourceMetadataData>, StorageOperationStatus> eitherValidate = Either.left(null);
+ when(resourceOperation.createResource(Mockito.any(Resource.class), Mockito.anyBoolean())).thenReturn(eitherCreate);
+ when(resourceOperation.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
+
+ // BL object
+ bl = new ResourceBusinessLogic();
+ bl.setElementDao(mockElementDao);
+ bl.setUserAdmin(mockUserAdmin);
+ bl.setResourceOperation(resourceOperation);
+ bl.setCapabilityTypeOperation(capabilityTypeOperation);
+ componentsUtils.Init();
+ componentsUtils.setAuditingManager(auditingManager);
+ bl.setComponentsUtils(componentsUtils);
+ bl.setLifecycleManager(lifecycleBl);
+ bl.setGraphLockOperation(graphLockOperation);
+ bl.setArtifactsManager(artifactManager);
+ bl.setPropertyOperation(propertyOperation);
+ bl.setTitanGenericDao(mockTitanDao);
+ bl.setApplicationDataTypeCache(applicationDataTypeCache);
+ bl.setCsarOperation(csarOperation);
+ bl.setCacheManagerOperation(cacheManager);
+
+ Resource resourceCsar = createResourceObjectCsar(true);
+ setCanWorkOnResource(resourceCsar);
+ Either<Resource, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
+ when(resourceOperation.getResource(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
+ when(resourceOperation.getLatestResourceByCsarOrName(resourceCsar.getCsarUUID(), resourceCsar.getSystemName())).thenReturn(oldResourceRes);
+ when(resourceOperation.updateResource(Mockito.any(Resource.class), Mockito.anyBoolean())).thenReturn(oldResourceRes);
+ responseManager = ResponseFormatManager.getInstance();
+
+ }
+
+ private Resource createResourceObject(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("ya5467");
+ resource.setIcon("MyIcon");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+ ;
+ resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug(gson.toJson(resource));
+ return resource;
+ }
+
+ private Resource createResourceObjectCsar(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("ya5467");
+ resource.setIcon("MyIcon");
+ resource.setCsarUUID("valid_vf.csar");
+ resource.setCsarVersion("1");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+ ;
+ resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug(gson.toJson(resource));
+ return resource;
+ }
+
+ private Resource setCanWorkOnResource(Resource resource) {
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setLastUpdaterUserId(user.getUserId());
+ return resource;
+ }
+
+ @Test
+ public void testHappyScenario() {
+ Resource resource = createResourceObject(false);
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, user, null, null);
+
+ if (createResponse.isRight()) {
+ assertEquals(new Integer(200), createResponse.right().value().getStatus());
+ }
+ assertEquals(createResourceObject(true), createResponse.left().value());
+ }
+
+ @Test
+ public void testUpdateHappyScenario() {
+ Resource resource = createResourceObjectCsar(true);
+ setCanWorkOnResource(resource);
+ Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
+ if (updateResponse.isRight()) {
+ assertEquals(new Integer(200), updateResponse.right().value().getStatus());
+ }
+ assertEquals(resource.getUniqueId(), updateResponse.left().value().getUniqueId());
+ }
+
+ /* CREATE validations - start ***********************/
+ // Resource name - start
+
+ @Test
+ public void testFailedResourceValidations() {
+ testResourceNameExist();
+ testResourceNameEmpty();
+ // testResourceNameExceedsLimit();
+ testResourceNameWrongFormat();
+ testResourceDescExceedsLimitCreate();
+ testResourceDescNotEnglish();
+ testResourceDescriptionEmpty();
+ testResourceDescriptionMissing();
+ testResourceIconMissing();
+ testResourceIconInvalid();
+ testResourceIconExceedsLimit();
+ testResourceTagNotExist();
+ testResourceTagEmpty();
+ testTagsExceedsLimitCreate();
+ // testTagsSingleExceedsLimit();
+ testTagsNoServiceName();
+ testInvalidTag();
+ // 1610OS Support - Because of changes in the validation in the ui these tests will fail. need to fix them
+ //testContactIdTooLong();
+ //testContactIdWrongFormatCreate();
+ testResourceContactIdEmpty();
+ testResourceContactIdMissing();
+ testVendorNameExceedsLimit();
+ testVendorNameWrongFormatCreate();
+ testVendorReleaseWrongFormat();
+ testVendorReleaseExceedsLimitCreate();
+ testResourceVendorNameMissing();
+ testResourceVendorReleaseMissing();
+ testResourceCategoryExist();
+ testResourceBadCategoryCreate();
+ testHappyScenarioCostLicenseType();
+ testCostWrongFormatCreate();
+ testLicenseTypeWrongFormatCreate();
+ testResourceTemplateNotExist();
+ testResourceTemplateEmpty();
+ testResourceTemplateInvalid();
+ }
+
+ private void testResourceNameExist() {
+ String resourceName = "alreadyExists";
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setName(resourceName);
+ resourceExist.getTags().add(resourceName);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
+ }
+
+ private void testResourceNameEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setName(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceNameExceedsLimit() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ // 51 chars, the limit is 50
+ String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
+ resourceExccedsNameLimit.setName(tooLongResourceName);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ }
+
+ private void testResourceNameWrongFormat() {
+ Resource resource = createResourceObject(false);
+ // contains :
+ String nameWrongFormat = "ljg?fd";
+ resource.setName(nameWrongFormat);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ // Resource name - end
+ // Resource description - start
+ private void testResourceDescExceedsLimitCreate() {
+ Resource resourceExccedsDescLimit = createResourceObject(false);
+ // 1025 chars, the limit is 1024
+ String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+
+ resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsDescLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ }
+
+ private void testResourceDescNotEnglish() {
+ Resource notEnglish = createResourceObject(false);
+ // Not english
+ String notEnglishDesc = "\uC2B5";
+ notEnglish.setDescription(notEnglishDesc);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(notEnglish, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceDescriptionEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDescription("");
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceDescriptionMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDescription(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ // Resource description - end
+ // Resource icon start
+
+ private void testResourceIconMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceIconInvalid() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon("kjk3453^&");
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceIconExceedsLimit() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ }
+
+ // Resource icon end
+ // Resource tags - start
+ private void testResourceTagNotExist() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setTags(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+
+ private void testResourceTagEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setTags(new ArrayList<String>());
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+
+ private void testTagsExceedsLimitCreate() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
+ String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
+ String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
+ String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
+ String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
+ String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
+ String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
+ String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
+ String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
+ String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
+ String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
+ String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
+ String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
+ String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
+ String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
+ String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
+ String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
+
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ tagsList.add(tag3);
+ tagsList.add(tag4);
+ tagsList.add(tag5);
+ tagsList.add(tag6);
+ tagsList.add(tag7);
+ tagsList.add(tag8);
+ tagsList.add(tag9);
+ tagsList.add(tag10);
+ tagsList.add(tag11);
+ tagsList.add(tag12);
+ tagsList.add(tag13);
+ tagsList.add(tag14);
+ tagsList.add(tag15);
+ tagsList.add(tag16);
+ tagsList.add(tag17);
+ tagsList.add(tag18);
+ tagsList.add(tag19);
+ tagsList.add(tag20);
+ tagsList.add(tag21);
+ tagsList.add(resourceExccedsNameLimit.getName());
+
+ resourceExccedsNameLimit.setTags(tagsList);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+
+ }
+
+ private void testTagsSingleExceedsLimit() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
+ String tag2 = resourceExccedsNameLimit.getName();
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+
+ resourceExccedsNameLimit.setTags(tagsList);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
+
+ }
+
+ private void testTagsNoServiceName() {
+ Resource serviceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb";
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+
+ }
+
+ private void testInvalidTag() {
+ Resource serviceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb%#%";
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
+
+ }
+
+ // Resource tags - stop
+ // Resource contact info start
+ private void testContactIdTooLong() {
+ Resource resourceContactId = createResourceObject(false);
+ // 7 chars instead of 6
+ String contactIdTooLong = "yrt1234";
+ resourceContactId.setContactId(contactIdTooLong);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testContactIdWrongFormatCreate() {
+ Resource resourceContactId = createResourceObject(false);
+ // 3 letters and 3 digits
+ String contactIdTooLong = "yrt134";
+ resourceContactId.setContactId(contactIdTooLong);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceContactIdEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setContactId("");
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceContactIdMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setContactId(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testVendorNameExceedsLimit() {
+ Resource resourceExccedsVendorNameLimit = createResourceObject(false);
+ String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
+ resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
+ }
+
+ private void testVendorNameWrongFormatCreate() {
+ Resource resource = createResourceObject(false);
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ resource.setVendorName(nameWrongFormat);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
+ }
+
+ private void testVendorReleaseWrongFormat() {
+ Resource resource = createResourceObject(false);
+ // contains >
+ String nameWrongFormat = "1>2";
+ resource.setVendorRelease(nameWrongFormat);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_VENDOR_RELEASE);
+
+ }
+
+ private void testVendorReleaseExceedsLimitCreate() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
+ resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ }
+
+ private void testResourceVendorNameMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setVendorName(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_VENDOR_NAME);
+ }
+
+ private void testResourceVendorReleaseMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setVendorRelease(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_VENDOR_RELEASE);
+ }
+
+ // Resource vendor name/release stop
+ // Category start
+ private void testResourceCategoryExist() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setCategories(null);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ private void testResourceBadCategoryCreate() {
+
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setCategories(null);
+ resourceExist.addCategory("koko", "koko");
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ // Category stop
+ // Cost start
+ private void testHappyScenarioCostLicenseType() {
+ Resource createResourceObject = createResourceObject(false);
+ Resource createResourceObjectAfterCreate = createResourceObject(true);
+ // Adding cost and licenseType to basic mock
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
+ when(resourceOperation.createResource(Mockito.any(Resource.class), Mockito.anyBoolean())).thenReturn(eitherCreate);
+
+ String cost = "123.456";
+ String licenseType = "User";
+ createResourceObject.setCost(cost);
+ createResourceObject.setLicenseType(licenseType);
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(createResourceObject, user, null, null);
+
+ if (createResponse.isRight()) {
+ assertEquals(new Integer(200), createResponse.right().value().getStatus());
+ }
+ createResourceObjectAfterCreate.setCost(cost);
+ createResourceObjectAfterCreate.setLicenseType(licenseType);
+ assertEquals(createResourceObjectAfterCreate, createResponse.left().value());
+ }
+
+ private void testCostWrongFormatCreate() {
+ Resource resourceCost = createResourceObject(false);
+ // Comma instead of fullstop
+ String cost = "12356,464";
+ resourceCost.setCost(cost);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceCost, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
+ }
+
+ // Cost stop
+ // License type start
+ private void testLicenseTypeWrongFormatCreate() {
+ Resource resourceLicenseType = createResourceObject(false);
+ // lowcase
+ String licenseType = "cpu";
+ resourceLicenseType.setLicenseType(licenseType);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceLicenseType, user, null, null);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
+ }
+
+ // License type stop
+ // Derived from start
+ private void testResourceTemplateNotExist() {
+ Resource resourceExist = createResourceObject(false);
+ List<String> list = null;
+ resourceExist.setDerivedFrom(list);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+
+ private void testResourceTemplateEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDerivedFrom(new ArrayList<String>());
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+
+ private void testResourceTemplateInvalid() {
+ Resource resourceExist = createResourceObject(false);
+ ArrayList<String> derivedFrom = new ArrayList<String>();
+ derivedFrom.add("kuku");
+ resourceExist.setDerivedFrom(derivedFrom);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ }
+ // Derived from stop
+
+ private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
+ ResponseFormat actualResponse = createResponse.right().value();
+ assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
+ assertEquals("assert error description", expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
+ }
+
+ // UPDATE tests - start
+ // Resource name
+ @Test
+ public void testResourceNameWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setName(nameWrongFormat);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+
+ }
+
+ @Test
+ public void testResourceNameAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ String name = "ljg";
+ updatedResource.setName(name);
+ resource.setVersion("1.0");
+ ;
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
+
+ }
+
+ @Test
+ @Ignore
+ public void testResourceNameExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // 51 chars, the limit is 50
+ String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
+ updatedResource.setName(tooLongResourceName);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ }
+
+ @Test
+ public void testResourceNameAlreadyExist_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ String resourceName = "alreadyExists";
+ updatedResource.setName(resourceName);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
+ }
+
+ //
+
+ @Test
+ public void testResourceDescExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // 1025 chars, the limit is 1024
+ String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+ updatedResource.setDescription(tooLongResourceDesc);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+
+ }
+
+ @Test
+ public void testIconWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // contains .
+ String icon = "icon.jpg";
+ updatedResource.setIcon(icon);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
+
+ }
+
+ @Test
+ public void testIconAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // contains
+ String icon = "icon";
+ updatedResource.setIcon(icon);
+
+ resource.setVersion("1.0");
+ ;
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
+
+ }
+
+ @Test
+ public void testTagsExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
+ String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
+ String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
+ String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
+ String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
+ String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
+ String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
+ String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
+ String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
+ String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
+ String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
+ String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
+ String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
+ String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
+ String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
+ String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
+ String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
+
+ List<String> tagsList = new ArrayList<String>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ tagsList.add(tag3);
+ tagsList.add(tag4);
+ tagsList.add(tag5);
+ tagsList.add(tag6);
+ tagsList.add(tag7);
+ tagsList.add(tag8);
+ tagsList.add(tag9);
+ tagsList.add(tag10);
+ tagsList.add(tag11);
+ tagsList.add(tag12);
+ tagsList.add(tag13);
+ tagsList.add(tag14);
+ tagsList.add(tag15);
+ tagsList.add(tag16);
+ tagsList.add(tag17);
+ tagsList.add(tag18);
+ tagsList.add(tag19);
+ tagsList.add(tag20);
+ tagsList.add(tag21);
+ tagsList.add(resource.getName());
+
+ updatedResource.setTags(tagsList);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ }
+
+ @Test
+ public void testVendorNameWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setVendorName(nameWrongFormat);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
+
+ }
+
+ @Test
+ public void testVendorNameAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setVendorName(nameWrongFormat);
+ resource.setVersion("1.0");
+ ;
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED);
+
+ }
+
+ @Test
+ public void testVendorReleaseExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ // 129 chars, the limit is 128
+ String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
+ updatedResource.setVendorRelease(tooLongVendorRelease);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+ assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ }
+
+ // 1610OS Support - Because of changes in the validation in the ui this test needs to be fixed
+// @Test
+// public void testContactIdWrongFormat_UPDATE() {
+// Resource resource = createResourceObject(true);
+// Resource updatedResource = createResourceObject(true);
+//
+// // this is in order to prevent failing with 403 earlier
+// Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+// // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+// when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+//
+// String resourceId = resource.getUniqueId();
+// // 3 letters and 3 digits
+// String contactIdTooLong = "yrt134";
+// updatedResource.setContactId(contactIdTooLong);
+// Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+// assertTrue(createResponse.isRight());
+//
+// assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+// }
+
+ @Test
+ public void testResourceBadCategory_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ String resourceId = resource.getUniqueId();
+ String badCategory = "ddfds";
+ updatedResource.setCategories(null);
+ updatedResource.addCategory(badCategory, "fikt");
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void testResourceCategoryAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ String resourceId = resource.getUniqueId();
+ updatedResource.setCategories(null);
+ updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
+ resource.setVersion("1.0");
+ ;
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
+ }
+
+ // Derived from start
+ @Test
+ public void testResourceTemplateNotExist_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+ String resourceId = resource.getUniqueId();
+
+ List<String> list = null;
+ updatedResource.setDerivedFrom(list);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+
+ @Test
+ public void testResourceTemplateEmpty_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ updatedResource.setDerivedFrom(new ArrayList<String>());
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+
+ @Test
+ public void testResourceTemplateInvalid_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+
+ ArrayList<String> derivedFrom = new ArrayList<String>();
+ derivedFrom.add("kuku");
+ updatedResource.setDerivedFrom(derivedFrom);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ }
+
+ @Test
+ public void testResourceTemplateCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(resourceOperation.getResource(resource.getUniqueId(), false)).thenReturn(eitherUpdate);
+ resource.setVersion("1.0");
+ ;
+
+ ArrayList<String> derivedFrom = new ArrayList<String>();
+ derivedFrom.add("tosca.nodes.Root");
+ updatedResource.setDerivedFrom(derivedFrom);
+
+ Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertTrue(createResponse.isRight());
+
+ assertResponse(createResponse, ActionStatus.RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED);
+ }
+ // Derived from stop
+
+ @Test
+ public void createOrUpdateResourceAlreadyCheckout() {
+ Resource resourceExist = createResourceObject(false);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+
+ createResponse.left().value().setLastUpdaterUserId(user.getUserId());
+ assertTrue(createResponse.isLeft());
+
+ Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createResponse.left().value());
+ when(resourceOperation.getLatestByName(resourceExist.getName(), true)).thenReturn(getLatestResult);
+ when(resourceOperation.overrideResource(Mockito.any(Resource.class), Mockito.any(Resource.class), Mockito.anyBoolean())).thenReturn(getLatestResult);
+
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false);
+ assertTrue(createOrUpdateResource.isLeft());
+
+ Mockito.verify(resourceOperation, Mockito.times(1)).overrideResource(Mockito.any(Resource.class), Mockito.any(Resource.class), Mockito.anyBoolean());
+ Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ public void createOrUpdateResourceCertified() {
+ Resource resourceExist = createResourceObject(false);
+
+ Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, user, null, null);
+
+ assertTrue(createResponse.isLeft());
+ Resource certifiedResource = createResponse.left().value();
+ certifiedResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ certifiedResource.setVersion("1.0");
+ ;
+
+ Either<Resource, StorageOperationStatus> getLatestResult = Either.left(certifiedResource);
+ when(resourceOperation.getLatestByName(resourceExist.getName(), true)).thenReturn(getLatestResult);
+ when(resourceOperation.overrideResource(Mockito.any(Resource.class), Mockito.any(Resource.class), Mockito.anyBoolean())).thenReturn(getLatestResult);
+
+ when(lifecycleBl.changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(createResponse);
+
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false);
+ assertTrue(createOrUpdateResource.isLeft());
+
+ Mockito.verify(resourceOperation, Mockito.times(1)).overrideResource(Mockito.any(Resource.class), Mockito.any(Resource.class), Mockito.anyBoolean());
+ Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ public void createOrUpdateResourceNotExist() {
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ Either<Resource, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(resourceOperation.getLatestByName(resourceToUpdtae.getName(), true)).thenReturn(getLatestResult);
+
+ Either<Resource, StorageOperationStatus> getLatestToscaNameResult = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(resourceOperation.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName(), true)).thenReturn(getLatestResult);
+
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false);
+ assertTrue(createOrUpdateResource.isLeft());
+
+ Mockito.verify(resourceOperation, Mockito.times(0)).overrideResource(Mockito.any(Resource.class), Mockito.any(Resource.class), Mockito.anyBoolean());
+ Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
+ Resource basic = createResourceObject(true);
+
+ Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
+ assertTrue(validatePropertiesDefaultValues.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
+ Resource basic = createResourceObject(true);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ property.setDefaultValue("1");
+ List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(property);
+ basic.setProperties(properties);
+ when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
+ when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
+ Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
+ assertTrue(validatePropertiesDefaultValues.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertiesDefaultValues_FailedWithProperties() {
+ Resource basic = createResourceObject(true);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ property.setDefaultValue("1.5");
+ List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(property);
+ basic.setProperties(properties);
+
+ when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
+ Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
+ assertTrue(validatePropertiesDefaultValues.isRight());
+ }
+
+ @Test
+ public void testDeleteMarkedResourcesNoResources() {
+ List<String> ids = new ArrayList<String>();
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
+ when(resourceOperation.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ assertTrue(deleteMarkedResources.left().value().isEmpty());
+
+ Mockito.verify(artifactManager, Mockito.times(0)).deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList());
+
+ }
+
+ @Test
+ public void testDeleteMarkedResources() {
+ List<String> ids = new ArrayList<String>();
+ String resourceInUse = "123";
+ ids.add(resourceInUse);
+ String resourceFree = "456";
+ ids.add(resourceFree);
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
+ when(resourceOperation.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
+
+ Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
+ Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
+
+ List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
+ Either<List<ArtifactDefinition>, StorageOperationStatus> getArtifactsResponse = Either.left(artifacts);
+ when(resourceOperation.getComponentArtifactsForDelete(resourceFree, NodeTypeEnum.Resource, true)).thenReturn(getArtifactsResponse);
+
+ when(resourceOperation.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
+ when(resourceOperation.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
+
+ Either<Component, StorageOperationStatus> eitherDelete = Either.left(new Resource());
+ when(resourceOperation.deleteComponent(resourceFree, true)).thenReturn(eitherDelete);
+
+ when(artifactManager.deleteAllComponentArtifactsIfNotOnGraph(artifacts)).thenReturn(StorageOperationStatus.OK);
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ List<String> resourceIdList = deleteMarkedResources.left().value();
+ assertFalse(resourceIdList.isEmpty());
+ assertTrue(resourceIdList.contains(resourceFree));
+ assertFalse(resourceIdList.contains(resourceInUse));
+
+ Mockito.verify(artifactManager, Mockito.times(1)).deleteAllComponentArtifactsIfNotOnGraph(artifacts);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceInstanceBusinessLogicTest.java
new file mode 100644
index 0000000000..d1597886d8
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceInstanceBusinessLogicTest.java
@@ -0,0 +1,284 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+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.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class ResourceInstanceBusinessLogicTest {
+
+ private static final String RESOURCE_ID_WITH_HEAT_PARAMS = "MyResourceId";
+ private static final String RESOURCE_ID_NO_PAYLOAD = "NoHeatPayload";
+ private static final String RESOURCE_ID_NO_HEAT_PARAMS = "NoHeatParams";
+ private static final String RESOURCE_INSTANCE_ID = "MyResourceInstanceId";
+ private static final String SERVICE_ID = "MyServiceId";
+ private static final String HEAT_LABEL = "myHeat";
+ private static final String HEAT_ENV_LABEL = HEAT_LABEL + "Env";
+ private static final String USER_ID = "jh0003";
+ private static final long ARTIFACT_CREATION_TIME = System.currentTimeMillis();
+
+ static User adminUser = new User("John", "Doh", USER_ID, "", "ADMIN", null);
+
+ @InjectMocks
+ static ServiceComponentInstanceBusinessLogic bl = new ServiceComponentInstanceBusinessLogic();
+
+ public static final ArtifactsBusinessLogic artifactBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
+ public static final UserBusinessLogic userAdminManager = Mockito.mock(UserBusinessLogic.class);
+ public static final ServiceOperation serviceOperation = Mockito.mock(ServiceOperation.class);
+ public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+
+ static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+ static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+
+ // @BeforeClass
+ public static void setup() {
+
+ Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getDeploymentResourceInstanceArtifacts();
+ Map<String, Object> placeHolderData = (Map<String, Object>) deploymentResourceArtifacts.get(ComponentInstanceBusinessLogic.HEAT_ENV_NAME);
+
+ ArtifactDefinition heatArtifact = getHeatArtifactDefinition(USER_ID, RESOURCE_ID_WITH_HEAT_PARAMS, HEAT_LABEL, ARTIFACT_CREATION_TIME, false, true);
+ Map<String, ArtifactDefinition> artifacts = new HashMap<String, ArtifactDefinition>();
+ artifacts.put(HEAT_LABEL.toLowerCase(), heatArtifact);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> eitherGetResourceArtifact = Either.left(artifacts);
+ Mockito.when(artifactBusinessLogic.getArtifacts(RESOURCE_ID_WITH_HEAT_PARAMS, NodeTypeEnum.Resource, true, ArtifactGroupTypeEnum.DEPLOYMENT)).thenReturn(eitherGetResourceArtifact);
+
+ ArtifactDefinition heatArtifactNoPayload = getHeatArtifactDefinition(USER_ID, RESOURCE_ID_NO_PAYLOAD, HEAT_LABEL, ARTIFACT_CREATION_TIME, true, false);
+ Map<String, ArtifactDefinition> artifactsNoPayload = new HashMap<String, ArtifactDefinition>();
+ artifactsNoPayload.put(HEAT_LABEL.toLowerCase(), heatArtifactNoPayload);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> eitherGetResourceArtifactNoPayload = Either.left(artifactsNoPayload);
+ Mockito.when(artifactBusinessLogic.getArtifacts(RESOURCE_ID_NO_PAYLOAD, NodeTypeEnum.Resource, true, ArtifactGroupTypeEnum.DEPLOYMENT)).thenReturn(eitherGetResourceArtifactNoPayload);
+
+ ArtifactDefinition heatArtifactNoParams = getHeatArtifactDefinition(USER_ID, RESOURCE_ID_NO_HEAT_PARAMS, HEAT_LABEL, ARTIFACT_CREATION_TIME, false, false);
+ Map<String, ArtifactDefinition> artifactsNoParams = new HashMap<String, ArtifactDefinition>();
+ artifactsNoParams.put(HEAT_LABEL.toLowerCase(), heatArtifactNoParams);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> eitherGetResourceArtifactNoParams = Either.left(artifactsNoParams);
+ Mockito.when(artifactBusinessLogic.getArtifacts(RESOURCE_ID_NO_HEAT_PARAMS, NodeTypeEnum.Resource, true, ArtifactGroupTypeEnum.DEPLOYMENT)).thenReturn(eitherGetResourceArtifactNoParams);
+
+ Either<ArtifactDefinition, ResponseFormat> eitherPlaceHolder = Either.left(getArtifactPlaceHolder(RESOURCE_INSTANCE_ID, HEAT_ENV_LABEL));
+ Mockito.when(artifactBusinessLogic.createArtifactPlaceHolderInfo(RESOURCE_INSTANCE_ID, HEAT_ENV_LABEL.toLowerCase(), placeHolderData, USER_ID, ArtifactGroupTypeEnum.DEPLOYMENT, false)).thenReturn(eitherPlaceHolder);
+
+ Mockito.when(artifactBusinessLogic.createArtifactAuditingFields(Mockito.any(ArtifactDefinition.class), Mockito.anyString(), Mockito.anyString())).thenReturn(new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class));
+
+ Either<ArtifactDefinition, StorageOperationStatus> eitherArtifact = Either.left(getHeatArtifactDefinition(USER_ID, RESOURCE_INSTANCE_ID, HEAT_ENV_LABEL, ARTIFACT_CREATION_TIME, true, false));
+ Mockito.when(artifactBusinessLogic.addHeatEnvArtifact(Mockito.any(ArtifactDefinition.class), Mockito.any(ArtifactDefinition.class), Mockito.anyString(), Mockito.any(NodeTypeEnum.class), Mockito.anyBoolean())).thenReturn(eitherArtifact);
+
+ Either<User, ActionStatus> eitherUser = Either.left(adminUser);
+ Mockito.when(userAdminManager.getUser(USER_ID, false)).thenReturn(eitherUser);
+
+ Object lightService = new Service();
+ Either<Object, StorageOperationStatus> eitherLightService = Either.left(lightService);
+ Mockito.when(serviceOperation.getLightComponent(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(eitherLightService);
+
+ Mockito.doNothing().when(componentsUtils).auditComponent(Mockito.any(ResponseFormat.class), Mockito.any(User.class), Mockito.any(Component.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(AuditingActionEnum.class),
+ Mockito.any(ComponentTypeEnum.class), Mockito.any(EnumMap.class));
+
+ }
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.reset(artifactBusinessLogic, serviceOperation, componentsUtils, userAdminManager);
+ setup();
+ }
+
+ @Test
+ public void testAddResourceInstanceArtifacts() throws Exception {
+ ComponentInstance resourceInstance = new ComponentInstance();
+ resourceInstance.setName(RESOURCE_INSTANCE_ID);
+ resourceInstance.setComponentUid(RESOURCE_ID_WITH_HEAT_PARAMS);
+ resourceInstance.setUniqueId(RESOURCE_INSTANCE_ID);
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ Either<ActionStatus, ResponseFormat> addArtifactsRes = bl.addComponentInstanceArtifacts(service, resourceInstance, USER_ID, false, null);
+ assertTrue(addArtifactsRes.isLeft());
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resourceInstance.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifacts);
+ assertTrue(deploymentArtifacts.size() == 2);
+
+ ArtifactDefinition heatDefinition = deploymentArtifacts.get(HEAT_LABEL.toLowerCase());
+ assertNotNull(heatDefinition);
+ assertEquals(getHeatArtifactDefinition(USER_ID, RESOURCE_ID_WITH_HEAT_PARAMS, HEAT_LABEL, ARTIFACT_CREATION_TIME, false, true), heatDefinition);
+
+ ArtifactDefinition heatEnvDefinition = deploymentArtifacts.get(HEAT_ENV_LABEL.toLowerCase());
+ assertNotNull(heatEnvDefinition);
+
+ List<HeatParameterDefinition> heatParameters = heatDefinition.getHeatParameters();
+ assertNotNull(heatParameters);
+
+ List<HeatParameterDefinition> heatEnvParameters = heatEnvDefinition.getHeatParameters();
+ assertNotNull(heatEnvParameters);
+
+ assertEquals(heatParameters.size(), heatEnvParameters.size());
+
+ int index = 0;
+ for (HeatParameterDefinition heatEnvParameter : heatEnvParameters) {
+ HeatParameterDefinition heatParameterDefinition = heatParameters.get(index);
+ assertEquals(heatEnvParameter.getUniqueId(), heatParameterDefinition.getUniqueId());
+ assertEquals(heatEnvParameter.getType(), heatParameterDefinition.getType());
+ assertEquals(heatEnvParameter.getName(), heatParameterDefinition.getName());
+ assertEquals(heatEnvParameter.getDescription(), heatParameterDefinition.getDescription());
+ assertEquals(heatEnvParameter.getCurrentValue(), heatParameterDefinition.getCurrentValue());
+ // current of heat parameter should be the default for heat env
+ // parameter
+ assertEquals(heatEnvParameter.getDefaultValue(), heatParameterDefinition.getCurrentValue());
+
+ index++;
+ }
+ }
+
+ @Test
+ public void testAddResourceInstanceArtifactsNoParams() throws Exception {
+ ComponentInstance resourceInstance = new ComponentInstance();
+ resourceInstance.setName(RESOURCE_INSTANCE_ID);
+ resourceInstance.setComponentUid(RESOURCE_ID_NO_HEAT_PARAMS);
+ resourceInstance.setUniqueId(RESOURCE_INSTANCE_ID);
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ Either<ActionStatus, ResponseFormat> addArtifactsRes = bl.addComponentInstanceArtifacts(service, resourceInstance, USER_ID, false, null);
+ assertTrue(addArtifactsRes.isLeft());
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resourceInstance.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifacts);
+ assertTrue(deploymentArtifacts.size() == 2);
+
+ ArtifactDefinition heatDefinition = deploymentArtifacts.get(HEAT_LABEL.toLowerCase());
+ assertNotNull(heatDefinition);
+ assertEquals(getHeatArtifactDefinition(USER_ID, RESOURCE_ID_NO_HEAT_PARAMS, HEAT_LABEL, ARTIFACT_CREATION_TIME, false, false), heatDefinition);
+
+ ArtifactDefinition heatEnvDefinition = deploymentArtifacts.get(HEAT_ENV_LABEL.toLowerCase());
+ assertNotNull(heatEnvDefinition);
+
+ List<HeatParameterDefinition> heatParameters = heatDefinition.getHeatParameters();
+ assertNull(heatParameters);
+
+ List<HeatParameterDefinition> heatEnvParameters = heatEnvDefinition.getHeatParameters();
+ assertNull(heatEnvParameters);
+
+ }
+
+ @Test
+ public void testAddResourceInstanceArtifactsNoArtifacts() throws Exception {
+ ComponentInstance resourceInstance = new ComponentInstance();
+ resourceInstance.setName(RESOURCE_INSTANCE_ID);
+ resourceInstance.setComponentUid(RESOURCE_ID_NO_PAYLOAD);
+ resourceInstance.setUniqueId(RESOURCE_INSTANCE_ID);
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ Either<ActionStatus, ResponseFormat> addArtifactsRes = bl.addComponentInstanceArtifacts(service, resourceInstance, USER_ID, false, null);
+ assertTrue(addArtifactsRes.isLeft());
+
+ Map<String, ArtifactDefinition> deploymentArtifacts = resourceInstance.getDeploymentArtifacts();
+ assertNotNull(deploymentArtifacts);
+ assertTrue(deploymentArtifacts.size() == 0);
+
+ Mockito.verify(artifactBusinessLogic, Mockito.times(0)).addHeatEnvArtifact(Mockito.any(ArtifactDefinition.class), Mockito.any(ArtifactDefinition.class), Mockito.anyString(), Mockito.any(NodeTypeEnum.class), Mockito.anyBoolean());
+ }
+
+ private static ArtifactDefinition getHeatArtifactDefinition(String userId, String resourceId, String artifactName, long time, boolean placeholderOnly, boolean withHeatParams) {
+ ArtifactDefinition artifactInfo = new ArtifactDefinition();
+
+ artifactInfo.setArtifactName(artifactName + ".yml");
+ artifactInfo.setArtifactType("HEAT");
+ artifactInfo.setDescription("hdkfhskdfgh");
+ artifactInfo.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+
+ artifactInfo.setUserIdCreator(userId);
+ String fullName = "Jim H";
+ artifactInfo.setUpdaterFullName(fullName);
+ // long time = System.currentTimeMillis();
+ artifactInfo.setCreatorFullName(fullName);
+ artifactInfo.setCreationDate(time);
+ artifactInfo.setLastUpdateDate(time);
+ artifactInfo.setUserIdLastUpdater(userId);
+ artifactInfo.setArtifactLabel(HEAT_LABEL.toLowerCase());
+ artifactInfo.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, artifactInfo.getArtifactLabel()));
+
+ if (!placeholderOnly) {
+ artifactInfo.setEsId(artifactInfo.getUniqueId());
+ artifactInfo.setArtifactChecksum("UEsDBAoAAAAIAAeLb0bDQz");
+
+ if (withHeatParams) {
+ List<HeatParameterDefinition> heatParams = new ArrayList<HeatParameterDefinition>();
+ HeatParameterDefinition heatParam = new HeatParameterDefinition();
+ heatParam.setCurrentValue("11");
+ heatParam.setDefaultValue("22");
+ heatParam.setDescription("desc");
+ heatParam.setName("myParam");
+ heatParam.setType("number");
+ heatParams.add(heatParam);
+ artifactInfo.setHeatParameters(heatParams);
+ }
+ }
+
+ return artifactInfo;
+ }
+
+ private static ArtifactDefinition getArtifactPlaceHolder(String resourceId, String logicalName) {
+ ArtifactDefinition artifact = new ArtifactDefinition();
+
+ artifact.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, logicalName.toLowerCase()));
+ artifact.setArtifactLabel(logicalName.toLowerCase());
+
+ return artifact;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransitionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransitionTest.java
new file mode 100644
index 0000000000..48cd83a7c8
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransitionTest.java
@@ -0,0 +1,169 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.CertificationChangeTransition;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class CertificationChangeTransitionTest extends LifecycleTestBase {
+
+ private CertificationChangeTransition certifyTransitionObj = null;
+ private CertificationChangeTransition certificationCancelObj = null;
+ private CertificationChangeTransition certificationFailObj = null;
+
+ private ComponentsUtils componentsUtils = new ComponentsUtils();
+ private String resourceName = "myResource";
+ private User owner = null;
+
+ protected ArtifactsBusinessLogic artifactsManager = Mockito.mock(ArtifactsBusinessLogic.class);
+
+ Resource resource;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setup() {
+
+ super.setup();
+ componentsUtils.Init();
+ // checkout transition object
+ certifyTransitionObj = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentsUtils, lcOperation);
+ certifyTransitionObj.setConfigurationManager(configurationManager);
+
+ certificationCancelObj = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentsUtils, lcOperation);
+ certificationCancelObj.setConfigurationManager(configurationManager);
+
+ certificationFailObj = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentsUtils, lcOperation);
+ certificationFailObj.setConfigurationManager(configurationManager);
+
+ owner = new User("cs0008", "Carlos", "Santana", "cs@sdc.com", "DESIGNER", null);
+
+ when(artifactsManager.deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
+ resource = createResourceObject(false);
+ }
+
+ @Test
+ public void testStateValidationSuccess() {
+
+ Either<Boolean, ResponseFormat> changeStateResult = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ }
+
+ @Test
+ public void testStateValidationFail() {
+
+ // checkout
+ Either<Boolean, ResponseFormat> validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ assertValidationStateErrorResponse(validateBeforeTransition);
+
+ // checkin
+ validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertValidationStateErrorResponse(validateBeforeTransition);
+
+ // rfc
+ validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertValidationStateErrorResponse(validateBeforeTransition);
+
+ // certified
+ validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFIED);
+ assertValidationStateErrorResponse(validateBeforeTransition);
+
+ }
+
+ @Test
+ public void testRolesFail() {
+ Either<Resource, ResponseFormat> changeStateResult;
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+ Either<User, ResponseFormat> ownerResponse = certifyTransitionObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+
+ Either<Boolean, ResponseFormat> validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION);
+
+ modifier.setRole(Role.TESTER.name());
+ validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testRolesSuccess() {
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ Either<User, ResponseFormat> ownerResponse = certifyTransitionObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+
+ Either<Boolean, ResponseFormat> validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, owner, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(true, validateBeforeTransition.isLeft());
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.ADMIN.name());
+ validateBeforeTransition = certifyTransitionObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(true, validateBeforeTransition.isLeft());
+
+ }
+
+ private void assertValidationStateErrorResponse(Either<Boolean, ResponseFormat> validateBeforeTransition) {
+ assertEquals(validateBeforeTransition.isRight(), true);
+ ResponseFormat error = validateBeforeTransition.right().value();
+ Either<Resource, ResponseFormat> changeStateResult = Either.right(error);
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTest.java
new file mode 100644
index 0000000000..b45aa61de1
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTest.java
@@ -0,0 +1,230 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.CertificationRequestTransition;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.tosca.ToscaError;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.tosca.ToscaRepresentation;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class CertificationRequestTest extends LifecycleTestBase {
+
+ private ComponentsUtils componentsUtils = new ComponentsUtils();
+
+ protected ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder = Mockito.mock(ServiceDistributionArtifactsBuilder.class);
+ protected ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
+ protected ResourceOperation resourceOperation = Mockito.mock(ResourceOperation.class);
+ protected CapabilityOperation capabilityOperation = Mockito.mock(CapabilityOperation.class);
+ protected ToscaExportHandler toscaExportUtils = Mockito.mock(ToscaExportHandler.class);
+ @InjectMocks
+ private CertificationRequestTransition rfcObj = new CertificationRequestTransition(componentsUtils, lcOperation, serviceDistributionArtifactsBuilder, serviceBusinessLogic, capabilityOperation, toscaExportUtils);
+
+ protected ToscaRepresentation toscaRepresentation = Mockito.mock(ToscaRepresentation.class);
+
+ @Before
+ public void setup() {
+ Mockito.reset(resourceOperation);
+ MockitoAnnotations.initMocks(this);
+ super.setup();
+
+ // checkout transition object
+ rfcObj.setLifeCycleOperation(lcOperation);
+ // checkoutObj.setAuditingManager(iAuditingManager);
+ rfcObj.setConfigurationManager(configurationManager);
+ componentsUtils.Init();
+
+ Either<ToscaRepresentation, ToscaError> either = Either.left(toscaRepresentation);
+ when(toscaExportUtils.exportComponent(Mockito.anyObject())).thenReturn(either);
+
+ }
+
+ @Test
+ public void testCheckoutStateValidation() {
+ Either<? extends Component, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> ownerResponse = rfcObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ // changeStateResult = rfcObj.changeStateOperation(resource, user,
+ // owner, false);
+ changeStateResult = rfcObj.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ // changeStateResult = rfcObj.changeStateOperation(resource, user,
+ // owner, false);
+ changeStateResult = rfcObj.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ assertEquals(changeStateResult.isLeft(), true);
+ }
+
+ @Test
+ public void testAlreadyRfc() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ Either<User, ResponseFormat> ownerResponse = rfcObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = rfcObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testCertificationInProgress() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ Either<User, ResponseFormat> ownerResponse = rfcObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = rfcObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testAlreadyCertified() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ Either<User, ResponseFormat> ownerResponse = rfcObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = rfcObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFIED);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CERTIFIED, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testValidateAllResourceInstanceCertified_SuccessWithoutRI() {
+ Resource resource = new Resource();
+ Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified = rfcObj.validateAllResourceInstanceCertified(resource);
+ assertTrue(validateAllResourceInstanceCertified.isLeft());
+ }
+
+ @Test
+ public void testValidateAllResourceInstanceCertified_SuccessWithCertifiedResources() {
+ Resource resource = new Resource();
+ List<ComponentInstance> riList = new ArrayList<ComponentInstance>();
+ ComponentInstance ri = new ComponentInstance();
+ ri.setComponentVersion("2.0");
+ riList.add(ri);
+ resource.setComponentInstances(riList);
+
+ Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified = rfcObj.validateAllResourceInstanceCertified(resource);
+ assertTrue(validateAllResourceInstanceCertified.isLeft());
+ }
+
+ @Test
+ public void testValidateAllResourceInstanceCertified_FailWithUnCertifiedResourcesMinorVersion() {
+ Resource resource = createVFWithRI("0.3");
+
+ simulateCertifiedVersionExistForRI();
+
+ Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified = rfcObj.validateAllResourceInstanceCertified(resource);
+
+ assertTrue(validateAllResourceInstanceCertified.isRight());
+ ResponseFormat responseFormat = validateAllResourceInstanceCertified.right().value();
+ assertTrue(responseFormat.getStatus() == HttpStatus.SC_FORBIDDEN);
+ assertTrue(responseFormat.getMessageId().equals("SVC4559"));
+
+ }
+
+ @Test
+ public void testValidateAllResourceInstanceCertified_FailWithUnCertifiedResourcesMajorVersion() {
+ Resource resource = createVFWithRI("1.3");
+
+ simulateCertifiedVersionExistForRI();
+
+ Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified = rfcObj.validateAllResourceInstanceCertified(resource);
+
+ assertTrue(validateAllResourceInstanceCertified.isRight());
+ ResponseFormat responseFormat = validateAllResourceInstanceCertified.right().value();
+ assertTrue(responseFormat.getStatus() == HttpStatus.SC_FORBIDDEN);
+ assertTrue(responseFormat.getMessageId().equals("SVC4559"));
+
+ }
+
+ private void simulateCertifiedVersionExistForRI() {
+ Resource dummyResource = new Resource();
+ Either<List<Resource>, StorageOperationStatus> result = Either.left(new ArrayList<Resource>() {
+ {
+ add(dummyResource);
+ }
+ });
+ Mockito.when(resourceOperation.getResource(Mockito.anyString())).thenReturn(Either.left(dummyResource));
+ Mockito.when(resourceOperation.findLastCertifiedResourceByUUID(Mockito.any(Resource.class))).thenReturn(result);
+ }
+
+ private Resource createVFWithRI(String riVersion) {
+ Resource resource = new Resource();
+ List<ComponentInstance> riList = new ArrayList<ComponentInstance>();
+ ComponentInstance ri = new ComponentInstance();
+
+ ri.setComponentVersion(riVersion);
+ ri.setComponentUid("someUniqueId");
+ riList.add(ri);
+ resource.setComponentInstances(riList);
+ return resource;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckinTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckinTest.java
new file mode 100644
index 0000000000..e0d942e2bc
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckinTest.java
@@ -0,0 +1,170 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.lifecycle.CheckinTransition;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class CheckinTest extends LifecycleTestBase {
+
+ private CheckinTransition checkinObj = null;
+ private ComponentsUtils componentsUtils = new ComponentsUtils();
+
+ @Before
+ public void setup() {
+
+ super.setup();
+
+ // checkout transition object
+ checkinObj = new CheckinTransition(componentsUtils, lcOperation);
+ checkinObj.setLifeCycleOperation(lcOperation);
+ checkinObj.setConfigurationManager(configurationManager);
+ componentsUtils.Init();
+ }
+
+ @Test
+ public void testSimpleCheckin() {
+ Either<Boolean, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkinObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ changeStateResult = checkinObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ }
+
+ @Test
+ public void testSimpleServiceCheckin() {
+ Either<Boolean, ResponseFormat> changeStateResult;
+ Service service = createServiceObject(false);
+
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkinObj.getComponentOwner(service, ComponentTypeEnum.SERVICE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ changeStateResult = checkinObj.validateBeforeTransition(service, ComponentTypeEnum.SERVICE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ }
+
+ @Test
+ public void testCheckinTwiceValidation() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> owner = checkinObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(owner.isLeft());
+ // changeStateResult = checkinObj.changeStateOperation(resource, user,
+ // owner.left().value());
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkinObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner.left().value(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testServiceCheckinTwiceValidation() {
+ Either<Service, ResponseFormat> changeStateResult;
+ Service service = createServiceObject(false);
+
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> owner = checkinObj.getComponentOwner(service, ComponentTypeEnum.SERVICE);
+ assertTrue(owner.isLeft());
+
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkinObj.validateBeforeTransition(service, ComponentTypeEnum.SERVICE, user, owner.left().value(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertServiceResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, service.getName(), ComponentTypeEnum.SERVICE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testCheckoutByAnotherUserValidation() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkinObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ // changeStateResult = checkinObj.changeStateOperation(resource,
+ // modifier, owner);
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkinObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testServiceCheckoutByAnotherUserValidation() {
+ Either<Service, ResponseFormat> changeStateResult;
+ Service service = createServiceObject(false);
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkinObj.getComponentOwner(service, ComponentTypeEnum.SERVICE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkinObj.validateBeforeTransition(service, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertServiceResponse(changeStateResult, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, service.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
new file mode 100644
index 0000000000..4a81653e14
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.CheckoutTransition;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class CheckoutTest extends LifecycleTestBase {
+
+ private CheckoutTransition checkoutObj = null;
+ private ComponentsUtils componentsUtils = new ComponentsUtils();
+ @InjectMocks
+ ResourceBusinessLogic bl = new ResourceBusinessLogic();
+
+ @Before
+ public void setup() {
+
+ super.setup();
+
+ // checkout transition object
+ checkoutObj = new CheckoutTransition(componentsUtils, lcOperation);
+ checkoutObj.setLifeCycleOperation(lcOperation);
+ checkoutObj.setConfigurationManager(configurationManager);
+ componentsUtils.Init();
+
+ }
+
+ @Test
+ public void testCheckoutStateValidation() {
+ Either<? extends Component, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+ assertEquals(changeStateResult.isLeft(), true);
+
+ }
+
+ @Test
+ public void testAlreadyCheckout() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertEquals(changeStateResult.isRight(), true);
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testCertificationInProgress() {
+ Either<? extends Component, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testReadyForCertification() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+
+ // if modifier = owner
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ // changeStateResult = checkoutObj.changeStateOperation(resource, user,
+ // owner);
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertEquals(validateBeforeTransition.isLeft(), true);
+
+ // else
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+
+ // admin
+ modifier.setRole(Role.ADMIN.name());
+ // changeStateResult = checkoutObj.changeStateOperation(resource, user,
+ // owner);
+ validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertEquals(validateBeforeTransition.isLeft(), true);
+
+ // designer
+ modifier.setRole(Role.TESTER.name());
+ validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertEquals(changeStateResult.isRight(), true);
+ assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testRoles() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ // changeStateResult = checkoutObj.changeStateOperation(resource,
+ // modifier, owner);
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertEquals(validateBeforeTransition.isLeft(), true);
+
+ modifier.setRole(Role.TESTER.name());
+ // changeStateResult = checkoutObj.changeStateOperation(resource,
+ // modifier, owner);
+ validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION);
+
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/LifecycleTestBase.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/LifecycleTestBase.java
new file mode 100644
index 0000000000..734a3d9bde
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/LifecycleTestBase.java
@@ -0,0 +1,215 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.AuditingMockManager;
+import org.openecomp.sdc.be.auditing.api.IAuditingManager;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.LifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+import junit.framework.Assert;
+
+public class LifecycleTestBase {
+ private static Logger log = LoggerFactory.getLogger(LifecycleTestBase.class.getName());
+ @InjectMocks
+ protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ protected IAuditingManager iAuditingManager = null;
+ protected UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ protected LifecycleOperation lcOperation = Mockito.mock(LifecycleOperation.class);
+ protected ArtifactsBusinessLogic artifactsManager = Mockito.mock(ArtifactsBusinessLogic.class);;
+ protected User user = null;
+ protected Resource resourceResponse;
+ protected Service serviceResponse;
+ protected ConfigurationManager configurationManager = null;
+ protected ResponseFormatManager responseManager = null;
+
+ public void setup() {
+
+ ExternalConfiguration.setAppName("catalog-be");
+
+ // Init Configuration
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+
+ // Auditing
+ iAuditingManager = new AuditingMockManager("lll");
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ Either<User, ActionStatus> eitherGetUser = Either.left(user);
+ when(mockUserAdmin.getUser("jh003", false)).thenReturn(eitherGetUser);
+
+ // Servlet Context attributes
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ // when(servletContext.getAttribute(Constants.AUDITING_MANAGER)).thenReturn(iAuditingManager);
+ // when(servletContext.getAttribute(Constants.RESOURCE_OPERATION_MANAGER)).thenReturn(resourceOperation);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
+ when(webAppContext.getBean(LifecycleOperation.class)).thenReturn(lcOperation);
+ when(webAppContext.getBean(ArtifactsBusinessLogic.class)).thenReturn(artifactsManager);
+
+ // Resource Operation mock methods
+ // getCount
+
+ // createResource
+ resourceResponse = createResourceObject(true);
+ serviceResponse = createServiceObject(true);
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
+ Either<? extends Component, StorageOperationStatus> eitherCreateComponent = Either.left(resourceResponse);
+ when((Either<Resource, StorageOperationStatus>) lcOperation.checkoutComponent(Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(User.class), Mockito.any(Boolean.class)))
+ .thenAnswer(createAnswer(eitherCreate));
+ when(lcOperation.checkoutComponent(Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(User.class), Mockito.any(Boolean.class))).thenAnswer(createAnswer(eitherCreateComponent));
+
+ when((Either<Resource, StorageOperationStatus>) lcOperation.checkinComponent(Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(User.class), Mockito.any(Boolean.class)))
+ .thenAnswer(createAnswer(eitherCreate));
+
+ when((Either<Resource, StorageOperationStatus>) lcOperation.requestCertificationComponent(Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Resource.class), Mockito.any(User.class), Mockito.any(User.class), Mockito.any(Boolean.class)))
+ .thenAnswer(createAnswer(eitherCreate));
+ when(lcOperation.requestCertificationComponent(Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Component.class), Mockito.any(User.class), Mockito.any(User.class), Mockito.any(Boolean.class))).thenAnswer(createAnswer(eitherCreateComponent));
+
+ Either<User, StorageOperationStatus> getOwnerResult = Either.left(user);
+ when(lcOperation.getComponentOwner(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource), Mockito.any(Boolean.class))).thenReturn(getOwnerResult);
+ when(lcOperation.getComponentOwner(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Service), Mockito.any(Boolean.class))).thenReturn(getOwnerResult);
+
+ responseManager = ResponseFormatManager.getInstance();
+
+ }
+
+ public static <T> Answer<T> createAnswer(final T value) {
+ Answer<T> dummy = new Answer<T>() {
+ @Override
+ public T answer(InvocationOnMock invocation) throws Throwable {
+ return value;
+ }
+
+ };
+ return dummy;
+ }
+
+ protected Resource createResourceObject(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName("MyResourceName");
+ resource.addCategory("VoIP", "INfra");
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("yavivi");
+ resource.setIcon("MyIcon.jpg");
+
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug(gson.toJson(resource));
+ return resource;
+ }
+
+ protected Service createServiceObject(boolean b) {
+ Service service = new Service();
+ service.setName("MyServiceName");
+ service.addCategory("VoIP", null);
+ service.setDescription("My short description");
+ List<String> tgs = new ArrayList<String>();
+ tgs.add("test");
+ service.setTags(tgs);
+ List<String> template = new ArrayList<String>();
+ template.add("Root");
+ service.setContactId("aa0001");
+ service.setIcon("MyIcon.jpg");
+
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.debug(gson.toJson(service));
+ return service;
+ }
+
+ protected void assertResponse(Either<? extends Component, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
+ Assert.assertTrue(createResponse.isRight());
+ ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
+ ResponseFormat actualResponse = createResponse.right().value();
+ Assert.assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
+ Assert.assertEquals("assert error description", expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
+ }
+
+ protected void assertServiceResponse(Either<Service, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
+ Assert.assertTrue(createResponse.isRight());
+ ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
+ ResponseFormat actualResponse = createResponse.right().value();
+ Assert.assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
+ Assert.assertEquals("assert error description", expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
+ }
+
+ protected static ArtifactDefinition getArtifactPlaceHolder(String resourceId, String logicalName) {
+ ArtifactDefinition artifact = new ArtifactDefinition();
+
+ artifact.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, logicalName.toLowerCase()));
+ artifact.setArtifactLabel(logicalName.toLowerCase());
+
+ return artifact;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTest.java
new file mode 100644
index 0000000000..6cc0385667
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTest.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.lifecycle;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.be.components.lifecycle.UndoCheckoutTransition;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+public class UndoCheckoutTest extends LifecycleTestBase {
+
+ private UndoCheckoutTransition undoCheckoutObj = null;
+ private ComponentsUtils componentsUtils = new ComponentsUtils();
+
+ @Before
+ public void setup() {
+
+ super.setup();
+
+ // checkout transition object
+ undoCheckoutObj = new UndoCheckoutTransition(componentsUtils, lcOperation);
+ undoCheckoutObj.setLifeCycleOperation(lcOperation);
+ undoCheckoutObj.setConfigurationManager(configurationManager);
+ componentsUtils.Init();
+
+ }
+
+ @Test
+ public void testResourceNotCheckedOutValidation() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> ownerResponse = undoCheckoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+
+ Either<Boolean, ResponseFormat> validateBeforeTransition = undoCheckoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ validateBeforeTransition = undoCheckoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ validateBeforeTransition = undoCheckoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.CERTIFIED);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ resource.setLifecycleState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ validateBeforeTransition = undoCheckoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testDifferentResourceOwnerValidation() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject(false);
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+
+ Either<User, ResponseFormat> ownerResponse = undoCheckoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = undoCheckoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertEquals(validateBeforeTransition.isRight(), true);
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertEquals(changeStateResult.isRight(), true);
+
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogicTest.java
new file mode 100644
index 0000000000..104cd14e7a
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogicTest.java
@@ -0,0 +1,192 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.BaseConfDependentTest;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaHandler;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.distribution.AuditHandler;
+import org.openecomp.sdc.be.distribution.DistributionBusinessLogic;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse;
+import org.openecomp.sdc.be.distribution.api.client.TopicUnregistrationResponse;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+
+public class DistributionBusinessLogicTest extends BaseConfDependentTest {
+
+ @InjectMocks
+ DistributionBusinessLogic distributionBusinessLogic = Mockito.spy(DistributionBusinessLogic.class);
+
+ CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
+ AuditHandler auditHandler = Mockito.mock(AuditHandler.class);
+
+ @Test
+ public void testHandleRegistrationHappyScenario() {
+ CambriaErrorResponse okResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+ Mockito.when(cambriaHandler.registerToTopic(Mockito.anyCollection(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SubscriberTypeEnum.class))).thenReturn(okResponse);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", "myEnv");
+ distributionBusinessLogic.handleRegistration(responseWrapper, registrationRequest, auditHandler);
+
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.CONSUMER);
+ Mockito.verify(cambriaHandler, Mockito.times(0)).unRegisterFromTopic(Mockito.anyCollection(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SubscriberTypeEnum.class));
+
+ assertTrue(!responseWrapper.isEmpty());
+ Response response = responseWrapper.getInnerElement();
+ assertTrue(response.getStatus() == HttpStatus.SC_OK);
+
+ TopicRegistrationResponse okTopicResponse = (TopicRegistrationResponse) response.getEntity();
+
+ String expectedStatusTopicName = DistributionEngineInitTask.buildTopicName(configurationManager.getDistributionEngineConfiguration().getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ String actualStatusTopicName = okTopicResponse.getDistrStatusTopicName();
+ assertEquals(expectedStatusTopicName, actualStatusTopicName);
+
+ String expectedNotificationTopicName = DistributionEngineInitTask.buildTopicName(configurationManager.getDistributionEngineConfiguration().getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+ String actualNotificationTopicName = okTopicResponse.getDistrNotificationTopicName();
+ assertEquals(expectedNotificationTopicName, actualNotificationTopicName);
+
+ }
+
+ @Test
+ public void testHandleRegistrationFailedScenario() {
+ CambriaErrorResponse okResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+ CambriaErrorResponse errorResponse = new CambriaErrorResponse(CambriaOperationStatus.CONNNECTION_ERROR, HttpStatus.SC_SERVICE_UNAVAILABLE);
+ DistributionEngineConfiguration config = configurationManager.getDistributionEngineConfiguration();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", "myEnv");
+ String expectedStatusTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ String expectedNotificationTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+
+ Mockito.when(cambriaHandler.registerToTopic(config.getUebServers(), expectedStatusTopicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), SubscriberTypeEnum.PRODUCER)).thenReturn(okResponse);
+ Mockito.when(cambriaHandler.registerToTopic(config.getUebServers(), expectedNotificationTopicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), SubscriberTypeEnum.CONSUMER))
+ .thenReturn(errorResponse);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+
+ distributionBusinessLogic.handleRegistration(responseWrapper, registrationRequest, auditHandler);
+
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.CONSUMER);
+ Mockito.verify(cambriaHandler, Mockito.times(1)).unRegisterFromTopic(config.getUebServers(), expectedStatusTopicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), SubscriberTypeEnum.PRODUCER);
+
+ assertTrue(!responseWrapper.isEmpty());
+ Response response = responseWrapper.getInnerElement();
+ assertTrue(response.getStatus() == HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ }
+
+ @Test
+ public void testHandleUnRegistrationHappyScenario() {
+ CambriaErrorResponse okResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+
+ Mockito.when(cambriaHandler.unRegisterFromTopic(Mockito.anyCollection(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SubscriberTypeEnum.class))).thenReturn(okResponse);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", "myEnv");
+ distributionBusinessLogic.handleUnRegistration(responseWrapper, registrationRequest, auditHandler);
+
+ Mockito.verify(distributionBusinessLogic, Mockito.times(0)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(0)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.CONSUMER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).unRegisterDistributionClientFromTopic(registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).unRegisterDistributionClientFromTopic(registrationRequest, SubscriberTypeEnum.CONSUMER);
+
+ Mockito.verify(cambriaHandler, Mockito.times(2)).unRegisterFromTopic(Mockito.anyCollection(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SubscriberTypeEnum.class));
+
+ assertTrue(!responseWrapper.isEmpty());
+ Response response = responseWrapper.getInnerElement();
+ assertTrue(response.getStatus() == HttpStatus.SC_OK);
+
+ TopicUnregistrationResponse okTopicUnregisterResponse = (TopicUnregistrationResponse) response.getEntity();
+
+ String expectedStatusTopicName = DistributionEngineInitTask.buildTopicName(configurationManager.getDistributionEngineConfiguration().getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ String actualStatusTopicName = okTopicUnregisterResponse.getDistrStatusTopicName();
+ assertEquals(expectedStatusTopicName, actualStatusTopicName);
+
+ String expectedNotificationTopicName = DistributionEngineInitTask.buildTopicName(configurationManager.getDistributionEngineConfiguration().getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+ String actualNotificationTopicName = okTopicUnregisterResponse.getDistrNotificationTopicName();
+ assertEquals(expectedNotificationTopicName, actualNotificationTopicName);
+
+ assertEquals(okTopicUnregisterResponse.getNotificationUnregisterResult(), CambriaOperationStatus.OK);
+ assertEquals(okTopicUnregisterResponse.getStatusUnregisterResult(), CambriaOperationStatus.OK);
+
+ }
+
+ @Test
+ public void testHandleUnRegistrationFailedScenario() {
+ CambriaErrorResponse okResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
+ CambriaErrorResponse errorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", "myEnv");
+ DistributionEngineConfiguration config = configurationManager.getDistributionEngineConfiguration();
+ String expectedStatusTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), registrationRequest.getDistrEnvName());
+ String expectedNotificationTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), registrationRequest.getDistrEnvName());
+ Mockito.when(cambriaHandler.unRegisterFromTopic(config.getUebServers(), expectedStatusTopicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), SubscriberTypeEnum.PRODUCER)).thenReturn(okResponse);
+ Mockito.when(cambriaHandler.unRegisterFromTopic(config.getUebServers(), expectedNotificationTopicName, config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(), SubscriberTypeEnum.CONSUMER))
+ .thenReturn(errorResponse);
+
+ distributionBusinessLogic.handleUnRegistration(responseWrapper, registrationRequest, auditHandler);
+
+ Mockito.verify(distributionBusinessLogic, Mockito.times(0)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(0)).registerDistributionClientToTopic(responseWrapper, registrationRequest, SubscriberTypeEnum.CONSUMER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).unRegisterDistributionClientFromTopic(registrationRequest, SubscriberTypeEnum.PRODUCER);
+ Mockito.verify(distributionBusinessLogic, Mockito.times(1)).unRegisterDistributionClientFromTopic(registrationRequest, SubscriberTypeEnum.CONSUMER);
+
+ assertTrue(!responseWrapper.isEmpty());
+ Response response = responseWrapper.getInnerElement();
+ assertTrue(response.getStatus() == HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ TopicUnregistrationResponse okTopicUnregisterResponse = (TopicUnregistrationResponse) response.getEntity();
+
+ String actualStatusTopicName = okTopicUnregisterResponse.getDistrStatusTopicName();
+ assertEquals(expectedStatusTopicName, actualStatusTopicName);
+
+ String actualNotificationTopicName = okTopicUnregisterResponse.getDistrNotificationTopicName();
+ assertEquals(expectedNotificationTopicName, actualNotificationTopicName);
+
+ assertEquals(okTopicUnregisterResponse.getNotificationUnregisterResult(), CambriaOperationStatus.AUTHENTICATION_ERROR);
+ assertEquals(okTopicUnregisterResponse.getStatusUnregisterResult(), CambriaOperationStatus.OK);
+
+ }
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.reset(cambriaHandler);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java
new file mode 100644
index 0000000000..d6274ad90e
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/servlet/DistributionServletTest.java
@@ -0,0 +1,159 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.distribution.servlet;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
+import org.openecomp.sdc.be.distribution.AuditHandler;
+import org.openecomp.sdc.be.distribution.DistributionBusinessLogic;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.distribution.api.client.TopicRegistrationResponse;
+import org.openecomp.sdc.be.distribution.servlet.DistributionServlet;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DistributionServletTest extends JerseyTest {
+
+ public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ public static final HttpSession session = Mockito.mock(HttpSession.class);
+ public static final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ public static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ public static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
+ public static final ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
+ public static final DistributionBusinessLogic distributionBusinessLogic = Mockito.mock(DistributionBusinessLogic.class);
+ public static final DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
+
+ public static final String ENV_NAME = "myEnv";
+ public static final String NOTIFICATION_TOPIC = ENV_NAME + "_Notification";
+ public static final String STATUS_TOPIC = ENV_NAME + "_Status";
+
+ @BeforeClass
+ public static void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+ when(request.getSession()).thenReturn(session);
+ when(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER)).thenReturn("myApplicationInstanceID");
+
+ when(session.getServletContext()).thenReturn(servletContext);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(DistributionBusinessLogic.class)).thenReturn(distributionBusinessLogic);
+ when(distributionBusinessLogic.getDistributionEngine()).thenReturn(distributionEngine);
+ when(distributionEngine.isEnvironmentAvailable(ENV_NAME)).thenReturn(StorageOperationStatus.OK);
+ when(distributionEngine.isEnvironmentAvailable()).thenReturn(StorageOperationStatus.OK);
+
+ mockBusinessLogicResponse();
+
+ }
+
+ private static void mockBusinessLogicResponse() {
+ // Mock Register
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ Wrapper<Response> responseWrapper = (Wrapper<Response>) args[0];
+ TopicRegistrationResponse okTopicResponse = new TopicRegistrationResponse();
+ okTopicResponse.setDistrNotificationTopicName(NOTIFICATION_TOPIC);
+ okTopicResponse.setDistrStatusTopicName(STATUS_TOPIC);
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(okTopicResponse).build());
+
+ return true;
+ }
+ }).when(distributionBusinessLogic).handleRegistration(Mockito.any(Wrapper.class), Mockito.any(RegistrationRequest.class), Mockito.any(AuditHandler.class));
+
+ // Mock Unregister
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ Wrapper<Response> responseWrapper = (Wrapper<Response>) args[0];
+ TopicRegistrationResponse okTopicResponse = new TopicRegistrationResponse();
+ okTopicResponse.setDistrNotificationTopicName(NOTIFICATION_TOPIC);
+ okTopicResponse.setDistrStatusTopicName(STATUS_TOPIC);
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(okTopicResponse).build());
+
+ return true;
+ }
+ }).when(distributionBusinessLogic).handleUnRegistration(Mockito.any(Wrapper.class), Mockito.any(RegistrationRequest.class), Mockito.any(AuditHandler.class));
+ }
+
+ @Test
+ public void registerSuccessTest() {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", ENV_NAME);
+ Response response = target().path("/v1/registerForDistribution").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(registrationRequest)), Response.class);
+ assertTrue(response.getStatus() == HttpStatus.SC_OK);
+
+ }
+
+ @Test
+ public void unRegisterSuccessTest() {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ RegistrationRequest registrationRequest = new RegistrationRequest("myPublicKey", ENV_NAME);
+ Response response = target().path("/v1/unRegisterForDistribution").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(registrationRequest)), Response.class);
+ assertTrue(response.getStatus() == HttpStatus.SC_OK);
+
+ }
+
+ @Override
+ protected Application configure() {
+
+ ResourceConfig resourceConfig = new ResourceConfig(DistributionServlet.class);
+ forceSet(TestProperties.CONTAINER_PORT, "0");
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ bind(request).to(HttpServletRequest.class);
+ }
+ });
+
+ return resourceConfig;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/GenerateEcompErrorFileTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/GenerateEcompErrorFileTest.java
new file mode 100644
index 0000000000..e4f46dd4dd
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/GenerateEcompErrorFileTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ecomp;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.common.config.EcompClassification;
+import org.openecomp.sdc.common.config.EcompErrorCode;
+import org.openecomp.sdc.common.config.EcompErrorEnum;
+import org.openecomp.sdc.common.config.generation.GenerateEcompErrorsCsv;
+
+import static org.junit.Assert.assertTrue;
+
+public class GenerateEcompErrorFileTest {
+
+ @Test
+ public void verifyNoDuplicatesInEcompErrorCodes() {
+
+ EcompErrorEnum[] ecompErrorEnums = EcompErrorEnum.values();
+
+ Map<EcompErrorCode, List<EcompClassification>> map = new HashMap<EcompErrorCode, List<EcompClassification>>();
+ for (EcompErrorEnum ecompErrorEnum : ecompErrorEnums) {
+
+ List<EcompClassification> list = map.get(ecompErrorEnum.getEcompErrorCode());
+ if (list == null) {
+ list = new ArrayList<>();
+
+ list.add(ecompErrorEnum.getClassification());
+
+ map.put(ecompErrorEnum.getEcompErrorCode(), list);
+ } else {
+ if (list.contains(ecompErrorEnum.getClassification())) {
+ assertTrue(ecompErrorEnum.getEcompErrorCode() + " already defined with ecomp classification " + ecompErrorEnum.getClassification(), false);
+ } else {
+ list.add(ecompErrorEnum.getClassification());
+ }
+
+ }
+
+ }
+
+ }
+
+ @Test
+ public void generateEcompErrorFileInTarget() {
+
+ GenerateEcompErrorsCsv ecompErrorsCsv = new GenerateEcompErrorsCsv();
+ boolean result = ecompErrorsCsv.generateEcompErrorsCsvFile("target", false);
+ assertTrue("check result from file generation", result);
+
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java
new file mode 100644
index 0000000000..d41e95da9d
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/AbstractValidationsServletTest.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import fj.data.Either;
+
+import static org.mockito.Mockito.mock;
+
+public class AbstractValidationsServletTest {
+ private static AbstractValidationsServlet servlet = mock(AbstractValidationsServlet.class);
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetScarFromPayload() {
+
+ String payloadName = "valid_vf.csar";
+ String rootPath = System.getProperty("user.dir");
+ Path path = null;
+ byte[] data = null;
+ String payloadData = null;
+ Either<Map<String, byte[]>, ResponseFormat> returnValue = null;
+ try {
+ path = Paths.get(rootPath + "/src/test/resources/valid_vf.csar");
+ data = Files.readAllBytes(path);
+ payloadData = Base64.encodeBase64String(data);
+ UploadResourceInfo resourceInfo = new UploadResourceInfo();
+ resourceInfo.setPayloadName(payloadName);
+ resourceInfo.setPayloadData(payloadData);
+ Method privateMethod = null;
+ privateMethod = AbstractValidationsServlet.class.getDeclaredMethod("getScarFromPayload", UploadResourceInfo.class);
+ privateMethod.setAccessible(true);
+ returnValue = (Either<Map<String, byte[]>, ResponseFormat>) privateMethod.invoke(servlet, resourceInfo);
+ } catch (IOException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ Assert.assertTrue(returnValue.isLeft());
+ Map<String, byte[]> csar = returnValue.left().value();
+ Assert.assertTrue(csar != null);
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ApplicationConfig.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ApplicationConfig.java
new file mode 100644
index 0000000000..2dda0f5d14
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ApplicationConfig.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.MultiPart;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.servlets.ResourceUploadServlet;
+
+public class ApplicationConfig extends Application {
+
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> resources = new HashSet<Class<?>>();
+
+ // Add your resources.
+ resources.add(ResourceUploadServlet.class);
+ resources.add(MultiPart.class);
+ resources.add(FormDataContentDisposition.class);
+
+ final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+
+ ResourceConfig resourceConfig = ResourceConfig.forApplication(this);
+
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ // TODO Auto-generated method stub
+ bind(request).to(HttpServletRequest.class);
+ }
+ });
+
+ return resources;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
new file mode 100644
index 0000000000..5e1e4577e2
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.servlets.ResourcesServlet;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class ResourceServletTest extends JerseyTest {
+ public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ public static final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
+ final static HttpSession session = Mockito.mock(HttpSession.class);
+ final static ServletContext servletContext = Mockito.mock(ServletContext.class);
+ final static WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ final static WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
+ public static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
+ public static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
+ public static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ @BeforeClass
+ public static void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(servletContext);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(ResourceImportManager.class)).thenReturn(resourceImportManager);
+ when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
+ when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
+ when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
+ String userId = "jh0003";
+ User user = new User();
+ user.setUserId(userId);
+ user.setRole(Role.ADMIN.name());
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+ when(userAdmin.getUser(userId, false)).thenReturn(eitherUser);
+ when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);
+
+ ImmutablePair<Resource, ActionStatus> pair = new ImmutablePair<Resource, ActionStatus>(new Resource(), ActionStatus.OK);
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> ret = Either.left(pair);
+ when(resourceImportManager.importUserDefinedResource(Mockito.anyString(), Mockito.any(UploadResourceInfo.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(ret);
+
+ }
+
+ @Before
+ public void beforeTest() {
+ Mockito.reset(componentUtils);
+
+ Mockito.doAnswer(new Answer<ResponseFormat>() {
+ public ResponseFormat answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ ActionStatus action = (ActionStatus) args[0];
+ ResponseFormat resp = (action == ActionStatus.OK) ? new ResponseFormat(HttpStatus.CREATED.value()) : new ResponseFormat(HttpStatus.INTERNAL_SERVER_ERROR.value());
+ return resp;
+ }
+ }).when(componentUtils).getResponseFormat(Mockito.any(ActionStatus.class));
+
+ }
+
+ @Test
+ public void testHappyScenarioTest() {
+ UploadResourceInfo validJson = buildValidJson();
+ setMD5OnRequest(true, validJson);
+ Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(validJson)), Response.class);
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.OK);
+ assertTrue(response.getStatus() == HttpStatus.CREATED.value());
+
+ }
+
+ @Test
+ public void testNonValidMd5Fail() {
+ UploadResourceInfo validJson = buildValidJson();
+
+ setMD5OnRequest(false, validJson);
+
+ Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(validJson)), Response.class);
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.INVALID_RESOURCE_CHECKSUM);
+ assertTrue(response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ }
+
+ @Test
+ public void testNonValidPayloadNameFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+ mdJson.setPayloadName("myCompute.xml");
+
+ runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_FILE_EXTENSION);
+
+ }
+
+ @Test
+ public void testNullPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+ mdJson.setPayloadData(null);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_PAYLOAD);
+
+ }
+
+ @Test
+ public void testNonYmlPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+ String payload = "{ json : { isNot : yaml } ";
+ encodeAndSetPayload(mdJson, payload);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_YAML_FILE);
+
+ }
+
+ @Test
+ public void testNonToscaPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+
+ String payload = "node_types: \r\n" + " org.openecomp.resource.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n" + " description: update update";
+ encodeAndSetPayload(mdJson, payload);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_TEMPLATE);
+
+ }
+
+ @Test
+ public void testServiceToscaPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+
+ String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + " org.openecomp.resource.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n" + " topology_template: thisIsService\r\n"
+ + " description: update update";
+
+ encodeAndSetPayload(mdJson, payload);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE);
+
+ }
+
+ @Test
+ public void testMultipleResourcesInPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+
+ String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + " org.openecomp.resource.importResource4test2:\r\n" + " derived_from: tosca.nodes.Root\r\n"
+ + " org.openecomp.resource.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n" + " description: update update";
+
+ encodeAndSetPayload(mdJson, payload);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_SINGLE_RESOURCE);
+
+ }
+
+ @Test
+ public void testNonValidNameSpaceInPayloadFail() {
+ UploadResourceInfo mdJson = buildValidJson();
+
+ String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + " org.openecomp.resourceX.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n" + " description: update update";
+
+ encodeAndSetPayload(mdJson, payload);
+ runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_NAMESPACE);
+
+ }
+
+ private void encodeAndSetPayload(UploadResourceInfo mdJson, String payload) {
+ Base64.encodeBase64(payload.getBytes());
+ mdJson.setPayloadData(payload);
+ }
+
+ private void runAndVerifyActionStatusError(UploadResourceInfo mdJson, ActionStatus invalidResourcePayload) {
+ setMD5OnRequest(true, mdJson);
+ Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(mdJson)), Response.class);
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
+ Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(invalidResourcePayload);
+ assertTrue(response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+
+ private void setMD5OnRequest(boolean isValid, UploadResourceInfo json) {
+ String md5 = (isValid) ? GeneralUtility.calculateMD5ByString(gson.toJson(json)) : "stam=";
+ when(request.getHeader(Constants.MD5_HEADER)).thenReturn(md5);
+
+ }
+
+ private UploadResourceInfo buildValidJson() {
+ UploadResourceInfo ret = new UploadResourceInfo();
+ ret.setName("MyCompute");
+ ret.setPayloadName("MyCompute.yml");
+ ret.addSubCategory("Application Layer 4+", "Application Servers");
+ ret.setDescription("ResourceDescription");
+ ret.setVendorName("VendorName");
+ ret.setVendorRelease("VendorRelease");
+ ret.setContactId("AT1234");
+ ret.setIcon("router");
+ ret.setTags(Arrays.asList(new String[] { "MyCompute" }));
+ ret.setPayloadData(
+ "dG9zY2FfZGVmaW5pdGlvbnNfdmVyc2lvbjogdG9zY2Ffc2ltcGxlX3lhbWxfMV8wXzANCm5vZGVfdHlwZXM6IA0KICBvcmcub3BlbmVjb21wLnJlc291cmNlLk15Q29tcHV0ZToNCiAgICBkZXJpdmVkX2Zyb206IHRvc2NhLm5vZGVzLlJvb3QNCiAgICBhdHRyaWJ1dGVzOg0KICAgICAgcHJpdmF0ZV9hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIHB1YmxpY19hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIG5ldHdvcmtzOg0KICAgICAgICB0eXBlOiBtYXANCiAgICAgICAgZW50cnlfc2NoZW1hOg0KICAgICAgICAgIHR5cGU6IHRvc2NhLmRhdGF0eXBlcy5uZXR3b3JrLk5ldHdvcmtJbmZvDQogICAgICBwb3J0czoNCiAgICAgICAgdHlwZTogbWFwDQogICAgICAgIGVudHJ5X3NjaGVtYToNCiAgICAgICAgICB0eXBlOiB0b3NjYS5kYXRhdHlwZXMubmV0d29yay5Qb3J0SW5mbw0KICAgIHJlcXVpcmVtZW50czoNCiAgICAgIC0gbG9jYWxfc3RvcmFnZTogDQogICAgICAgICAgY2FwYWJpbGl0eTogdG9zY2EuY2FwYWJpbGl0aWVzLkF0dGFjaG1lbnQNCiAgICAgICAgICBub2RlOiB0b3NjYS5ub2Rlcy5CbG9ja1N0b3JhZ2UNCiAgICAgICAgICByZWxhdGlvbnNoaXA6IHRvc2NhLnJlbGF0aW9uc2hpcHMuQXR0YWNoZXNUbw0KICAgICAgICAgIG9jY3VycmVuY2VzOiBbMCwgVU5CT1VOREVEXSAgDQogICAgY2FwYWJpbGl0aWVzOg0KICAgICAgaG9zdDogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5Db250YWluZXINCiAgICAgICAgdmFsaWRfc291cmNlX3R5cGVzOiBbdG9zY2Eubm9kZXMuU29mdHdhcmVDb21wb25lbnRdIA0KICAgICAgZW5kcG9pbnQgOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuRW5kcG9pbnQuQWRtaW4gDQogICAgICBvczogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5PcGVyYXRpbmdTeXN0ZW0NCiAgICAgIHNjYWxhYmxlOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuU2NhbGFibGUNCiAgICAgIGJpbmRpbmc6DQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5uZXR3b3JrLkJpbmRhYmxl");
+ return ret;
+ }
+
+ @Override
+ protected Application configure() {
+
+ ResourceConfig resourceConfig = new ResourceConfig(ResourcesServlet.class);
+ forceSet(TestProperties.CONTAINER_PORT, "0");
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ bind(request).to(HttpServletRequest.class);
+ }
+ });
+
+ return resourceConfig;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceUploadServletTest.java
new file mode 100644
index 0000000000..252e9d8fbc
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceUploadServletTest.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.resources.api.IResourceUploader;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.servlets.ResourceUploadServlet;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+
+public class ResourceUploadServletTest extends JerseyTest {
+ private static Logger log = LoggerFactory.getLogger(ResourceUploadServletTest.class.getName());
+ final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ final HttpSession session = Mockito.mock(HttpSession.class);
+ final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
+ final IResourceUploader iResourceUploader = Mockito.mock(IResourceUploader.class);
+ final AuditingManager iAuditingManager = Mockito.mock(AuditingManager.class);
+
+ Gson gson = new Gson();
+
+ public void zipDirectory() {
+
+ }
+
+ @Before
+ public void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ // when(servletContext.getAttribute(Constants.AUDITING_MANAGER)).thenReturn(iAuditingManager);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(IResourceUploader.class)).thenReturn(iResourceUploader);
+ when(iResourceUploader.saveArtifact((ESArtifactData) anyObject(), eq(true))).thenReturn(ResourceUploadStatus.OK);
+ when(webApplicationContext.getBean(AuditingManager.class)).thenReturn(iAuditingManager);
+ }
+
+ @Override
+ protected Application configure() {
+
+ ResourceConfig resourceConfig = new ResourceConfig(ResourceUploadServlet.class);
+
+ resourceConfig.register(MultiPartFeature.class);
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ // The below code was cut-pasted to here from setup() because
+ // due to it now has
+ // to be executed during servlet initialization
+ bind(request).to(HttpServletRequest.class);
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(servletContext);
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ for (String mandatoryHeader : configurationManager.getConfiguration().getIdentificationHeaderFields()) {
+
+ when(request.getHeader(mandatoryHeader)).thenReturn(mandatoryHeader);
+
+ }
+
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ }
+ });
+
+ return resourceConfig;
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ public class DelegatingServletInputStream extends ServletInputStream {
+
+ private final InputStream sourceStream;
+
+ /**
+ * Create a DelegatingServletInputStream for the given source stream.
+ *
+ * @param sourceStream
+ * the source stream (never <code>null</code>)
+ */
+ public DelegatingServletInputStream(InputStream sourceStream) {
+ // Assert.notNull(sourceStream,
+ // "Source InputStream must not be null");
+ this.sourceStream = sourceStream;
+ }
+
+ /**
+ * Return the underlying source stream (never <code>null</code>).
+ */
+ public final InputStream getSourceStream() {
+ return this.sourceStream;
+ }
+
+ public int read() throws IOException {
+ return this.sourceStream.read();
+ }
+
+ public void close() throws IOException {
+ super.close();
+ this.sourceStream.close();
+ }
+
+ }
+
+ @Test
+ public void testMultipart() {
+ FileDataBodyPart filePart = new FileDataBodyPart("resourceZip", new File("src/test/resources/config/normative-types-root.zip"));
+
+ List<String> tags = new ArrayList<String>();
+ tags.add("tag1");
+ tags.add("tag2");
+ UploadResourceInfo resourceInfo = new UploadResourceInfo("payload", "normative-types-root.yml", "my_description", "category/mycategory", tags, null);
+
+ FormDataBodyPart metadataPart = new FormDataBodyPart("resourceMetadata", gson.toJson(resourceInfo), MediaType.APPLICATION_JSON_TYPE);
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.bodyPart(metadataPart);
+
+ Response response = target().path("/v1/catalog/upload/" + ResourceUploadServlet.NORMATIVE_TYPE_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+ log.debug("{}", response);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
new file mode 100644
index 0000000000..420cbcca6b
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
@@ -0,0 +1,154 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.servlets.TypesUploadServlet;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.web.context.WebApplicationContext;
+
+import fj.data.Either;
+
+public class TypesUploadServletTest extends JerseyTest {
+
+ public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ public static final HttpSession session = Mockito.mock(HttpSession.class);
+ public static final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ public static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ public static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
+ public static final CapabilityTypeImportManager importManager = Mockito.mock(CapabilityTypeImportManager.class);
+ public static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
+ public static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
+ public static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
+ public static final ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
+
+ @BeforeClass
+ public static void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(CapabilityTypeImportManager.class)).thenReturn(importManager);
+ when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
+ when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
+ when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
+ String userId = "jh0003";
+ User user = new User();
+ user.setUserId(userId);
+ user.setRole(Role.ADMIN.name());
+ Either<User, ActionStatus> eitherUser = Either.left(user);
+ when(userAdmin.getUser(userId, false)).thenReturn(eitherUser);
+ when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);
+ when(responseFormat.getStatus()).thenReturn(HttpStatus.CREATED_201.getStatusCode());
+ when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(responseFormat);
+
+ }
+
+ @Test
+ public void creatingCapabilityTypeSuccessTest() {
+ List<CapabilityTypeDefinition> emptyList = new ArrayList<CapabilityTypeDefinition>();
+ Either<List<CapabilityTypeDefinition>, ResponseFormat> either = Either.left(emptyList);
+ when(importManager.createCapabilityTypes(Mockito.anyString())).thenReturn(either);
+ FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ Response response = target().path("/v1/catalog/uploadType/capability").request(MediaType.APPLICATION_JSON).post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertTrue(response.getStatus() == HttpStatus.CREATED_201.getStatusCode());
+
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ @Override
+ protected Application configure() {
+ ResourceConfig resourceConfig = new ResourceConfig(TypesUploadServlet.class);
+
+ resourceConfig.register(MultiPartFeature.class);
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ // The below code was cut-pasted to here from setup() because
+ // due to it now has
+ // to be executed during servlet initialization
+ bind(request).to(HttpServletRequest.class);
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(servletContext);
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ for (String mandatoryHeader : configurationManager.getConfiguration().getIdentificationHeaderFields()) {
+
+ when(request.getHeader(mandatoryHeader)).thenReturn(mandatoryHeader);
+
+ }
+
+ when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+ }
+ });
+
+ return resourceConfig;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/UserAdminServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/UserAdminServletTest.java
new file mode 100644
index 0000000000..ed69f104d2
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/UserAdminServletTest.java
@@ -0,0 +1,148 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.servlets.UserAdminServlet;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.UserRoleEnum;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+
+import fj.data.Either;
+
+public class UserAdminServletTest extends JerseyTest {
+
+ final static HttpServletRequest request = mock(HttpServletRequest.class);
+ final static HttpSession session = mock(HttpSession.class);
+ final static ServletContext servletContext = mock(ServletContext.class);
+ final static WebAppContextWrapper webAppContextWrapper = mock(WebAppContextWrapper.class);
+ final static WebApplicationContext webApplicationContext = mock(WebApplicationContext.class);
+ final static UserBusinessLogic userAdminManager = spy(UserBusinessLogic.class);
+ final static AuditingManager auditingManager = mock(AuditingManager.class);
+ final static ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ final static ResponseFormat okResponseFormat = mock(ResponseFormat.class);
+
+ final static String ADMIN_ATT_UID = "jh0003";
+ Gson gson = new Gson();
+
+ @BeforeClass
+ public static void setup() {
+ ExternalConfiguration.setAppName("catalog-be");
+
+ when(session.getServletContext()).thenReturn(servletContext);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
+ when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+
+ when(webApplicationContext.getBean(UserBusinessLogic.class)).thenReturn(userAdminManager);
+ when(webApplicationContext.getBean(ComponentsUtils.class)).thenReturn(componentsUtils);
+ when(componentsUtils.getAuditingManager()).thenReturn(auditingManager);
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(okResponseFormat);
+ when(okResponseFormat.getStatus()).thenReturn(HttpStatus.OK.value());
+
+ }
+
+ @Before
+ public void beforeTest() {
+ reset(userAdminManager);
+ doReturn(buildEitherUser(ADMIN_ATT_UID, true)).when(userAdminManager).getUser(ADMIN_ATT_UID, false);
+
+ reset(request);
+ when(request.getSession()).thenReturn(session);
+ when(request.getHeader("USER_ID")).thenReturn(ADMIN_ATT_UID);
+ }
+
+ /*
+ * @Test public void deactivateUserSuccessfullyTest(){ String userToDeleteUserId = "admin1"; User adminUser = new User(); adminUser.setUserId(ADMIN_ATT_UID); Either<User, ActionStatus> eitherActiveUser = buildEitherUser(userToDeleteUserId, true);
+ * User userToDelete = eitherActiveUser.left().value(); doReturn(eitherActiveUser).when(userAdminManager).getUser( userToDeleteUserId);
+ *
+ * Either<User, ActionStatus> eitherInactiveUser = buildEitherUser(userToDeleteUserId, false); doReturn(eitherInactiveUser).when(userAdminManager).deActivateUser( adminUser, userToDelete.getUserId());
+ *
+ *
+ * Response response = target().path("/v1/user/"+userToDeleteUserId).request().delete(); assertTrue(response.getStatus() == HttpStatus.OK.value()); verify(userAdminManager, times(1)).deActivateUser(adminUser, userToDelete.getUserId()); }
+ *
+ *
+ * @Test public void forceDeleteUserSuccessfullyTest(){ String userToDeleteUserId = "admin1"; when(request.getHeader(User.FORCE_DELETE_HEADER_FLAG)).thenReturn(User. FORCE_DELETE_HEADER_FLAG);
+ *
+ * User adminUser = new User(); adminUser.setUserId(ADMIN_ATT_UID);
+ *
+ * Either<User, ActionStatus> eitherActiveUser = buildEitherUser(userToDeleteUserId, true); User userToDelete = eitherActiveUser.left().value(); doReturn(eitherActiveUser).when(userAdminManager).getUser( userToDeleteUserId);
+ *
+ * Either<User, ActionStatus> eitherUser = buildEitherUser(userToDeleteUserId, true); doReturn(eitherUser).when(userAdminManager).deleteUser(userToDelete. getUserId());
+ *
+ *
+ * Response response = target().path("/v1/user/"+userToDeleteUserId).request().delete(); assertTrue(response.getStatus() == HttpStatus.OK.value()); verify(userAdminManager, times(0)).deActivateUser(adminUser, userToDelete.getUserId());
+ * verify(userAdminManager, times(1)).deleteUser(userToDelete.getUserId()); }
+ */
+
+ @Override
+ protected Application configure() {
+
+ ResourceConfig resourceConfig = new ResourceConfig(UserAdminServlet.class);
+
+ resourceConfig.register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ bind(request).to(HttpServletRequest.class);
+ }
+ });
+
+ return resourceConfig;
+ }
+
+ private static Either<User, ActionStatus> buildEitherUser(String userId, boolean isActive) {
+ User user = new User();
+ user.setUserId(userId);
+ user.setRole(UserRoleEnum.ADMIN.getName());
+ if (!isActive) {
+ user.setStatus(UserStatusEnum.INACTIVE);
+ }
+ return Either.left(user);
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserAdminManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserAdminManagerTest.java
new file mode 100644
index 0000000000..4b01b4fd61
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserAdminManagerTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.api.IUsersDAO;
+import org.openecomp.sdc.be.dao.impl.Neo4jUsersDAO;
+import org.openecomp.sdc.be.resources.data.UserData;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+public class UserAdminManagerTest {
+
+ final IUsersDAO usersDao = Mockito.mock(Neo4jUsersDAO.class);
+ Gson gson;
+
+ @Before
+ public void setup() {
+ Either<UserData, ActionStatus> eitherOk = Either.right(ActionStatus.OK);
+ gson = new GsonBuilder().setPrettyPrinting().create();
+ when(usersDao.getUserData(anyString())).thenReturn(eitherOk);
+ when(usersDao.saveUserData((UserData) anyObject())).thenReturn(ActionStatus.OK);
+ when(usersDao.updateUserData((UserData) anyObject())).thenReturn(ActionStatus.OK);
+ when(usersDao.deleteUserData(anyString())).thenReturn(ActionStatus.OK);
+ }
+
+ // @Test
+ // public void testCreateUser() {
+ // String json = "{\"firstName\": \"James\",\"lastName\":
+ // \"Brown\",\"userId\": \"jb1234u\",\"email\":
+ // \"jb1234u@sdc.com\",\"role\": \"ADMIN\"}";
+ // UserData user = gson.fromJson(json, UserData.class);
+ // Either<UserData,ActionStatus> either =
+ // UserAdminManager.getInstance().createUser(user);
+ // assertTrue(either.isRight());
+ // assertEquals(ActionStatus.OK, either.right().value());
+ // }
+ //
+ //
+ // @Test
+ // public void testCreateUserInvalidEmail() {
+ // String json = "{\"firstName\": \"James\",\"lastName\":
+ // \"Brown\",\"userId\": \"jb1234u\",\"email\": \"@sdc.com\",\"role\":
+ // \"ADMIN\"}";
+ // UserData user = gson.fromJson(json, UserData.class);
+ // Either<UserData,ActionStatus> either =
+ // UserAdminManager.getInstance().createUser(user);
+ // assertTrue(either.isRight());
+ // assertEquals(ActionStatus.INVALID_EMAIL_ADDRESS, either.right().value());
+ // }
+ //
+ // @Test
+ // public void testCreateUserInvalidRole() {
+ // String json = "{\"firstName\": \"James\",\"lastName\":
+ // \"Brown\",\"userId\": \"jb1234u\",\"email\":
+ // \"jb1234u@sdc.com\",\"role\": \"MIN\"}";
+ // UserData user = gson.fromJson(json, UserData.class);
+ // Either<UserData,ActionStatus> either =
+ // UserAdminManager.getInstance().createUser(user);
+ // assertTrue(either.isRight());
+ // assertEquals(ActionStatus.INVALID_EMAIL_ADDRESS, either.right().value());
+ // }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java
new file mode 100644
index 0000000000..bf87033bfe
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/common/transaction/mngr/SdncTransactionTest.java
@@ -0,0 +1,437 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.transaction.mngr;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.common.transaction.api.IDBAction;
+import org.openecomp.sdc.common.transaction.api.RollbackHandler;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionCodeEnum;
+import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionStatusEnum;
+import org.openecomp.sdc.common.transaction.mngr.CommitManager;
+import org.openecomp.sdc.common.transaction.mngr.TransactionSdncImpl;
+import org.slf4j.Logger;
+
+import fj.data.Either;
+
+public class SdncTransactionTest {
+ private static ESCatalogDAO esCatalogDao = Mockito.mock(ESCatalogDAO.class);
+ private static TitanGenericDao titanGenericDao = Mockito.mock(TitanGenericDao.class);
+ private static Logger log = Mockito.spy(Logger.class);
+ private static int transactionId = 0;
+ private static ConfigurationManager configurationManager;
+
+ public enum TestAction {
+ TitanAction, Rollback, GeneralAction
+ }
+
+ public enum TestResponse {
+ TitanResponseSuccess, GeneralSuccess
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ TransactionSdncImpl.setLog(log);
+ CommitManager.setLog(log);
+ RollbackHandler.setLog(log);
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+ }
+
+ @Before
+ public void beforeTest() {
+ reset(log);
+ reset(esCatalogDao);
+ reset(titanGenericDao);
+ }
+
+ @Test
+ public void testInvokeTitanAction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+
+ doBasicTitanAction(transactionId, tx, false, true);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.OPEN);
+ }
+
+ @Test
+ public void testInvokeESAction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+
+ doESAddArtifactAction(transactionId, tx, true, true);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.OPEN);
+ }
+
+ @Test
+ public void testfinishTransaction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doFinishTransaction(transactionId, tx, true);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+ }
+
+ @Test
+ public void testFinishOnClosedTransaction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doFinishTransaction(transactionId, tx, true);
+
+ TransactionCodeEnum finishTransaction = tx.finishTransaction();
+ assertTrue(finishTransaction == TransactionCodeEnum.TRANSACTION_CLOSED);
+ // verify(log).error(LogMessages.COMMIT_ON_CLOSED_TRANSACTION,
+ // transactionId, TransactionStatusEnum.CLOSED.name(),
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, TransactionStatusEnum.CLOSED.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+
+ }
+
+ @Test
+ public void testCallingLastActionTwice() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doBasicTitanAction(transactionId, tx, true, true);
+ Either<TestResponse, TransactionCodeEnum> doBasicTitanAction = doBasicTitanAction(transactionId, tx, true, false);
+ assertTrue(doBasicTitanAction.isRight());
+ assertTrue(tx.getStatus() != TransactionStatusEnum.OPEN);
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, DBTypeEnum.TITAN.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ // verify(log).error( LogMessages.DOUBLE_FINISH_FLAG_ACTION,
+ // transactionId, DBTypeEnum.TITAN.name(), TransactionUtils.DUMMY_USER,
+ // ActionTypeEnum.ADD_ARTIFACT.name());
+ }
+
+ @Test
+ public void testActionOnClosedTransaction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doFinishTransaction(transactionId, tx, true);
+
+ Either<DBActionCodeEnum, TransactionCodeEnum> eitherESResult = tx.invokeESAction(false, ESActionTypeEnum.ADD_ARTIFACT, createDummyArtifactData());
+ assertTrue(eitherESResult.isRight());
+ assertTrue(eitherESResult.right().value() == TransactionCodeEnum.TRANSACTION_CLOSED);
+
+ Either<Object, TransactionCodeEnum> eitherTitanResult = tx.invokeTitanAction(false, createBasicAction(TestAction.TitanAction, TestResponse.TitanResponseSuccess));
+ assertTrue(eitherTitanResult.isRight());
+ assertTrue(eitherTitanResult.right().value() == TransactionCodeEnum.TRANSACTION_CLOSED);
+
+ Either<Object, TransactionCodeEnum> eitherGeneralDBAction = tx.invokeGeneralDBAction(true, DBTypeEnum.TITAN, createBasicAction(TestAction.TitanAction, TestResponse.TitanResponseSuccess),
+ createBasicAction(TestAction.Rollback, TestResponse.TitanResponseSuccess));
+ assertTrue(eitherGeneralDBAction.isRight());
+ assertTrue(eitherGeneralDBAction.right().value() == TransactionCodeEnum.TRANSACTION_CLOSED);
+
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+ // verify(log, times(3)).error(LogMessages.ACTION_ON_CLOSED_TRANSACTION,
+ // transactionId, TransactionUtils.DUMMY_USER,
+ // ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(3)).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ }
+
+ @Test
+ public void testBasicHappyScenario() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+
+ doBasicTitanAction(transactionId, tx, false, true);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.OPEN);
+
+ doESAddArtifactAction(transactionId, tx, true, true);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.OPEN);
+
+ doFinishTransaction(transactionId, tx, true);
+
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+
+ }
+
+ @Test
+ public void testRollbackSucceededOnAction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doESAddArtifactAction(transactionId, tx, false, true);
+
+ when(titanGenericDao.rollback()).thenReturn(TitanOperationStatus.OK);
+ String crushMessage = "DB Crush Simulation";
+ Either<TestResponse, TransactionCodeEnum> eitherTransactionResult = tx.invokeTitanAction(false, createCrushingAction(TestAction.TitanAction, crushMessage));
+
+ assertTrue(eitherTransactionResult.isRight());
+ assertTrue(eitherTransactionResult.right().value() == TransactionCodeEnum.ROLLBACK_SUCCESS);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+ // verify(log).error(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION,
+ // DBTypeEnum.TITAN.name(), transactionId, crushMessage,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.TITAN.name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log).info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ }
+
+ @Test
+ public void testRollbackFailedOnAction() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+
+ doESAddArtifactAction(transactionId, tx, false, true);
+
+ when(titanGenericDao.rollback()).thenReturn(TitanOperationStatus.NOT_CONNECTED);
+ String crushMessage = "DB Crush Simulation";
+ Either<TestResponse, TransactionCodeEnum> eitherTransactionResult = tx.invokeTitanAction(false, createCrushingAction(TestAction.TitanAction, crushMessage));
+
+ assertTrue(eitherTransactionResult.isRight());
+ assertTrue(tx.getStatus() == TransactionStatusEnum.FAILED_ROLLBACK);
+ assertTrue(eitherTransactionResult.right().value() == TransactionCodeEnum.ROLLBACK_FAILED);
+ // verify(log).error(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION,
+ // DBTypeEnum.TITAN.name(), transactionId, crushMessage,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.TITAN.name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ // verify(log, times(1)).error(LogMessages.ROLLBACK_FAILED_GENERAL,
+ // transactionId, TransactionUtils.DUMMY_USER,
+ // ActionTypeEnum.ADD_ARTIFACT.name());
+ // verify(log, times(1)).error(TransactionUtils.TRANSACTION_MARKER,
+ // LogMessages.ROLLBACK_FAILED_GENERAL, transactionId,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ }
+
+ @Test
+ public void testRollbackSucceededOnCommit() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doESAddArtifactAction(transactionId, tx, false, true);
+ doBasicTitanAction(transactionId, tx, true, true);
+
+ when(titanGenericDao.commit()).thenReturn(TitanOperationStatus.GENERAL_ERROR);
+ when(titanGenericDao.rollback()).thenReturn(TitanOperationStatus.OK);
+ // finishTransaction
+ TransactionCodeEnum transactionCode = tx.finishTransaction();
+ assertTrue(transactionCode == TransactionCodeEnum.ROLLBACK_SUCCESS);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log).info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ }
+
+ @Test
+ public void testRollbackFailedOnCommit() {
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ doESAddArtifactAction(transactionId, tx, false, true);
+ doBasicTitanAction(transactionId, tx, true, true);
+
+ when(titanGenericDao.commit()).thenReturn(TitanOperationStatus.GENERAL_ERROR);
+ when(titanGenericDao.rollback()).thenReturn(TitanOperationStatus.OK);
+ String esError = "No Connection to Es";
+ Mockito.doThrow(new RuntimeException(esError)).when(esCatalogDao).deleteArtifact(Mockito.anyString());
+ // finishTransaction
+ TransactionCodeEnum transactionCode = tx.finishTransaction();
+ assertTrue(transactionCode == TransactionCodeEnum.ROLLBACK_FAILED);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.FAILED_ROLLBACK);
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.ELASTIC_SEARCH.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(1)).debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(1)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, DBTypeEnum.TITAN.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ // verify(log).error(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION,
+ // transactionId, DBTypeEnum.ELASTIC_SEARCH.name(), esError,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ // verify(log).error(TransactionUtils.TRANSACTION_MARKER,
+ // LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId,
+ // DBTypeEnum.ELASTIC_SEARCH.name(), esError,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ // verify(log, times(1)).error(LogMessages.ROLLBACK_FAILED_GENERAL,
+ // transactionId, TransactionUtils.DUMMY_USER,
+ // ActionTypeEnum.ADD_ARTIFACT.name());
+ // verify(log, times(1)).error(TransactionUtils.TRANSACTION_MARKER,
+ // LogMessages.ROLLBACK_FAILED_GENERAL, transactionId,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ }
+
+ @Test
+ public void testInvokeGeneralAction() {
+ when(titanGenericDao.rollback()).thenReturn(TitanOperationStatus.OK);
+ int transactionId = getNextTransactionId();
+ TransactionSdncImpl tx = new TransactionSdncImpl(transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT, esCatalogDao, titanGenericDao);
+ IDBAction generalAction = createBasicAction(TestAction.GeneralAction, TestResponse.GeneralSuccess);
+ IDBAction rollbackAction = createBasicAction(TestAction.Rollback, TestResponse.GeneralSuccess);
+ String crushMessage = "No DB Connection";
+ IDBAction crushingAction = createCrushingAction(TestAction.GeneralAction, crushMessage);
+
+ Either<TestResponse, TransactionCodeEnum> eitherResult = tx.invokeGeneralDBAction(false, DBTypeEnum.MYSTERY, generalAction, rollbackAction);
+ assertTrue(eitherResult.isLeft());
+ assertTrue(eitherResult.left().value() == TestResponse.GeneralSuccess);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.OPEN);
+ eitherResult = tx.invokeGeneralDBAction(false, DBTypeEnum.MYSTERY, crushingAction, rollbackAction);
+
+ assertTrue(eitherResult.isRight());
+ assertTrue(eitherResult.right().value() == TransactionCodeEnum.ROLLBACK_SUCCESS);
+ assertTrue(tx.getStatus() == TransactionStatusEnum.CLOSED);
+
+ // verify(log).error(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION,
+ // DBTypeEnum.MYSTERY.name(), transactionId, crushMessage,
+ // TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, DBTypeEnum.MYSTERY.name(), transactionId, crushMessage, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log, times(2)).debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.MYSTERY.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log, times(2)).debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, DBTypeEnum.MYSTERY.name(), transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ verify(log).info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+
+ }
+
+ private Either<TestResponse, TransactionCodeEnum> doBasicTitanAction(int transactionId, TransactionSdncImpl tx, boolean isLastAction, boolean isVerifyAction) {
+ // Add Titan Action
+ Either<TestResponse, TransactionCodeEnum> eitherTitanResult = tx.invokeTitanAction(isLastAction, createBasicAction(TestAction.TitanAction, TestResponse.TitanResponseSuccess));
+ if (isVerifyAction) {
+ // Check Titan Action
+ assertTrue(eitherTitanResult.isLeft());
+ assertTrue(eitherTitanResult.left().value() == TestResponse.TitanResponseSuccess);
+ verify(log).debug(TestAction.TitanAction.name());
+ verify(log).debug(LogMessages.INVOKE_ACTION, transactionId, DBTypeEnum.TITAN.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verifyNoErrorsInLog();
+ verifyNoInfoInLog();
+ }
+ return eitherTitanResult;
+ }
+
+ private TransactionCodeEnum doFinishTransaction(int transactionId, TransactionSdncImpl tx, boolean isVerifyAction) {
+ // Prerequisite finishTransaction
+ when(titanGenericDao.commit()).thenReturn(TitanOperationStatus.OK);
+ // finishTransaction
+ TransactionCodeEnum transactionCode = tx.finishTransaction();
+ if (isVerifyAction) {
+ // Check finishTransaction
+ verify(log).debug(LogMessages.COMMIT_ACTION_ALL_DB, transactionId, TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verify(log).debug(LogMessages.COMMIT_ACTION_SPECIFIC_DB, transactionId, DBTypeEnum.TITAN.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ assertTrue(transactionCode == TransactionCodeEnum.SUCCESS);
+ }
+ return transactionCode;
+ }
+
+ private void doESAddArtifactAction(int transactionId, TransactionSdncImpl tx, boolean isLastAction, boolean isVerifyAction) {
+ // Prerequisite ES Action
+ Either<ESArtifactData, ResourceUploadStatus> eitherBeforeAddArtifact = Either.right(ResourceUploadStatus.NOT_EXIST);
+ when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(eitherBeforeAddArtifact);
+
+ // Add ES Action
+ Either<DBActionCodeEnum, TransactionCodeEnum> eitherEsAction = tx.invokeESAction(isLastAction, ESActionTypeEnum.ADD_ARTIFACT, createDummyArtifactData());
+
+ if (isVerifyAction) {
+ // Check Titan Action
+ assertTrue(eitherEsAction.isLeft());
+ assertTrue(eitherEsAction.left().value() == DBActionCodeEnum.SUCCESS);
+ verify(log).debug(LogMessages.INVOKE_ACTION, transactionId, DBTypeEnum.ELASTIC_SEARCH.name(), TransactionUtils.DUMMY_USER, ActionTypeEnum.ADD_ARTIFACT.name());
+ verifyNoErrorsInLog();
+ verifyNoInfoInLog();
+ }
+ }
+
+ private ESArtifactData createDummyArtifactData() {
+ String strData = "qweqwqweqw34e4wrwer";
+ String myNodeType = "MyNewNodeType";
+ ESArtifactData arData = new ESArtifactData("artifactNewMarina11", strData.getBytes());
+ return arData;
+ }
+
+ private void verifyNoErrorsInLog() {
+ verify(log, Mockito.times(0)).error(Mockito.anyString(), Mockito.any(Object[].class));
+ verify(log, Mockito.times(0)).error(Mockito.anyString());
+ }
+
+ private void verifyNoInfoInLog() {
+ verify(log, Mockito.times(0)).info(Mockito.anyString(), Mockito.any(Object[].class));
+ verify(log, Mockito.times(0)).info(Mockito.anyString());
+ }
+
+ private IDBAction createBasicAction(TestAction action, TestResponse resp) {
+ final TestAction finalAction = action;
+ final TestResponse finalResp = resp;
+ return new IDBAction() {
+ @Override
+ public TestResponse doAction() {
+ log.debug(finalAction.name());
+ return finalResp;
+ }
+ };
+ }
+
+ private IDBAction createCrushingAction(TestAction action, final String crushMessage) {
+ final TestAction finalAction = action;
+ return new IDBAction() {
+ @Override
+ public TestResponse doAction() {
+ log.debug(finalAction.name());
+ throw new RuntimeException(crushMessage);
+ }
+ };
+ }
+
+ public int getNextTransactionId() {
+ transactionId++;
+ return transactionId;
+ }
+}
diff --git a/catalog-be/src/test/resources/config/catalog-be/configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml
new file mode 100644
index 0000000000..18d23707b1
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/configuration.yaml
@@ -0,0 +1,427 @@
+identificationHeaderFields:
+ - HTTP_IV_USER
+ - HTTP_CSP_FIRSTNAME
+ - HTTP_CSP_LASTNAME
+ - HTTP_IV_REMOTE_ADDRESS
+ - HTTP_CSP_WSTYPE
+
+
+
+# catalog backend hostname
+beFqdn: localhost
+
+# catalog backend http port
+beHttpPort: 8080
+
+# catalog backend http context
+beContext: /sdc/rest/config/get
+
+# catalog backend protocol
+beProtocol: http
+
+# catalog backend ssl port
+beSslPort: 8443
+
+version: 1.0
+released: 2012-11-30
+
+titanCfgFile: /home/vagrant/catalog-be/config/catalog-be/titan.properties
+titanInMemoryGraph: true
+titanLockTimeout: 600
+titanReconnectIntervalInSeconds: 3
+titanHealthCheckReadTimeout: 1
+esReconnectIntervalInSeconds: 3
+uebHealthCheckReconnectIntervalInSeconds: 15
+uebHealthCheckReadTimeout: 4
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd
+
+neo4j:
+ host: neo4jhost
+ port: 7474
+ user: neo4j
+ password: "12345"
+
+
+#Application-specific settings of ES
+elasticSearch:
+ # Mapping of index prefix to time-based frame. For example, if below is configured:
+ #
+ # - indexPrefix: auditingevents
+ # creationPeriod: minute
+ #
+ # then ES object of type which is mapped to "auditingevents-*" template, and created on 2015-12-23 13:24:54, will enter "auditingevents-2015-12-23-13-24" index.
+ # Another object created on 2015-12-23 13:25:54, will enter "auditingevents-2015-12-23-13-25" index.
+ # If creationPeriod: month, both of the above will enter "auditingevents-2015-12" index.
+ #
+ # PLEASE NOTE: the timestamps are created in UTC/GMT timezone! This is needed so that timestamps will be correctly presented in Kibana.
+ #
+ # Legal values for creationPeriod - year, month, day, hour, minute, none (meaning no time-based behaviour).
+ #
+ # If no creationPeriod is configured for indexPrefix, default behavour is creationPeriod: month.
+
+ indicesTimeFrequency:
+ - indexPrefix: auditingevents
+ creationPeriod: month
+ - indexPrefix: monitoring_events
+ creationPeriod: month
+
+artifactTypes:
+ - CHEF
+ - PUPPET
+ - SHELL
+ - YANG
+ - YANG_XML
+ - HEAT
+ - BPEL
+ - DG_XML
+ - MURANO_PKG
+ - WORKFLOW
+ - NETWORK_CALL_FLOW
+ - TOSCA_TEMPLATE
+ - TOSCA_CSAR
+ - AAI_SERVICE_MODEL
+ - AAI_VF_MODEL
+ - AAI_VF_MODULE_MODEL
+ - AAI_VF_INSTANCE_MODEL
+ - OTHER
+
+licenseTypes:
+ - User
+ - Installation
+ - CPU
+
+#Deployment artifacts placeHolder
+resourceTypes: &allResourceTypes
+ - VFC
+ - CP
+ - VL
+ - VF
+
+# validForResourceTypes usage
+# validForResourceTypes:
+# - VF
+# - VL
+deploymentResourceArtifacts:
+# heat:
+# displayName: "Base HEAT Template"
+# type: HEAT
+# validForResourceTypes: *allResourceTypes
+# heatVol:
+# displayName: "Volume HEAT Template"
+# type: HEAT_VOL
+# validForResourceTypes: *allResourceTypes
+# heatNet:
+# displayName: "Network HEAT Template"
+# type: HEAT_NET
+# validForResourceTypes: *allResourceTypes
+
+deploymentResourceInstanceArtifacts:
+ heatEnv:
+ displayName: "HEAT ENV"
+ type: HEAT_ENV
+ description: "Auto-generated HEAT Environment deployment artifact"
+ fileExtension: "env"
+
+#tosca artifacts placeholders
+toscaArtifacts:
+ assetToscaTemplate:
+ artifactName: -template.yml
+ displayName: Tosca Template
+ type: TOSCA_TEMPLATE
+ description: TOSCA representation of the asset
+ assetToscaCsar:
+ artifactName: -csar.csar
+ displayName: Tosca Model
+ type: TOSCA_CSAR
+ description: TOSCA definition package of the asset
+
+#Informational artifacts placeHolder
+excludeResourceCategory:
+ - Generic
+informationalResourceArtifacts:
+ features:
+ displayName: Features
+ type: OTHER
+ capacity:
+ displayName: Capacity
+ type: OTHER
+ vendorTestResult:
+ displayName: Vendor Test Result
+ type: OTHER
+ testScripts:
+ displayName: Test Scripts
+ type: OTHER
+ cloudQuestionnaire:
+ displayName: Cloud Questionnaire (completed)
+ type: OTHER
+ HEATTemplateFromVendor:
+ displayName: HEAT Template from Vendor
+ type: HEAT
+ resourceSecurityTemplate:
+ displayName: Resource Security Template
+ type: OTHER
+
+excludeServiceCategory:
+
+informationalServiceArtifacts:
+ serviceArtifactPlan:
+ displayName: Service Artifact Plan
+ type: OTHER
+ summaryOfImpactsToECOMPElements:
+ displayName: Summary of impacts to ECOMP elements,OSSs, BSSs
+ type: OTHER
+ controlLoopFunctions:
+ displayName: Control Loop Functions
+ type: OTHER
+ dimensioningInfo:
+ displayName: Dimensioning Info
+ type: OTHER
+ affinityRules:
+ displayName: Affinity Rules
+ type: OTHER
+ operationalPolicies:
+ displayName: Operational Policies
+ type: OTHER
+ serviceSpecificPolicies:
+ displayName: Service-specific Policies
+ type: OTHER
+ engineeringRules:
+ displayName: Engineering Rules (ERD)
+ type: OTHER
+ distributionInstructions:
+ displayName: Distribution Instructions
+ type: OTHER
+ certificationTestResults:
+ displayName: TD Certification Test Results
+ type: OTHER
+ deploymentVotingRecord:
+ displayName: Deployment Voting Record
+ type: OTHER
+ serviceQuestionnaire:
+ displayName: Service Questionnaire
+ type: OTHER
+ serviceSecurityTemplate:
+ displayName: Service Security Template
+ type: OTHER
+
+serviceApiArtifacts:
+ configuration:
+ displayName: Configuration
+ type: OTHER
+ instantiation:
+ displayName: Instantiation
+ type: OTHER
+ monitoring:
+ displayName: Monitoring
+ type: OTHER
+ reporting:
+ displayName: Reporting
+ type: OTHER
+ logging:
+ displayName: Logging
+ type: OTHER
+ testing:
+ displayName: Testing
+ type: OTHER
+
+
+additionalInformationMaxNumberOfKeys: 50
+
+systemMonitoring:
+ enabled: false
+ isProxy: false
+ probeIntervalInSeconds: 15
+
+defaultHeatArtifactTimeoutMinutes: 60
+
+serviceDeploymentArtifacts:
+ YANG_XML:
+ acceptedTypes:
+ - xml
+ VNF_CATALOG:
+ acceptedTypes:
+ - xml
+ MODEL_INVENTORY_PROFILE:
+ acceptedTypes:
+ - xml
+ MODEL_QUERY_SPEC:
+ acceptedTypes:
+ - xml
+ AAI_SERVICE_MODEL:
+ acceptedTypes:
+ - xml
+ AAI_VF_MODULE_MODEL:
+ acceptedTypes:
+ - xml
+ AAI_VF_INSTANCE_MODEL:
+ acceptedTypes:
+ - xml
+ OTHER:
+ acceptedTypes:
+
+resourceDeploymentArtifacts:
+ HEAT:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_VOL:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_NESTED:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ HEAT_ARTIFACT:
+ acceptedTypes:
+ validForResourceTypes: *allResourceTypes
+ HEAT_NET:
+ acceptedTypes:
+ - yaml
+ - yml
+ validForResourceTypes: *allResourceTypes
+ YANG_XML:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VNF_CATALOG:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VF_LICENSE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ VENDOR_LICENSE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ MODEL_INVENTORY_PROFILE:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ MODEL_QUERY_SPEC:
+ acceptedTypes:
+ - xml
+ validForResourceTypes: *allResourceTypes
+ APPC_CONFIG:
+ acceptedTypes:
+ validForResourceTypes:
+ - VF
+ AAI_VF_MODEL:
+ acceptedTypes:
+ - xml
+ validForResourceTypes:
+ - VF
+ AAI_VF_MODULE_MODEL:
+ acceptedTypes:
+ - xml
+ validForResourceTypes:
+ - VF
+ OTHER:
+ acceptedTypes:
+ validForResourceTypes: *allResourceTypes
+
+resourceInstanceDeploymentArtifacts:
+ HEAT_ENV:
+ acceptedTypes:
+ - env
+ VF_MODULES_METADATA:
+ acceptedTypes:
+ - json
+
+resourceInformationalDeployedArtifacts:
+
+
+requirementsToFulfillBeforeCert:
+ CP:
+ - tosca.capabilities.network.Bindable
+
+capabilitiesToConsumeBeforeCert:
+
+unLoggedUrls:
+ - /sdc2/rest/healthCheck
+
+cleanComponentsConfiguration:
+ cleanIntervalInMinutes: 1440
+ componentsToClean:
+ - Resource
+ - Service
+
+artifactsIndex: resources
+
+cassandraConfig:
+ cassandraHosts: ['localhost']
+ localDataCenter:
+ reconnectTimeout : 30000
+ authenticate: false
+ username: koko
+ password: bobo
+ ssl: false
+ truststorePath : /path/path
+ truststorePassword : 123123
+ keySpaces:
+ - { name: sdcaudit, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: sdcartifact, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+
+switchoverDetector:
+ gBeFqdn:
+ gFeFqdn:
+ beVip: 1.2.3.4
+ feVip: 1.2.3.4
+ beResolveAttempts: 3
+ feResolveAttempts: 3
+ enabled: false
+ interval: 60
+ changePriorityUser: ecompasdc
+ changePriorityPassword: ecompasdc123
+ publishNetworkUrl: "http://cora.web/crt/CipDomain.ECOMP-ASDC-DEVST/config/update_network?user=root"
+ publishNetworkBody: '{"note":"publish network"}'
+ groups:
+ beSet: { changePriorityUrl: "http://cora.web/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-BE.ecomp.idns.cip?user=root",
+ changePriorityBody: '{"name":"AIO-BE.ecomp.idns.cip","uri":"/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-BE.ecomp.idns.cip","no_ad_redirection":false,"v4groups":{"failover_groups":["/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_mg_be","/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_bs_be"],"failover_policy":["FAILALL"]},"comment":"AIO BE G-fqdn","intended_app_proto":"DNS"}'}
+ feSet: { changePriorityUrl: "http://cora.web/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-FE.ecomp.idns.cip?user=root",
+ changePriorityBody: '{"comment":"AIO G-fqdn","name":"AIO-FE.ecomp.idns.cip","v4groups":{"failover_groups":["/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_mg_fe","/crt/CipDomain.ECOMP-ASDC-DEVST/config/groups/group_bs_fe"],"failover_policy":["FAILALL"]},"no_ad_redirection":false,"intended_app_proto":"DNS","uri":"/crt/CipDomain.ECOMP-ASDC-DEVST/config/sites/AIO-FE.ecomp.idns.cip"}'}
+
+
+heatEnvArtifactHeader:
+ ""
+heatEnvArtifactFooter:
+ ""
+
+onboarding:
+ protocol: http
+ host: localhost
+ port: 8080
+ downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
+
+applicationL1Cache:
+ datatypes:
+ enabled: true
+ firstRunDelay: 10
+ pollIntervalInSec: 60
+
+applicationL2Cache:
+ enabled: false
+ catalogL1Cache:
+ enabled: true
+ resourcesSizeInCache: 300
+ servicesSizeInCache: 200
+ productsSizeInCache: 100
+ queue:
+ syncIntervalInSecondes: 60
+ waitOnShutDownInMinutes: 30
+ numberOfCacheWorkers: 4
+
diff --git a/catalog-be/src/test/resources/config/catalog-be/distribution-engine-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/distribution-engine-configuration.yaml
new file mode 100644
index 0000000000..a64ea7f364
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/distribution-engine-configuration.yaml
@@ -0,0 +1,43 @@
+uebServers:
+ - uebsb91kcdc.it.att.com:3904
+ - uebsb92kcdc.it.att.com:3904
+# - uebsb93kcdc.it.att.com:3904
+
+uebPublicKey: 8F3MDAtMSBwwpSMy
+
+uebSecretKey: gzFmsTxSCtO5RQfAccM6PqqX
+
+distributionNotifTopicName: ASDC-DISTR-NOTIF-TOPIC
+distributionStatusTopicName: ASDC-DISTR-STATUS-TOPIC
+
+initRetryIntervalSec: 5
+initMaxIntervalSec: 60
+
+distribNotifServiceArtifactTypes:
+ info:
+ - MURANO-PKG
+
+distribNotifResourceArtifactTypes:
+ lifecycle:
+ - HEAT
+ - DG-XML
+
+environments:
+ - PROD
+
+distributionStatusTopic:
+ pollingIntervalSec: 60
+ fetchTimeSec: 15
+ consumerGroup: asdc
+ consumerId: asdc-id
+
+distributionNotificationTopic:
+ minThreadPoolSize: 0
+ maxThreadPoolSize: 10
+ maxWaitingAfterSendingSeconds: 5
+
+createTopic:
+ partitionCount: 1
+ replicationCount: 1
+
+startDistributionEngine: true \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/catalog-be/ecomp-error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/ecomp-error-configuration.yaml
new file mode 100644
index 0000000000..9d7cd74a2b
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/ecomp-error-configuration.yaml
@@ -0,0 +1,383 @@
+###########################################
+# Note the conventions of the field values:
+# type can be one of: CONFIG_ERROR, SYSTEM_ERROR, DATA_ERROR, CONNECTION_PROBLEM, AUTHENTICATION_PROBLEM
+# severity can be one of: WARN, ERROR, FATAL
+# alarmSeverity can be one of: CRITICAL,MAJOR,MINOR,INFORMATIONAL,NONE
+# code is a unique integer in range of 3003-9999 (3000-3002 are occupied for internal usage)
+# The above enumeration values are out-of-the-box and can be changed in code.
+# In case of config and code mismatch, the appropriate error will be printed to log
+#
+## Range of BE codes - 3010-7999
+
+errors:
+
+ BeRestApiGeneralError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4000,
+ severity: ERROR,
+ description: "Unexpected error during BE REST API execution",
+ alarmSeverity: CRITICAL
+ }
+
+ BeHealthCheckError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3010,
+ severity: ERROR,
+ description: "Error during BE Health Check",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInitializationError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4019,
+ severity: ERROR,
+ description: "Catalog-BE was not initialized properly",
+ alarmSeverity: CRITICAL
+ }
+
+ BeResourceMissingError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3011,
+ severity: ERROR,
+ description: "Mandatory resource %s cannot be found in repository",
+ alarmSeverity: MAJOR
+ }
+
+ BeServiceMissingError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3012,
+ severity: ERROR,
+ description: "Mandatory service %s cannot be found in repository",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedAddingResourceInstanceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3013,
+ severity: ERROR,
+ description: "Failed to add resource instance of resource %s to service %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeIncorrectServiceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3014,
+ severity: ERROR,
+ description: "Service %s is not valid",
+ alarmSeverity: MAJOR
+ }
+
+ BeRepositoryDeleteError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3015,
+ severity: ERROR,
+ description: "Failed to delete object %s from repository",
+ alarmSeverity: CRITICAL
+ }
+
+ BeRepositoryQueryError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3016,
+ severity: ERROR,
+ description: "Failed to fetch from repository %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeInvalidConfigurationError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3017,
+ severity: FATAL,
+ description: "Configuration parameter %s is invalid. Value configured is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebConnectionError: {
+ type: CONNECTION_PROBLEM,
+ code: ASDC_4001,
+ severity: ERROR,
+ description: "Connection problem towards U-EB server. Reason: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3019,
+ severity: ERROR,
+ description: "Error occured during access to U-EB Server. Operation: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebObjectNotFoundError: {
+ type: DATA_ERROR,
+ code: ASDC_4005,
+ severity: ERROR,
+ description: "Error occured during access to U-EB Server. Data not found: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionEngineSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3021,
+ severity: ERROR,
+ description: "Error occured in Distribution Engine. Failed operation: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebAuthenticationError: {
+ type: AUTHENTICATION_PROBLEM,
+ code: ASDC_4003,
+ severity: ERROR,
+ description: "Authentication problem towards U-EB server. Reason: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeUebUnkownHostError: {
+ type: CONNECTION_PROBLEM,
+ code: ASDC_4002,
+ severity: ERROR,
+ description: "Connection problem towards U-EB server. Cannot reach host %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionEngineInvalidArtifactType: {
+ type: DATA_ERROR,
+ code: ASDC_4006,
+ severity: WARN,
+ description: "The artifact type %s does not appear in the list of valid artifacts %s",
+ alarmSeverity: MAJOR
+ }
+ BeInvalidTypeError: {
+ type: DATA_ERROR,
+ code: ASDC_4008,
+ severity: WARN,
+ description: "The type %s of %s is invalid",
+ alarmSeverity: MAJOR
+ }
+ BeInvalidValueError: {
+ type: DATA_ERROR,
+ code: ASDC_3028,
+ severity: WARN,
+ description: "The value %s of %s from type %s is invalid",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedDeletingResourceInstanceError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_3029,
+ severity: ERROR,
+ description: "Failed to delete resource instance %s from service %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeMissingConfigurationError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3030,
+ severity: FATAL,
+ description: "Configuration parameter %s is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeConfigurationInvalidListSizeError: {
+ type: CONFIG_ERROR,
+ code: ASDC_3031,
+ severity: FATAL,
+ description: "Configuration parameter %s is invalid. At least %s values shall be configured",
+ alarmSeverity: MAJOR
+ }
+
+ ErrorConfigFileFormat: {
+ type: CONFIG_ERROR,
+ code: ASDC_3032,
+ severity: ERROR,
+ description: "Error element not found in YAML name: %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeMissingArtifactInformationError: {
+ type: DATA_ERROR,
+ code: ASDC_4010,
+ severity: ERROR,
+ description: "Artifact uploaded has missing information. Missing %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4011,
+ severity: ERROR,
+ description: "Artifact %s requested is not found",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactPayloadInvalid: {
+ type: DATA_ERROR,
+ code: ASDC_4012,
+ severity: ERROR,
+ description: "Payload of artifact uploaded is invalid (invalid MD5 or encryption)",
+ alarmSeverity: MAJOR
+ }
+
+ BeUserMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4009,
+ severity: ERROR,
+ description: "User %s requested is not found",
+ alarmSeverity: MAJOR
+ }
+
+ BeArtifactInformationInvalidError: {
+ type: DATA_ERROR,
+ code: ASDC_4013,
+ severity: ERROR,
+ description: "Input for artifact metadata is invalid",
+ alarmSeverity: MAJOR
+ }
+ BeFailedAddingCapabilityTypeError: {
+ type: DATA_ERROR,
+ code: ASDC_4015,
+ severity: ERROR,
+ description: "Failed adding capability type",
+ alarmSeverity: CRITICAL
+ }
+
+ BeCapabilityTypeMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4016,
+ severity: ERROR,
+ description: "Capability Type %s not found",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInterfaceMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4020,
+ severity: ERROR,
+ description: "Interface %s required is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeDaoSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4014,
+ severity: ERROR,
+ description: "Operation towards database failed",
+ alarmSeverity: CRITICAL
+ }
+
+ BeSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4017,
+ severity: ERROR,
+ description: "Unexpected error during operation",
+ alarmSeverity: CRITICAL
+ }
+
+ BeFailedLockObjectError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4007,
+ severity: WARN,
+ description: "Failed to lock object for update",
+ alarmSeverity: CRITICAL
+ }
+
+ BeInvalidJsonInput: {
+ type: SYSTEM_ERROR,
+ code: ASDC_4018,
+ severity: ERROR,
+ description: "Failed to convert json input to object",
+ alarmSeverity: MAJOR
+ }
+
+ BeDistributionMissingError: {
+ type: DATA_ERROR,
+ code: ASDC_4021,
+ severity: ERROR,
+ description: "Distribution %s required is missing",
+ alarmSeverity: MAJOR
+ }
+
+ BeHealthCheckRecovery: {
+ type: RECOVERY,
+ code: ASDC_4022,
+ severity: INFO,
+ description: "BE Health Check Recovery",
+ alarmSeverity: INFORMATIONAL
+ }
+ BeFailedCreateNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6000,
+ severity: ERROR,
+ description: "Failed to create node %s on graph. status is %s",
+ alarmSeverity: MAJOR
+ }
+ BeFailedUpdateNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6001,
+ severity: ERROR,
+ description: "Failed to update node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedDeleteNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6002,
+ severity: ERROR,
+ description: "Failed to delete node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedRetrieveNodeError: {
+ type: DATA_ERROR,
+ code: ASDC_6003,
+ severity: ERROR,
+ description: "Failed to retrieve node %s from graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeExecuteRollbackError: {
+ type: DATA_ERROR,
+ code: ASDC_6004,
+ severity: ERROR,
+ description: "Going to execute rollback on graph.",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindParentError: {
+ type: DATA_ERROR,
+ code: ASDC_6005,
+ severity: ERROR,
+ description: "Failed to find parent node %s on graph. Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAllNodesError: {
+ type: DATA_ERROR,
+ code: ASDC_6006,
+ severity: ERROR,
+ description: "Failed to fetch all nodes with type %s of parent node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAssociationError: {
+ type: DATA_ERROR,
+ code: ASDC_6007,
+ severity: ERROR,
+ description: "Cannot find node with type %s associated with node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+
+ BeFailedFindAssociationError: {
+ type: DATA_ERROR,
+ code: ASDC_6008,
+ severity: ERROR,
+ description: "Cannot find node with type %s associated with node %s . Status is %s",
+ alarmSeverity: MAJOR
+ }
+ BeComponentCleanerSystemError: {
+ type: SYSTEM_ERROR,
+ code: ASDC_6009,
+ severity: ERROR,
+ description: "Error occured in Component Cleaner Task. Failed operation: %s",
+ alarmSeverity: MAJOR
+ }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
new file mode 100644
index 0000000000..89b44d94d6
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -0,0 +1,1583 @@
+# Errors
+errors:
+ OK: {
+ code: 200,
+ message: "OK"
+ }
+ CREATED: {
+ code: 201,
+ message: "OK"
+ }
+ NO_CONTENT: {
+ code: 204,
+ message: "No Content"
+ }
+#--------POL4050-----------------------------
+ NOT_ALLOWED: {
+ code: 405,
+ message: "Error: Method not allowed.",
+ messageId: "POL4050"
+ }
+#--------POL5000-----------------------------
+ GENERAL_ERROR: {
+ code: 500,
+ message: "Error: Internal Server Error. Please try again later.",
+ messageId: "POL5000"
+ }
+#---------POL5001------------------------------
+ MISSING_X_ECOMP_INSTANCE_ID: {
+ code: 400 ,
+ message: "Error: Missing 'X-ECOMP-InstanceID' HTTP header.",
+ messageId: "POL5001"
+ }
+#---------POL5002------------------------------
+ AUTH_REQUIRED: {
+ code: 401 ,
+ message: "Error: Authentication is required to use the API.",
+ messageId: "POL5002"
+ }
+#---------POL5003------------------------------
+ AUTH_FAILED: {
+ code: 403 ,
+ message: "Error: Not authorized to use the API.",
+ messageId: "POL5003"
+ }
+#---------SVC4000-----------------------------
+ INVALID_CONTENT: {
+ code: 400,
+ message: "Error: Invalid content.",
+ messageId: "SVC4000"
+ }
+#---------SVC4002-----------------------------
+ MISSING_INFORMATION: {
+ code: 403,
+ message: "Error: Missing information.",
+ messageId: "SVC4002"
+ }
+#---------SVC4003------------------------------
+# %1 - Users's USER_ID
+ USER_NOT_FOUND: {
+ code: 404,
+ message: "Error: User '%1' was not found.",
+ messageId: "SVC4003"
+ }
+#---------SVC4004-----------------------------
+# %1 - Users's email address
+ INVALID_EMAIL_ADDRESS: {
+ code: 400,
+ message: "Error: Invalid email address '%1'.",
+ messageId: "SVC4004"
+ }
+#---------SVC4005------------------------------
+# %1 - role
+ INVALID_ROLE: {
+ code: 400,
+ message: "Error: Invalid role '%1'.",
+ messageId: "SVC4005"
+ }
+#---------SVC4006------------------------------
+# %1 - Users's USER_ID
+ USER_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: User with '%1' ID already exists.",
+ messageId: "SVC4006"
+ }
+#---------SVC4007------------------------------
+ DELETE_USER_ADMIN_CONFLICT: {
+ code: 409,
+ message: "Error: An administrator can only be deleted by another administrator.",
+ messageId: "SVC4007"
+ }
+#---------SVC4008-----------------------------
+# %1 - Users's userId
+ INVALID_USER_ID: {
+ code: 400,
+ message: "Error: Invalid userId '%1'.",
+ messageId: "SVC4008"
+ }
+#---------SVC4049------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_CONTACT: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 contact id.",
+ messageId: "SVC4049"
+ }
+#---------SVC4050-----------------------------
+# %1 - Service/Resource/Additional parameter
+# %2 - service/resource/label name
+ COMPONENT_NAME_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: %1 with name '%2' already exists.",
+ messageId: "SVC4050"
+ }
+#---------SVC4051------------------------------
+# %1 - resource/service
+ COMPONENT_MISSING_CATEGORY: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 category.",
+ messageId: "SVC4051"
+ }
+
+#---------SVC4052------------------------------
+ COMPONENT_MISSING_TAGS: {
+ code: 400,
+ message: "Error: Invalid Content. At least one tag has to be specified.",
+ messageId: "SVC4052"
+ }
+
+#---------SVC4053------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_DESCRIPTION: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 description.",
+ messageId: "SVC4053"
+ }
+#---------SVC4054------------------------------
+# %1 - resource/service
+ COMPONENT_INVALID_CATEGORY: {
+ code: 400,
+ message: "Error: Invalid Content. Invalid %1 category.",
+ messageId: "SVC4054"
+ }
+#---------SVC4055------------------------------
+ MISSING_VENDOR_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. Missing vendor name.",
+ messageId: "SVC4055"
+ }
+#---------SVC4056------------------------------
+ MISSING_VENDOR_RELEASE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing vendor release.",
+ messageId: "SVC4056"
+ }
+
+#---------SVC4057------------------------------
+ MISSING_DERIVED_FROM_TEMPLATE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing derived from template specification.",
+ messageId: "SVC4057"
+ }
+
+#---------SVC4058------------------------------
+# %1 - service/resource
+ COMPONENT_MISSING_ICON: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 icon.",
+ messageId: "SVC4058"
+ }
+#---------SVC4059------------------------------
+# %1 - service/resource
+ COMPONENT_INVALID_ICON: {
+ code: 400,
+ message: "Error: Invalid Content. Invalid %1 icon.",
+ messageId: "SVC4059"
+ }
+#---------SVC4060------------------------------
+ PARENT_RESOURCE_NOT_FOUND: {
+ code: 400,
+ message: "Error: Invalid Content. Derived from resource template was not found.",
+ messageId: "SVC4060"
+ }
+#---------SVC4061------------------------------
+ MULTIPLE_PARENT_RESOURCE_FOUND: {
+ code: 400,
+ message: "Error: Invalid Content. Multiple derived from resource template is not allowed.",
+ messageId: "SVC4061"
+ }
+
+#---------SVC4062------------------------------
+# %1 - service/resource
+ MISSING_COMPONENT_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. Missing %1 name.",
+ messageId: "SVC4062"
+ }
+#---------SVC4063------------------------------
+ #%1  -  resource/service name
+ RESOURCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' resource was not found.",
+ messageId: "SVC4063"
+ }
+
+#---------SVC4064------------------------------
+# %1 - Service/Resource
+ COMPONENT_INVALID_DESCRIPTION: {
+ code: 400,
+ message: "Error: Invalid Content. %1 description contains non-english characters.",
+ messageId: "SVC4064"
+ }
+#---------SVC4065------------------------------
+# %1 - Service/Resource
+# %2 - max resource/service name length
+ COMPONENT_DESCRIPTION_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 description exceeds limit of %2 characters.",
+ messageId: "SVC4065"
+ }
+#---------SVC4066------------------------------
+# %1 - max length
+ COMPONENT_TAGS_EXCEED_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Tags overall length exceeds limit of %1 characters.",
+ messageId: "SVC4066"
+ }
+#---------SVC4067------------------------------
+# %1 - max length
+ VENDOR_NAME_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Vendor name exceeds limit of %1 characters.",
+ messageId: "SVC4067"
+ }
+#---------SVC4068------------------------------
+# %1 - max length
+ VENDOR_RELEASE_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Vendor release exceeds limit of %1 characters.",
+ messageId: "SVC4068"
+ }
+
+#---------SVC4069------------------------------
+# %1 - Service/Resource/Product
+ COMPONENT_INVALID_CONTACT_ID: {
+ code: 400,
+ message: "Error: Invalid Content. %1 contact id should be in format 'mnnnnnn' or 'aannna' or 'aannnn', where m=m ,a=a-zA-Z and n=0-9",
+ messageId: "SVC4069"
+ }
+#---------SVC4070------------------------------
+# %1 - Service/Resource
+ INVALID_COMPONENT_NAME: {
+ code: 400,
+ message: 'Error: Invalid Content. %1 name is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4070"
+ }
+
+#---------SVC4071------------------------------
+ INVALID_VENDOR_NAME: {
+ code: 400,
+ message: 'Error: Invalid Content. Vendor name is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4071"
+ }
+#---------SVC4072------------------------------
+ INVALID_VENDOR_RELEASE: {
+ code: 400,
+ message: 'Error: Invalid Content. Vendor release is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4072"
+ }
+#---------SVC4073------------------------------
+# %1 - Service/Resource
+# %2 - max resource/service name
+ COMPONENT_NAME_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 name exceeds limit of %2 characters.",
+ messageId: "SVC4073"
+ }
+#---------SVC4080------------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_IN_CHECKOUT_STATE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is locked for modification by %3 %4(%5).",
+ messageId: "SVC4080"
+ }
+#---------SVC4081-----------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_IN_CERT_IN_PROGRESS_STATE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is locked for certification by %3 %4(%5).",
+ messageId: "SVC4081"
+ }
+
+#-----------SVC4082---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_SENT_FOR_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is sent for certification by %3 %4(%5).",
+ messageId: "SVC4082"
+ }
+#-----------SVC4083---------------------------
+ COMPONENT_VERSION_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Version of this %1 was already promoted.",
+ messageId: "SVC4083"
+ }
+#-----------SVC4084---------------------------
+# %1 - resource/service/product name
+# %2 - resource/service/product
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_ALREADY_CHECKED_IN: {
+ code: 409,
+ message: "Error: The current version of '%1' %2 was already checked-in by %3 %4(%5).",
+ messageId: "SVC4084"
+ }
+#-----------SVC4085---------------------------
+# %1 - resource/service/product name
+# %2 - resource/service/product
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_CHECKOUT_BY_ANOTHER_USER: {
+ code: 403,
+ message: "Error: %1 %2 has already been checked out by %3 %4(%5).",
+ messageId: "SVC4085"
+ }
+#-----------SVC4086---------------------------
+# %1  - resource/service name
+# %2  - resource/service
+ COMPONENT_IN_USE: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is in use by another user.",
+ messageId: "SVC4086"
+ }
+#-----------SVC4087---------------------------
+# %1 - component name
+# %2 - resource/service/product
+ COMPONENT_HAS_NEWER_VERSION: {
+ code: 409,
+ message: "Error: Checking out of the requested version of the '%1' %2 is not allowed as a newer version exists.",
+ messageId: "SVC4087"
+ }
+#-----------SVC4088---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+# %3 - First name of last modifier
+# %4 - Last name of last modifier
+# %5 - USER_ID of last modifier
+ COMPONENT_ALREADY_CERTIFIED: {
+ code: 403,
+ message: "Error: Requested %1 %2 has already been certified by %3 %4(%5).",
+ messageId: "SVC4088"
+ }
+#-----------SVC4089---------------------------
+# %1 - resource/service name
+# %2 - resource/service
+ COMPONENT_NOT_READY_FOR_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is not ready for certification.",
+ messageId: "SVC4089"
+ }
+#-----------SVC4100---------------------------
+#%1 - property name
+ PROPERTY_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' property was not found.",
+ messageId: "SVC4100"
+ }
+#-----------SVC4101---------------------------
+#%1 - property name
+ PROPERTY_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Property with '%1' name already exists.",
+ messageId: "SVC4101"
+ }
+
+#-----------SVC4102---------------------------
+# %1 - capability type name
+ CAPABILITY_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Capability Type with name '%1' already exists.",
+ messageId: "SVC4102"
+ }
+#-----------SVC4114---------------------------
+ AUTH_FAILED_INVALIDE_HEADER: {
+ code: 400,
+ message: "Error: Invalid Authorization header.",
+ messageId: "SVC4114"
+ }
+#-----------SVC4115---------------------------
+# %1 - capability type name
+ MISSING_CAPABILITY_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing Capability Type '%1'.",
+ messageId: "SVC4115"
+ }
+ RESOURCE_INSTANCE_BAD_REQUEST: {
+ code: 400,
+ message: "Error: Invalid Content.",
+ messageId: "SVC4116"
+ }
+#-----------SVC4117---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_MATCH_NOT_FOUND: {
+ code: 404,
+ message: "Error: Match not found between resource instance '%1' and resource instance '%2' for requirement '%3'.",
+ messageId: "SVC4117"
+ }
+#-----------SVC4118---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Resource instances '%1' and '%2' are already associated with requirement '%3'.",
+ messageId: "SVC4118"
+ }
+#-----------SVC4119---------------------------
+# %1 - resource instance name
+# %2 - resource instance name
+# %3 - requirement name
+ RESOURCE_INSTANCE_RELATION_NOT_FOUND: {
+ code: 404,
+ message: "Error: No relation found between resource instances '%1' and '%2' for requirement '%3'.",
+ messageId: "SVC4119"
+ }
+#-----------SVC4120---------------------------
+# %1 - User's USER_ID
+ USER_INACTIVE: {
+ code: 404,
+ message: "Error: User %1 was not found.",
+ messageId: "SVC4120"
+ }
+#-----------SVC4121---------------------------
+# %1 - User's USER_ID
+ USER_HAS_ACTIVE_ELEMENTS: {
+ code: 403,
+ message: "Error: User with %1 ID can not be deleted since it has active elements(resources/services/artifacts).",
+ messageId: "SVC4121"
+ }
+#-----------SVC4122---------------------------
+# %1 - artifact type
+ ARTIFACT_TYPE_NOT_SUPPORTED: {
+ code: 400,
+ message: "Error: Invalid artifact type '%1'.",
+ messageId: "SVC4122"
+ }
+#-----------SVC4123---------------------------
+ ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Artifact logical name cannot be changed.",
+ messageId: "SVC4123"
+ }
+#-----------SVC4124---------------------------
+ MISSING_ARTIFACT_TYPE: {
+ code: 400,
+ message: "Error: Missing artifact type.",
+ messageId: "SVC4124"
+ }
+#-----------SVC4125---------------------------
+# %1-artifact name
+ ARTIFACT_EXIST: {
+ code: 400,
+ message: "Error: Artifact '%1' already exists.",
+ messageId: "SVC4125"
+ }
+#---------SVC4126------------------------------
+# %1 - resource/service/product/...
+# %2 - field (tag, vendor name...)
+ INVALID_FIELD_FORMAT: {
+ code: 400,
+ message: "Error: Invalid %1 %2 format.",
+ messageId: "SVC4126"
+ }
+#-----------SVC4127---------------------------
+ ARTIFACT_INVALID_MD5: {
+ code: 400,
+ message: "Error: Invalid artifact checksum.",
+ messageId: "SVC4127"
+ }
+#-----------SVC4128---------------------------
+ MISSING_ARTIFACT_NAME: {
+ code: 400,
+ message: "Error: Invalid content. Missing artifact name.",
+ messageId: "SVC4128"
+ }
+#-----------SVC4129---------------------------
+ MISSING_PROJECT_CODE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing PROJECT_CODE number.",
+ messageId: "SVC4129"
+ }
+#-----------SVC4130---------------------------
+ INVALID_PROJECT_CODE: {
+ code: 400,
+ message: "Error: Invalid Content. PROJECT_CODE number must be numeric from 5 up to 10 digits.",
+ messageId: "SVC4130"
+ }
+#-----------SVC4131---------------------------
+# %1-resource/service
+# %2-srtifact/artifacts
+# %3-semicolomn separated list of artifact
+ COMPONENT_MISSING_MANDATORY_ARTIFACTS: {
+ code: 403,
+ message: "Error: Missing mandatory informational %1 %2: [%3].",
+ messageId: "SVC4131"
+ }
+#-----------SVC4132---------------------------
+# %1 - lifecycle type name
+ LIFECYCLE_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Lifecycle Type with name '%1' already exists.",
+ messageId: "SVC4132"
+ }
+#-----------SVC4133---------------------------
+# %1 - service version
+# %2 - service name
+ SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION: {
+ code: 403,
+ message: "Error: Version %1 of '%2' service is not available for distribution.",
+ messageId: "SVC4133"
+ }
+#-----------SVC4134---------------------------
+ MISSING_LIFECYCLE_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing interface life-cycle type.",
+ messageId: "SVC4134"
+ }
+#---------SVC4135------------------------------
+ SERVICE_CATEGORY_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Service category cannot be changed once the service is certified.",
+ messageId: "SVC4135"
+ }
+#---------SVC4136------------------------------
+# %1 - distribution environment name
+ DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE: {
+ code: 500,
+ message: "Error: Requested distribution environment '%1' is not available.",
+ messageId: "SVC4136"
+ }
+#---------SVC4137------------------------------
+# %1 - distribution environment name
+ DISTRIBUTION_ENVIRONMENT_NOT_FOUND: {
+ code: 400,
+ message: "Error: Requested distribution environment '%1' was not found.",
+ messageId: "SVC4137"
+ }
+#---------SVC4138------------------------------
+ DISTRIBUTION_ENVIRONMENT_INVALID: {
+ code: 400,
+ message: "Error: Invalid distribution environment.",
+ messageId: "SVC4138"
+ }
+#---------SVC4139------------------------------
+# %1 - service name
+ DISTRIBUTION_ARTIFACT_NOT_FOUND: {
+ code: 409,
+ message: "Error: Service '%1' cannot be distributed due to missing deployment artifacts.",
+ messageId: "SVC4139"
+ }
+#---------SVC4200------------------------------
+# %1 - Service/Resource
+# %2 - max icon name length
+ COMPONENT_ICON_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 icon name exceeds limit of %2 characters.",
+ messageId: "SVC4200"
+ }
+#---------SVC4300------------------------------
+ RESTRICTED_ACCESS: {
+ code: 403,
+ message: "Error: Restricted access.",
+ messageId: "SVC4300"
+ }
+#---------SVC4301------------------------------
+ RESTRICTED_OPERATION: {
+ code: 409,
+ message: "Error: Restricted operation.",
+ messageId: "SVC4301"
+ }
+#---------SVC4500------------------------------
+ MISSING_BODY: {
+ code: 400 ,
+ message: "Error: Missing request body.",
+ messageId: "SVC4500"
+ }
+#---------SVC4501------------------------------
+ MISSING_PUBLIC_KEY: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'apiPublicKey'." ,
+ messageId: "SVC4501"
+ }
+#---------SVC4502------------------------------
+ DISTRIBUTION_ENV_DOES_NOT_EXIST: {
+ code: 400 ,
+ message: "Error: Invalid Body : Missing mandatory parameter 'distrEnvName'." ,
+ messageId: "SVC4502"
+ }
+#-----------SVC4503---------------------------
+# %1 - service name
+ SERVICE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' service was not found.",
+ messageId: "SVC4503"
+ }
+
+#---------SVC4504------------------------------
+# %1 - Service/Resource
+# %2 - service/resource version
+ COMPONENT_VERSION_NOT_FOUND: {
+ code: 404,
+ message: "Error: %1 version %2 was not found.",
+ messageId: "SVC4504"
+ }
+#-----------SVC4505---------------------------
+ #%1-artifact name
+
+ ARTIFACT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Artifact '%1' was not found.",
+ messageId: "SVC4505"
+ }
+#---------SVC4506------------------------------
+ MISSING_ENV_NAME: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'distrEnvName'.",
+ messageId: "SVC4506"
+ }
+#---------SVC4507------------------------------
+ COMPONENT_INVALID_TAGS_NO_COMP_NAME: {
+ code: 400,
+ message: "Error: Invalid Content. One of the tags should be the component name.",
+ messageId: "SVC4507"
+ }
+
+#---------SVC4508------------------------------
+ SERVICE_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Service name cannot be changed once the service is certified.",
+ messageId: "SVC4508"
+ }
+
+#---------SVC4509------------------------------
+ SERVICE_ICON_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Icon cannot be changed once the service is certified.",
+ messageId: "SVC4509"
+ }
+#---------SVC4510------------------------------
+# %1 - icon name max length
+ SERVICE_ICON_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Icon name exceeds limit of %1 characters.",
+ messageId: "SVC4510"
+ }
+#---------SVC4511------------------------------
+ DISTRIBUTION_REQUESTED_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested distribution was not found.",
+ messageId: "SVC4511"
+ }
+#---------SVC4512------------------------------
+# %1 - Distribution ID
+ DISTRIBUTION_REQUESTED_FAILED: {
+ code: 403,
+ message: "Error: Requested distribution '%1' failed.",
+ messageId: "SVC4512"
+ }
+#---------SVC4513------------------------------
+ RESOURCE_CATEGORY_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Resource category cannot be changed once the resource is certified.",
+ messageId: "SVC4513"
+ }
+#---------SVC4514------------------------------
+ RESOURCE_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Resource name cannot be changed once the resource is certified.",
+ messageId: "SVC4514"
+ }
+#---------SVC4515------------------------------
+ RESOURCE_ICON_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Icon cannot be changed once the resource is certified.",
+ messageId: "SVC4515"
+ }
+#---------SVC4516------------------------------
+ RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Vendor name cannot be changed once the resource is certified.",
+ messageId: "SVC4516"
+ }
+#---------SVC4517------------------------------
+ RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: Derived from resource template cannot be changed once the resource is certified.",
+ messageId: "SVC4517"
+ }
+#---------SVC4518------------------------------
+# %1 - max length
+ COMPONENT_SINGLE_TAG_EXCEED_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Single tag exceeds limit of %1 characters.",
+ messageId: "SVC4518"
+ }
+#---------SVC4519------------------------------
+ INVALID_DEFAULT_VALUE: {
+ code: 400,
+ message: "Error: mismatch in data-type occurred for property %1. data type is %2 and default value found is %3.",
+ messageId: "SVC4519"
+ }
+#---------SVC4520------------------------------
+# %1 - service or resource
+ ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED: {
+ code: 409,
+ message: "Error: Maximal number of additional %1 parameters was reached.",
+ messageId: "SVC4520"
+ }
+#---------SVC4521------------------------------
+ ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED: {
+ code: 400,
+ message: "Error: Invalid Content. The Additional information label and value cannot be empty.",
+ messageId: "SVC4521"
+ }
+#---------SVC4522------------------------------
+# %1 - label/value
+# %2 - Maximal length of %1
+ ADDITIONAL_INFORMATION_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Additional information %1 exceeds limit of %2 characters.",
+ messageId: "SVC4522"
+ }
+#---------SVC4523------------------------------
+ ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS: {
+ code: 400,
+ message: 'Error: Invalid Content. Additional information label is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4523"
+ }
+#---------SVC4524------------------------------
+ ADDITIONAL_INFORMATION_NOT_FOUND: {
+ code: 409,
+ message: "Error: Requested additional information was not found.",
+ messageId: "SVC4524"
+ }
+#---------SVC4525------------------------------
+ ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS: {
+ code: 400,
+ message: 'Error: Invalid Content. Additional information contains non-english characters.',
+ messageId: "SVC4525"
+ }
+#---------SVC4526------------------------------
+ RESOURCE_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' resource instance was not found.",
+ messageId: "SVC4526"
+ }
+#---------SVC4527------------------------------
+ ASDC_VERSION_NOT_FOUND: {
+ code: 500,
+ message: 'Error: ASDC version cannot be displayed.',
+ messageId: "SVC4527"
+ }
+#---------SVC4528------------------------------
+# %1-artifact url/artifact label/artifact description/VNF Service Indicator
+ MISSING_DATA: {
+ code: 400,
+ message: "Error: Invalid content. Missing %1.",
+ messageId: "SVC4528"
+ }
+#---------SVC4529------------------------------
+# %1-artifact url/artifact label/artifact description/artifact name
+# %2 - Maximal length of %1
+ EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 exceeds limit of %2 characters.",
+ messageId: "SVC4529"
+ }
+#---------SVC4530------------------------------
+ ARTIFACT_INVALID_TIMEOUT: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact Timeout should be set to valid positive non-zero number of minutes.",
+ messageId: "SVC4530"
+ }
+#---------SVC4531------------------------------
+ SERVICE_IS_VNF_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: VNF Indicator cannot be updated for certified service.",
+ messageId: "SVC4531"
+ }
+ #---------SVC4532------------------------------
+ RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE: {
+ code: 404,
+ message: "Error: Requested '%1' resource instance was not found on the service '%2.",
+ messageId: "SVC4532"
+ }
+ #---------SVC4533------------------------------
+ # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
+ WRONG_ARTIFACT_FILE_EXTENSION: {
+ code: 400,
+ message: "Error: Invalid file extension for %1 artifact type.",
+ messageId: "SVC4533"
+ }
+
+#---------SVC4534------------------------------
+# %1 - "HEAT"/"HEAT_ENV"
+ INVALID_YAML: {
+ code: 400,
+ message: "Error: Uploaded YAML file for %1 artifact is invalid.",
+ messageId: "SVC4534"
+ }
+
+#---------SVC4535------------------------------
+# %1 - "HEAT"
+ INVALID_DEPLOYMENT_ARTIFACT_HEAT: {
+ code: 400,
+ message: "Error: Invalid %1 artifact.",
+ messageId: "SVC4535"
+ }
+#---------SVC4536------------------------------
+# %1 - "Resource"/"Service"
+# %2 - resource/service name
+# %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
+# %4 - "HEAT"/"HEAT_ENV"/"MURANO_PKG
+ DEPLOYMENT_ARTIFACT_OF_TYPE_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: %1 '%2' already has a deployment artifact of %3 type .Please delete or update an existing %4 artifact.",
+ messageId: "SVC4536"
+ }
+
+#---------SVC4537------------------------------
+ MISSING_HEAT: {
+ code: 400,
+ message: "Error: Missing HEAT artifact. HEAT_ENV artifact cannot be uploaded without corresponding HEAT template.",
+ messageId: "SVC4537"
+ }
+#---------SVC4538------------------------------
+ MISMATCH_HEAT_VS_HEAT_ENV: {
+ code: 400,
+ message: "Error: Invalid artifact content. Parameter's set in HEAT_ENV '%1' artifact doesn't match the parameters in HEAT '%2' artifact.",
+ messageId: "SVC4538"
+ }
+#---------SVC4539------------------------------
+ INVALID_RESOURCE_PAYLOAD: {
+ code: 400,
+ message: "Error: Invalid resource payload.",
+ messageId: "SVC4539"
+ }
+#---------SVC4540------------------------------
+ INVALID_TOSCA_FILE_EXTENSION: {
+ code: 400,
+ message: "Error: Invalid file extension for TOSCA template.",
+ messageId: "SVC4540"
+ }
+#---------SVC4541------------------------------
+ INVALID_YAML_FILE: {
+ code: 400,
+ message: "Error: Invalid YAML file.",
+ messageId: "SVC4541"
+ }
+#---------SVC4542------------------------------
+ INVALID_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: Invalid TOSCA template.",
+ messageId: "SVC4542"
+ }
+#---------SVC4543------------------------------
+ NOT_RESOURCE_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: Imported Service TOSCA template.",
+ messageId: "SVC4543"
+ }
+#---------SVC4544------------------------------
+ NOT_SINGLE_RESOURCE: {
+ code: 400,
+ message: "Error: Imported TOSCA template should contain one resource definition.",
+ messageId: "SVC4544"
+ }
+#---------SVC4545------------------------------
+ INVALID_RESOURCE_NAMESPACE: {
+ code: 400,
+ message: "Error: Invalid resource namespace.",
+ messageId: "SVC4545"
+ }
+#---------SVC4546------------------------------
+ RESOURCE_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: Imported resource already exists in ASDC Catalog.",
+ messageId: "SVC4546"
+ }
+#---------SVC4549------------------------------
+ INVALID_RESOURCE_CHECKSUM: {
+ code: 400,
+ message: "Error: Invalid resource checksum.",
+ messageId: "SVC4549"
+ }
+#---------SVC4550------------------------------
+ #%1  -  Consumer salt
+ INVALID_LENGTH: {
+ code: 400,
+ message: "Error: Invalid %1 length.",
+ messageId: "SVC4550"
+ }
+ #---------SVC4551------------------------------
+ #%1  -  ECOMP User name
+ ECOMP_USER_NOT_FOUND: {
+ code: 404,
+ message: "Error: ECOMP User '%1' was not found.",
+ messageId: "SVC4551"
+ }
+#---------SVC4552------------------------------
+ CONSUMER_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: ECOMP User already exists.",
+ messageId: "SVC4552"
+ }
+#---------SVC4553-----------------------------
+ #%1  -  Consumer name / Consumer password/ Consumer salt
+ INVALID_CONTENT_PARAM: {
+ code: 400,
+ message: "Error: %1 is invalid.",
+ messageId: "SVC4553"
+ }
+ #---------SVC4554------------------------------
+# %1 - "Resource"/"Service"
+ COMPONENT_ARTIFACT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested artifact doesn't belong to specified %1.",
+ messageId: "SVC4554"
+ }
+#---------SVC4554------------------------------
+# %1 - "Service name"
+ SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND: {
+ code: 403,
+ message: "Error: Requested '%1' service is not ready for certification. Service has to have at least one deployment artifact.",
+ messageId: "SVC4554"
+ }
+#---------SVC4555------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category"
+ COMPONENT_ELEMENT_INVALID_NAME_LENGTH: {
+ code: 400,
+ message: "Error: Invalid %1 %2 name length.",
+ messageId: "SVC4555"
+ }
+#---------SVC4556------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category"
+ COMPONENT_ELEMENT_INVALID_NAME_FORMAT: {
+ code: 400,
+ message: "Error: Invalid %1 %2 name format.",
+ messageId: "SVC4556"
+ }
+#---------SVC4557------------------------------
+#%1 - "Resource"/"Service"/"Product"
+#%2 - "category name"
+ COMPONENT_CATEGORY_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: %1 category name '%2' already exists.",
+ messageId: "SVC4557"
+ }
+#---------SVC4558------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ VALIDATED_RESOURCE_NOT_FOUND: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource.",
+ messageId: "SVC4558"
+ }
+#---------SVC4559------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ FOUND_ALREADY_VALIDATED_RESOURCE: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use already available validated resource version.",
+ messageId: "SVC4559"
+ }
+#---------SVC4560------------------------------
+# %1 - "service"/"VF"
+# %2 - "Resource name"
+ FOUND_LIST_VALIDATED_RESOURCES: {
+ code: 403,
+ message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use one of available validated resource versions.",
+ messageId: "SVC4560"
+ }
+#---------SVC4561------------------------------
+# %1 - "resource"/"product"
+# %2 - "category"
+# %2 - "category name"
+ COMPONENT_CATEGORY_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested %1 %2 '%3' was not found.",
+ messageId: "SVC4561"
+ }
+#---------SVC4562------------------------------
+# %1 - "Resource"/"Product"
+# %2 - "sub-category name"
+# %2 - "category name"
+ COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY: {
+ code: 409,
+ message: "Error: %1 sub-category '%2' already exists under '%3' category.",
+ messageId: "SVC4562"
+ }
+#---------SVC4563------------------------------
+# %1 - "Product"
+# %2 - "grouping name"
+# %2 - "sub-category name"
+ COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY: {
+ code: 409,
+ message: "Error: %1 grouping '%2' already exists under '%3' sub-category.",
+ messageId: "SVC4563"
+ }
+#---------SVC4564------------------------------
+# %1 - product name
+ PRODUCT_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' product was not found.",
+ messageId: "SVC4564"
+ }
+#---------SVC4565------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
+# %3 - parameter name
+ INVALID_HEAT_PARAMETER_VALUE: {
+ code: 400,
+ message: "Error: Invalid %1 artifact. Invalid %2 value set for '%3' parameter.",
+ messageId: "SVC4565"
+ }
+#---------SVC4566------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
+ INVALID_HEAT_PARAMETER_TYPE: {
+ code: 400,
+ message: "Error: Invalid %1 artifact. Unsupported '%2' parameter type.",
+ messageId: "SVC4566"
+ }
+#---------SVC4567------------------------------
+# %1 - "YANG_XML"
+ INVALID_XML: {
+ code: 400,
+ message: "Error: Uploaded XML file for %1 artifact is invalid.",
+ messageId: "SVC4567"
+ }
+#---------SVC4567------------------------------
+# %1 - "User Name and userId"
+# %2 -"checked-out"/"in-certification"
+ CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS: {
+ code: 409,
+ message: "Error: User cannot be deleted. User '%1' has %2 projects.",
+ messageId: "SVC4567"
+ }
+#---------SVC4568------------------------------
+# %1 - "User Name and userId"
+# %2 -"checked-out"/"in-certification"
+ CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS: {
+ code: 409,
+ message: "Error: Role cannot be changed. User '%1' has %2 projects.",
+ messageId: "SVC4568"
+ }
+#---------SVC4570------------------------------
+ UPDATE_USER_ADMIN_CONFLICT: {
+ code: 409,
+ message: "Error: An administrator is not allowed to change his/her role.",
+ messageId: "SVC4570"
+ }
+#---------SVC4571------------------------------
+ SERVICE_CANNOT_CONTAIN_SUBCATEGORY: {
+ code: 400,
+ message: "Error: Sub category cannot be defined for service",
+ messageId: "SVC4571"
+ }
+#---------SVC4572------------------------------
+# %1 - "Resource"/"Service"
+ COMPONENT_TOO_MUCH_CATEGORIES: {
+ code: 400,
+ message: "Error: %1 must have only 1 category",
+ messageId: "SVC4572"
+ }
+#---------SVC4574------------------------------
+ RESOURCE_TOO_MUCH_SUBCATEGORIES: {
+ code: 400,
+ message: "Error: Resource must have only 1 sub category",
+ messageId: "SVC4574"
+ }
+#---------SVC4575------------------------------
+ COMPONENT_MISSING_SUBCATEGORY: {
+ code: 400,
+ message: "Error: Missing sub category",
+ messageId: "SVC4575"
+ }
+ #---------SVC4576------------------------------
+# %1 - "component type"
+ UNSUPPORTED_ERROR: {
+ code: 400,
+ message: "Error : Requested component type %1 is unsupported.",
+ messageId: "SVC4576"
+ }
+ #---------SVC4577------------------------------
+# %1 - "resource type"
+ RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES: {
+ code: 409,
+ message: "Error : Resource of type %1 cannot contain resource instances.",
+ messageId: "SVC4577"
+ }
+#---------SVC4578------------------------------
+# %1 - "Resource"/"Service"
+# %2 - resource/service name
+# %3 - "artifact name"
+ DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: %1 '%2' already has a deployment artifact named '%3'.",
+ messageId: "SVC4578"
+ }
+#---------SVC4579------------------------------
+# %1 - "Category"/"Sub-Category"/"Group"
+# %2 - category/sub-category/grouping name.
+ INVALID_GROUP_ASSOCIATION: {
+ code: 400,
+ message: "Error: Invalid group association. %1 '%2' was not found.",
+ messageId: "SVC4579"
+ }
+#---------SVC4580------------------------------
+ EMPTY_PRODUCT_CONTACTS_LIST: {
+ code: 400,
+ message: "Error: Invalid content. At least one Product Contact has to be specified.",
+ messageId: "SVC4580"
+ }
+#---------SVC4581------------------------------
+# %1 - userId
+ INVALID_PRODUCT_CONTACT: {
+ code: 400,
+ message: "Error: Invalid content. User '%1' cannot be set as Product Contact.",
+ messageId: "SVC4581"
+ }
+#---------SVC4582------------------------------
+# %1 - Product
+# %2 - "abbreviated"/"full"
+ MISSING_ONE_OF_COMPONENT_NAMES: {
+ code: 400,
+ message: "Error: Invalid content. Missing %1 %2 name.",
+ messageId: "SVC4582"
+ }
+#---------SVC4583------------------------------
+# %1 - "Icon"
+# %2 - "resource"/"service"/"product"
+ COMPONENT_PARAMETER_CANNOT_BE_CHANGED: {
+ code: 400,
+ message: "Error: %1 cannot be changed once the %2 is certified.",
+ messageId: "SVC4583"
+ }
+#---------SVC4584------------------------------
+# %1 - service/VF name
+# %2 - "service" /"VF"
+# %3 - resource instance origin type
+# %4 - resource instance name
+# %5 - requirement/capability
+# %6 - requirement/capability name
+# %7 - "fulfilled" (for req)/"consumed (for cap)"
+ REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION: {
+ code: 403,
+ message: "Error: Requested '%1' %2 is not ready for certification. %3 '%4' has to have %5 '%6' %7.",
+ messageId: "SVC4584"
+ }
+#---------SVC4585------------------------------
+ INVALID_OCCURRENCES: {
+ code: 400,
+ message: "Error: Invalid occurrences format.",
+ messageId: "SVC4585"
+ }
+#---------SVC4586------------------------------
+#---------SVC4586------------------------------
+ INVALID_SERVICE_API_URL: {
+ code: 400,
+ message: 'Error: Invalid Service API URL. Please check whether your URL has a valid domain extension and does not contain the following characters - #?&@%+;,=$<>~^`\[]{}|"*!',
+ messageId: "SVC4586"
+ }
+#---------SVC4587------------------------------
+# %1 - Data type name
+ DATA_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: 'Error: Data type %1 already exists.',
+ messageId: "SVC4587"
+ }
+#---------SVC4588------------------------------
+# %1 - Data type name
+ DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM: {
+ code: 400,
+ message: 'Error: Invalid Data type %1. Data type must have either a valid derived from declaration or at least one valid property',
+ messageId: "SVC4588"
+ }
+#---------SVC4589------------------------------
+# %1 - Data type name
+ DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Data type %1. 'properties' parameter cannot be empty if provided.",
+ messageId: "SVC4589"
+ }
+#---------SVC4590------------------------------
+# %1 - Property type name
+# %2 - Property name
+ INVALID_PROPERTY_TYPE: {
+ code: 400,
+ message: "Error: Invalid Property type %1 in property %2.",
+ messageId: "SVC4590"
+ }
+#---------SVC4591------------------------------
+# %1 - Property inner type
+# %2 - Property name
+ INVALID_PROPERTY_INNER_TYPE: {
+ code: 400,
+ message: "Error: Invalid property inner type %1, in property %2",
+ messageId: "SVC4591"
+ }
+#---------SVC4592------------------------------
+# %1 - component instance name
+# %2 - "resource instance"/"service instance"
+ COMPONENT_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "Error: Requested '%1' %2 was not found.",
+ messageId: "SVC4592"
+ }
+#---------SVC4593------------------------------
+# %1 - component instance name
+# %2 - "resource instance"/"service instance"
+# %3 - "resource/"service"/"product"
+# %4 - container name
+ COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER: {
+ code: 404,
+ message: "Error: Requested '%1' %2 was not found on the %3 '%4'.",
+ messageId: "SVC4593"
+ }
+#---------SVC4594------------------------------
+#%1 - requirement / capability
+#%2 - requirement name
+ IMPORT_DUPLICATE_REQ_CAP_NAME: {
+ code: 400,
+ message: "Error: Imported TOSCA template contains more than one %1 named '%2'.",
+ messageId: "SVC4594"
+ }
+#---------SVC4595------------------------------
+#%1 - requirement / capability
+#%2 - requirement name
+#%3 - parent containing the requirement
+ IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED: {
+ code: 400,
+ message: "Error: Imported TOSCA template contains %1 '%2' that is already defined by derived template %3.",
+ messageId: "SVC4595"
+ }
+#---------SVC4596------------------------------
+# %1 - Data type name
+ DATA_TYPE_DERIVED_IS_MISSING: {
+ code: 400,
+ message: "Error: Invalid Content. The ancestor data type %1 cannot be found in the system.",
+ messageId: "SVC4596"
+ }
+#---------SVC4597------------------------------
+# %1 - Data type name
+# %2 - Property names
+ DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains properties named %2 which are already defined in one of its ancestors.",
+ messageId: "SVC4597"
+ }
+#---------SVC4598------------------------------
+# %1 - Data type name
+ DATA_TYPE_DUPLICATE_PROPERTY: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains duplicate property.",
+ messageId: "SVC4598"
+ }
+#---------SVC4599------------------------------
+# %1 - Data type name
+# %2 - Property names
+ DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 contains properties %2 which their type is this data type.",
+ messageId: "SVC4599"
+ }
+#---------SVC4600------------------------------
+# %1 - Data type name
+ DATA_TYPE_CANNOT_HAVE_PROPERTIES: {
+ code: 400,
+ message: "Error: Invalid Content. The data type %1 cannot have properties since it is of type scalar",
+ messageId: "SVC4600"
+ }
+#---------SVC4601------------------------------
+ NOT_TOPOLOGY_TOSCA_TEMPLATE: {
+ code: 400,
+ message: "Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain 'topology_template.",
+ messageId: "SVC4601"
+ }
+#---------SVC4602--------------------------------
+# %1 - yaml file name
+# %2 - node_template label
+# %3 - node_template type
+ INVALID_NODE_TEMPLATE: {
+ code: 400,
+ message: "Error: TOSCA yaml file '%1' contains node_template '%2' of type '%3' that does not represent existing VFC/CP/VL",
+ messageId: "SVC4602"
+ }
+#---------SVC4603------------------------------
+# %1 - component type
+# %2 - component name
+# %3 - state
+ ILLEGAL_COMPONENT_STATE: {
+ code: 403,
+ message: "Error: Component instance of %1 can not be created because the component '%2' is in an illegal state %3.",
+ messageId: "SVC4603"
+ }
+#---------SVC4604------------------------------
+# %1 - csar file name
+ CSAR_INVALID: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is invalid. 'TOSCA-Metadata/Tosca.meta' file must be provided.",
+ messageId: "SVC4604"
+ }
+#---------SVC4605------------------------------
+# %1 - csar file name
+ CSAR_INVALID_FORMAT: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is invalid. Invalid 'TOSCA-Metadata/Tosca.meta' file format.",
+ messageId: "SVC4605"
+ }
+#---------SVC4606------------------------------
+# %1 - property name
+# %2 - property type
+# %3 - property innerType
+# %4 - default value is
+ INVALID_COMPLEX_DEFAULT_VALUE: {
+ code: 400,
+ message: "Error: Invalid default value of property %1. Data type is %2 with inner type %3 and default value found is %4.",
+ messageId: "SVC4606"
+ }
+#---------SVC4607------------------------------
+# %1 - csar file name
+ CSAR_NOT_FOUND: {
+ code: 400,
+ message: "Error: TOSCA CSAR '%1' is not found.",
+ messageId: "SVC4607"
+ }
+#---------SVC4608------------------------------
+# %1 - artifact name
+# %2 - component type
+# %3 - actual component type
+ MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE: {
+ code: 400,
+ message: "Error: Artifact %1 is only compatible with component of type %2, but component type is %3.",
+ messageId: "SVC4608"
+ }
+
+#---------SVC4609------------------------------
+# %1 - "INVALID_JSON"
+ INVALID_JSON: {
+ code: 400,
+ message: "Error: Uploaded JSON file for %1 artifact is invalid.",
+ messageId: "SVC4609"
+ }
+#---------SVC4610------------------------------
+# %1 - csar file name
+# %2 - missing file name
+ YAML_NOT_FOUND_IN_CSAR: {
+ code: 400,
+ message: "Error - TOSCA CSAR %1 is invalid. TOSCA-Metadata/Tosca.meta refers to file %2 that is not provided.",
+ messageId: "SVC4610"
+ }
+#---------SVC4611------------------------------
+# %1 - group name
+ GROUP_MEMBER_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Content. Group %1 member list was provided but does not have values",
+ messageId: "SVC4611"
+ }
+#---------SVC4612------------------------------
+# %1 - group name
+ GROUP_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: 'Error: Group type %1 already exists.',
+ messageId: "SVC4612"
+ }
+#---------SVC4613------------------------------
+# %1 - group name
+# %2 - VF name(component name)
+# %3 - actual component type [VF]
+ GROUP_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Group with name '%1' already exists in %2 %3.",
+ messageId: "SVC4613"
+ }
+#---------SVC4614------------------------------
+# %1 - group type
+ GROUP_TYPE_IS_INVALID: {
+ code: 400,
+ message: "Error: Invalid content. Group type %1 does not exist",
+ messageId: "SVC4614"
+ }
+#---------SVC4615------------------------------
+# %1 - group name
+ GROUP_MISSING_GROUP_TYPE: {
+ code: 400,
+ message: "Error: Invalid Content. Missing Group Type for group '%1'",
+ messageId: "SVC4615"
+ }
+#---------SVC4616------------------------------
+# %1 - member name
+# %2 - group name
+# %3 - VF name
+# %4 - component type [VF ]
+ GROUP_INVALID_COMPONENT_INSTANCE: {
+ code: 400,
+ message: "Error: member %1 listed in group %2 is not part of %3 %4.",
+ messageId: "SVC4616"
+ }
+#---------SVC4617------------------------------
+# %1 - member name
+# %2 - group name
+# %3 - group type
+ GROUP_INVALID_TOSCA_NAME_OF_COMPONENT_INSTANCE: {
+ code: 400,
+ message: "Error: member %1 listed in group %2 is not part of allowed members of group type %3.",
+ messageId: "SVC4617"
+ }
+#---------SVC4618------------------------------
+# %1 - missing file name
+# %2 - csar file name
+ ARTIFACT_NOT_FOUND_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
+ messageId: "SVC4618"
+ }
+#---------SVC4619------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - existing artifact type
+ ARTIFACT_ALRADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 in type %2 already exists in type %3.",
+ messageId: "SVC4619"
+ }
+#---------SVC4620------------------------------
+ FAILED_RETRIVE_ARTIFACTS_TYPES: {
+ code: 400,
+ message: "Error: Failed to retrieve list of suported artifact types.",
+ messageId: "SVC4620"
+ }
+#---------SVC4621------------------------------
+# %1 - artifact name
+# %2 - master
+ ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR: {
+ code: 400,
+ message: "Error: artifact %1 already exists in master %2 .",
+ messageId: "SVC4621"
+ }
+#---------SVC4622------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - master name
+# %4 - master type
+ ARTIFACT_NOT_VALID_IN_MASTER: {
+ code: 400,
+ message: "Error: artifact %1 in type %2 can not be exists under master %3 in type %4.",
+ messageId: "SVC4622"
+ }
+#---------SVC4623------------------------------
+# %1 - artifact name
+# %2 - artifact type
+# %3 - env name
+# %4 - existing env
+ ARTIFACT_NOT_VALID_ENV: {
+ code: 400,
+ message: "Error: Artifact %1 in type %2 with env %3 already exists with another env %4",
+ messageId: "SVC4623"
+ }
+#---------SVC4624------------------------------
+# %1 - groups names
+# %2 - VF name
+# %3 - component type [VF ]
+ GROUP_IS_MISSING: {
+ code: 400,
+ message: "Error: Invalid Content. The groups '%1' cannot be found under %2 %3.",
+ messageId: "SVC4624"
+ }
+#---------SVC4625------------------------------
+# %1 - groups name
+ GROUP_ARTIFACT_ALREADY_ASSOCIATED: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact already associated to group '%1'.",
+ messageId: "SVC4625"
+ }
+#---------SVC4626------------------------------
+# %1 - groups name
+ GROUP_ARTIFACT_ALREADY_DISSOCIATED: {
+ code: 400,
+ message: "Error: Invalid Content. Artifact already dissociated from group '%1'.",
+ messageId: "SVC4626"
+ }
+#---------SVC4627------------------------------
+# %1 - property name
+# %2 - group name
+# %3 - group type name
+ GROUP_PROPERTY_NOT_FOUND: {
+ code: 400,
+ message: "Error: property %1 listed in group %2 is not exist in group type %3.",
+ messageId: "SVC4627"
+ }
+#---------SVC4628------------------------------
+# %1 - csarUUID
+# %2 - VF name
+ VSP_ALREADY_EXISTS: {
+ code: 400,
+ message: "Error: The VSP with UUID %1 was already imported for VF %2. Please select another or update the existing VF.",
+ messageId: "SVC4628"
+ }
+#---------SVC4629------------------------------
+# %1 - VF name
+ MISSING_CSAR_UUID: {
+ code: 400,
+ message: "Error: The Csar UUID or payload name is missing for VF %1.",
+ messageId: "SVC4629"
+ }
+#---------SVC4630------------------------------
+# %1 - VF name
+# %2 - new csarUUID
+# %3 - old csarUUID
+ RESOURCE_LINKED_TO_DIFFERENT_VSP: {
+ code: 400,
+ message: "Error: Resource %1 cannot be updated using CsarUUID %2 since the resource is linked to a different VSP with csarUUID %3.",
+ messageId: "SVC4630"
+ }
+#---------SVC4631------------------------------
+# %1 - policy name
+ POLICY_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Policy type %1 already exists.",
+ messageId: "SVC4631"
+ }
+#---------SVC4632------------------------------
+# %1 - target name
+# %2 - policy type name
+ TARGETS_NON_VALID: {
+ code: 400,
+ message: "Error: target %1 listed in policy type %2 is not a group or resource.",
+ messageId: "SVC4632"
+ }
+#---------SVC4633------------------------------
+# %1 - policy name
+ TARGETS_EMPTY: {
+ code: 400,
+ message: "Error: Invalid Content. Policy %1 target list was provided but does not have values",
+ messageId: "SVC4633"
+ }
+#---------SVC4634------------------------------
+ DATA_TYPE_CANNOT_BE_EMPTY: {
+ code: 500,
+ message: "Error: Data types are empty. Please import the data types.",
+ messageId: "SVC4634"
+ }
+#---------SVC4635------------------------------
+# %1 - csar uuid
+ RESOURCE_FROM_CSAR_NOT_FOUND: {
+ code: 400,
+ message: "Error: resource from csar uuid %1 not found",
+ messageId: "SVC4635"
+ }
+#---------SVC4636------------------------------
+# %1 - Data type name
+ DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST: {
+ code: 400,
+ message: 'Error: Data type %1 cannot be upgraded. The new data type does not contain old properties or the type of one of the properties has been changed.',
+ messageId: "SVC4636"
+ } \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/catalog-be/neo4j-errors-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/neo4j-errors-configuration.yaml
new file mode 100644
index 0000000000..7a0d6dbfd4
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/neo4j-errors-configuration.yaml
@@ -0,0 +1,60 @@
+# Errors
+errors:
+ Neo_ClientError_General_ReadOnly: "This is a read only database, writing or modifying the database is not allowed."
+ Neo_ClientError_LegacyIndex_NoSuchIndex: "The request (directly or indirectly) referred to a index that does not exist."
+ Neo_ClientError_Request_Invalid: "The client provided an invalid Request."
+ Neo_ClientError_Request_InvalidFormat: "The client provided a request that was missing required fields, or had values that are not allowed."
+ Neo_ClientError_Schema_ConstraintAlreadyExists: "Unable to perform operation because it would clash with a pre-existing constraint."
+ Neo_ClientError_Schema_ConstraintVerificationFailure: "Unable to create constraint because data that exists in the database violates it."
+ Neo_ClientError_Schema_ConstraintViolation: "A constraint imposed by the database was violated."
+ Neo_ClientError_Schema_IllegalTokenName: "A token name, such as a label, relationship type or property key, used is not valid. Tokens cannot be empty strings and cannot be null."
+ Neo_ClientError_Schema_IndexAlreadyExists: "Unable to perform operation because it would clash with a pre-existing index."
+ Neo_ClientError_Schema_IndexBelongsToConstraint: "A requested operation can not be performed on the specified index because the index is part of a constraint. If you want to drop the index, for instance, you must drop the constraint."
+ Neo_ClientError_Schema_IndexLimitReached: "The maximum number of index entries supported has been reached, no more entities can be indexed."
+ Neo_ClientError_Schema_LabelLimitReached: "The maximum number of labels supported has been reached, no more labels can be created."
+ Neo_ClientError_Schema_NoSuchConstraint: "The request (directly or indirectly) referred to a constraint that does not exist."
+ Neo_ClientError_Schema_NoSuchIndex: "The request (directly or indirectly) referred to an index that does not exist."
+ Neo_ClientError_Security_AuthenticationFailed: "The client provided an incorrect username and/or password."
+ Neo_ClientError_Security_AuthenticationRateLimit: "The client has provided incorrect authentication details too many times in a row."
+ Neo_ClientError_Security_AuthorizationFailed: "The client does not have privileges to perform the operation requested."
+ Neo_ClientError_Statement_ArithmeticError: "Invalid use of arithmetic, such as dividing by zero."
+ Neo_ClientError_Statement_ConstraintViolation: "A constraint imposed by the statement is violated by the data in the database."
+ Neo_ClientError_Statement_EntityNotFound: "The statement is directly referring to an entity that does not exist."
+ Neo_ClientError_Statement_InvalidArguments: "The statement is attempting to perform operations using invalid arguments"
+ Neo_ClientError_Statement_InvalidSemantics: "The statement is syntactically valid, but expresses something that the database cannot do."
+ Neo_ClientError_Statement_InvalidSyntax: "The statement contains invalid or unsupported syntax."
+ Neo_ClientError_Statement_InvalidType: "The statement is attempting to perform operations on values with types that are not supported by the operation."
+ Neo_ClientError_Statement_NoSuchLabel: "The statement is referring to a label that does not exist."
+ Neo_ClientError_Statement_NoSuchProperty: "The statement is referring to a property that does not exist."
+ Neo_ClientError_Statement_ParameterMissing: "The statement is referring to a parameter that was not provided in the Request."
+ Neo_ClientError_Transaction_ConcurrentRequest: "There were concurrent requests accessing the same transaction, which is not allowed."
+ Neo_ClientError_Transaction_EventHandlerThrewException: "A transaction event handler threw an exception. The transaction will be rolled back."
+ Neo_ClientError_Transaction_HookFailed: "Transaction hook failure."
+ Neo_ClientError_Transaction_InvalidType: "The transaction is of the wrong type to service the Request_ For instance, a transaction that has had schema modifications performed in it cannot be used to subsequently perform data operations, and vice versa."
+ Neo_ClientError_Transaction_MarkedAsFailed: "Transaction was marked as both successful and failed. Failure takes precedence and so this transaction was rolled back although it may have looked like it was going to be committed"
+ Neo_ClientError_Transaction_UnknownId: "The request referred to a transaction that does not exist."
+ Neo_ClientError_Transaction_ValidationFailed: "Transaction changes did not pass validation checks"
+ Neo_DatabaseError_General_CorruptSchemaRule: "A malformed schema rule was encountered. Please contact your support representative."
+ Neo_DatabaseError_General_FailedIndex: "The request (directly or indirectly) referred to an index that is in a failed state. The index needs to be dropped and recreated manually."
+ Neo_DatabaseError_General_UnknownFailure: "An unknown failure occurred."
+ Neo_DatabaseError_Schema_ConstraintCreationFailure: "Creating a requested constraint failed."
+ Neo_DatabaseError_Schema_ConstraintDropFailure: "The database failed to drop a requested constraint."
+ Neo_DatabaseError_Schema_IndexCreationFailure: "Failed to create an index."
+ Neo_DatabaseError_Schema_IndexDropFailure: "The database failed to drop a requested index."
+ Neo_DatabaseError_Schema_NoSuchLabel: "The request accessed a label that did not exist."
+ Neo_DatabaseError_Schema_NoSuchPropertyKey: "The request accessed a property that does not exist."
+ Neo_DatabaseError_Schema_NoSuchRelationshipType: "The request accessed a relationship type that does not exist."
+ Neo_DatabaseError_Schema_NoSuchSchemaRule: "The request referred to a schema rule that does not exist."
+ Neo_DatabaseError_Statement_ExecutionFailure: "The database was unable to execute the Statement."
+ Neo_DatabaseError_Transaction_CouldNotBegin: "The database was unable to start the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotCommit: "The database was unable to commit the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotRollback: "The database was unable to roll back the Transaction."
+ Neo_DatabaseError_Transaction_CouldNotWriteToLog: "The database was unable to write transaction to log."
+ Neo_DatabaseError_Transaction_ReleaseLocksFailed: "The transaction was unable to release one or more of its locks."
+ Neo_TransientError_General_DatabaseUnavailable: "The database is not currently available to serve your request, refer to the database logs for more details. Retrying your request at a later time may succeed."
+ Neo_TransientError_Network_UnknownFailure: "An unknown network failure occurred, a retry may resolve the issue."
+ Neo_TransientError_Schema_ModifiedConcurrently: "The database schema was modified while this transaction was running, the transaction should be retried."
+ Neo_TransientError_Security_ModifiedConcurrently: "The user was modified concurrently to this Request."
+ Neo_TransientError_Statement_ExternalResourceFailure: "The external resource is not available"
+ Neo_TransientError_Transaction_AcquireLockTimeout: "The transaction was unable to acquire a lock, for instance due to a timeout or the transaction thread being interrupted."
+ Neo_TransientError_Transaction_DeadlockDetected: "This transaction, and at least one more transaction, has acquired locks in a way that it will wait indefinitely, and the database has aborted it. Retrying this transaction will most likely be successful." \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/catalog-be/users-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/users-configuration.yaml
new file mode 100644
index 0000000000..a6c23653f0
--- /dev/null
+++ b/catalog-be/src/test/resources/config/catalog-be/users-configuration.yaml
@@ -0,0 +1,2 @@
+userCredentials:
+ ci: 2a1f887d607d4515d4066fe0f5452a50:0a0dc557c3bf594b1a48030e3e99227580168b21f44e285c69740b8d5b13e33b \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/configuration1.yaml b/catalog-be/src/test/resources/config/configuration1.yaml
new file mode 100644
index 0000000000..12ab2c777f
--- /dev/null
+++ b/catalog-be/src/test/resources/config/configuration1.yaml
@@ -0,0 +1,17 @@
+version: 1.0
+released: 2012-11-30
+
+# Connection parameters
+connection:
+ url: jdbc:mysql://localhost:3306/db
+ poolSize: 5
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/elasticsearch.yml b/catalog-be/src/test/resources/config/elasticsearch.yml
new file mode 100644
index 0000000000..a6a2c1b950
--- /dev/null
+++ b/catalog-be/src/test/resources/config/elasticsearch.yml
@@ -0,0 +1,387 @@
+
+cluster.name: elasticsearch_1_5_2
+
+discovery.zen.ping.multicast.enabled: false
+discovery.zen.ping.unicast.enabled: true
+discovery.zen.ping.unicast.hosts: elasticsearch_host
+
+
+
+##################### Elasticsearch Configuration Example #####################
+
+# This file contains an overview of various configuration settings,
+# targeted at operations staff. Application developers should
+# consult the guide at <http://elasticsearch.org/guide>.
+#
+# The installation procedure is covered at
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
+#
+# Elasticsearch comes with reasonable defaults for most settings,
+# so you can try it out without bothering with configuration.
+#
+# Most of the time, these defaults are just fine for running a production
+# cluster. If you're fine-tuning your cluster, or wondering about the
+# effect of certain configuration option, please _do ask_ on the
+# mailing list or IRC channel [http://elasticsearch.org/community].
+
+# Any element in the configuration can be replaced with environment variables
+# by placing them in ${...} notation. For example:
+#
+# node.rack: ${RACK_ENV_VAR}
+
+# For information on supported formats and syntax for the config file, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html>
+
+
+################################### Cluster ###################################
+
+# Cluster name identifies your cluster for auto-discovery. If you're running
+# multiple clusters on the same network, make sure you're using unique names.
+#
+# cluster.name: elasticsearch
+
+
+#################################### Node #####################################
+
+# Node names are generated dynamically on startup, so you're relieved
+# from configuring them manually. You can tie this node to a specific name:
+#
+# node.name: "Franz Kafka"
+
+# Every node can be configured to allow or deny being eligible as the master,
+# and to allow or deny to store the data.
+#
+# Allow this node to be eligible as a master node (enabled by default):
+#
+# node.master: true
+#
+# Allow this node to store data (enabled by default):
+#
+# node.data: true
+
+# You can exploit these settings to design advanced cluster topologies.
+#
+# 1. You want this node to never become a master node, only to hold data.
+# This will be the "workhorse" of your cluster.
+#
+# node.master: false
+# node.data: true
+#
+# 2. You want this node to only serve as a master: to not store any data and
+# to have free resources. This will be the "coordinator" of your cluster.
+#
+# node.master: true
+# node.data: false
+#
+# 3. You want this node to be neither master nor data node, but
+# to act as a "search load balancer" (fetching data from nodes,
+# aggregating results, etc.)
+#
+# node.master: false
+# node.data: false
+
+# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
+# Node Info API [http://localhost:9200/_nodes] or GUI tools
+# such as <http://www.elasticsearch.org/overview/marvel/>,
+# <http://github.com/karmi/elasticsearch-paramedic>,
+# <http://github.com/lukas-vlcek/bigdesk> and
+# <http://mobz.github.com/elasticsearch-head> to inspect the cluster state.
+
+# A node can have generic attributes associated with it, which can later be used
+# for customized shard allocation filtering, or allocation awareness. An attribute
+# is a simple key value pair, similar to node.key: value, here is an example:
+#
+# node.rack: rack314
+
+# By default, multiple nodes are allowed to start from the same installation location
+# to disable it, set the following:
+# node.max_local_storage_nodes: 1
+
+
+#################################### Index ####################################
+
+# You can set a number of options (such as shard/replica options, mapping
+# or analyzer definitions, translog settings, ...) for indices globally,
+# in this file.
+#
+# Note, that it makes more sense to configure index settings specifically for
+# a certain index, either when creating it or by using the index templates API.
+#
+# See <http://elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules.html> and
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
+# for more information.
+
+# Set the number of shards (splits) of an index (5 by default):
+#
+# index.number_of_shards: 5
+
+# Set the number of replicas (additional copies) of an index (1 by default):
+#
+# index.number_of_replicas: 1
+
+# Note, that for development on a local machine, with small indices, it usually
+# makes sense to "disable" the distributed features:
+#
+index.number_of_shards: 1
+index.number_of_replicas: 0
+
+# These settings directly affect the performance of index and search operations
+# in your cluster. Assuming you have enough machines to hold shards and
+# replicas, the rule of thumb is:
+#
+# 1. Having more *shards* enhances the _indexing_ performance and allows to
+# _distribute_ a big index across machines.
+# 2. Having more *replicas* enhances the _search_ performance and improves the
+# cluster _availability_.
+#
+# The "number_of_shards" is a one-time setting for an index.
+#
+# The "number_of_replicas" can be increased or decreased anytime,
+# by using the Index Update Settings API.
+#
+# Elasticsearch takes care about load balancing, relocating, gathering the
+# results from nodes, etc. Experiment with different settings to fine-tune
+# your setup.
+
+# Use the Index Status API (<http://localhost:9200/A/_status>) to inspect
+# the index status.
+
+
+#################################### Paths ####################################
+
+# Path to directory containing configuration (this file and logging.yml):
+#
+path.conf: /src/test/resources
+
+# Path to directory where to store index data allocated for this node.
+#
+path.data: target/esdata
+#
+# Can optionally include more than one location, causing data to be striped across
+# the locations (a la RAID 0) on a file level, favouring locations with most free
+# space on creation. For example:
+#
+# path.data: /path/to/data1,/path/to/data2
+
+# Path to temporary files:
+#
+path.work: /target/eswork
+
+# Path to log files:
+#
+path.logs: /target/eslogs
+
+# Path to where plugins are installed:
+#
+# path.plugins: /path/to/plugins
+
+
+#################################### Plugin ###################################
+
+# If a plugin listed here is not installed for current node, the node will not start.
+#
+# plugin.mandatory: mapper-attachments,lang-groovy
+
+
+################################### Memory ####################################
+
+# Elasticsearch performs poorly when JVM starts swapping: you should ensure that
+# it _never_ swaps.
+#
+# Set this property to true to lock the memory:
+#
+# bootstrap.mlockall: true
+
+# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
+# to the same value, and that the machine has enough memory to allocate
+# for Elasticsearch, leaving enough memory for the operating system itself.
+#
+# You should also make sure that the Elasticsearch process is allowed to lock
+# the memory, eg. by using `ulimit -l unlimited`.
+
+
+############################## Network And HTTP ###############################
+
+# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
+# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
+# communication. (the range means that if the port is busy, it will automatically
+# try the next port).
+
+# Set the bind address specifically (IPv4 or IPv6):
+#
+# network.bind_host: 192.168.0.1
+
+# Set the address other nodes will use to communicate with this node. If not
+# set, it is automatically derived. It must point to an actual IP address.
+#
+# network.publish_host: 192.168.0.1
+
+# Set both 'bind_host' and 'publish_host':
+#
+# network.host: 192.168.0.1
+
+# Set a custom port for the node to node communication (9300 by default):
+#
+# transport.tcp.port: 9300
+
+# Enable compression for all communication between nodes (disabled by default):
+#
+# transport.tcp.compress: true
+
+# Set a custom port to listen for HTTP traffic:
+#
+# http.port: 9200
+
+# Set a custom allowed content length:
+#
+# http.max_content_length: 100mb
+
+# Disable HTTP completely:
+#
+# http.enabled: false
+
+
+################################### Gateway ###################################
+
+# The gateway allows for persisting the cluster state between full cluster
+# restarts. Every change to the state (such as adding an index) will be stored
+# in the gateway, and when the cluster starts up for the first time,
+# it will read its state from the gateway.
+
+# There are several types of gateway implementations. For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-gateway.html>.
+
+# The default gateway type is the "local" gateway (recommended):
+#
+# gateway.type: local
+
+# Settings below control how and when to start the initial recovery process on
+# a full cluster restart (to reuse as much local data as possible when using shared
+# gateway).
+
+# Allow recovery process after N nodes in a cluster are up:
+#
+gateway.recover_after_nodes: 1
+
+# Set the timeout to initiate the recovery process, once the N nodes
+# from previous setting are up (accepts time value):
+#
+# gateway.recover_after_time: 5m
+
+# Set how many nodes are expected in this cluster. Once these N nodes
+# are up (and recover_after_nodes is met), begin recovery process immediately
+# (without waiting for recover_after_time to expire):
+#
+gateway.expected_nodes: 1
+
+
+############################# Recovery Throttling #############################
+
+# These settings allow to control the process of shards allocation between
+# nodes during initial recovery, replica allocation, rebalancing,
+# or when adding and removing nodes.
+
+# Set the number of concurrent recoveries happening on a node:
+#
+# 1. During the initial recovery
+#
+# cluster.routing.allocation.node_initial_primaries_recoveries: 4
+#
+# 2. During adding/removing nodes, rebalancing, etc
+#
+# cluster.routing.allocation.node_concurrent_recoveries: 2
+
+# Set to throttle throughput when recovering (eg. 100mb, by default 20mb):
+#
+# indices.recovery.max_bytes_per_sec: 20mb
+
+# Set to limit the number of open concurrent streams when
+# recovering a shard from a peer:
+#
+# indices.recovery.concurrent_streams: 5
+
+
+################################## Discovery ##################################
+
+# Discovery infrastructure ensures nodes can be found within a cluster
+# and master node is elected. Multicast discovery is the default.
+
+# Set to ensure a node sees N other master eligible nodes to be considered
+# operational within the cluster. Its recommended to set it to a higher value
+# than 1 when running more than 2 nodes in the cluster.
+#
+# discovery.zen.minimum_master_nodes: 1
+
+# Set the time to wait for ping responses from other nodes when discovering.
+# Set this option to a higher value on a slow or congested network
+# to minimize discovery failures:
+#
+# discovery.zen.ping.timeout: 3s
+
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html>
+
+# Unicast discovery allows to explicitly control which nodes will be used
+# to discover the cluster. It can be used when multicast is not present,
+# or to restrict the cluster communication-wise.
+#
+# 1. Disable multicast discovery (enabled by default):
+#
+# discovery.zen.ping.multicast.enabled: false
+#
+# 2. Configure an initial list of master nodes in the cluster
+# to perform discovery when new nodes (master or data) are started:
+#
+# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]
+
+# EC2 discovery allows to use AWS EC2 API in order to perform discovery.
+#
+# You have to install the cloud-aws plugin for enabling the EC2 discovery.
+#
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html>
+#
+# See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/>
+# for a step-by-step tutorial.
+
+# GCE discovery allows to use Google Compute Engine API in order to perform discovery.
+#
+# You have to install the cloud-gce plugin for enabling the GCE discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>.
+
+# Azure discovery allows to use Azure API in order to perform discovery.
+#
+# You have to install the cloud-azure plugin for enabling the Azure discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
+
+################################## Slow Log ##################################
+
+# Shard level query and fetch threshold logging.
+
+#index.search.slowlog.threshold.query.warn: 10s
+#index.search.slowlog.threshold.query.info: 5s
+#index.search.slowlog.threshold.query.debug: 2s
+#index.search.slowlog.threshold.query.trace: 500ms
+
+#index.search.slowlog.threshold.fetch.warn: 1s
+#index.search.slowlog.threshold.fetch.info: 800ms
+#index.search.slowlog.threshold.fetch.debug: 500ms
+#index.search.slowlog.threshold.fetch.trace: 200ms
+
+#index.indexing.slowlog.threshold.index.warn: 10s
+#index.indexing.slowlog.threshold.index.info: 5s
+#index.indexing.slowlog.threshold.index.debug: 2s
+#index.indexing.slowlog.threshold.index.trace: 500ms
+
+################################## GC Logging ################################
+
+#monitor.jvm.gc.young.warn: 1000ms
+#monitor.jvm.gc.young.info: 700ms
+#monitor.jvm.gc.young.debug: 400ms
+
+#monitor.jvm.gc.old.warn: 10s
+#monitor.jvm.gc.old.info: 5s
+#monitor.jvm.gc.old.debug: 2s
+
diff --git a/catalog-be/src/test/resources/config/elasticsearch.yml.bak b/catalog-be/src/test/resources/config/elasticsearch.yml.bak
new file mode 100644
index 0000000000..98c6864bf2
--- /dev/null
+++ b/catalog-be/src/test/resources/config/elasticsearch.yml.bak
@@ -0,0 +1,387 @@
+
+cluster.name: elasticsearch_pavel
+
+discovery.zen.ping.multicast.enabled: false
+discovery.zen.ping.unicast.enabled: true
+discovery.zen.ping.unicast.hosts: elasticsearch_host
+
+
+
+##################### Elasticsearch Configuration Example #####################
+
+# This file contains an overview of various configuration settings,
+# targeted at operations staff. Application developers should
+# consult the guide at <http://elasticsearch.org/guide>.
+#
+# The installation procedure is covered at
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
+#
+# Elasticsearch comes with reasonable defaults for most settings,
+# so you can try it out without bothering with configuration.
+#
+# Most of the time, these defaults are just fine for running a production
+# cluster. If you're fine-tuning your cluster, or wondering about the
+# effect of certain configuration option, please _do ask_ on the
+# mailing list or IRC channel [http://elasticsearch.org/community].
+
+# Any element in the configuration can be replaced with environment variables
+# by placing them in ${...} notation. For example:
+#
+# node.rack: ${RACK_ENV_VAR}
+
+# For information on supported formats and syntax for the config file, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html>
+
+
+################################### Cluster ###################################
+
+# Cluster name identifies your cluster for auto-discovery. If you're running
+# multiple clusters on the same network, make sure you're using unique names.
+#
+# cluster.name: elasticsearch
+
+
+#################################### Node #####################################
+
+# Node names are generated dynamically on startup, so you're relieved
+# from configuring them manually. You can tie this node to a specific name:
+#
+# node.name: "Franz Kafka"
+
+# Every node can be configured to allow or deny being eligible as the master,
+# and to allow or deny to store the data.
+#
+# Allow this node to be eligible as a master node (enabled by default):
+#
+# node.master: true
+#
+# Allow this node to store data (enabled by default):
+#
+# node.data: true
+
+# You can exploit these settings to design advanced cluster topologies.
+#
+# 1. You want this node to never become a master node, only to hold data.
+# This will be the "workhorse" of your cluster.
+#
+# node.master: false
+# node.data: true
+#
+# 2. You want this node to only serve as a master: to not store any data and
+# to have free resources. This will be the "coordinator" of your cluster.
+#
+# node.master: true
+# node.data: false
+#
+# 3. You want this node to be neither master nor data node, but
+# to act as a "search load balancer" (fetching data from nodes,
+# aggregating results, etc.)
+#
+# node.master: false
+# node.data: false
+
+# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
+# Node Info API [http://localhost:9200/_nodes] or GUI tools
+# such as <http://www.elasticsearch.org/overview/marvel/>,
+# <http://github.com/karmi/elasticsearch-paramedic>,
+# <http://github.com/lukas-vlcek/bigdesk> and
+# <http://mobz.github.com/elasticsearch-head> to inspect the cluster state.
+
+# A node can have generic attributes associated with it, which can later be used
+# for customized shard allocation filtering, or allocation awareness. An attribute
+# is a simple key value pair, similar to node.key: value, here is an example:
+#
+# node.rack: rack314
+
+# By default, multiple nodes are allowed to start from the same installation location
+# to disable it, set the following:
+# node.max_local_storage_nodes: 1
+
+
+#################################### Index ####################################
+
+# You can set a number of options (such as shard/replica options, mapping
+# or analyzer definitions, translog settings, ...) for indices globally,
+# in this file.
+#
+# Note, that it makes more sense to configure index settings specifically for
+# a certain index, either when creating it or by using the index templates API.
+#
+# See <http://elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules.html> and
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
+# for more information.
+
+# Set the number of shards (splits) of an index (5 by default):
+#
+# index.number_of_shards: 5
+
+# Set the number of replicas (additional copies) of an index (1 by default):
+#
+# index.number_of_replicas: 1
+
+# Note, that for development on a local machine, with small indices, it usually
+# makes sense to "disable" the distributed features:
+#
+index.number_of_shards: 1
+index.number_of_replicas: 0
+
+# These settings directly affect the performance of index and search operations
+# in your cluster. Assuming you have enough machines to hold shards and
+# replicas, the rule of thumb is:
+#
+# 1. Having more *shards* enhances the _indexing_ performance and allows to
+# _distribute_ a big index across machines.
+# 2. Having more *replicas* enhances the _search_ performance and improves the
+# cluster _availability_.
+#
+# The "number_of_shards" is a one-time setting for an index.
+#
+# The "number_of_replicas" can be increased or decreased anytime,
+# by using the Index Update Settings API.
+#
+# Elasticsearch takes care about load balancing, relocating, gathering the
+# results from nodes, etc. Experiment with different settings to fine-tune
+# your setup.
+
+# Use the Index Status API (<http://localhost:9200/A/_status>) to inspect
+# the index status.
+
+
+#################################### Paths ####################################
+
+# Path to directory containing configuration (this file and logging.yml):
+#
+path.conf: /src/test/resources
+
+# Path to directory where to store index data allocated for this node.
+#
+path.data: target/esdata
+#
+# Can optionally include more than one location, causing data to be striped across
+# the locations (a la RAID 0) on a file level, favouring locations with most free
+# space on creation. For example:
+#
+# path.data: /path/to/data1,/path/to/data2
+
+# Path to temporary files:
+#
+path.work: /target/eswork
+
+# Path to log files:
+#
+path.logs: /target/eslogs
+
+# Path to where plugins are installed:
+#
+# path.plugins: /path/to/plugins
+
+
+#################################### Plugin ###################################
+
+# If a plugin listed here is not installed for current node, the node will not start.
+#
+# plugin.mandatory: mapper-attachments,lang-groovy
+
+
+################################### Memory ####################################
+
+# Elasticsearch performs poorly when JVM starts swapping: you should ensure that
+# it _never_ swaps.
+#
+# Set this property to true to lock the memory:
+#
+# bootstrap.mlockall: true
+
+# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
+# to the same value, and that the machine has enough memory to allocate
+# for Elasticsearch, leaving enough memory for the operating system itself.
+#
+# You should also make sure that the Elasticsearch process is allowed to lock
+# the memory, eg. by using `ulimit -l unlimited`.
+
+
+############################## Network And HTTP ###############################
+
+# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
+# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
+# communication. (the range means that if the port is busy, it will automatically
+# try the next port).
+
+# Set the bind address specifically (IPv4 or IPv6):
+#
+# network.bind_host: 192.168.0.1
+
+# Set the address other nodes will use to communicate with this node. If not
+# set, it is automatically derived. It must point to an actual IP address.
+#
+# network.publish_host: 192.168.0.1
+
+# Set both 'bind_host' and 'publish_host':
+#
+# network.host: 192.168.0.1
+
+# Set a custom port for the node to node communication (9300 by default):
+#
+# transport.tcp.port: 9300
+
+# Enable compression for all communication between nodes (disabled by default):
+#
+# transport.tcp.compress: true
+
+# Set a custom port to listen for HTTP traffic:
+#
+# http.port: 9200
+
+# Set a custom allowed content length:
+#
+# http.max_content_length: 100mb
+
+# Disable HTTP completely:
+#
+# http.enabled: false
+
+
+################################### Gateway ###################################
+
+# The gateway allows for persisting the cluster state between full cluster
+# restarts. Every change to the state (such as adding an index) will be stored
+# in the gateway, and when the cluster starts up for the first time,
+# it will read its state from the gateway.
+
+# There are several types of gateway implementations. For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-gateway.html>.
+
+# The default gateway type is the "local" gateway (recommended):
+#
+# gateway.type: local
+
+# Settings below control how and when to start the initial recovery process on
+# a full cluster restart (to reuse as much local data as possible when using shared
+# gateway).
+
+# Allow recovery process after N nodes in a cluster are up:
+#
+gateway.recover_after_nodes: 1
+
+# Set the timeout to initiate the recovery process, once the N nodes
+# from previous setting are up (accepts time value):
+#
+# gateway.recover_after_time: 5m
+
+# Set how many nodes are expected in this cluster. Once these N nodes
+# are up (and recover_after_nodes is met), begin recovery process immediately
+# (without waiting for recover_after_time to expire):
+#
+gateway.expected_nodes: 1
+
+
+############################# Recovery Throttling #############################
+
+# These settings allow to control the process of shards allocation between
+# nodes during initial recovery, replica allocation, rebalancing,
+# or when adding and removing nodes.
+
+# Set the number of concurrent recoveries happening on a node:
+#
+# 1. During the initial recovery
+#
+# cluster.routing.allocation.node_initial_primaries_recoveries: 4
+#
+# 2. During adding/removing nodes, rebalancing, etc
+#
+# cluster.routing.allocation.node_concurrent_recoveries: 2
+
+# Set to throttle throughput when recovering (eg. 100mb, by default 20mb):
+#
+# indices.recovery.max_bytes_per_sec: 20mb
+
+# Set to limit the number of open concurrent streams when
+# recovering a shard from a peer:
+#
+# indices.recovery.concurrent_streams: 5
+
+
+################################## Discovery ##################################
+
+# Discovery infrastructure ensures nodes can be found within a cluster
+# and master node is elected. Multicast discovery is the default.
+
+# Set to ensure a node sees N other master eligible nodes to be considered
+# operational within the cluster. Its recommended to set it to a higher value
+# than 1 when running more than 2 nodes in the cluster.
+#
+# discovery.zen.minimum_master_nodes: 1
+
+# Set the time to wait for ping responses from other nodes when discovering.
+# Set this option to a higher value on a slow or congested network
+# to minimize discovery failures:
+#
+# discovery.zen.ping.timeout: 3s
+
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html>
+
+# Unicast discovery allows to explicitly control which nodes will be used
+# to discover the cluster. It can be used when multicast is not present,
+# or to restrict the cluster communication-wise.
+#
+# 1. Disable multicast discovery (enabled by default):
+#
+# discovery.zen.ping.multicast.enabled: false
+#
+# 2. Configure an initial list of master nodes in the cluster
+# to perform discovery when new nodes (master or data) are started:
+#
+# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]
+
+# EC2 discovery allows to use AWS EC2 API in order to perform discovery.
+#
+# You have to install the cloud-aws plugin for enabling the EC2 discovery.
+#
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html>
+#
+# See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/>
+# for a step-by-step tutorial.
+
+# GCE discovery allows to use Google Compute Engine API in order to perform discovery.
+#
+# You have to install the cloud-gce plugin for enabling the GCE discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>.
+
+# Azure discovery allows to use Azure API in order to perform discovery.
+#
+# You have to install the cloud-azure plugin for enabling the Azure discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
+
+################################## Slow Log ##################################
+
+# Shard level query and fetch threshold logging.
+
+#index.search.slowlog.threshold.query.warn: 10s
+#index.search.slowlog.threshold.query.info: 5s
+#index.search.slowlog.threshold.query.debug: 2s
+#index.search.slowlog.threshold.query.trace: 500ms
+
+#index.search.slowlog.threshold.fetch.warn: 1s
+#index.search.slowlog.threshold.fetch.info: 800ms
+#index.search.slowlog.threshold.fetch.debug: 500ms
+#index.search.slowlog.threshold.fetch.trace: 200ms
+
+#index.indexing.slowlog.threshold.index.warn: 10s
+#index.indexing.slowlog.threshold.index.info: 5s
+#index.indexing.slowlog.threshold.index.debug: 2s
+#index.indexing.slowlog.threshold.index.trace: 500ms
+
+################################## GC Logging ################################
+
+#monitor.jvm.gc.young.warn: 1000ms
+#monitor.jvm.gc.young.info: 700ms
+#monitor.jvm.gc.young.debug: 400ms
+
+#monitor.jvm.gc.old.warn: 10s
+#monitor.jvm.gc.old.info: 5s
+#monitor.jvm.gc.old.debug: 2s
+
diff --git a/catalog-be/src/test/resources/config/mysql-type-empty-nodes.zip b/catalog-be/src/test/resources/config/mysql-type-empty-nodes.zip
new file mode 100644
index 0000000000..d317bccd1e
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type-empty-nodes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/mysql-type-no-nodes.zip b/catalog-be/src/test/resources/config/mysql-type-no-nodes.zip
new file mode 100644
index 0000000000..09999faed5
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type-no-nodes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/mysql-type-no-version.zip b/catalog-be/src/test/resources/config/mysql-type-no-version.zip
new file mode 100644
index 0000000000..fa1319f311
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type-no-version.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/mysql-type-only-yaml.zip b/catalog-be/src/test/resources/config/mysql-type-only-yaml.zip
new file mode 100644
index 0000000000..b4b1946940
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type-only-yaml.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/mysql-type-with-scripts.zip b/catalog-be/src/test/resources/config/mysql-type-with-scripts.zip
new file mode 100644
index 0000000000..d689b668a1
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type-with-scripts.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/mysql-type.yml b/catalog-be/src/test/resources/config/mysql-type.yml
new file mode 100644
index 0000000000..f1985a0bdc
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type.yml
@@ -0,0 +1,82 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0_wd03
+description: MySQL RDBMS installation on a specific mounted volume path.
+template_name: mysql-type
+template_version: 1.1.1-SNAPSHOT
+template_author: FastConnect
+
+imports:
+ - "tosca-normative-types:1.0.0.wd03-SNAPSHOT"
+
+node_types:
+ alien.nodes.Mysql:
+ derived_from: tosca.nodes.Database
+ description: >
+ A node to install MySQL v5.5 database with data
+ on a specific attached volume.
+ capabilities:
+ host:
+ type: alien.capabilities.MysqlDatabase
+ properties:
+ valid_node_types: [ tosca.nodes.WebApplication ]
+ requirements:
+ - host: tosca.nodes.Compute
+ type: tosca.relationships.HostedOn
+ tags:
+ icon: /images/mysql.png
+ properties:
+ db_port:
+ type: integer
+ default: 3306
+ description: The port on which the underlying database service will listen to data.
+ db_name:
+ type: string
+ required: true
+ default: wordpress
+ description: The logical name of the database.
+ db_user:
+ type: string
+ default: pass
+ description: The special user account used for database administration.
+ db_password:
+ type: string
+ default: pass
+ description: The password associated with the user account provided in the ‘db_user’ property.
+ bind_address:
+ type: boolean
+ default: true
+ required: false
+ description: If true,the server accepts TCP/IP connections on all server host IPv4 interfaces.
+ storage_path:
+ type: string
+ default: /mountedStorage
+ constraints:
+ - valid_values: [ "/mountedStorage", "/var/mysql" ]
+ interfaces:
+ Standard:
+ create: scripts/install_mysql.sh
+ start:
+ inputs:
+ VOLUME_HOME: { get_property: [SELF, storage_path] }
+ PORT: { get_property: [SELF, db_port] }
+ DB_NAME: { get_property: [SELF, db_name] }
+ DB_USER: { get_property: [SELF, db_user] }
+ DB_PASSWORD: { get_property: [SELF, db_password] }
+ BIND_ADRESS: { get_property: [SELF, bind_address] }
+ implementation: scripts/start_mysql.sh
+ fastconnect.cloudify.extensions:
+ start_detection:
+ inputs:
+ PORT: { get_property: [SELF, db_port] }
+ implementation: scripts/mysql_start_detection.groovy
+ artifacts:
+ - scripts: scripts
+ type: tosca.artifacts.File
+
+capability_types:
+ alien.capabilities.MysqlDatabase:
+ derived_from: tosca.capabilities.Container
+
+artifact_types:
+ tosca.artifacts.GroovyScript:
+ description: A groovy script (.groovy file)
+ file_ext: [groovy]
diff --git a/catalog-be/src/test/resources/config/mysql-type.zip b/catalog-be/src/test/resources/config/mysql-type.zip
new file mode 100644
index 0000000000..b4b1946940
--- /dev/null
+++ b/catalog-be/src/test/resources/config/mysql-type.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/normative-types-root.zip b/catalog-be/src/test/resources/config/normative-types-root.zip
new file mode 100644
index 0000000000..b0c39962d1
--- /dev/null
+++ b/catalog-be/src/test/resources/config/normative-types-root.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/config/sample.yaml b/catalog-be/src/test/resources/config/sample.yaml
new file mode 100644
index 0000000000..12ab2c777f
--- /dev/null
+++ b/catalog-be/src/test/resources/config/sample.yaml
@@ -0,0 +1,17 @@
+version: 1.0
+released: 2012-11-30
+
+# Connection parameters
+connection:
+ url: jdbc:mysql://localhost:3306/db
+ poolSize: 5
+
+# Protocols
+protocols:
+ - http
+ - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd \ No newline at end of file
diff --git a/catalog-be/src/test/resources/config/sampleNoProtocol.yaml b/catalog-be/src/test/resources/config/sampleNoProtocol.yaml
new file mode 100644
index 0000000000..6197232aa4
--- /dev/null
+++ b/catalog-be/src/test/resources/config/sampleNoProtocol.yaml
@@ -0,0 +1,17 @@
+version: 1.0
+released: 2012-11-30
+
+# Connection parameters
+connection:
+ url: jdbc:mysql://localhost:3306/db
+ poolSize: 5
+
+# Protocols
+#protocols:
+# - http
+# - https
+
+# Users
+users:
+ tom: passwd
+ bob: passwd \ No newline at end of file
diff --git a/catalog-be/src/test/resources/elasticsearch.yml b/catalog-be/src/test/resources/elasticsearch.yml
new file mode 100644
index 0000000000..eba942dc31
--- /dev/null
+++ b/catalog-be/src/test/resources/elasticsearch.yml
@@ -0,0 +1,391 @@
+
+elasticSearch.local: true
+elasticSearch.transportclient: false
+cluster.name: elasticsearch_1_5_2222
+
+discovery.zen.ping.multicast.enabled: false
+discovery.zen.ping.unicast.enabled: true
+discovery.zen.ping.unicast.hosts: 1.2.3.4
+transport.client.initial_nodes:
+ - 1.2.3.4:9300
+
+#plugin.types: "DeleteByQueryPlugin"
+
+##################### Elasticsearch Configuration Example #####################
+
+# This file contains an overview of various configuration settings,
+# targeted at operations staff. Application developers should
+# consult the guide at <http://elasticsearch.org/guide>.
+#
+# The installation procedure is covered at
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
+#
+# Elasticsearch comes with reasonable defaults for most settings,
+# so you can try it out without bothering with configuration.
+#
+# Most of the time, these defaults are just fine for running a production
+# cluster. If you're fine-tuning your cluster, or wondering about the
+# effect of certain configuration option, please _do ask_ on the
+# mailing list or IRC channel [http://elasticsearch.org/community].
+
+# Any element in the configuration can be replaced with environment variables
+# by placing them in ${...} notation. For example:
+#
+# node.rack: ${RACK_ENV_VAR}
+
+# For information on supported formats and syntax for the config file, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html>
+
+
+################################### Cluster ###################################
+
+# Cluster name identifies your cluster for auto-discovery. If you're running
+# multiple clusters on the same network, make sure you're using unique names.
+#
+# cluster.name: elasticsearch
+
+
+#################################### Node #####################################
+
+# Node names are generated dynamically on startup, so you're relieved
+# from configuring them manually. You can tie this node to a specific name:
+#
+# node.name: "Franz Kafka"
+
+# Every node can be configured to allow or deny being eligible as the master,
+# and to allow or deny to store the data.
+#
+# Allow this node to be eligible as a master node (enabled by default):
+#
+# node.master: true
+#
+# Allow this node to store data (enabled by default):
+#
+# node.data: true
+
+# You can exploit these settings to design advanced cluster topologies.
+#
+# 1. You want this node to never become a master node, only to hold data.
+# This will be the "workhorse" of your cluster.
+#
+# node.master: false
+# node.data: true
+#
+# 2. You want this node to only serve as a master: to not store any data and
+# to have free resources. This will be the "coordinator" of your cluster.
+#
+# node.master: true
+# node.data: false
+#
+# 3. You want this node to be neither master nor data node, but
+# to act as a "search load balancer" (fetching data from nodes,
+# aggregating results, etc.)
+#
+# node.master: false
+# node.data: false
+
+# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
+# Node Info API [http://localhost:9200/_nodes] or GUI tools
+# such as <http://www.elasticsearch.org/overview/marvel/>,
+# <http://github.com/karmi/elasticsearch-paramedic>,
+# <http://github.com/lukas-vlcek/bigdesk> and
+# <http://mobz.github.com/elasticsearch-head> to inspect the cluster state.
+
+# A node can have generic attributes associated with it, which can later be used
+# for customized shard allocation filtering, or allocation awareness. An attribute
+# is a simple key value pair, similar to node.key: value, here is an example:
+#
+# node.rack: rack314
+
+# By default, multiple nodes are allowed to start from the same installation location
+# to disable it, set the following:
+# node.max_local_storage_nodes: 1
+
+
+#################################### Index ####################################
+
+# You can set a number of options (such as shard/replica options, mapping
+# or analyzer definitions, translog settings, ...) for indices globally,
+# in this file.
+#
+# Note, that it makes more sense to configure index settings specifically for
+# a certain index, either when creating it or by using the index templates API.
+#
+# See <http://elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules.html> and
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
+# for more information.
+
+# Set the number of shards (splits) of an index (5 by default):
+#
+# index.number_of_shards: 5
+
+# Set the number of replicas (additional copies) of an index (1 by default):
+#
+# index.number_of_replicas: 1
+
+# Note, that for development on a local machine, with small indices, it usually
+# makes sense to "disable" the distributed features:
+#
+index.number_of_shards: 1
+index.number_of_replicas: 0
+
+# These settings directly affect the performance of index and search operations
+# in your cluster. Assuming you have enough machines to hold shards and
+# replicas, the rule of thumb is:
+#
+# 1. Having more *shards* enhances the _indexing_ performance and allows to
+# _distribute_ a big index across machines.
+# 2. Having more *replicas* enhances the _search_ performance and improves the
+# cluster _availability_.
+#
+# The "number_of_shards" is a one-time setting for an index.
+#
+# The "number_of_replicas" can be increased or decreased anytime,
+# by using the Index Update Settings API.
+#
+# Elasticsearch takes care about load balancing, relocating, gathering the
+# results from nodes, etc. Experiment with different settings to fine-tune
+# your setup.
+
+# Use the Index Status API (<http://localhost:9200/A/_status>) to inspect
+# the index status.
+
+
+#################################### Paths ####################################
+path.home: /src/test/resources
+# Path to directory containing configuration (this file and logging.yml):
+#
+path.conf: /src/test/resources
+
+# Path to directory where to store index data allocated for this node.
+#
+path.data: target/esdata
+#
+# Can optionally include more than one location, causing data to be striped across
+# the locations (a la RAID 0) on a file level, favouring locations with most free
+# space on creation. For example:
+#
+# path.data: /path/to/data1,/path/to/data2
+
+# Path to temporary files:
+#
+path.work: /target/eswork
+
+# Path to log files:
+#
+path.logs: /target/eslogs
+
+# Path to where plugins are installed:
+#
+# path.plugins: /path/to/plugins
+
+
+#################################### Plugin ###################################
+
+# If a plugin listed here is not installed for current node, the node will not start.
+#
+# plugin.mandatory: mapper-attachments,lang-groovy
+
+
+################################### Memory ####################################
+
+# Elasticsearch performs poorly when JVM starts swapping: you should ensure that
+# it _never_ swaps.
+#
+# Set this property to true to lock the memory:
+#
+# bootstrap.mlockall: true
+
+# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
+# to the same value, and that the machine has enough memory to allocate
+# for Elasticsearch, leaving enough memory for the operating system itself.
+#
+# You should also make sure that the Elasticsearch process is allowed to lock
+# the memory, eg. by using `ulimit -l unlimited`.
+
+
+############################## Network And HTTP ###############################
+
+# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
+# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
+# communication. (the range means that if the port is busy, it will automatically
+# try the next port).
+
+# Set the bind address specifically (IPv4 or IPv6):
+#
+# network.bind_host: 192.168.0.1
+
+# Set the address other nodes will use to communicate with this node. If not
+# set, it is automatically derived. It must point to an actual IP address.
+#
+# network.publish_host: 192.168.0.1
+
+# Set both 'bind_host' and 'publish_host':
+#
+# network.host: 192.168.0.1
+
+# Set a custom port for the node to node communication (9300 by default):
+#
+# transport.tcp.port: 9300
+
+# Enable compression for all communication between nodes (disabled by default):
+#
+# transport.tcp.compress: true
+
+# Set a custom port to listen for HTTP traffic:
+#
+# http.port: 9200
+
+# Set a custom allowed content length:
+#
+# http.max_content_length: 100mb
+
+# Disable HTTP completely:
+#
+# http.enabled: false
+
+
+################################### Gateway ###################################
+
+# The gateway allows for persisting the cluster state between full cluster
+# restarts. Every change to the state (such as adding an index) will be stored
+# in the gateway, and when the cluster starts up for the first time,
+# it will read its state from the gateway.
+
+# There are several types of gateway implementations. For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-gateway.html>.
+
+# The default gateway type is the "local" gateway (recommended):
+#
+# gateway.type: local
+
+# Settings below control how and when to start the initial recovery process on
+# a full cluster restart (to reuse as much local data as possible when using shared
+# gateway).
+
+# Allow recovery process after N nodes in a cluster are up:
+#
+gateway.recover_after_nodes: 1
+
+# Set the timeout to initiate the recovery process, once the N nodes
+# from previous setting are up (accepts time value):
+#
+# gateway.recover_after_time: 5m
+
+# Set how many nodes are expected in this cluster. Once these N nodes
+# are up (and recover_after_nodes is met), begin recovery process immediately
+# (without waiting for recover_after_time to expire):
+#
+gateway.expected_nodes: 1
+
+
+############################# Recovery Throttling #############################
+
+# These settings allow to control the process of shards allocation between
+# nodes during initial recovery, replica allocation, rebalancing,
+# or when adding and removing nodes.
+
+# Set the number of concurrent recoveries happening on a node:
+#
+# 1. During the initial recovery
+#
+# cluster.routing.allocation.node_initial_primaries_recoveries: 4
+#
+# 2. During adding/removing nodes, rebalancing, etc
+#
+# cluster.routing.allocation.node_concurrent_recoveries: 2
+
+# Set to throttle throughput when recovering (eg. 100mb, by default 20mb):
+#
+# indices.recovery.max_bytes_per_sec: 20mb
+
+# Set to limit the number of open concurrent streams when
+# recovering a shard from a peer:
+#
+# indices.recovery.concurrent_streams: 5
+
+
+################################## Discovery ##################################
+
+# Discovery infrastructure ensures nodes can be found within a cluster
+# and master node is elected. Multicast discovery is the default.
+
+# Set to ensure a node sees N other master eligible nodes to be considered
+# operational within the cluster. Its recommended to set it to a higher value
+# than 1 when running more than 2 nodes in the cluster.
+#
+# discovery.zen.minimum_master_nodes: 1
+
+# Set the time to wait for ping responses from other nodes when discovering.
+# Set this option to a higher value on a slow or congested network
+# to minimize discovery failures:
+#
+# discovery.zen.ping.timeout: 3s
+
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html>
+
+# Unicast discovery allows to explicitly control which nodes will be used
+# to discover the cluster. It can be used when multicast is not present,
+# or to restrict the cluster communication-wise.
+#
+# 1. Disable multicast discovery (enabled by default):
+#
+# discovery.zen.ping.multicast.enabled: false
+#
+# 2. Configure an initial list of master nodes in the cluster
+# to perform discovery when new nodes (master or data) are started:
+#
+# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]
+
+# EC2 discovery allows to use AWS EC2 API in order to perform discovery.
+#
+# You have to install the cloud-aws plugin for enabling the EC2 discovery.
+#
+# For more information, see
+# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html>
+#
+# See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/>
+# for a step-by-step tutorial.
+
+# GCE discovery allows to use Google Compute Engine API in order to perform discovery.
+#
+# You have to install the cloud-gce plugin for enabling the GCE discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>.
+
+# Azure discovery allows to use Azure API in order to perform discovery.
+#
+# You have to install the cloud-azure plugin for enabling the Azure discovery.
+#
+# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
+
+################################## Slow Log ##################################
+
+# Shard level query and fetch threshold logging.
+
+#index.search.slowlog.threshold.query.warn: 10s
+#index.search.slowlog.threshold.query.info: 5s
+#index.search.slowlog.threshold.query.debug: 2s
+#index.search.slowlog.threshold.query.trace: 500ms
+
+#index.search.slowlog.threshold.fetch.warn: 1s
+#index.search.slowlog.threshold.fetch.info: 800ms
+#index.search.slowlog.threshold.fetch.debug: 500ms
+#index.search.slowlog.threshold.fetch.trace: 200ms
+
+#index.indexing.slowlog.threshold.index.warn: 10s
+#index.indexing.slowlog.threshold.index.info: 5s
+#index.indexing.slowlog.threshold.index.debug: 2s
+#index.indexing.slowlog.threshold.index.trace: 500ms
+
+################################## GC Logging ################################
+
+#monitor.jvm.gc.young.warn: 1000ms
+#monitor.jvm.gc.young.info: 700ms
+#monitor.jvm.gc.young.debug: 400ms
+
+#monitor.jvm.gc.old.warn: 10s
+#monitor.jvm.gc.old.info: 5s
+#monitor.jvm.gc.old.debug: 2s
+
diff --git a/catalog-be/src/test/resources/logback-test.xml b/catalog-be/src/test/resources/logback-test.xml
new file mode 100644
index 0000000000..d2b9bff23f
--- /dev/null
+++ b/catalog-be/src/test/resources/logback-test.xml
@@ -0,0 +1,13 @@
+<!-- only one line, shut up logback ! -->
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
+ </Pattern>
+ </encoder>
+ </appender>
+ <root level="OFF">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration> \ No newline at end of file
diff --git a/catalog-be/src/test/resources/mock_vf.csar b/catalog-be/src/test/resources/mock_vf.csar
new file mode 100644
index 0000000000..4b37f44c73
--- /dev/null
+++ b/catalog-be/src/test/resources/mock_vf.csar
Binary files differ
diff --git a/catalog-be/src/test/resources/normativeTypes/importToscaProperties.yml b/catalog-be/src/test/resources/normativeTypes/importToscaProperties.yml
new file mode 100644
index 0000000000..f856603397
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/importToscaProperties.yml
@@ -0,0 +1,452 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resource.vl.LinkTest:
+ derived_from: tosca.nodes.Root
+ properties:
+ string_prop01:
+ type: map
+ description : another description
+ default: {keyA : val1 , keyB : val2}
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop02:
+ type: map
+ description : another description
+ default: {keyA : "val1" , keyB : "val2"}
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop03:
+ type: map
+ description : another description
+ default: {"keyA" : "val1" , keyB : val2}
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop04:
+ type: map
+ description : another description
+ default: {"keyA" : 10 , keyB : <b>true</b> }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop05:
+ type: map
+ description : another description
+ default: {"keyA" : , keyB : "Big" }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop06:
+ type: map
+ description : another description
+ default: {"keyA" : aaaA , keyB : null }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop07:
+ type: map
+ description : another description
+ default: {"keyA" : NULL , keyB : Null }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop08:
+ type: map
+ description : another description
+ default: {"keyA" : "" , keyB : "abcd" }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop09:
+ type: map
+ description : another description
+ default: {"keyA" : " " , keyB : "abcd" }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop10:
+ type: map
+ description : another description
+ default: {"keyA" : " aaaa" , keyB : " bbbb" }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop11:
+ type: map
+ description : another description
+ default: {"keyA" : "aaaa " , keyB : "bbbb " }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop12:
+ type: map
+ description : another description
+ default: {"keyA" : " aaaa " , keyB : " bbbb ccccc " }
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop13:
+ type: map
+ description : another description
+ default:
+ keyA : "aaaa"
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop14:
+ type: map
+ description : another description
+ default:
+ keyA : " aaaa "
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop15:
+ type: map
+ description : another description
+ default:
+ keyA : AbcD
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop16:
+ type: map
+ description : another description
+ default:
+ keyA : AbcD
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop17:
+ type: map
+ description : another description
+ default:
+ keyA : AbcD
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop18:
+ type: map
+ description : another description
+ default:
+ keyA : <b>AbcD</b>
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop19:
+ type: map
+ description : another description
+ default:
+ keyA : <b>AbcD
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop20:
+ type: map
+ description : another description
+ default:
+ keyA : aaaa
+ keya : aaaa
+ Keya : Aaaa
+ KEYA : nnnn
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop21:
+ type: map
+ description : another description
+ default:
+ keyA : NULL
+ keyB : null
+ keyC : Null
+ entry_schema:
+ description: This is my property
+ type: string
+ string_prop22:
+ type: map
+ description : another description
+ default:
+ entry_schema:
+ description: This is my property
+ type: string
+ integer_prop01:
+ type: map
+ description : another description
+ default: {keyA : 1 , keyB : 1000}
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop02:
+ type: map
+ description : another description
+ default: {keyA : Null , keyB : NULL ,keyC : null }
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop03:
+ type: map
+ description : another description
+ default: {keyA : , keyB : -600}
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop03:
+ type: map
+ description : another description
+ default: {keyA : 800 , keyB : -600}
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop04:
+ type: map
+ description : another description
+ default: {keyA : , keyB : -600}
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop05:
+ type: map
+ description : another description
+ default: {keyA : 100 , keyB : 0 }
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop06:
+ type: map
+ description : another description
+ default: {keyA : 100 , keyB : 00}
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop07:
+ type: map
+ description : another description
+ default: {keyA : 100 , keyB : 100 }
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop08:
+ type: map
+ description : another description
+ default:
+ keyA : 100
+ keyB : 200
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop09:
+ type: map
+ description : another description
+ default:
+ keyA : 100
+ keyB : 200
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop10:
+ type: map
+ description : another description
+ default:
+ keyA : null
+ keyA : Null
+ keyB : 1111
+ keyB : 2222
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop11:
+ type: map
+ description : another description
+ default:
+ keyA : null
+ keyB : Null
+ keyC : NULL
+ keyD :
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop12:
+ type: map
+ description : another description
+ default:
+ entry_schema:
+ description: This is my property
+ type: integer
+ integer_prop13:
+ type: map
+ description : another description
+ default: {keyA : 100 , keyA : 200}
+ entry_schema:
+ description: This is my property
+ type: integer
+ boolean_prop01:
+ type: map
+ description : another description
+ default: {keyA : true , keyB : false , keyC : false }
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop02:
+ type: map
+ description : another description
+ default: {keyA : TRUE , keyB : FALSE , keyC : False }
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop03:
+ type: map
+ description : another description
+ default:
+ keyA : null
+ keyB : Null
+ keyC : NULL
+ keyD :
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop04:
+ type: map
+ description : another description
+ default: {keyA : Null , keyB : NULL ,keyC : null ,keyD : }
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop05:
+ type: map
+ description : another description
+ default: {keyA : true , keyB : false , keyC : false }
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop06:
+ type: map
+ description : another description
+ default:
+ keyA : true
+ keyB : true
+ keyC : false
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop07:
+ type: map
+ description : another description
+ default:
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop08:
+ type: map
+ description : another description
+ default:
+ keyA : false
+ keyA : true
+ keyB : true
+ keyB : false
+ entry_schema:
+ description: This is my property
+ type: boolean
+ boolean_prop09:
+ type: map
+ description : another description
+ default: {keyA : true,keyA : false,keyB : false,keyB : true}
+ entry_schema:
+ description: This is my property
+ type: boolean
+ float_prop01:
+ type: map
+ description : another description
+ default: {keyA : 1.20 , keyB : 3.56f , keyC : 33}
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop02:
+ type: map
+ description : another description
+ default: {keyA : 0.00, keyB : 0.0 , keyC : 0 }
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop03:
+ type: map
+ description : another description
+ default: {keyA : null, keyB : Null , keyC : NULL , keyD : }
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop04:
+ type: map
+ description : another description
+ default: {keyA : 1.20 , keyB : 3.56f , keyC : 33 }
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop05:
+ type: map
+ description : another description
+ default:
+ keyA : 33
+ keyB : 1.2000
+ keyC : 3.607f
+ keyD : 0
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop06:
+ type: map
+ description : another description
+ default:
+ keyA : 33
+ keyB : 1.2000
+ keyC : 3.607f
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop07:
+ type: map
+ description : another description
+ default:
+ keyA : null
+ keyB : Null
+ keyC : NULL
+ keyD :
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop08:
+ type: map
+ description : another description
+ default:
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop09:
+ type: map
+ description : another description
+ default:
+ keyA : 3.5
+ keyA : 0.01
+ keyB : 3.6
+ keyB :
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop10:
+ type: map
+ description : another description
+ default: {keyA : 0.0002}
+ entry_schema:
+ description: This is my property
+ type: float
+ float_prop11:
+ type: map
+ description : another description
+ default: {keyA : 0.000 , keyA : 003.56f, keyB : 33}
+ entry_schema:
+ description: This is my property
+ type: float
+ capabilities:
+ link:
+ type: tosca.capabilities.network.Linkable \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/importToscaWithAttribute.yml b/catalog-be/src/test/resources/normativeTypes/importToscaWithAttribute.yml
new file mode 100644
index 0000000000..5a51e9e198
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/importToscaWithAttribute.yml
@@ -0,0 +1,41 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resource.MyComputeTest:
+ derived_from: tosca.nodes.Root
+ attributes:
+ private_address:
+ type: string
+ status: supported
+ public_address:
+ type: string
+ networks:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.NetworkInfo
+ myAttr:
+ type: list
+ description: this is my description
+ entry_schema:
+ type: string
+ ports:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.PortInfo
+ requirements:
+ - local_storage:
+ capability: tosca.capabilities.Attachment
+ node: tosca.nodes.BlockStorage
+ relationship: tosca.relationships.AttachesTo
+ occurrences: [0, UNBOUNDED]
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [tosca.nodes.SoftwareComponent]
+ endpoint :
+ type: tosca.capabilities.Endpoint.Admin
+ os:
+ type: tosca.capabilities.OperatingSystem
+ scalable:
+ type: tosca.capabilities.Scalable
+ binding:
+ type: tosca.capabilities.network.Bindable
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-all-map-test.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-all-map-test.yml
new file mode 100644
index 0000000000..4cf82d8b8f
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-all-map-test.yml
@@ -0,0 +1,30 @@
+tosca.nodes.BlockStorage:
+ allTestTag: tosca.nodes.Root
+ properties:
+ mapTestTag:
+ stringTestTag: stringVal1
+ listTestTag:
+ - allTestTag: 1 MB
+ - listTestTag: 2 MB
+ - stringTestTag: stringVal2
+ volume_id:
+ type: string
+ required: false
+ allTestTag:
+ - greater_or_equal: 1 MB
+ - stringTestTag: stringVal3
+ allTestTag:
+ mapTestTag: string
+ required: true
+ snapshot_id:
+ stringTestTag: stringVal4
+ required: false
+ listTestTag:
+ - testTag1: 1 MB
+ - mapTestTag:
+ - testTag1: 1 MB
+ - type: stringVal2
+ capabilities:
+ mapTestTag:
+ type: tosca.capabilities.Attachment
+ allTestTag: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-DBMS.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-DBMS.yml
new file mode 100644
index 0000000000..28919d38e4
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-DBMS.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.DBMS:
+ derived_from: tosca.nodes.SoftwareComponent
+ properties:
+ root_password:
+ type: string
+ required: false
+ description: the optional root password for the DBMS service
+ port:
+ type: integer
+ required: false
+ description: the port the DBMS service will listen to for data and requests
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [ tosca.nodes.Database ]
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-Root.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-Root.yml
new file mode 100644
index 0000000000..e9b1de9518
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-Root.yml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from
+ attributes:
+ tosca_id:
+ type: string
+ tosca_name:
+ type: string
+ state:
+ type: string
+ capabilities:
+ feature:
+ type: tosca.capabilities.Node
+ requirements:
+ - dependency :
+ capability: tosca.capabilities.Node
+ node: tosca.nodes.Root
+ relationship: tosca.relationships.DependsOn
+ occurrences: [ 0, UNBOUNDED ]
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Standard
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-blockStorage.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-blockStorage.yml
new file mode 100644
index 0000000000..a82965215f
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-blockStorage.yml
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.BlockStorage:
+ derived_from: tosca.nodes.Root
+ properties:
+ size:
+ type: scalar-unit.size
+ constraints:
+ - greater_or_equal: 1 MB
+ volume_id:
+ type: string
+ required: false
+ snapshot_id:
+ type: string
+ required: false
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-compute.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-compute.yml
new file mode 100644
index 0000000000..00b07fb908
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-compute.yml
@@ -0,0 +1,35 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Compute:
+ derived_from: tosca.nodes.Root
+ attributes:
+ private_address:
+ type: string
+ public_address:
+ type: string
+ networks:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.NetworkInfo
+ ports:
+ type: map
+ entry_schema:
+ type: tosca.datatypes.network.PortInfo
+ requirements:
+ - local_storage:
+ capability: tosca.capabilities.Attachment
+ node: tosca.nodes.BlockStorage
+ relationship: tosca.relationships.AttachesTo
+ occurrences: [0, UNBOUNDED]
+ capabilities:
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [tosca.nodes.SoftwareComponent]
+ endpoint :
+ type: tosca.capabilities.Endpoint.Admin
+ os:
+ type: tosca.capabilities.OperatingSystem
+ scalable:
+ type: tosca.capabilities.Scalable
+ binding:
+ type: tosca.capabilities.network.Bindable
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-database.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-database.yml
new file mode 100644
index 0000000000..5166150c73
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-database.yml
@@ -0,0 +1,27 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.Database:
+ derived_from: tosca.nodes.Root
+ properties:
+ name:
+ type: string
+ description: the logical name of the database
+ port:
+ type: integer
+ description: the port the underlying database service will listen to for data
+ user:
+ type: string
+ description: the optional user account name for DB administration
+ required: false
+ password:
+ type: string
+ description: the optional password for the DB user account
+ required: false
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.DBMS
+ relationship: tosca.relationships.HostedOn
+ capabilities:
+ database_endpoint:
+ type: tosca.capabilities.Endpoint.Database
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-port.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-port.yml
new file mode 100644
index 0000000000..2d1540b27b
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-port.yml
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.network.Port:
+ derived_from: tosca.nodes.Root
+ properties:
+ ip_address:
+ type: string
+ required: false
+ order:
+ type: integer
+ required: true
+ default: 0
+ constraints:
+ - greater_or_equal: 0
+ is_default:
+ type: boolean
+ required: false
+ default: false
+ ip_range_start:
+ type: string
+ required: false
+ ip_range_end:
+ type: string
+ required: false
+ requirements:
+ - link:
+ capability: tosca.capabilities.network.Linkable
+ relationship: tosca.relationships.network.LinksTo
+ - binding:
+ capability: tosca.capabilities.network.Bindable
+ relationship: tosca.relationships.network.BindsTo
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-softwareComponent.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-softwareComponent.yml
new file mode 100644
index 0000000000..9beb93a75a
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-softwareComponent.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.SoftwareComponent:
+ derived_from: tosca.nodes.Root
+ properties:
+ # domain-specific software component version
+ component_version:
+ type: version
+ required: false
+ #admin_credential:
+ # type: tosca.datatypes.Credential
+ # required: false
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.Compute
+ relationship: tosca.relationships.HostedOn
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-new-webServer.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-new-webServer.yml
new file mode 100644
index 0000000000..7c957b5247
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-new-webServer.yml
@@ -0,0 +1,11 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ tosca.nodes.WebServer:
+ derived_from: tosca.nodes.SoftwareComponent
+ capabilities:
+ # Private, layer 4 endpoints
+ data_endpoint: tosca.capabilities.Endpoint
+ admin_endpoint: tosca.capabilities.Endpoint.Admin
+ host:
+ type: tosca.capabilities.Container
+ valid_source_types: [ tosca.nodes.WebApplication ] \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/normative-types-string-list-test.yml b/catalog-be/src/test/resources/normativeTypes/normative-types-string-list-test.yml
new file mode 100644
index 0000000000..0a292b3418
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/normative-types-string-list-test.yml
@@ -0,0 +1,29 @@
+tosca.nodes.BlockStorage:
+ derived_from: tosca.nodes.Root
+ properties:
+ listTestTag:
+ stringTestTag: stringVal1
+ listTestTag:
+ - listTestTag: 1 MB
+ - listTestTag: 2 MB
+ - stringTestTag: stringVal2
+ volume_id:
+ type: string
+ required: false
+ stringTestTag:
+ - greater_or_equal: 1 MB
+ - stringTestTag: stringVal3
+ stringTestTag:
+ listTestTag: string
+ required: false
+ snapshot_id:
+ stringTestTag: stringVal4
+ required: false
+ listTestTag:
+ - testTag1: 1 MB
+ - listTestTag:
+ - testTag1: 1 MB
+ - type: stringVal2
+ capabilities:
+ attachment:
+ type: tosca.capabilities.Attachment
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_duplicateNode.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_duplicateNode.yml
new file mode 100644
index 0000000000..be16f471fc
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_duplicateNode.yml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ node_templates:
+ mongo_server:
+ type: tosca.nodes.Database
+ mongo_server:
+ type: tosca.nodes.Compute
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_empty.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_empty.yml
new file mode 100644
index 0000000000..43ad624300
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_empty.yml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_inputs.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_inputs.yml
new file mode 100644
index 0000000000..fbc64e05fe
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_inputs.yml
@@ -0,0 +1,103 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ inputs:
+ vf_module_id:
+ hidden: false
+ immutable: false
+ type: string
+ description: Unique ID for this VF Module instance
+ default: dummy
+ cmd_fw_srv_grp_id:
+ hidden: false
+ immutable: false
+ type: string
+ description: uuid of the server group
+ default: be97d566-35c1-4bc6-a9dd-a5f193cba314
+ nimbus_hsl_interface_type:
+ hidden: false
+ immutable: false
+ type: string
+ description: service_interface_type for ServiceInstance
+ default: other
+ cmd_fw_names:
+ hidden: false
+ immutable: false
+ type: list
+ description: Comma Delimited List of Names for ServiceInstance VMs
+ default:
+ - ZRDM2FCMD01CMD001
+ - ' ZRDM2FCMD01CMD002'
+ - ' ZRDM2FCMD01CMD003'
+ - ' ZRDM2FCMD01CMD004'
+ entry_schema:
+ type: string
+ cmd_fw_shc_max_retries:
+ hidden: false
+ immutable: false
+ type: integer
+ description: max_retries for the ServiceHealthCheck
+ default: 2
+ cmd_fw_shc_url_path:
+ hidden: false
+ immutable: false
+ type: string
+ description: url_path for the ServiceHealthCheck
+ default: local-ip
+ node_templates:
+ nodejs:
+ type: tosca.nodes.WebServer
+ requirements:
+ - host:
+ node: app_server
+ mongo_db:
+ type: tosca.nodes.Database
+ requirements:
+ - host: mongo_dbms
+ mongo_dbms:
+ type: tosca.nodes.DBMS
+ properties:
+ root_password:
+ get_input: nimbus_hsl_interface_type
+ # fixed_ips:
+ # - ip_address:
+ # get_input: app2_int_ota_apps_ip_1
+ # subnet_id:
+ # get_input: pmaa_dpu_subnet_id
+ # - ip_address:
+ # get_input: app2_int_ota_apps_ip_3
+ # subnet_id:
+ # get_input: pmaa_dpu_subnet_id
+ # name:
+ # get_input:
+ # - mnsoamvfw_names
+ # - get_input: index
+ # metadata:
+ # pmaa.sb_nic:
+ # address:
+ # get_input: pmaa_dpu_fixed_ip
+ # cidr:
+ # get_input: pmaa_dpu_cidr
+ # gateway:
+ # get_input: pmaa_dpu_gateway
+ #port:
+ # get_input: cmd_fw_shc_max_retries
+ requirements:
+ - host: mongo_server
+ app_server:
+ type: tosca.nodes.Compute
+ mongo_server:
+ type: tosca.nodes.Compute
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_nodeEmpty.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_nodeEmpty.yml
new file mode 100644
index 0000000000..3f8f3d15f8
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_nodeEmpty.yml
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_nodeVF.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_nodeVF.yml
new file mode 100644
index 0000000000..4f1966315a
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_nodeVF.yml
@@ -0,0 +1,38 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ node_templates:
+ my_node:
+ type: org.openecomp.resource.vf.Resource19
+ nodejs:
+ type: tosca.nodes.WebServer
+ requirements:
+ - host:
+ node: app_server
+ mongo_db:
+ type: tosca.nodes.Database
+ requirements:
+ - host: mongo_dbms
+ mongo_dbms:
+ type: tosca.nodes.DBMS
+ requirements:
+ - host: mongo_server
+ app_server:
+ type: tosca.nodes.Compute
+ mongo_server:
+ type: tosca.nodes.Compute
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_notValidNode.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_notValidNode.yml
new file mode 100644
index 0000000000..a4534fc03d
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_notValidNode.yml
@@ -0,0 +1,36 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ node_templates:
+ nodejs:
+ type: tosca.nodes.KUKU
+ requirements:
+ - host:
+ node: app_server
+ mongo_db:
+ type: tosca.nodes.Database
+ requirements:
+ - host: mongo_dbms
+ mongo_dbms:
+ type: tosca.nodes.DBMS
+ requirements:
+ - host: mongo_server
+ app_server:
+ type: tosca.nodes.Compute
+ mongo_server:
+ type: tosca.nodes.Compute
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_notValidRelationNode.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_notValidRelationNode.yml
new file mode 100644
index 0000000000..f606769387
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_notValidRelationNode.yml
@@ -0,0 +1,36 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ node_templates:
+ nodejs:
+ type: tosca.nodes.WebServer
+ requirements:
+ - host:
+ node: KUKU
+ mongo_db:
+ type: tosca.nodes.Database
+ requirements:
+ - host: mongo_dbms
+ mongo_dbms:
+ type: tosca.nodes.DBMS
+ requirements:
+ - host: mongo_server
+ app_server:
+ type: tosca.nodes.Compute
+ mongo_server:
+ type: tosca.nodes.Compute
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/normativeTypes/topology_template_sample.yml b/catalog-be/src/test/resources/normativeTypes/topology_template_sample.yml
new file mode 100644
index 0000000000..4b685a4497
--- /dev/null
+++ b/catalog-be/src/test/resources/normativeTypes/topology_template_sample.yml
@@ -0,0 +1,36 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ This TOSCA simple profile deploys nodejs, mongodb, each on a separate server
+ with monitoring enabled for nodejs server where a sample nodejs application is running.
+
+topology_template:
+ node_templates:
+ nodejs:
+ type: tosca.nodes.WebServer
+ requirements:
+ - host:
+ node: app_server
+ mongo_db:
+ type: tosca.nodes.Database
+ requirements:
+ - host: mongo_dbms
+ mongo_dbms:
+ type: tosca.nodes.DBMS
+ requirements:
+ - host: mongo_server
+ app_server:
+ type: tosca.nodes.Compute
+ mongo_server:
+ type: tosca.nodes.Compute
+
+
+
+ outputs:
+ nodejs_url:
+ description: URL for the nodejs server, http://<IP>:3000
+ value: { get_attribute: [ app_server, private_address ] }
+ mongodb_url:
+ description: URL for the mongodb server.
+ value: { get_attribute: [ mongo_server, private_address ] }
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/capabilityTypes.yml b/catalog-be/src/test/resources/types/capabilityTypes.yml
new file mode 100644
index 0000000000..58d661b17e
--- /dev/null
+++ b/catalog-be/src/test/resources/types/capabilityTypes.yml
@@ -0,0 +1,148 @@
+tosca.capabilities.Root:
+ description: The TOSCA root Capability Type all other TOSCA base Capability Types derive from
+tosca.capabilities.Attachment:
+ derived_from: tosca.capabilities.Root
+tosca.capabilities.Node:
+ derived_from: tosca.capabilities.Root
+tosca.capabilities.Container:
+ derived_from: tosca.capabilities.Root
+ properties:
+ num_cpus:
+ type: integer
+ required: false
+ constraints:
+ - greater_or_equal: 1
+ cpu_frequency:
+ type: scalar-unit.frequency
+ required: false
+ constraints:
+ - greater_or_equal: 0.1 GHz
+ disk_size:
+ type: scalar-unit.size
+ required: false
+ constraints:
+ - greater_or_equal: 0 MB
+ mem_size:
+ type: scalar-unit.size
+ required: false
+ constraints:
+ - greater_or_equal: 0 MB
+tosca.capabilities.Endpoint:
+ derived_from: tosca.capabilities.Root
+ properties:
+ protocol:
+ type: string
+ default: tcp
+ port:
+ type: PortDef
+ required: false
+ secure:
+ type: boolean
+ default: false
+ url_path:
+ type: string
+ required: false
+ port_name:
+ type: string
+ required: false
+ network_name:
+ type: string
+ required: false
+ default: PRIVATE
+ initiator:
+ type: string
+ default: source
+ constraints:
+ - valid_values: [ source, target, peer ]
+ ports:
+ type: map
+ required: false
+ constraints:
+ - min_length: 1
+ entry_schema:
+ type: PortSpec
+ attributes:
+ ip_address:
+ type: string
+tosca.capabilities.DatabaseEndpoint:
+ derived_from: tosca.capabilities.Endpoint
+tosca.capabilities.Endpoint.Public:
+ derived_from: tosca.capabilities.Endpoint
+ properties:
+ # Change the default network_name to use the first public network found
+ network_name: PUBLIC
+ floating:
+ description: >
+ indicates that the public address should be allocated from a pool of floating IPs that are associated with the network.
+ type: boolean
+ default: false
+ status: experimental
+ dns_name:
+ description: The optional name to register with DNS
+ type: string
+ required: false
+ status: experimental
+tosca.capabilities.Endpoint.Admin:
+ derived_from: tosca.capabilities.Endpoint
+ # Change Endpoint secure indicator to true from its default of false
+ properties:
+ secure: true
+tosca.capabilities.Endpoint.Database:
+ derived_from: tosca.capabilities.Endpoint
+tosca.capabilities.OperatingSystem:
+ derived_from: tosca.capabilities.Root
+ properties:
+ architecture:
+ type: string
+ required: false
+ type:
+ type: string
+ required: false
+ distribution:
+ type: string
+ required: false
+ version:
+ type: version
+ required: false
+tosca.capabilities.Scalable:
+ derived_from: tosca.capabilities.Root
+ properties:
+ min_instances:
+ type: integer
+ default: 1
+ max_instances:
+ type: integer
+ default: 1
+ default_instances:
+ type: integer
+tosca.capabilities.network.Bindable:
+ derived_from: tosca.capabilities.Node
+
+
+tosca.capabilities.Container.Docker:
+ derived_from: tosca.capabilities.Container
+ properties:
+ version:
+ type: list
+ required: false
+ entry_schema: version
+ publish_all:
+ type: boolean
+ default: false
+ required: false
+ publish_ports:
+ type: list
+ entry_schema: PortSpec
+ required: false
+ expose_ports:
+ type: list
+ entry_schema: PortSpec
+ required: false
+ volumes:
+ type: list
+ entry_schema: string
+ required: false
+tosca.capabilities.network.Linkable:
+ derived_from: tosca.capabilities.Root
+
+
diff --git a/catalog-be/src/test/resources/types/capabilityTypes.zip b/catalog-be/src/test/resources/types/capabilityTypes.zip
new file mode 100644
index 0000000000..4f945a7d1f
--- /dev/null
+++ b/catalog-be/src/test/resources/types/capabilityTypes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/types/categoryTypes.yml b/catalog-be/src/test/resources/types/categoryTypes.yml
new file mode 100644
index 0000000000..c853f9a52c
--- /dev/null
+++ b/catalog-be/src/test/resources/types/categoryTypes.yml
@@ -0,0 +1,74 @@
+services:
+ Mobility:
+ name: "Mobility"
+ icons: ['mobility']
+ Network_L1_3:
+ name: "Network L1-3"
+ icons: ['network_l_1-3']
+ Network_L4:
+ name: "Network L4"
+ icons: ['network_l_4']
+ VoIP_Call_Control:
+ name: "VoIP Call Control"
+ icons: ['call_controll']
+resources:
+ NetworkLayer23:
+ name: "Network Layer 2-3"
+ subcategories:
+ Router:
+ name: "Router"
+ icons: ['router']
+ Gateway:
+ name: "Gateway"
+ icons: ['gateway']
+ WAN_Connectors:
+ name: "WAN Connectors"
+ icons: ['connector']
+ LAN_Connectors:
+ name: "LAN Connectors"
+ icons: ['connector']
+ NetworkLayer4:
+ name: "Network Layer 4+"
+ subcategories:
+ Common_Network_Resources:
+ name: "Common Network Resources"
+ icons: ['network', 'loadBalancer']
+ ApplicationLayer4:
+ name: "Application Layer 4+"
+ subcategories:
+ Border_Elements:
+ name: "Border Elements"
+ icons: ['borderElement']
+ Application_Servers:
+ name: "Application Servers"
+ icons: ['applicationServer', 'server']
+ Web_Server:
+ name: "Web Server"
+ icons: ['applicationServer', 'server']
+ Call_Control:
+ name: "Call Control"
+ icons: ['call_controll']
+ Media_Servers:
+ name: "Media Servers"
+ icons: ['applicationServer', 'server']
+ Load_Balancer:
+ name: "Load Balancer"
+ icons: ['loadBalancer']
+ Database:
+ name: "Database"
+ icons: ['database']
+ Generic:
+ name: "Generic"
+ subcategories:
+ Infrastructure:
+ name: "Infrastructure"
+ icons: ['objectStorage', 'compute']
+ Abstract:
+ name: "Abstract"
+ icons: ['objectStorage', 'compute']
+ Network_Elements:
+ name: "Network Elements"
+ icons: ['port', 'network', 'router']
+ Database:
+ name: "Database"
+ icons: ['database']
diff --git a/catalog-be/src/test/resources/types/categoryTypes.zip b/catalog-be/src/test/resources/types/categoryTypes.zip
new file mode 100644
index 0000000000..2e08a6b43c
--- /dev/null
+++ b/catalog-be/src/test/resources/types/categoryTypes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeDeriveFromIntegerWithProperty.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeDeriveFromIntegerWithProperty.yml
new file mode 100644
index 0000000000..7040f8717a
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeDeriveFromIntegerWithProperty.yml
@@ -0,0 +1,8 @@
+integer:
+
+mytypes.phonenumber:
+ derived_from: integer
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeDerivedFromRootNoProperties.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeDerivedFromRootNoProperties.yml
new file mode 100644
index 0000000000..ce72cf52c4
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeDerivedFromRootNoProperties.yml
@@ -0,0 +1,4 @@
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: tosca.datatypes.Root
+ description: custom phone number type that extends the basic phonenumber type
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeDuplicateProperty.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeDuplicateProperty.yml
new file mode 100644
index 0000000000..32ed904882
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeDuplicateProperty.yml
@@ -0,0 +1,11 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode1:
+ type: integer
+ number:
+ type: integer
+ areacode1:
+ type: integer
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeForGroup.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeForGroup.yml
new file mode 100644
index 0000000000..e811a1ff30
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeForGroup.yml
@@ -0,0 +1,40 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+string:
+ derived_from: tosca.datatypes.Root
+
+boolean:
+ derived_from: tosca.datatypes.Root
+
+float:
+ derived_from: tosca.datatypes.Root
+
+list:
+ derived_from: tosca.datatypes.Root
+
+map:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false
+ token_type:
+ type: string
+ default: password
+ token:
+ type: string
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: string
+ user:
+ type: string
+ required: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part1.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part1.yml
new file mode 100644
index 0000000000..b8cdc3bf62
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part1.yml
@@ -0,0 +1,15 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol1:
+ type: string
+ required: false
+ protocol2:
+ type: string
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part2.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part2.yml
new file mode 100644
index 0000000000..5a5be60ee3
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdatePropertyRemoved_part2.yml
@@ -0,0 +1,12 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol1:
+ type: string
+ required: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part1.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part1.yml
new file mode 100644
index 0000000000..f7aaff2236
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part1.yml
@@ -0,0 +1,19 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part2.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part2.yml
new file mode 100644
index 0000000000..e1897d1f72
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentDerivedDataType_part2.yml
@@ -0,0 +1,19 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Credential2
+ properties:
+ protocol:
+ type: string
+ required: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part1.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part1.yml
new file mode 100644
index 0000000000..d5784d1e61
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part1.yml
@@ -0,0 +1,20 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+map:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: integer
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part2.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part2.yml
new file mode 100644
index 0000000000..4a5539dcaa
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentEntryType_part2.yml
@@ -0,0 +1,20 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+map:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: string
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part1.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part1.yml
new file mode 100644
index 0000000000..70e4976b2f
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part1.yml
@@ -0,0 +1,22 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: integer
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part2.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part2.yml
new file mode 100644
index 0000000000..71e26a7320
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithDifferentPropertyType_part2.yml
@@ -0,0 +1,19 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part1.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part1.yml
new file mode 100644
index 0000000000..71e26a7320
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part1.yml
@@ -0,0 +1,19 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part2.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part2.yml
new file mode 100644
index 0000000000..b4945fcd7f
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeUpdateWithExistingPropertyNameInAncestor_part2.yml
@@ -0,0 +1,25 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+string:
+ derived_from: tosca.datatypes.Root
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol2:
+ type: string
+ required: false
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Credential2
+ properties:
+ protocol:
+ type: integer
+ required: false
+ protocol2:
+ type: integer
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypeWithPropertyTypeThisDataType.yml b/catalog-be/src/test/resources/types/datatypes/dataTypeWithPropertyTypeThisDataType.yml
new file mode 100644
index 0000000000..c142b1d2c4
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypeWithPropertyTypeThisDataType.yml
@@ -0,0 +1,9 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: mytypes.phonenumber
diff --git a/catalog-be/src/test/resources/types/datatypes/dataTypes.yml b/catalog-be/src/test/resources/types/datatypes/dataTypes.yml
new file mode 100644
index 0000000000..188c85bef3
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/dataTypes.yml
@@ -0,0 +1,129 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+
+integer:
+ derived_from: tosca.datatypes.Root
+
+string:
+ derived_from: tosca.datatypes.Root
+
+boolean:
+ derived_from: tosca.datatypes.Root
+
+float:
+ derived_from: tosca.datatypes.Root
+
+list:
+ derived_from: tosca.datatypes.Root
+
+map:
+ derived_from: tosca.datatypes.Root
+
+tosca.datatypes.Credential:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false
+ token_type:
+ type: string
+ default: password
+ token:
+ type: string
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: string
+ user:
+ type: string
+ required: false
+
+tosca.datatypes.TimeInterval:
+ derived_from: tosca.datatypes.Root
+ properties:
+ start_time:
+ type: timestamp
+ required: true
+ end_time:
+ type: timestamp
+ required: true
+
+tosca.datatypes.network.NetworkInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ network_name:
+ type: string
+ network_id:
+ type: string
+ addresses:
+ type: list
+ entry_schema:
+ type: string
+
+tosca.datatypes.network.PortInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ port_name:
+ type: string
+ port_id:
+ type: string
+ network_id:
+ type: string
+ mac_address:
+ type: string
+ addresses:
+ type: list
+ entry_schema:
+ type: string
+
+tosca.datatypes.network.PortDef:
+ derived_from: integer
+ constraints:
+ - in_range: [ 1, 65535 ]
+
+tosca.datatypes.network.PortSpec:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: true
+ default: tcp
+ constraints:
+ - valid_values: [ udp, tcp, igmp ]
+ target:
+ type: tosca.datatypes.network.PortDef
+ target_range:
+ type: range
+ constraints:
+ - in_range: [ 1, 65535 ]
+ source:
+ type: tosca.datatypes.network.PortDef
+ source_range:
+ type: range
+ constraints:
+ - in_range: [ 1, 65535 ]
+
+tosca.datatypes.complexEntryTypeMapList:
+ derived_from: tosca.datatypes.Root
+ properties:
+ protocol:
+ type: string
+ required: false
+ token_type:
+ type: string
+ default: password
+ token:
+ type: string
+ keys:
+ type: map
+ required: false
+ entry_schema:
+ type: tosca.datatypes.Credential
+ addresses:
+ type: list
+ entry_schema:
+ type: tosca.datatypes.Credential
+ user:
+ type: string
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes/derived3levelDataType.yml b/catalog-be/src/test/resources/types/datatypes/derived3levelDataType.yml
new file mode 100644
index 0000000000..f185167b80
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/derived3levelDataType.yml
@@ -0,0 +1,37 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
+
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: mytypes.phonenumber
+ description: custom phone number type that extends the basic phonenumber type
+ properties:
+ phone_description:
+ type: string
+ constraints:
+ - max_length: 128
+
+
+
+
+mytypes.phonenumber.extended.extended:
+ derived_from: mytypes.phonenumber.extended
+ description: custom phone number type that extends the basic phonenumber type
+ properties:
+ email:
+ type: string
+ constraints:
+ - max_length: 128
+ complex1:
+ type: mytypes.phonenumber.extended
+ constraints:
+ - max_length: 128
+
+ \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/datatypes/derivedDataType.yml b/catalog-be/src/test/resources/types/datatypes/derivedDataType.yml
new file mode 100644
index 0000000000..1c4ca88ff9
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/derivedDataType.yml
@@ -0,0 +1,19 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
+
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: mytypes.phonenumber
+ description: custom phone number type that extends the basic phonenumber type
+ properties:
+ phone_description:
+ type: string
+ constraints:
+ - max_length: 128
diff --git a/catalog-be/src/test/resources/types/datatypes/derivedDataTypeNoProperties.yml b/catalog-be/src/test/resources/types/datatypes/derivedDataTypeNoProperties.yml
new file mode 100644
index 0000000000..2e6b35978e
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/derivedDataTypeNoProperties.yml
@@ -0,0 +1,15 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
+
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: mytypes.phonenumber
+ description: custom phone number type that extends the basic phonenumber type
+
diff --git a/catalog-be/src/test/resources/types/datatypes/derivedInvalidDataType.yml b/catalog-be/src/test/resources/types/datatypes/derivedInvalidDataType.yml
new file mode 100644
index 0000000000..d76cc5f219
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/derivedInvalidDataType.yml
@@ -0,0 +1,15 @@
+mytypes.phonenumber2:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
+
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: mytypes.phonenumber3
+ description: custom phone number type that extends the basic phonenumber type
+
diff --git a/catalog-be/src/test/resources/types/datatypes/emptyDataType.yml b/catalog-be/src/test/resources/types/datatypes/emptyDataType.yml
new file mode 100644
index 0000000000..6a0318eca4
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/emptyDataType.yml
@@ -0,0 +1,4 @@
+mytypes.phonenumber.empty:
+ description: my phone number datatype
+ properties:
+
diff --git a/catalog-be/src/test/resources/types/datatypes/emptyDataTypeNoPropertiesTag.yml b/catalog-be/src/test/resources/types/datatypes/emptyDataTypeNoPropertiesTag.yml
new file mode 100644
index 0000000000..933c14f778
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/emptyDataTypeNoPropertiesTag.yml
@@ -0,0 +1,3 @@
+mytypes.phonenumber.empty:
+ description: my phone number datatype
+
diff --git a/catalog-be/src/test/resources/types/datatypes/exitingPropertyAtAncestor.yml b/catalog-be/src/test/resources/types/datatypes/exitingPropertyAtAncestor.yml
new file mode 100644
index 0000000000..0e46cc2a98
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/exitingPropertyAtAncestor.yml
@@ -0,0 +1,19 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
+
+# define a new datatype that derives from existing type and extends it
+mytypes.phonenumber.extended:
+ derived_from: mytypes.phonenumber
+ description: custom phone number type that extends the basic phonenumber type
+ properties:
+ areacode:
+ type: integer
+
+
diff --git a/catalog-be/src/test/resources/types/datatypes/invalidDataType.yml b/catalog-be/src/test/resources/types/datatypes/invalidDataType.yml
new file mode 100644
index 0000000000..d5ad5a93ba
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/invalidDataType.yml
@@ -0,0 +1 @@
+mytypes.phonenumber.empty
diff --git a/catalog-be/src/test/resources/types/datatypes/oneDataType.yml b/catalog-be/src/test/resources/types/datatypes/oneDataType.yml
new file mode 100644
index 0000000000..114236fb3e
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes/oneDataType.yml
@@ -0,0 +1,9 @@
+mytypes.phonenumber:
+ description: my phone number datatype
+ properties:
+ countrycode:
+ type: integer
+ areacode:
+ type: integer
+ number:
+ type: integer
diff --git a/catalog-be/src/test/resources/types/interfaceLifecycleTypes.yml b/catalog-be/src/test/resources/types/interfaceLifecycleTypes.yml
new file mode 100644
index 0000000000..1b67118934
--- /dev/null
+++ b/catalog-be/src/test/resources/types/interfaceLifecycleTypes.yml
@@ -0,0 +1,11 @@
+tosca.interfaces.node.lifecycle.Standard:
+ create:
+ description: Standard lifecycle create operation.
+ configure:
+ description: Standard lifecycle configure operation.
+ start:
+ description: Standard lifecycle start operation.
+ stop:
+ description: Standard lifecycle stop operation.
+ delete:
+ description: Standard lifecycle delete operation. \ No newline at end of file
diff --git a/catalog-be/src/test/resources/types/interfaceLifecycleTypes.zip b/catalog-be/src/test/resources/types/interfaceLifecycleTypes.zip
new file mode 100644
index 0000000000..9bcf93ab7d
--- /dev/null
+++ b/catalog-be/src/test/resources/types/interfaceLifecycleTypes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/valid_vf.csar b/catalog-be/src/test/resources/valid_vf.csar
new file mode 100644
index 0000000000..01bf159071
--- /dev/null
+++ b/catalog-be/src/test/resources/valid_vf.csar
Binary files differ