From b835053e5f195ef90a8e90be641342fb768e83e7 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 26 Jan 2015 16:44:41 +0100 Subject: [PATCH] * Makefile: * CatalogManager.cs: Let the catalog manager ensure all command form are instancied * PhysicalProduct.cs: A better ToString method * SaleForm.cs: doc * NpgsqlContentProvider.cs: registers a command * FrontOfficeApiController.cs: Set the catalog referer uri in each command form found in the catalog * FrontOfficeController.cs: creates the catalog with referer uri * instdbws.sql: the command has got a client, as registered user * Commande.cs: The command has an id and a product reference * IContentProvider.cs: new RegisterCommand method * WorkFlowManager.cs: yavscModel/WorkFlow/IContentProvider.cs --- Makefile | 14 +++++++++-- SalesCatalog/CatalogManager.cs | 18 ++++++++++++-- SalesCatalog/Model/PhysicalProduct.cs | 2 +- SalesCatalog/Model/SaleForm.cs | 20 +++++++++++++++ WorkFlowProvider/NpgsqlContentProvider.cs | 16 ++++++++++++ web/Controllers/FrontOfficeApiController.cs | 4 +-- web/Controllers/FrontOfficeController.cs | 10 ++++---- web/instdbws.sql | 27 +++++++++++++++++++-- yavscModel/WorkFlow/Commande.cs | 17 ++++++++++--- yavscModel/WorkFlow/IContentProvider.cs | 6 +++++ yavscModel/WorkFlow/WorkFlowManager.cs | 7 +++++- 11 files changed, 122 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 5f5fa4a2..9a03daf2 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,10 @@ VERSION=1.1 CONFIG=Debug DESTDIR=build/web/$(CONFIG) COPYUNCHANGED="false" -PREPRODHOSTDIR=localhost:/srv/www/yavsc -PRODHOSTDIR=localhost:/srv/www/lua +LOCALHOSTDIR=localhost:/srv/www/lua +TESTHOSTDIR=localhost:/srv/www/yavsc +PREPRODHOSTDIR=lua.localdomain:/srv/yavsc +PRODHOSTDIR=lua.localdomain:/srv/www/lua all: deploy ddir: @@ -24,12 +26,20 @@ clean: xbuild /t:Clean rm -rf $(DESTDIR) +rsync-local: deploy + rsync -ravu build/web/$(CONFIG)/ root@$(LOCALHOSTDIR) + +rsync-test: deploy + rsync -ravu build/web/$(CONFIG)/ root@$(TESTHOSTDIR) + rsync-preprod: deploy rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOSTDIR) rsync-prod: deploy rsync -ravu build/web/$(CONFIG)/ root@$(PRODHOSTDIR) +rsync-all: rsync-local rsync-test rsync-preprod rsync-prod + sourcepkg: git archive --format=tar --prefix=yavsc-$(CONFIG)/ $(CONFIG) | bzip2 > yavsc-$(CONFIG).tar.bz2 diff --git a/SalesCatalog/CatalogManager.cs b/SalesCatalog/CatalogManager.cs index a6f71d2c..c9552a86 100644 --- a/SalesCatalog/CatalogManager.cs +++ b/SalesCatalog/CatalogManager.cs @@ -10,15 +10,29 @@ namespace SalesCatalog public static class CatalogManager { private static CatalogProvider defaultProvider = null; - public static Catalog GetCatalog () + public static Catalog GetCatalog (string catalogUri) { + if (defaultProvider == null) { if (CatalogHelper.Config == null) CatalogHelper.LoadConfig (); defaultProvider = CatalogHelper.GetDefaultProvider (); + } + Catalog res = defaultProvider.GetCatalog (); + // Assert res.Brands.All( x => x.DefaultForm != null ); + // Sanity fixes + foreach (Brand b in res.Brands) { + if (b.DefaultForm.CatalogReference==null) + b.DefaultForm.CatalogReference = catalogUri; + foreach (ProductCategory pc in b.Categories) { + foreach (Product p in pc.Products) { + if (p.CommandForm == null) + p.CommandForm = b.DefaultForm; + } + } } - return defaultProvider.GetCatalog (); + return res; } } } diff --git a/SalesCatalog/Model/PhysicalProduct.cs b/SalesCatalog/Model/PhysicalProduct.cs index c90c14ee..158c0d5d 100644 --- a/SalesCatalog/Model/PhysicalProduct.cs +++ b/SalesCatalog/Model/PhysicalProduct.cs @@ -20,7 +20,7 @@ namespace SalesCatalog.Model public override string ToString () { - return string.Format ("[PhysicalProduct: UnitaryPrice={0}]", UnitaryPrice); + return string.Format ("[PhysicalProduct: Reference:{0} UnitaryPrice={1}]", Reference, UnitaryPrice); } } } diff --git a/SalesCatalog/Model/SaleForm.cs b/SalesCatalog/Model/SaleForm.cs index 436b1032..ea4f0c4e 100644 --- a/SalesCatalog/Model/SaleForm.cs +++ b/SalesCatalog/Model/SaleForm.cs @@ -5,15 +5,35 @@ namespace SalesCatalog.Model { public class SaleForm { + /// + /// Gets or sets the catalog reference. + /// It must be non null, + /// it is an Uri, returning the Xml + /// Catalog at Http GET request + /// + /// The catalog reference. + public string CatalogReference { get; set; } + public SaleForm () { } + /// + /// Gets or sets the action, that is, + /// the Method of the FrontOffice controller + /// called to post this Command form. + /// It defaults to "Command" + /// + /// The action. public string Action { get; set; } + /// + /// Gets or sets the input values of this command form. + /// + /// The items. public FormElement[] Items { get; set; } } } diff --git a/WorkFlowProvider/NpgsqlContentProvider.cs b/WorkFlowProvider/NpgsqlContentProvider.cs index b15132fa..9385be7f 100644 --- a/WorkFlowProvider/NpgsqlContentProvider.cs +++ b/WorkFlowProvider/NpgsqlContentProvider.cs @@ -12,6 +12,22 @@ namespace WorkFlowProvider { public class NpgsqlContentProvider: ProviderBase, IContentProvider { + public long RegisterCommand (Commande com) + { + long id; + using (NpgsqlConnection cnx = CreateConnection ()) { + using (NpgsqlCommand cmd = cnx.CreateCommand ()) { + cmd.CommandText = + "insert into commandes (pref,creation) values (@pref,@creat) returning _id"; + cmd.Parameters.Add ("@pref", com.ProdRef); + cmd.Parameters.Add ("@creat", com.CreationDate); + cnx.Open (); + com.Id = id = (long)cmd.ExecuteScalar (); + } + } + return id; + } + public StatusChange[] GetWrittingStatuses (long wrid) { throw new NotImplementedException (); diff --git a/web/Controllers/FrontOfficeApiController.cs b/web/Controllers/FrontOfficeApiController.cs index 39be81db..3dd7a266 100644 --- a/web/Controllers/FrontOfficeApiController.cs +++ b/web/Controllers/FrontOfficeApiController.cs @@ -41,14 +41,14 @@ namespace Yavsc.ApiControllers [AcceptVerbs("GET")] public Catalog Catalog () { - Catalog c = CatalogManager.GetCatalog (); + Catalog c = CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath); return c; } [AcceptVerbs("GET")] public ProductCategory GetProductCategorie (string brandName, string prodCategorie) { - return CatalogManager.GetCatalog ().GetBrand (brandName).GetProductCategory (prodCategorie) + return CatalogManager.GetCatalog (Request.RequestUri.AbsolutePath).GetBrand (brandName).GetProductCategory (prodCategorie) ; } /* diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index f96a8ae5..dbc9d373 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -91,7 +91,7 @@ namespace Yavsc.Controllers public ActionResult Catalog () { return View ( - CatalogManager.GetCatalog () + CatalogManager.GetCatalog (Request.Url.AbsolutePath) ); } @@ -101,7 +101,7 @@ namespace Yavsc.Controllers [AcceptVerbs("GET")] public ActionResult Brand (string id) { - Catalog c = CatalogManager.GetCatalog (); + Catalog c = CatalogManager.GetCatalog (Request.Url.AbsolutePath); ViewData ["BrandName"] = id; return View ( c.GetBrand (id) ); } @@ -117,7 +117,7 @@ namespace Yavsc.Controllers { ViewData ["BrandName"] = id; return View ( - CatalogManager.GetCatalog ().GetBrand (id).GetProductCategory (pc) + CatalogManager.GetCatalog (Request.Url.AbsolutePath).GetBrand (id).GetProductCategory (pc) ); } @@ -128,7 +128,7 @@ namespace Yavsc.Controllers ViewData ["BrandName"] = id; ViewData ["ProdCatRef"] = pc; ViewData ["ProdRef"] = pref; - Catalog cat = CatalogManager.GetCatalog (); + Catalog cat = CatalogManager.GetCatalog (Request.Url.AbsolutePath); if (cat == null) { ViewData ["Message"] = "Catalog introuvable"; ViewData ["RefType"] = "Catalog"; @@ -189,7 +189,7 @@ namespace Yavsc.Controllers Session["Basket"]=new List(); List basket = Session["Basket"] as List; // Add specified product command to the basket, - basket.Add(new Commande(0,0,collection)); + basket.Add(Commande.Create(collection)); return View (collection); } catch (Exception e) { diff --git a/web/instdbws.sql b/web/instdbws.sql index 8d0e51f6..3184f66e 100644 --- a/web/instdbws.sql +++ b/web/instdbws.sql @@ -202,17 +202,40 @@ COMMENT ON COLUMN blfiles.blid IS 'Blog entry identifier (foreign key)'; CREATE TABLE commandes ( - id bigint NOT NULL, -- Identifiant unique de commande e, cours + id bigserial NOT NULL, -- Identifiant unique de commande e, cours validation date, -- Date de validation prdref character varying(255) NOT NULL, -- Product reference from the unique valid catalog at the validation date - CONSTRAINT commandes_pkey PRIMARY KEY (id) + creation timestamp with time zone, -- creation date + clientname character varying(255), -- user who created the command, client of this command + applicationname character varying(255), -- application concerned by this command + CONSTRAINT commandes_pkey PRIMARY KEY (id), + CONSTRAINT commforeignuser FOREIGN KEY (clientname, applicationname) + REFERENCES users (username, applicationname) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE ) WITH ( OIDS=FALSE ); +ALTER TABLE commandes + OWNER TO yavsc; COMMENT ON COLUMN commandes.id IS 'Identifiant unique de commande e, cours'; COMMENT ON COLUMN commandes.validation IS 'Date de validation'; COMMENT ON COLUMN commandes.prdref IS 'Product reference from the unique valid catalog at the validation date'; +COMMENT ON COLUMN commandes.creation IS 'creation date'; +COMMENT ON COLUMN commandes.clientname IS 'user who created the command, client of this command'; +COMMENT ON COLUMN commandes.applicationname IS 'application concerned by this command'; + + +-- Index: fki_commforeignuser + +-- DROP INDEX fki_commforeignuser; + +CREATE INDEX fki_commforeignuser + ON commandes + USING btree + (clientname COLLATE pg_catalog."default", applicationname COLLATE pg_catalog."default"); + + -- Table: comment diff --git a/yavscModel/WorkFlow/Commande.cs b/yavscModel/WorkFlow/Commande.cs index 65bc9646..1ca2d31b 100644 --- a/yavscModel/WorkFlow/Commande.cs +++ b/yavscModel/WorkFlow/Commande.cs @@ -10,11 +10,20 @@ namespace Yavsc.Model.WorkFlow public class Commande { public DateTime CreationDate { get; set; } - long Id { get; set; } - public Commande(long catid, long pref, NameValueCollection collection) + public long Id { get; set; } + public string ProdRef { get; set; } + public Commande() { + } + + public static Commande Create(NameValueCollection collection) { - CreationDate = DateTime.Now; - //TODO save it and get the id + Commande cmd = new Commande (); + // string catref=collection["catref"]; // Catalog Url from which formdata has been built + cmd.ProdRef=collection["prodref"]; // Required product reference + cmd.CreationDate = DateTime.Now; + WorkFlowManager wm = new WorkFlowManager (); + wm.RegisterCommand (cmd); // sets cmd.Id + return cmd; } } } diff --git a/yavscModel/WorkFlow/IContentProvider.cs b/yavscModel/WorkFlow/IContentProvider.cs index 0a1f14ef..f97d8b74 100644 --- a/yavscModel/WorkFlow/IContentProvider.cs +++ b/yavscModel/WorkFlow/IContentProvider.cs @@ -112,6 +112,12 @@ namespace Yavsc.Model.WorkFlow /// Status. /// Username. void SetEstimateStatus (long estid,int status,string username); + /// + /// Registers the command. + /// + /// The command id in db. + /// COM. + long RegisterCommand (Commande com); } } diff --git a/yavscModel/WorkFlow/WorkFlowManager.cs b/yavscModel/WorkFlow/WorkFlowManager.cs index c6173fb4..5e502b56 100644 --- a/yavscModel/WorkFlow/WorkFlowManager.cs +++ b/yavscModel/WorkFlow/WorkFlowManager.cs @@ -16,6 +16,11 @@ namespace Yavsc.Model.WorkFlow { public static Catalog Catalog { get; set; } + public long RegisterCommand(Commande com) + { + return ContentProvider.RegisterCommand (com); + } + public void UpdateEstimate (Estimate estim) { ContentProvider.UpdateEstimate (estim); @@ -105,7 +110,7 @@ namespace Yavsc.Model.WorkFlow { if (!string.IsNullOrWhiteSpace(productid)) { if (Catalog == null) - Catalog = SalesCatalog.CatalogManager.GetCatalog (); + Catalog = SalesCatalog.CatalogManager.GetCatalog ("/WorkFlowApi"); if (Catalog == null) throw new Exception ("No catalog"); Product p = Catalog.FindProduct (productid);