001/*
002 *  Copyright 2016 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.form;
017
018import java.util.List;
019import java.util.Map;
020
021/**
022 * This field is used for subcontent metadata
023 */
024public class SubContentField extends AbstractField
025{
026    private List<Map<String, Object>> _contentValues;
027    
028    private String[] _names;
029    private Boolean[] _isNew;
030    private String[] _contentTypes;
031    private String _workflowName;
032    private int _initWorkflowActionId;
033    private String _contentLanguage;
034
035    /**
036     * Creates a {@link SubContentField}
037     * @param contentValues The content values
038     * @param contentLanguage The contents languages
039     */
040    public SubContentField (List<Map<String, Object>> contentValues, String contentLanguage)
041    {
042        _contentValues = contentValues;
043        _contentLanguage = contentLanguage;
044        
045        _names = new String[contentValues.size()];
046        _contentTypes = new String[contentValues.size()];
047        _isNew = new Boolean[contentValues.size()];
048        
049        int index = 0;
050        for (Map<String, Object> contentValue : contentValues)
051        {
052            if (contentValue.containsKey("id"))
053            {
054                _names[index] = (String) contentValue.get("id");
055                _isNew[index] = false;
056            }
057            else
058            {
059                _names[index] = (String) contentValue.get("title");
060                _contentTypes[index] = (String) contentValue.get("contentType");
061                _isNew[index] = true;
062            }
063            
064            index++;
065        }
066    }
067    
068    /**
069     * Set the workflow properties
070     * @param workflowName The workflow name
071     * @param initWorkflowActionId The id of initial workflow action
072     */
073    public void setWorkflow (String workflowName, int initWorkflowActionId)
074    {
075        _workflowName = workflowName;
076        _initWorkflowActionId = initWorkflowActionId;
077    }
078    
079    /**
080     * Get the content values
081     * @return The content values
082     */
083    public List<Map<String, Object>> getContentValues()
084    {
085        return _contentValues;
086    }
087    
088    /**
089     * Get the names or ids of content values
090     * @return The names or ids
091     */
092    public String[] getContentNamesOrIds ()
093    {
094        return _names;
095    }
096    
097    /**
098     * Get the 'isNew' properties
099     * @return the 'isNew' properties
100     */
101    public Boolean[] getIsNew()
102    {
103        return _isNew;
104    }
105    
106    /**
107     * Get the content types to create
108     * @return the content types to create
109     */
110    public String[] getContentTypes()
111    {
112        return _contentTypes;
113    }
114    
115    /**
116     * Get the workflow name
117     * @return the workflow name
118     */
119    public String getWorkflowName()
120    {
121        return _workflowName;
122    }
123    
124    /**
125     * Get the workflow action id
126     * @return the workflow action id
127     */
128    public int getWorkflowActionId()
129    {
130        return _initWorkflowActionId;
131    }
132    
133    /**
134     * Get the content language
135     * @return the content language
136     */
137    public String getContentLanguage()
138    {
139        return _contentLanguage;
140    }
141}