Пример #1
0
  @Mapping(from = QoS.class, to = QosBase.class)
  public static QosBase map(QoS model, QosBase template) {
    QosBase entity = null;
    if (template != null) {
      entity = template;
    }
    QosType qosType =
        model.getType() != null
            ? QosType.valueOf(model.getType().toUpperCase())
            : entity != null
                ? QosType.valueOf(entity.getQosType().toString().toUpperCase())
                : QosType.STORAGE;
    switch (qosType) {
      case STORAGE:
        if (entity == null) {
          entity = new StorageQos();
        }
        if (model.isSetMaxThroughput()) {
          ((StorageQos) entity)
              .setMaxThroughput(IntegerMapper.mapMinusOneToNull(model.getMaxThroughput()));
        }
        if (model.isSetMaxReadThroughput()) {
          ((StorageQos) entity)
              .setMaxReadThroughput(IntegerMapper.mapMinusOneToNull(model.getMaxReadThroughput()));
        }
        if (model.isSetMaxWriteThroughput()) {
          ((StorageQos) entity)
              .setMaxWriteThroughput(
                  IntegerMapper.mapMinusOneToNull(model.getMaxWriteThroughput()));
        }
        if (model.isSetMaxIops()) {
          ((StorageQos) entity).setMaxIops(IntegerMapper.mapMinusOneToNull(model.getMaxIops()));
        }
        if (model.isSetMaxReadIops()) {
          ((StorageQos) entity)
              .setMaxReadIops(IntegerMapper.mapMinusOneToNull(model.getMaxReadIops()));
        }
        if (model.isSetMaxWriteIops()) {
          ((StorageQos) entity)
              .setMaxWriteIops(IntegerMapper.mapMinusOneToNull(model.getMaxWriteIops()));
        }
        break;
      case CPU:
        if (entity == null) {
          entity = new CpuQos();
        }
        if (model.isSetCpuLimit()) {
          ((CpuQos) entity).setCpuLimit(IntegerMapper.mapMinusOneToNull(model.getCpuLimit()));
        }
        break;
      case NETWORK:
        if (entity == null) {
          entity = new NetworkQoS();
        }
        if (model.isSetInboundAverage()) {
          ((NetworkQoS) entity)
              .setInboundAverage(IntegerMapper.mapMinusOneToNull(model.getInboundAverage()));
        }
        if (model.isSetInboundPeak()) {
          ((NetworkQoS) entity)
              .setInboundPeak(IntegerMapper.mapMinusOneToNull(model.getInboundPeak()));
        }
        if (model.isSetInboundBurst()) {
          ((NetworkQoS) entity)
              .setInboundBurst(IntegerMapper.mapMinusOneToNull(model.getInboundBurst()));
        }
        if (model.isSetOutboundAverage()) {
          ((NetworkQoS) entity)
              .setOutboundAverage(IntegerMapper.mapMinusOneToNull(model.getOutboundAverage()));
        }
        if (model.isSetOutboundPeak()) {
          ((NetworkQoS) entity)
              .setOutboundPeak(IntegerMapper.mapMinusOneToNull(model.getOutboundPeak()));
        }
        if (model.isSetOutboundBurst()) {
          ((NetworkQoS) entity)
              .setOutboundBurst(IntegerMapper.mapMinusOneToNull(model.getOutboundBurst()));
        }
        break;
      default:
        break;
    }

    if (model.isSetId()) {
      entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetName()) {
      entity.setName(model.getName());
    }
    if (model.isSetDataCenter() && model.getDataCenter().isSetId()) {
      entity.setStoragePoolId(GuidUtils.asGuid(model.getDataCenter().getId()));
    }
    if (model.isSetDescription()) {
      entity.setDescription(model.getDescription());
    }

    return entity;
  }