@ -18,7 +18,6 @@
package org.wso2.carbon.device.mgt.jaxrs.service.impl ;
package org.wso2.carbon.device.mgt.jaxrs.service.impl ;
import org.wso2.carbon.context.PrivilegedCarbonContext ;
import org.wso2.carbon.context.PrivilegedCarbonContext ;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MappingProperty ;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MappingProperty ;
@ -116,8 +115,12 @@ public class AnalyticsArtifactsManagementServiceImpl
public Response deployEventDefinitionAsDto ( @Valid EventStream stream ) {
public Response deployEventDefinitionAsDto ( @Valid EventStream stream ) {
String tenantDomain = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ;
String tenantDomain = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ;
try {
try {
validateStreamProperties ( stream ) ;
deployStream ( stream ) ;
deployStream ( stream ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
} catch ( BadRequestException e ) {
log . error ( e . getMessage ( ) , e ) ;
return e . getResponse ( ) ;
} catch ( AxisFault e ) {
} catch ( AxisFault e ) {
String errMsg = "Failed to create event definitions for tenant " + tenantDomain ;
String errMsg = "Failed to create event definitions for tenant " + tenantDomain ;
log . error ( errMsg , e ) ;
log . error ( errMsg , e ) ;
@ -187,6 +190,9 @@ public class AnalyticsArtifactsManagementServiceImpl
}
}
deployReceiver ( receiver , customMapping , adapterConfiguration ) ;
deployReceiver ( receiver , customMapping , adapterConfiguration ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
} catch ( BadRequestException e ) {
log . error ( e . getMessage ( ) , e ) ;
return e . getResponse ( ) ;
} catch ( AxisFault e ) {
} catch ( AxisFault e ) {
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
log . error ( errMsg , e ) ;
log . error ( errMsg , e ) ;
@ -256,6 +262,9 @@ public class AnalyticsArtifactsManagementServiceImpl
}
}
deployPublisher ( publisher , customMapping , adapterConfiguration ) ;
deployPublisher ( publisher , customMapping , adapterConfiguration ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
} catch ( BadRequestException e ) {
log . error ( e . getMessage ( ) , e ) ;
return e . getResponse ( ) ;
} catch ( AxisFault e ) {
} catch ( AxisFault e ) {
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
log . error ( errMsg , e ) ;
log . error ( errMsg , e ) ;
@ -283,8 +292,11 @@ public class AnalyticsArtifactsManagementServiceImpl
@Valid SiddhiExecutionPlan plan ) {
@Valid SiddhiExecutionPlan plan ) {
String tenantDomain = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ;
String tenantDomain = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantDomain ( ) ;
try {
try {
publish SiddhiExecutionPlan( name , isEdited , plan . getDefinition ( ) ) ;
deploy SiddhiExecutionPlan( name , isEdited , plan . getDefinition ( ) ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
} catch ( InvalidExecutionPlanException e ) {
log . error ( e . getMessage ( ) , e ) ;
return e . getResponse ( ) ;
} catch ( AxisFault e ) {
} catch ( AxisFault e ) {
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain ;
log . error ( errMsg , e ) ;
log . error ( errMsg , e ) ;
@ -315,14 +327,6 @@ public class AnalyticsArtifactsManagementServiceImpl
List < Attribute > metaData = stream . getMetaData ( ) ;
List < Attribute > metaData = stream . getMetaData ( ) ;
List < Attribute > payloadData = stream . getPayloadData ( ) ;
List < Attribute > payloadData = stream . getPayloadData ( ) ;
List < Attribute > correlationData = stream . getCorrelationData ( ) ;
List < Attribute > correlationData = stream . getCorrelationData ( ) ;
if ( metaData . isEmpty ( ) & & correlationData . isEmpty ( ) & & payloadData . isEmpty ( ) ) {
String errMsg = String . format ( "Failed to validate Stream property attributes of %s:%s" ,
stream . getName ( ) , stream . getVersion ( ) ) ;
ErrorResponse errorResponse = new ErrorResponse ( ) ;
errorResponse . setMessage ( errMsg ) ;
log . error ( errMsg ) ;
throw new BadRequestException ( errorResponse ) ;
}
try {
try {
eventStreamAdminServiceStub = DeviceMgtAPIUtils . getEventStreamAdminServiceStub ( ) ;
eventStreamAdminServiceStub = DeviceMgtAPIUtils . getEventStreamAdminServiceStub ( ) ;
@ -331,10 +335,15 @@ public class AnalyticsArtifactsManagementServiceImpl
eventStreamDefinitionDto . setVersion ( stream . getVersion ( ) ) ;
eventStreamDefinitionDto . setVersion ( stream . getVersion ( ) ) ;
eventStreamDefinitionDto . setNickName ( stream . getNickName ( ) ) ;
eventStreamDefinitionDto . setNickName ( stream . getNickName ( ) ) ;
eventStreamDefinitionDto . setDescription ( stream . getDescription ( ) ) ;
eventStreamDefinitionDto . setDescription ( stream . getDescription ( ) ) ;
if ( metaData ! = null ) {
eventStreamDefinitionDto . setMetaData ( addEventAttributesToDto ( metaData ) ) ;
eventStreamDefinitionDto . setMetaData ( addEventAttributesToDto ( metaData ) ) ;
}
if ( payloadData ! = null ) {
eventStreamDefinitionDto . setPayloadData ( addEventAttributesToDto ( payloadData ) ) ;
eventStreamDefinitionDto . setPayloadData ( addEventAttributesToDto ( payloadData ) ) ;
}
if ( correlationData ! = null ) {
eventStreamDefinitionDto . setCorrelationData ( addEventAttributesToDto ( correlationData ) ) ;
eventStreamDefinitionDto . setCorrelationData ( addEventAttributesToDto ( correlationData ) ) ;
}
String streamId = stream . getName ( ) + ":" + stream . getVersion ( ) ;
String streamId = stream . getName ( ) + ":" + stream . getVersion ( ) ;
if ( eventStreamAdminServiceStub . getStreamDefinitionDto ( streamId ) ! = null ) {
if ( eventStreamAdminServiceStub . getStreamDefinitionDto ( streamId ) ! = null ) {
eventStreamAdminServiceStub . editEventStreamDefinitionAsDto ( eventStreamDefinitionDto , streamId ) ;
eventStreamAdminServiceStub . editEventStreamDefinitionAsDto ( eventStreamDefinitionDto , streamId ) ;
@ -344,7 +353,6 @@ public class AnalyticsArtifactsManagementServiceImpl
} finally {
} finally {
cleanup ( eventStreamAdminServiceStub ) ;
cleanup ( eventStreamAdminServiceStub ) ;
}
}
}
}
/ * *
/ * *
@ -360,8 +368,8 @@ public class AnalyticsArtifactsManagementServiceImpl
private void deployReceiver ( Adapter receiver , boolean customMapping ,
private void deployReceiver ( Adapter receiver , boolean customMapping ,
AdapterConfiguration adapterConfiguration )
AdapterConfiguration adapterConfiguration )
throws RemoteException , UserStoreException , JWTClientException {
throws RemoteException , UserStoreException , JWTClientException {
EventReceiverAdminServiceStub eventReceiverAdminServiceStub = DeviceMgtAPIUtils . getEventReceiverAdminServiceStub ( ) ;
EventReceiverAdminServiceStub eventReceiverAdminServiceStub = DeviceMgtAPIUtils
. getEventReceiverAdminServiceStub ( ) ;
try {
try {
String receiverName = receiver . getAdapterName ( ) ;
String receiverName = receiver . getAdapterName ( ) ;
String adapterType = receiver . getAdapterType ( ) . toStringFormatted ( ) ;
String adapterType = receiver . getAdapterType ( ) . toStringFormatted ( ) ;
@ -374,7 +382,9 @@ public class AnalyticsArtifactsManagementServiceImpl
}
}
BasicInputAdapterPropertyDto [ ] basicInputAdapterPropertyDtos = addReceiverConfigToDto ( adapterProperties ) ;
BasicInputAdapterPropertyDto [ ] basicInputAdapterPropertyDtos = addReceiverConfigToDto ( adapterProperties ) ;
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration . getAdapterMappingConfiguration ( ) ;
if ( customMapping ) {
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration
. getAdapterMappingConfiguration ( ) ;
MessageFormat messageFormat = adapterMappingConfiguration . getMessageFormat ( ) ;
MessageFormat messageFormat = adapterMappingConfiguration . getMessageFormat ( ) ;
if ( ! messageFormat . toString ( ) . equals ( "wso2event" ) ) {
if ( ! messageFormat . toString ( ) . equals ( "wso2event" ) ) {
EventMappingPropertyDto [ ] inputMappingPropertyDtos =
EventMappingPropertyDto [ ] inputMappingPropertyDtos =
@ -385,20 +395,20 @@ public class AnalyticsArtifactsManagementServiceImpl
eventReceiverAdminServiceStub . deployXmlEventReceiverConfiguration ( receiverName
eventReceiverAdminServiceStub . deployXmlEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , null
, eventStreamWithVersion , adapterType , null
, namespaceMappingPropertyDtos , inputMappingPropertyDtos
, namespaceMappingPropertyDtos , inputMappingPropertyDtos
, basicInputAdapterPropertyDtos , customMapping ) ;
, basicInputAdapterPropertyDtos , true ) ;
} else {
} else {
if ( messageFormat . toString ( ) . equals ( "map" ) ) {
if ( messageFormat . toString ( ) . equals ( "map" ) ) {
eventReceiverAdminServiceStub . deployMapEventReceiverConfiguration ( receiverName
eventReceiverAdminServiceStub . deployMapEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, basicInputAdapterPropertyDtos , customMapping ) ;
, basicInputAdapterPropertyDtos , true ) ;
} else if ( messageFormat . toString ( ) . equals ( "text" ) ) {
} else if ( messageFormat . toString ( ) . equals ( "text" ) ) {
eventReceiverAdminServiceStub . deployTextEventReceiverConfiguration ( receiverName
eventReceiverAdminServiceStub . deployTextEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, basicInputAdapterPropertyDtos , customMapping ) ;
, basicInputAdapterPropertyDtos , true ) ;
} else {
} else {
eventReceiverAdminServiceStub . deployJsonEventReceiverConfiguration ( receiverName
eventReceiverAdminServiceStub . deployJsonEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, basicInputAdapterPropertyDtos , customMapping ) ;
, basicInputAdapterPropertyDtos , true ) ;
}
}
}
}
} else {
} else {
@ -415,14 +425,52 @@ public class AnalyticsArtifactsManagementServiceImpl
eventReceiverAdminServiceStub . deployWso2EventReceiverConfiguration ( receiverName
eventReceiverAdminServiceStub . deployWso2EventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , metaMappingPropertyDtos
, eventStreamWithVersion , adapterType , metaMappingPropertyDtos
, correlationMappingPropertyDtos , payloadMappingPropertyDtos
, correlationMappingPropertyDtos , payloadMappingPropertyDtos
, basicInputAdapterPropertyDtos , customMapping
, basicInputAdapterPropertyDtos , true
, eventStreamWithVersion ) ;
, eventStreamWithVersion ) ;
}
}
} else {
deployReceiverWithoutMapping ( receiverName , eventStreamWithVersion , adapterType ,
eventReceiverAdminServiceStub , basicInputAdapterPropertyDtos ) ;
}
} finally {
} finally {
cleanup ( eventReceiverAdminServiceStub ) ;
cleanup ( eventReceiverAdminServiceStub ) ;
}
}
}
}
/ * *
* To deploy receiver if custom mapping is false
*
* @param receiverName Name of the receiver
* @param eventStreamWithVersion Attached event stream of the receiver
* @param adapterType Adapter type name
* @param eventReceiverAdminServiceStub Stub to deploy receiver
* @param basicInputAdapterPropertyDtos DTO to attach receiver data
* @throws RemoteException Exception that may occur during a remote method call
* /
private void deployReceiverWithoutMapping ( String receiverName , String eventStreamWithVersion
, String adapterType , EventReceiverAdminServiceStub eventReceiverAdminServiceStub
, BasicInputAdapterPropertyDto [ ] basicInputAdapterPropertyDtos )
throws RemoteException {
switch ( adapterType ) {
case "iot-event" :
case "wso2event" :
eventReceiverAdminServiceStub . deployWso2EventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , null , null
, null , basicInputAdapterPropertyDtos , false
, eventStreamWithVersion ) ;
break ;
case "soap" :
eventReceiverAdminServiceStub . deployXmlEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , null , null
, null , basicInputAdapterPropertyDtos , false ) ;
break ;
default :
eventReceiverAdminServiceStub . deployTextEventReceiverConfiguration ( receiverName
, eventStreamWithVersion , adapterType , null
, basicInputAdapterPropertyDtos , false ) ;
}
}
/ * *
/ * *
* Set data to a publisher dto and deploy dto through a stub
* Set data to a publisher dto and deploy dto through a stub
*
*
@ -436,7 +484,8 @@ public class AnalyticsArtifactsManagementServiceImpl
private void deployPublisher ( Adapter publisher , boolean customMapping ,
private void deployPublisher ( Adapter publisher , boolean customMapping ,
AdapterConfiguration adapterConfiguration )
AdapterConfiguration adapterConfiguration )
throws RemoteException , UserStoreException , JWTClientException {
throws RemoteException , UserStoreException , JWTClientException {
EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils . getEventPublisherAdminServiceStub ( ) ;
EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils
. getEventPublisherAdminServiceStub ( ) ;
try {
try {
String publisherName = publisher . getAdapterName ( ) ;
String publisherName = publisher . getAdapterName ( ) ;
String adapterType = publisher . getAdapterType ( ) . toStringFormatted ( ) ;
String adapterType = publisher . getAdapterType ( ) . toStringFormatted ( ) ;
@ -451,25 +500,30 @@ public class AnalyticsArtifactsManagementServiceImpl
BasicOutputAdapterPropertyDto [ ] basicOutputAdapterPropertyDtos =
BasicOutputAdapterPropertyDto [ ] basicOutputAdapterPropertyDtos =
addPublisherConfigToDto ( adapterProperties ) ;
addPublisherConfigToDto ( adapterProperties ) ;
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration . getAdapterMappingConfiguration ( ) ;
if ( customMapping ) {
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration
. getAdapterMappingConfiguration ( ) ;
MessageFormat messageFormat = adapterMappingConfiguration . getMessageFormat ( ) ;
MessageFormat messageFormat = adapterMappingConfiguration . getMessageFormat ( ) ;
if ( ! messageFormat . toString ( ) . equals ( "wso2event" ) ) {
if ( ! messageFormat . toString ( ) . equals ( "wso2event" ) ) {
if ( ! messageFormat . toString ( ) . equals ( "map" ) ) {
if ( ! messageFormat . toString ( ) . equals ( "map" ) ) {
if ( messageFormat . toString ( ) . equals ( "xml" ) ) {
if ( messageFormat . toString ( ) . equals ( "xml" ) ) {
eventPublisherAdminServiceStub . deployXmlEventPublisherConfiguration ( publisherName
eventPublisherAdminServiceStub . deployXmlEventPublisherConfiguration (
, eventStreamWithVersion , adapterType , adapterMappingConfiguration . getInputMappingString ( )
publisherName , eventStreamWithVersion , adapterType
, adapterMappingConfiguration . getInputMappingString ( )
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, customMapping ) ;
, true ) ;
} else if ( messageFormat . toString ( ) . equals ( "text" ) ) {
} else if ( messageFormat . toString ( ) . equals ( "text" ) ) {
eventPublisherAdminServiceStub . deployTextEventPublisherConfiguration ( publisherName
eventPublisherAdminServiceStub . deployTextEventPublisherConfiguration (
, eventStreamWithVersion , adapterType , adapterMappingConfiguration . getInputMappingString ( )
publisherName , eventStreamWithVersion , adapterType
, adapterMappingConfiguration . getInputMappingString ( )
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, customMapping ) ;
, true ) ;
} else {
} else {
eventPublisherAdminServiceStub . deployJsonEventPublisherConfiguration ( publisherName
eventPublisherAdminServiceStub . deployJsonEventPublisherConfiguration (
, eventStreamWithVersion , adapterType , adapterMappingConfiguration . getInputMappingString ( )
publisherName , eventStreamWithVersion , adapterType
, adapterMappingConfiguration . getInputMappingString ( )
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, customMapping ) ;
, true ) ;
}
}
} else {
} else {
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ] inputMappingPropertyDtos =
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ] inputMappingPropertyDtos =
@ -478,33 +532,83 @@ public class AnalyticsArtifactsManagementServiceImpl
) ;
) ;
eventPublisherAdminServiceStub . deployMapEventPublisherConfiguration ( publisherName
eventPublisherAdminServiceStub . deployMapEventPublisherConfiguration ( publisherName
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, eventStreamWithVersion , adapterType , inputMappingPropertyDtos
, basicOutputAdapterPropertyDtos , customMapping ) ;
, basicOutputAdapterPropertyDtos , true ) ;
}
}
} else {
} else {
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ] correlationMappingPropertyDtos =
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ]
addPublisherMappingToDto (
correlationMappingPropertyDtos = addPublisherMappingToDto
(
adapterMappingConfiguration . getCorrelationMappingProperties ( )
adapterMappingConfiguration . getCorrelationMappingProperties ( )
) ;
) ;
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ] metaMappingPropertyDtos =
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ]
addPublisherMappingToDto (
metaMappingPropertyDtos = addPublisherMappingToDto
(
adapterMappingConfiguration . getMetaMappingProperties ( )
adapterMappingConfiguration . getMetaMappingProperties ( )
) ;
) ;
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ] payloadMappingPropertyDtos =
org . wso2 . carbon . event . publisher . stub . types . EventMappingPropertyDto [ ]
addPublisherMappingToDto (
payloadMappingPropertyDtos = addPublisherMappingToDto
(
adapterMappingConfiguration . getPayloadMappingProperties ( )
adapterMappingConfiguration . getPayloadMappingProperties ( )
) ;
) ;
eventPublisherAdminServiceStub . deployWSO2EventPublisherConfiguration ( publisherName
eventPublisherAdminServiceStub . deployWSO2EventPublisherConfiguration (
, eventStreamWithVersion , adapterType , metaMappingPropertyDtos
publisherName , eventStreamWithVersion , adapterType , metaMappingPropertyDtos
, correlationMappingPropertyDtos , payloadMappingPropertyDtos
, correlationMappingPropertyDtos , payloadMappingPropertyDtos
, basicOutputAdapterPropertyDtos , customMapping
, basicOutputAdapterPropertyDtos , true
, eventStreamWithVersion ) ;
, eventStreamWithVersion ) ;
}
}
} else {
deployPublisherWithoutMapping ( publisherName , eventStreamWithVersion , adapterType
, eventPublisherAdminServiceStub , basicOutputAdapterPropertyDtos ) ;
}
} finally {
} finally {
cleanup ( eventPublisherAdminServiceStub ) ;
cleanup ( eventPublisherAdminServiceStub ) ;
}
}
}
}
/ * *
* To deploy publisher if custom mapping is false
*
* @param publisherName Name of the publisher
* @param eventStreamWithVersion Attached event stream of the publisher
* @param adapterType Adapter type name
* @param eventPublisherAdminServiceStub Stub to deploy publisher
* @param basicOutputAdapterPropertyDtos DTO to attach publisher data
* @throws RemoteException Exception that may occur during a remote method call
* /
private void deployPublisherWithoutMapping ( String publisherName , String eventStreamWithVersion
, String adapterType , EventPublisherAdminServiceStub eventPublisherAdminServiceStub
, BasicOutputAdapterPropertyDto [ ] basicOutputAdapterPropertyDtos )
throws RemoteException {
switch ( adapterType ) {
case "wso2event" :
case "ui" :
case "secured-websocket" :
eventPublisherAdminServiceStub . deployWSO2EventPublisherConfiguration ( publisherName
, eventStreamWithVersion , adapterType , null
, null , null , basicOutputAdapterPropertyDtos
, false , eventStreamWithVersion ) ;
break ;
case "soap" :
eventPublisherAdminServiceStub . deployXmlEventPublisherConfiguration ( publisherName
, eventStreamWithVersion , adapterType , null
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, false ) ;
break ;
case "cassandra" :
case "rdbms" :
eventPublisherAdminServiceStub . deployMapEventPublisherConfiguration ( publisherName
, eventStreamWithVersion , adapterType , null
, basicOutputAdapterPropertyDtos , false ) ;
break ;
default :
eventPublisherAdminServiceStub . deployTextEventPublisherConfiguration ( publisherName
, eventStreamWithVersion , adapterType , null
, basicOutputAdapterPropertyDtos , eventStreamWithVersion
, false ) ;
}
}
/ * *
/ * *
* Publish a siddhi execution plan using a stub
* Publish a siddhi execution plan using a stub
*
*
@ -516,9 +620,9 @@ public class AnalyticsArtifactsManagementServiceImpl
* @throws JWTClientException Exception that may occur during connecting to client store
* @throws JWTClientException Exception that may occur during connecting to client store
* @throws InvalidExecutionPlanException Exception that may occur if execution plan validation fails
* @throws InvalidExecutionPlanException Exception that may occur if execution plan validation fails
* /
* /
private void publish SiddhiExecutionPlan( String name , boolean isEdited ,
private void deploy SiddhiExecutionPlan( String name , boolean isEdited , String plan )
String plan )
throws RemoteException , UserStoreException , JWTClientException ,
throws RemoteException , UserStoreException , JWTClient Exception {
InvalidExecutionPlan Exception {
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null ;
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null ;
try {
try {
eventProcessorAdminServiceStub = DeviceMgtAPIUtils . getEventProcessorAdminServiceStub ( ) ;
eventProcessorAdminServiceStub = DeviceMgtAPIUtils . getEventProcessorAdminServiceStub ( ) ;
@ -532,7 +636,6 @@ public class AnalyticsArtifactsManagementServiceImpl
} else {
} else {
ErrorDTO errorDTO = new ErrorDTO ( ) ;
ErrorDTO errorDTO = new ErrorDTO ( ) ;
errorDTO . setMessage ( validationResponse ) ;
errorDTO . setMessage ( validationResponse ) ;
log . error ( validationResponse ) ;
throw new InvalidExecutionPlanException ( errorDTO ) ;
throw new InvalidExecutionPlanException ( errorDTO ) ;
}
}
} finally {
} finally {
@ -541,20 +644,21 @@ public class AnalyticsArtifactsManagementServiceImpl
}
}
/ * *
/ * *
* This will set payload of event attribute ' s mapping to the DTO
* Validate stream properties
*
*
* @param attributes list of event attributes
* @param stream EventStream object
* @return DTO with all the event attributes
* /
* /
private EventStreamAttributeDto [ ] addEventAttributesToDto ( List < Attribute > attributes ) {
private void validateStreamProperties ( EventStream stream ) throws BadRequestException {
EventStreamAttributeDto [ ] eventStreamAttributeDtos = new EventStreamAttributeDto [ attributes . size ( ) ] ;
if ( ( stream . getMetaData ( ) = = null | | stream . getMetaData ( ) . isEmpty ( ) ) & &
for ( Attribute attribute : attributes ) {
( stream . getCorrelationData ( ) = = null | | stream . getCorrelationData ( ) . isEmpty ( ) ) & &
EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto ( ) ;
( stream . getPayloadData ( ) = = null | | stream . getPayloadData ( ) . isEmpty ( ) ) ) {
eventStreamAttributeDto . setAttributeName ( attribute . getName ( ) ) ;
String errMsg = String . format ( "Failed to validate Stream property attributes of %s:%s. " +
eventStreamAttributeDto . setAttributeType ( attribute . getType ( ) . toString ( ) ) ;
"Stream mapping can't be null or empty" ,
stream . getName ( ) , stream . getVersion ( ) ) ;
ErrorDTO errorDTO = new ErrorDTO ( ) ;
errorDTO . setMessage ( errMsg ) ;
throw new BadRequestException ( errorDTO ) ;
}
}
return eventStreamAttributeDtos ;
}
}
/ * *
/ * *
@ -562,13 +666,13 @@ public class AnalyticsArtifactsManagementServiceImpl
*
*
* @param adapterProperties Adapter payload attributes
* @param adapterProperties Adapter payload attributes
* /
* /
private void validateAdapterProperties ( List < AdapterProperty > adapterProperties ) {
private void validateAdapterProperties ( List < AdapterProperty > adapterProperties )
if ( adapterProperties . isEmpty ( ) ) {
throws BadRequestException {
String errMsg = "Invalid payload: event property attributes invalid!!!" ;
if ( adapterProperties = = null ) {
ErrorResponse errorResponse = new ErrorResponse ( ) ;
String errMsg = "Failed to validate adapter attributes. Adapter attributes can't be null" ;
errorResponse. setMessage ( errMsg ) ;
ErrorDTO errorDTO = new ErrorDTO ( ) ;
log. error ( errMsg ) ;
errorDTO. setMessage ( errMsg ) ;
throw new BadRequestException ( error Response ) ;
throw new BadRequestException ( error DTO ) ;
}
}
}
}
@ -583,23 +687,51 @@ public class AnalyticsArtifactsManagementServiceImpl
*
*
* @param adapterMappingConfiguration Adapter mapping attributes
* @param adapterMappingConfiguration Adapter mapping attributes
* /
* /
private void validateAdapterMapping ( AdapterMappingConfiguration adapterMappingConfiguration ) {
private void validateAdapterMapping ( AdapterMappingConfiguration adapterMappingConfiguration )
throws BadRequestException {
if ( adapterMappingConfiguration = = null ) {
String errMsg = "Failed to validate adapter mapping attributes. " +
"Adapter mapping configuration can't be null" ;
ErrorDTO errorDTO = new ErrorDTO ( ) ;
errorDTO . setMessage ( errMsg ) ;
throw new BadRequestException ( errorDTO ) ;
} else if ( adapterMappingConfiguration . getMessageFormat ( ) = = null | |
( ( adapterMappingConfiguration . getInputMappingString ( ) = = null )
& & ( adapterMappingConfiguration . getInputMappingProperties ( ) = = null | |
adapterMappingConfiguration . getInputMappingProperties ( ) . isEmpty ( ) )
& & ( adapterMappingConfiguration . getNamespaceMappingProperties ( ) = = null | |
adapterMappingConfiguration . getNamespaceMappingProperties ( ) . isEmpty ( ) ) )
& &
( ( adapterMappingConfiguration . getCorrelationMappingProperties ( ) = = null | |
adapterMappingConfiguration . getCorrelationMappingProperties ( ) . isEmpty ( ) )
& & ( adapterMappingConfiguration . getPayloadMappingProperties ( ) = = null | |
adapterMappingConfiguration . getPayloadMappingProperties ( ) . isEmpty ( ) )
& & ( adapterMappingConfiguration . getMetaMappingProperties ( ) = = null | |
adapterMappingConfiguration . getMetaMappingProperties ( ) . isEmpty ( ) ) )
) {
String errMsg = "Failed to validate adapter mapping attributes. " +
"Adapter mapping configuration invalid" ;
ErrorDTO errorDTO = new ErrorDTO ( ) ;
errorDTO . setMessage ( errMsg ) ;
throw new BadRequestException ( errorDTO ) ;
}
}
if ( adapterMappingConfiguration . getInputMappingString ( ) = = null & &
/ * *
( adapterMappingConfiguration . getInputMappingProperties ( ) . isEmpty ( ) & &
* This will set payload of event attribute ' s mapping to the DTO
adapterMappingConfiguration . getNamespaceMappingProperties ( ) . isEmpty ( ) ) & &
*
(
* @param attributes list of event attributes
adapterMappingConfiguration . getCorrelationMappingProperties ( ) . isEmpty ( ) & &
* @return DTO with all the event attributes
adapterMappingConfiguration . getPayloadMappingProperties ( ) . isEmpty ( ) & &
* /
adapterMappingConfiguration . getMetaMappingProperties ( ) . isEmpty ( )
private EventStreamAttributeDto [ ] addEventAttributesToDto ( List < Attribute > attributes ) {
)
EventStreamAttributeDto [ ] eventStreamAttributeDtos = new EventStreamAttributeDto [ attributes . size ( ) ] ;
| | adapterMappingConfiguration . getMessageFormat ( ) = = null ) {
for ( int i = 0 ; i < attributes . size ( ) ; i + + ) {
String errMsg = "Invalid payload: event mapping attributes invalid!!!" ;
EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto ( ) ;
ErrorResponse errorResponse = new ErrorResponse ( ) ;
eventStreamAttributeDto . setAttributeName ( attributes . get ( i ) . getName ( ) ) ;
errorResponse . setMessage ( errMsg ) ;
eventStreamAttributeDto . setAttributeType ( attributes . get ( i ) . getType ( ) . toString ( ) ) ;
log . error ( errMsg ) ;
eventStreamAttributeDtos [ i ] = eventStreamAttributeDto ;
throw new BadRequestException ( errorResponse ) ;
}
}
return eventStreamAttributeDtos ;
}
}
/ * *
/ * *