2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package oic.simulator.serviceprovider.model;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
23 import oic.simulator.serviceprovider.utils.Constants;
25 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
28 * This is a helper class for providing the automation settings information to
31 public class AutomationSettingHelper {
32 private String settingID;
33 private String settingValue;
34 private List<String> allowedValues;
36 public String getSettingID() {
40 public void setSettingID(String settingID) {
41 this.settingID = settingID;
44 public String getSettingValue() {
48 public void setSettingValue(String settingValue) {
49 this.settingValue = settingValue;
52 public List<String> getAllowedValues() {
56 public void setAllowedValues(List<String> allowedValues) {
57 this.allowedValues = allowedValues;
60 public void addAllowedValue(String newText) {
61 if (null != allowedValues) {
62 allowedValues.add(newText);
66 public static List<AutomationSettingHelper> getAutomationSettings(
67 LocalResourceAttribute attribute) {
68 List<AutomationSettingHelper> settingList = null;
69 boolean invalidSetting;
71 settingList = new ArrayList<AutomationSettingHelper>();
72 for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
73 invalidSetting = false;
74 AutomationSettingHelper setting = new AutomationSettingHelper();
75 if (Constants.AUTOMATION_SETTINGS[count]
76 .equals(Constants.AUTOMATION_TYPE)) {
77 setting.setSettingID(Constants.AUTOMATION_TYPE);
78 if (null != attribute) {
79 setting.setSettingValue(attribute.getAutomationType()
82 setting.setSettingValue(AutoUpdateType.ONE_TIME.toString());
84 List<String> valueList = new ArrayList<String>();
85 valueList.add(AutoUpdateType.ONE_TIME.toString());
86 valueList.add(AutoUpdateType.REPEAT.toString());
87 setting.setAllowedValues(valueList);
88 } else if (Constants.AUTOMATION_SETTINGS[count]
89 .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
90 setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
91 if (null != attribute) {
92 setting.setSettingValue(String.valueOf(attribute
93 .getAutomationUpdateInterval()));
95 setting.setSettingValue(String
96 .valueOf(Constants.DEFAULT_AUTOMATION_INTERVAL));
98 List<String> valueList = new ArrayList<String>();
99 for (int index = 1; index <= 10; index++) {
100 valueList.add(String.valueOf(index * 500));
102 setting.setAllowedValues(valueList);
104 invalidSetting = true;
106 if (!invalidSetting) {
107 settingList.add(setting);
113 public static void updateAutomationStatus(
114 List<AutomationSettingHelper> localSettingList, String status) {
115 if (null != localSettingList && null != status) {
116 Iterator<AutomationSettingHelper> settingItr = localSettingList
118 AutomationSettingHelper setting;
119 while (settingItr.hasNext()) {
120 setting = settingItr.next();
121 if (null != setting) {
122 if (setting.getSettingID().equals(Constants.AUTOMATION)) {
123 setting.setSettingValue(status);