2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.openecomp.sdc.generator.aai.model;
 
  23 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
 
  25 import org.openecomp.sdc.generator.aai.types.ModelType;
 
  26 import org.openecomp.sdc.generator.aai.types.ModelWidget;
 
  27 import org.openecomp.sdc.generator.data.ArtifactType;
 
  28 import org.openecomp.sdc.generator.data.GeneratorConstants;
 
  29 import org.openecomp.sdc.generator.data.WidgetConfigurationUtil;
 
  30 import org.openecomp.sdc.generator.error.IllegalAccessException;
 
  32 import java.util.Collections;
 
  33 import java.util.HashSet;
 
  34 import java.util.List;
 
  35 import java.util.Properties;
 
  38 public abstract class Widget extends Model {
 
  40   private Set<String> keys = new HashSet<>();
 
  45    * @param type the type
 
  48   public static Widget getWidget(Type type) {
 
  52         return new ServiceWidget();
 
  54         return new VfWidget();
 
  56         return new VfcWidget();
 
  58         return new VServerWidget();
 
  60         return new VolumeWidget();
 
  62         return new FlavorWidget();
 
  64         return new TenantWidget();
 
  66         return new VolumeGroupWidget();
 
  68         return new LIntfWidget();
 
  70         return new L3NetworkWidget();
 
  72         return new VfModuleWidget();
 
  74         return new ImageWidget();
 
  76         return new OamNetwork();
 
  77       case ALLOTTED_RESOURCE:
 
  78         return new AllotedResourceWidget();
 
  80         return new TunnelXconnectWidget();
 
  92   public String getId() {
 
  93     Properties properties = WidgetConfigurationUtil.getConfig();
 
  94     String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
 
  96       throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
 
  97           ArtifactType.AAI.name() + ".model-version-id." + getName()));
 
 102   public ModelType getType() {
 
 103     ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
 
 104     return widgetModel.type();
 
 107   public String getName() {
 
 108     ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
 
 109     return widgetModel.name();
 
 113    * Get Widget Id from properties file.
 
 114    * @return - Widget Id
 
 116   public String getWidgetId() {
 
 117     Properties properties = WidgetConfigurationUtil.getConfig();
 
 118     String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id."
 
 121       throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
 
 122           ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
 
 127   public int hashCode() {
 
 128     return getId().hashCode();
 
 132   public Type getWidgetType() {
 
 140    * @return the boolean
 
 142   public boolean equals(Object obj) {
 
 143     if (obj instanceof Widget) {
 
 144       if (getId().equals(((Widget) obj).getId())) {
 
 145         ((Widget) obj).keys.addAll(this.keys);
 
 154   public void addKey(String key) {
 
 161    * @param keys the keys
 
 162    * @return the boolean
 
 164   public boolean memberOf(List<String> keys) {
 
 168     return !Collections.disjoint(this.keys, keys);
 
 172    * All instances used boolean.
 
 174    * @param collection the collection
 
 175    * @return the boolean
 
 177   public boolean allInstancesUsed(Set<String> collection) {
 
 178     Set<String> keyCopy = new HashSet<>(keys);
 
 179     keyCopy.removeAll(collection);
 
 180     return keyCopy.isEmpty();
 
 183   public boolean addResource(Resource resource) {
 
 184     throw new IllegalAccessException(GeneratorConstants
 
 185         .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
 
 188   public boolean addWidget(Widget widget) {
 
 193     SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE,
 
 194     OAM_NETWORK,ALLOTTED_RESOURCE,TUNNEL_XCONNECT