All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cosmicpush.gateway.push.NotificationPush Maven / Gradle / Ivy

/*
 * Copyright (c) 2014 Jacob D. Parr
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cosmicpush.gateway.push;

import com.cosmicpush.gateway.CosmicPushGateway;
import com.cosmicpush.gateway.common.*;
import com.cosmicpush.gateway.internal.*;
import com.fasterxml.jackson.annotation.*;

import java.util.*;
import org.crazyyak.dev.common.*;

public class NotificationPush implements Push {

  private String message;
  private LinkedHashMap traits = new LinkedHashMap();

  private PushType pushType = PushType.notification;

  private NotificationPush() {
  }

  public NotificationPush(String message) {
    this(message, new LinkedHashMap());
  }

  public NotificationPush(String message, LinkedHashMap traits) {
    this.message = (message == null) ? "No message" : message.trim();
    this.traits.putAll(traits);

    // Get a list of all the keys so that we can loop on the map
    // and remove anything without an actual value (purge nulls).
    String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet());

    for (String key : keys) {
      if (StringUtils.isBlank(traits.get(key))) {
        traits.remove(key);
      }
    }
  }

  @Override
  public PushType getPushType() {
    return pushType;
  }

  public String getMessage() {
    return message;
  }

  public LinkedHashMap getTraits() {
    return traits;
  }

  @Override
  @JsonIgnore
  public String getEndPoint() {
    return CosmicPushGateway.PUSH_NOTIFICATION;
  }

  @Override
  public RequestErrors validate(RequestErrors errors) {
    ValidationUtils.requireValue(errors, message, "The message must be specified.");
    return errors;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy