Best practice for saving / publishing when creating web content

I have a website where authenticated users can create new projects. At several points in the process, the user can choose to save the project or publish the project. Thus, for the same project there are several records, one project and one public

In the past, I did this for a blog site where posts have a project object that is created or deleted depending on what happens in the save / publish stream,

I wonder what other approaches might work better. Is there a design template for this kind of thing?

Re projects, they are quite large, divided into 5 pages for input, each page can be saved or published.

+4
source share
1 answer

The specific design for a project against publishing or staging against production is basically an abstraction of the data source layer. Basically, the data layer is divided into two implementations that have the same interface.

Here is a very simple interface that two implementations (project versus publication) of a data source can use

public interface CMSDatasource { /*** * Save the data * @param data the data needed to be saved * @return The key for the data */ public String saveData(String data); /*** * Delete the data given a particular key * @param key */ public void deleteData(String key); /*** * Get the data given a particular key * @param key * @return */ public String getData(String key); /*** * Get all the data that has been put into the system * @return Return a Map of timestamp and the String being put * into the system */ public Map getHistory(); } 

Now both data sources for the project / publication will have to be able to do all this anyway, the only thing that sets them apart is where they will be stored.

Note also that these two modes work with the same data type (in this case, String), so they must be normalized at the logical level of the CMS.

Using this construct, we do not need to rewrite the logic for the CMS module or data model. All we need to do is exchange data sources between the project and the publication. To get the appropriate data source, we could implement the Factory pattern.

Abstract data sources through the interface will also allow the implementation to freely choose the basic implementation of the data source. For example, you can select a relational database such as MySQL to store a draft, but you can use NoSQL, such as CouchDB, to store published data. By making an interface over a data source, it is easy to replace the original data source from one implementation to another.

For further illustration, suppose the CMS has a very simple text module that will contain an article that the user can enter. The class will look something like this:

 public class ArticleModule { String article; int publishingMode; /*** * Save the data based on user action */ public void saveData() { // get the datasource depending on the publishing mode set for this // module (DRAFT vs. PUBLISHED) CMSDatasource datasource = CMSDatasourceFactory.getDatasource(publishingMode); // save the article, note that nothing is required to change in this class // since the datasource is completely abstracted by the interface datasource.saveData(article); } // below is the getter/setter for the article and publishing mode // ...... } 

To create an article, CMS users will interact with this class by installing the article that they contribute through the user interface. After the user is ready to save, the user interface will eventually call saveData , note that in this implementation we do not need to change any article code, regardless of whether it is in draft or publication mode, since Factory implementation of the data source.

And finally, here is the skeleton for Factory

 public class CMSDatasourceFactory { public static final int DRAFT_MODE = 1; public static final int PUBLISHED_MODE = 2; /*** * Get a specific implementation of the datasource based on publishing mode * @param publishingMode Either draft or published mode, * use the constant DRAFT_MODE or PUBLISHED_MODE * @return A specific implementation for the datasource wrapped in CMSDatasource interface */ public static CMSDatasource getDatasource(int publishingMode) { switch(publishingMode) { case CMSDatasourceFactory.DRAFT_MODE : return new CMSDraftDatasource(); case CMSDatasourceFactory.PUBLISHED_MODE: return new CMSPublishedDatasource(); } return null; } } 
+1
source

All Articles