bda-controller/src/main/java/gr/ntua/ece/cslab/selis/bda/controller/resources/MessageResource.java
@PUT
    @Path("{slug}/{messageTypeId}")
    public Response insert(@PathParam("slug") String slug,
                           @PathParam("messageTypeId") Integer messageId,
                           @QueryParam("connector_id") Integer connectorId,
                           @QueryParam("external_datasource") String datasource) {
        String details;
        MessageType m;
        Connector conn;
        try {
            m = MessageType.getMessageById(slug, messageId);
        } catch (Exception e) {
            e.printStackTrace();

            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid message id.")
            ).build();
        }
        try {
            conn = Connector.getConnectorInfoById(connectorId);
            if (!conn.isExternal())
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not insert new Message Type. Connector is not external.")
                ).build();
        } catch (Exception e) {
            e.printStackTrace();

            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid connector id.")
            ).build();
        }
        try {
            if (!conn.getMetadata().getDatasources().contains(m.getExternalDatasource())){
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid datasource specified for connector.")
                ).build();
            }
            m.setExternalConnectorId(connectorId);
            m.setExternalDatasource(datasource);
            m.save(slug);
            details = Integer.toString(m.getId());
        } catch (Exception e) {
            e.printStackTrace();

            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type.")
            ).build();
        }

        boolean externalConnector = !(m.getExternalConnectorId() == null);
        PubSubConnector.getInstance().reloadSubscriptions(slug, externalConnector);

        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
/**
     * Message service to update external connector and metadata
     */
Message service to update external connector and metadata
Message service to update external connector and metadata
@PUT
    @Path("{slug}/{messageTypeId}")
    public Response insert(@PathParam("slug") String slug,
                           @PathParam("messageTypeId") Integer messageId,
                           @QueryParam("connector_id") Integer connectorId,
                           @QueryParam("external_datasource") String datasource) {
        String details;
        MessageType m;
        Connector conn;
        try {
            m = MessageType.getMessageById(slug, messageId);
        } catch (Exception e) {
            e.printStackTrace();
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid message id.")
            ).build();
        }
        try {
            conn = Connector.getConnectorInfoById(connectorId);
            if (!conn.isExternal())
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not insert new Message Type. Connector is not external.")
                ).build();
        } catch (Exception e) {
            e.printStackTrace();
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid connector id.")
            ).build();
        }
        try {
            if (!conn.getMetadata().getDatasources().contains(m.getExternalDatasource())){
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Could not create new service for Message Type. Invalid datasource specified for connector.")
                ).build();
            }
            m.setExternalConnectorId(connectorId);
            m.setExternalDatasource(datasource);
            m.save(slug);
            details = Integer.toString(m.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new service for Message Type.")
            ).build();
        }
        boolean externalConnector = !(m.getExternalConnectorId() == null);
        PubSubConnector.getInstance().reloadSubscriptions(slug, externalConnector);
        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
@ PUT @ Path ( "{slug}/{messageTypeId}" ) public Response insert ( @ PathParam ( "slug" ) String slug , @ PathParam ( "messageTypeId" ) Integer messageId , @ QueryParam ( "connector_id" ) Integer connectorId , @ QueryParam ( "external_datasource" ) String datasource ) { String details ; MessageType m ; Connector conn ; try { m = MessageType . getMessageById ( slug , messageId ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create new service for Message Type. Invalid message id." ) ) . build ( ) ; } try { conn = Connector . getConnectorInfoById ( connectorId ) ; if ( ! conn . isExternal ( ) ) return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not insert new Message Type. Connector is not external." ) ) . build ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create new service for Message Type. Invalid connector id." ) ) . build ( ) ; } try { if ( ! conn . getMetadata ( ) . getDatasources ( ) . contains ( m . getExternalDatasource ( ) ) ) { return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create new service for Message Type. Invalid datasource specified for connector." ) ) . build ( ) ; } m . setExternalConnectorId ( connectorId ) ; m . setExternalDatasource ( datasource ) ; m . save ( slug ) ; details = Integer . toString ( m . getId ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create new service for Message Type." ) ) . build ( ) ; } boolean externalConnector = ! ( m . getExternalConnectorId ( ) == null ) ; PubSubConnector . getInstance ( ) . reloadSubscriptions ( slug , externalConnector ) ; return Response . ok ( new RequestResponse ( "OK" , details ) ) . build ( ) ; }
Message service to update external connector and metadata
Message service to update external connector and metadata