How to create soap service in zf2? - soap

I have a table named 'Restaurant' with following fields:
CREATE TABLE IF NOT EXISTS `restaurant` (
`restaurant_id` int(11) NOT NULL AUTO_INCREMENT COMMENT,
`restaurant_id_name` varchar(100) NOT NULL COMMENT ,
`restaurant_name` varchar(100) NOT NULL COMMENT,
`restaurant_score` int(10) NOT NULL,
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=95 ;
I need to utilize the SOAP server using the ZF2 component Zend\Soap\Server using WSDL for concrete entity/mapper/model(ex Restaurant)(insert/update/delete/retrieve).
Yes I have read the documentation, but I haven't searched for more examples on how to develop a SOAP server in module(Controller\View\Model). If you have any concrete examples or detailed explanations using instances of Zend\Soap\Server and/or Zend\Soap\Client I would be appreciative of reviewing those to help me out.

Related

confused about design RBAC in RESTful api while a resource has subclass

I am designing a RESTful API for an applicaiton ,the resources is project-level, and people should create project before they create a resource.
first, I design the path as below,
path = api/v1/projects ,METHOD = ['POST'] # create a project
path = api/v1/projects/$PROJECT-ID/users , METHOD=['POST'] # add a user to a project
path = api/v1/projects/$PROJECT-ID/books , METHOD=['POST'] # add a book to a project
path = api/v1/users METHOD=['POST'] # user register
it seems good, each path of an api is unique, but while I design the permission model ,It confused me. it is hard to map a permission from api path.
in order to differentiate create project and add a user to a project api, I create table for permission include parent column whose value may be like 'projects/$project-ID', So while a request sent to the api gateway, I can verify which permission the request match by check if it has a parent(prefix) via Re.
# permission model one
CREATE TABLE `permission` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'permission name',
`action` varchar(32) NOT NULL DEFAULT '' COMMENT ' http method DELETE, POST,GET,PUT ',
`resource` varchar(64) NOT NULL DEFAULT '' COMMENT 'resource type such as user',
`parent` varchar(64) NOT NULL DEFAULT '' COMMENT 'the parent class of resources, not all the resource has parent ',
PRIMARY KEY (`id`),
UNIQUE KEY `name_unique` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'permisson model';
I think it can work ,but the design is ugly , what do you think about it?

Can't create table with text[] data type

I'm trying to store an entity in my postgresql database. This entity has a List in it, so I'd like to use postgresql type TEXT[]. But everytime I'm trying I get a SQL error, I have no idea why.
I don't get the syntax error, really. I'm sure it's a dumb issue but can you help me?
Thank you
I tried some alternatives, creating it directly from h2 console but I always get the same error
The script I use with flyway for creating the table
CREATE TABLE discrimination(
id SERIAL PRIMARY KEY NOT NULL ,
location VARCHAR(255) NOT NULL,
criteria TEXT[] NOT NULL,
domain VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
name_organ VARCHAR(55) NOT NULL,
function_disc VARCHAR(55) NOT NULL
);
my application config for h2 & flyway
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:formation-iris;MODE=PostgreSQL
username: test
password: test
driver-class-name: org.h2.Driver
flyway:
locations: classpath:db/migration
enabled: true
And the error I get
Syntax error in SQL statement "CREATE TABLE DISCRIMINATION(
ID SERIAL PRIMARY KEY NOT NULL ,
LOCATION VARCHAR(255) NOT NULL,
CRITERIA TEXT[[*]] NOT NULL,
DOMAIN VARCHAR(255) NOT NULL,
DESCRIPTION TEXT NOT NULL,
NAME_ORGAN VARCHAR(55) NOT NULL,
FUNCTION_DISC VARCHAR(55) NOT NULL
) "; expected "(, FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
From H2 documentation:
Compatibility Modes
For certain features, this database can emulate
the behavior of specific databases. However, only a small subset of
the differences between databases are implemented in this way.
Which means that H2 can emulate certain DB-specific behaviours, but it won't be fully compatible with the selected DB.
That's especially true for SQL syntax.
So, if you want to use arrays in H2, then you should use the H2 syntax ARRAY instead of TEXT[]
Which also means that you will need a separate SQL script for production (PostgreSQL) and for tests (H2). Luckily, flyway supports that. It can load the vendor-specific scripts from different folders. Extend the flyway configuration this way:
spring.flyway.locations=classpath:db/migration/{vendor}
and add the vendor-specific SQL scripts under the /h2 and /postgresql folders respectively.

Update multiple related tables using Spring Data Rest

I have two tables Employee and Address having one-to-one relationship.
CREATE TABLE EMPLOYEE(
ID BIGINT PRIMARY KEY NOT NULL,
EMP_NAME VARCHAR(50) NOT NULL,
PHONE_ID BIGINT,
DELETED BOOLEAN NOT NULL DEFAULT FALSE,
CONSTRAINT CONSTRAINT1 FOREIGN KEY (PHONE_ID)
REFERENCES PHONE (ID)
)
CREATE TABLE PHONE(
ID BIGINT PRIMARY KEY NOT NULL,
PH_NUMBER VARCHAR(20) NOT NULL,
DELETED BOOLEAN NOT NULL DEFAULT FALSE,
)
I am using Spring Data REST.
Q1. I want to expose a single data rest repository method to update DELETED column for both EMPLOYEE and `PHONE.
Something like below:
TestRepository implements CrudRepository{
#Query(value="update both table query", native=false)
public void updateBoth();
}
Q2. Is doing so even possible using Spring data REST.
PLEASE NOTE: I do not want to use native query, i.e. #Query(value="", native="true")
You have to find the balance between using the framework properly and overusing it.
Spring Data REST is to expose your repositories to HTTP but you can't solve everything with it.
The proper way here is to create a custom Controller and implement the functionality you want with proper transaction management to have the data integrity you need.

LocalDB, table definition with comments

I am using Visual Studio ...if I am creating a LocalDb with the framework, everything is fine. After creating or updating an table with a comment on an column and opening table definition ...The comments I created are gone away!?
Creating:
CREATE TABLE [dbo].[Filter] (
[Id] INT IDENTITY (1, 1) NOT NULL,
-- some very usefull hint
[Name] NVARCHAR (256) NOT NULL,
-- some important hint
[Description] NVARCHAR (512) NOT NULL,
-- some very usefull hint
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Updating:
CREATE TABLE [dbo].[Filter] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (256) NOT NULL,
[Description] NVARCHAR (512) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Is it not possible to add some comments?
The database does not store comments in its schema definitions.
All you can do is store and or check in your table definition SQL script (with our without comments) along with other files of your Visual Studio project if you like to.

Declaring a default constraint when creating a table

I am creating a new table in Microsoft SQL server 2000 by writing the code instead of using the GUI, I am trying to learn how to do it "the manual way".
This is the code I am actually using, and it works fine:
CREATE TABLE "attachments"
(
"attachment_id" INT NOT NULL,
"load_date" SMALLDATETIME NOT NULL,
"user" VARCHAR(25) NOT NULL,
"file_name" VARCHAR(50) NOT NULL,
CONSTRAINT "pk_attachments" PRIMARY KEY ("attachment_id"),
CONSTRAINT "fk_users" FOREIGN KEY ("user") REFERENCES "users" ("user"),
CONSTRAINT "ch_load_date" CHECK ("load_date" < GETDATE())
)
I have specified the primary key, foreign key and check constraints on their own because in this way I can define a name for them, otherwise declaring them inline would make SQL Server generate a random name, and I do not "like" it.
The problem arose when I tried to declare the default value constraint: looking at the informations on the internet and how Microsoft SLQ Server Management Studio creates it, I understood that it can be created both inline and on its own:
"load_date" SMALLDATETIME NOT NULL DEFAULT GETDATE()
or
CONSTRAINT "df_load_date" DEFAULT GETDATE() FOR "load_date"
The inline method works fine, but it generates as usual a random name for the constaint, the stand alone method throws an error, saying Incorrect syntax near 'FOR'..
Also, if I create the table and then ALTER it, the command works:
ALTER TABLE "attachments"
ADD CONSTRAINT "df_load_date" DEFAULT GETDATE() FOR "load_date"
As a reference, here is the full code I am trying to execute:
CREATE TABLE "attachments"
(
"attachment_id" INT NOT NULL,
"load_date" SMALLDATETIME NOT NULL,
"user" VARCHAR(25) NOT NULL,
"file_name" VARCHAR(50) NOT NULL,
CONSTRAINT "pk_attachments" PRIMARY KEY ("attachment_id"),
CONSTRAINT "fk_users" FOREIGN KEY ("user") REFERENCES "users" ("user"),
CONSTRAINT "ch_load_date" CHECK ("load_date" < GETDATE()),
CONSTRAINT "df_load_date" DEFAULT GETDATE() FOR "load_date"
)
I'm totally at loss here, is what I am trying to do not possible, or I am doing something wrong?
Edit:
David M showed how to add a named default constraint using the inline syntax, I am still looking to understand if the stand alone syntax is completely wrong or it is my fault.
Do it inline with the column creation:
[load_date] SMALLDATETIME NOT NULL
CONSTRAINT [df_load_date] DEFAULT GETDATE()
I have used square brackets rather than quotes as many readers won't work with QUOTED_IDENTIFIERS on by default.