public static AssociationDTOA Convert(AssociationEN en, NHibernate.ISession session = null)
        {
            AssociationDTOA    dto = null;
            AssociationRESTCAD associationRESTCAD = null;
            AssociationCEN     associationCEN     = null;
            AssociationCP      associationCP      = null;

            if (en != null)
            {
                dto = new AssociationDTOA();
                associationRESTCAD = new AssociationRESTCAD(session);
                associationCEN     = new AssociationCEN(associationRESTCAD);
                associationCP      = new AssociationCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                dto.Type = en.Type;


                dto.CardinalityOrigin = en.CardinalityOrigin;


                dto.CardinalityTarget = en.CardinalityTarget;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
示例#2
0
        public HttpResponseMessage New_([FromBody] AssociationDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AssociationRESTCAD associationRESTCAD = null;
            AssociationCEN     associationCEN     = null;
            AssociationDTOA    returnValue        = null;
            int returnOID = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                associationRESTCAD = new AssociationRESTCAD(session);
                associationCEN     = new AssociationCEN(associationRESTCAD);

                // Create
                returnOID = associationCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    ,
                    //Atributo OID: p_rolOrigin
                    // attr.estaRelacionado: true
                    dto.RolOrigin_oid                     // association role

                    ,
                    //Atributo OID: p_rolTarget
                    // attr.estaRelacionado: true
                    dto.RolTarget_oid                     // association role

                    , dto.Type                            //Atributo Primitivo: p_type
                    , dto.CardinalityOrigin               //Atributo Primitivo: p_cardinalityOrigin
                    , dto.CardinalityTarget               //Atributo Primitivo: p_cardinalityTarget
                    ,
                    //Atributo OID: p_entityOrigin
                    // attr.estaRelacionado: true
                    dto.EntityOrigin_oid                     // association role

                    ,
                    //Atributo OID: p_entityTarget
                    // attr.estaRelacionado: true
                    dto.EntityTarget_oid                     // association role

                    ,
                    //Atributo OID: p_ioTScenario
                    // attr.estaRelacionado: true
                    dto.IoTScenario_oid                     // association role

                    , dto.Description                       //Atributo Primitivo: p_description
                    );
                SessionCommit();

                // Convert return
                returnValue = AssociationAssembler.Convert(associationRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDAssociation", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
示例#3
0
        public HttpResponseMessage Modify(int idAssociation, [FromBody] AssociationDTO dto)
        {
            // CAD, CEN, returnValue
            AssociationRESTCAD associationRESTCAD = null;
            AssociationCEN     associationCEN     = null;
            AssociationDTOA    returnValue        = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                associationRESTCAD = new AssociationRESTCAD(session);
                associationCEN     = new AssociationCEN(associationRESTCAD);

                // Modify
                associationCEN.Modify(idAssociation,
                                      dto.Name
                                      ,
                                      dto.Type
                                      ,
                                      dto.CardinalityOrigin
                                      ,
                                      dto.CardinalityTarget
                                      ,
                                      dto.Description
                                      );

                // Return modified object
                returnValue = AssociationAssembler.Convert(associationRESTCAD.ReadOIDDefault(idAssociation), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
示例#4
0
        public HttpResponseMessage ReadOID(int idAssociation)
        {
            // CAD, CEN, EN, returnValue
            AssociationRESTCAD associationRESTCAD = null;
            AssociationCEN     associationCEN     = null;
            AssociationEN      associationEN      = null;
            AssociationDTOA    returnValue        = null;

            try
            {
                SessionInitializeWithoutTransaction();


                associationRESTCAD = new AssociationRESTCAD(session);
                associationCEN     = new AssociationCEN(associationRESTCAD);

                // Data
                associationEN = associationCEN.ReadOID(idAssociation);

                // Convert return
                if (associationEN != null)
                {
                    returnValue = AssociationAssembler.Convert(associationEN, session);
                }
            }

            catch (Exception e)
            {
                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }