@Override
  public String setOutputProperty(String name, String value) {
    Validate.notEmpty(name, "name cannot be null");
    Validate.notEmpty(value, "value cannot be null");

    return this.outputProperties.put(name, value);
  }
  @Override
  public String setStylesheetParameter(String name, String value) {
    Validate.notEmpty(name, "name cannot be null");
    Validate.notEmpty(value, "value cannot be null");

    return this.parameters.put(name, value);
  }
예제 #3
0
  /**
   * main method to interact with {@link AvailableApplicationTool}.
   *
   * @param args
   * @throws SchedulingException
   * @throws NotAVisitorException
   * @throws CalendarAccountNotFoundException
   */
  public static void main(String[] args)
      throws CalendarAccountNotFoundException, NotAVisitorException, SchedulingException {
    // scan the arguments
    if (args.length == 0) {
      System.err.println(
          "Usage: AppointmentTool create [-owner username] [-visitor username] [-start YYYYmmdd-hhmm] [-duration minutes]");
      System.exit(1);
    }

    if (CREATE.equals(args[0])) {
      String visitorUsername = null;
      String ownerUsername = null;
      Date startTime = null;
      int duration = 30;

      for (int i = 1; i < args.length; i++) {
        if (OWNER_ARG.equalsIgnoreCase(args[i])) {
          ownerUsername = args[++i];
        } else if (VISITOR_ARG.equalsIgnoreCase(args[i])) {
          visitorUsername = args[++i];
        } else if (START_ARG.equalsIgnoreCase(args[i])) {
          String start = args[++i];
          SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
          try {
            startTime = df.parse(start);
          } catch (ParseException e) {
            System.err.println("Invalid format for start parameter, must match: " + DATE_FORMAT);
            System.exit(1);
          }
        } else if (DURATION_ARG.equalsIgnoreCase(args[i])) {
          String dur = args[++i];
          duration = Integer.parseInt(dur);
        }
      }

      Validate.notEmpty(ownerUsername, "owner argument cannot be empty");
      Validate.notEmpty(visitorUsername, "visitor argument cannot be empty");
      Validate.notNull(startTime, "start argument cannot be empty");

      ApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG);

      AppointmentTool tool =
          new AppointmentTool(
              (SchedulingAssistantService) applicationContext.getBean("schedulingAssistantService"),
              (ICalendarAccountDao) applicationContext.getBean("calendarAccountDao"),
              (OwnerDao) applicationContext.getBean("ownerDao"),
              (VisitorDao) applicationContext.getBean("visitorDao"),
              (AvailableScheduleDao) applicationContext.getBean("availableScheduleDao"));

      Date endDate = DateUtils.addMinutes(startTime, duration);
      VEvent event =
          tool.createAvailableAppointment(visitorUsername, ownerUsername, startTime, endDate);
      System.out.println("Event successfully created: ");
      System.out.println(event.toString());
    } else {
      System.err.println("Unrecognized command: " + args[0]);
      System.exit(1);
    }
  }
예제 #4
0
  /**
   * Construct a new {@link MessagePayload}
   *
   * @param hostname the hostname to be sent in this passive check
   * @param level the level
   * @param serviceName the service name
   * @param message the message
   */
  public MessagePayload(String hostname, Level level, String serviceName, String message) {
    Validate.notEmpty(hostname, "hostname cannot be null or an empty String");
    Validate.notEmpty(serviceName, "serviceName cannot be null or an empty String");

    this.hostname = hostname;
    this.level = level;
    this.serviceName = serviceName;
    this.message = message;
  }
예제 #5
0
 @Override
 @PortalTransactional
 public IPortletDefinition savePortletDefinition(IPortletDefinition portletDefinition) {
   Validate.notNull(portletDefinition, "portletDefinition can not be null");
   Validate.notNull(portletDefinition.getType(), "portletDefinition portlet type can not be null");
   Validate.notEmpty(portletDefinition.getFName(), "portletDefinition fname can not be null");
   Validate.notEmpty(portletDefinition.getName(), "portletDefinition name can not be null");
   Validate.notEmpty(portletDefinition.getTitle(), "portletDefinition title can not be null");
   this.getEntityManager().persist(portletDefinition);
   return portletDefinition;
 }
  /* (non-Javadoc)
   * @see org.jasig.portal.layout.om.IStylesheetUserPreferences#removeLayoutAttribute(java.lang.String, java.lang.String)
   */
  @Override
  public String removeLayoutAttribute(String nodeId, String name) {
    Validate.notEmpty(nodeId, "nodeId cannot be null");
    Validate.notEmpty(name, "name cannot be null");

    final Map<String, String> nodeAttributes = this.layoutAttributes.get(nodeId);
    if (nodeAttributes == null) {
      return null;
    }

    return nodeAttributes.remove(name);
  }
예제 #7
0
 @Override
 public void createTagsForResources(Map<String, String> keyValueMap, String... resourceIds) {
   Validate.notNull(keyValueMap);
   Validate.notEmpty(keyValueMap);
   Validate.notNull(resourceIds);
   Validate.notEmpty(resourceIds);
   AmazonEC2 ec2Client = ec2Client();
   List<Tag> tags = new ArrayList<Tag>();
   for (Map.Entry<String, String> entry : keyValueMap.entrySet()) {
     tags.add(new Tag(entry.getKey(), entry.getValue()));
   }
   CreateTagsRequest req = new CreateTagsRequest(Arrays.asList(resourceIds), tags);
   ec2Client.createTags(req);
 }
예제 #8
0
  public void mail(
      String aTo,
      String aSubject,
      String aMessage,
      Map<HeaderType, String> aHeaders,
      Map<String, byte[]> aAttachments)
      throws MessagingException {
    Validate.notEmpty(aTo, "The receiver must be specified.");
    Validate.notEmpty(aSubject, "The subject must be specified.");
    Validate.notEmpty(aMessage, "The message cannot be empty.");

    MimeMessage message = m_MailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true);

    helper.setFrom(m_From);
    helper.setSubject(aSubject);
    helper.setText(aMessage);

    setHelperMethod(addTo, aTo, helper);

    if (aHeaders != null)
      for (HeaderType headerType : aHeaders.keySet()) {
        Validate.notEmpty(
            aHeaders.get(headerType),
            "The value attached to headers key " + headerType + " cannot be empty.");

        if (HeaderType.CC.equals(headerType))
          setHelperMethod(addCC, aHeaders.get(headerType), helper);

        if (HeaderType.BCC.equals(headerType))
          setHelperMethod(addBCC, aHeaders.get(headerType), helper);
      }

    if (aAttachments != null)
      for (String attachmentName : aAttachments.keySet()) {
        Validate.notEmpty(attachmentName, "All attachments must have a non empty name");
        Validate.isTrue(
            aAttachments.get(attachmentName).length > 0,
            "The content of attachment " + attachmentName + " cannot be empty.");

        helper.addAttachment(
            attachmentName, new ByteArrayResource(aAttachments.get(attachmentName)));
      }

    log.info("Sending message " + aSubject + " to " + aTo);

    m_MailSender.send(message);
  }
예제 #9
0
 public RouteScriptLoader(
     final String pathToScript, final RouteConfigurationScriptEvaluator scriptEvaluator) {
   notEmpty(pathToScript, "Null or empty script path is not allowed.");
   notNull(scriptEvaluator, "Null evaluator is not allowed.");
   this.pathToScript = pathToScript;
   this.scriptEvaluator = scriptEvaluator;
 }
  public void mkview(String viewPath, String viewTag, String streamSelector)
      throws IOException, InterruptedException {
    Validate.notEmpty(viewPath);
    boolean isOptionalParamContainsHost = false;
    ArgumentListBuilder cmd = new ArgumentListBuilder();
    cmd.add("mkview");
    cmd.add("-snapshot");
    if (streamSelector != null) {
      cmd.add("-stream");
      cmd.add(streamSelector);
    }
    cmd.add("-tag");
    cmd.add(viewTag);

    if ((optionalMkviewParameters != null) && (optionalMkviewParameters.length() > 0)) {
      String variabledResolvedParams =
          Util.replaceMacro(optionalMkviewParameters, this.variableResolver);
      cmd.addTokenized(variabledResolvedParams);
      isOptionalParamContainsHost = optionalMkviewParameters.contains("-host");
    }

    if (!isOptionalParamContainsHost) {
      cmd.add(viewPath);
    }

    launcher.run(cmd.toCommandArray(), null, null, null);
  }
예제 #11
0
    private Criterion(String name, CriterionType type) {
        Validate.notEmpty(name);
        Validate.notNull(type);

        this.name = name;
        this.type = type;
    }
예제 #12
0
  /**
   * Returns all values for the given key
   *
   * @param key key (case insensitive)
   * @return all values of the given header or {@code null}, if there is no such a key in this
   *     instance
   */
  public List<String> getValues(final String key) {
    Validate.notEmpty(key, "name cannot be empty");

    @SuppressWarnings("unchecked")
    final List<String> result = (List<String>) values.get(key.toLowerCase());
    return result == null || result.isEmpty() ? null : new ArrayList<String>(result);
  }
 @Override
 public void delete(Account actor, String uuid) throws BusinessException {
   preChecks(actor);
   Validate.notEmpty(uuid, "filter uuid is required");
   UploadPropositionFilter entity = find(actor, uuid);
   businessService.delete(entity);
 }
예제 #14
0
  private void validateIntersections(
      final PreparedUpdate update,
      final UpdateContext updateContext,
      final IpInterval ipInterval,
      final IpTree ipTree) {
    final List<IpEntry> parent = ipTree.findFirstLessSpecific(ipInterval);
    Validate.notEmpty(parent, "Should always have a parent");

    Interval firstIntersecting = null;
    final List<IpEntry> childEntries =
        ipTree.findFirstMoreSpecific((IpInterval) parent.get(0).getKey());
    for (final IpEntry childEntry : childEntries) {
      final Interval child = childEntry.getKey();

      if (child.intersects(ipInterval)
          && !(child.contains(ipInterval) || ipInterval.contains(child))) {
        if (firstIntersecting == null
            || firstIntersecting
                    .singletonIntervalAtLowerBound()
                    .compareUpperBound(child.singletonIntervalAtLowerBound())
                > 0) {
          firstIntersecting = child;
        }
      }
    }

    if (firstIntersecting != null) {
      updateContext.addMessage(update, UpdateMessages.intersectingRange(firstIntersecting));
    }
  }
예제 #15
0
파일: Client.java 프로젝트: kwjones/leshan
  public Client(
      String registrationId,
      String endpoint,
      InetAddress address,
      int port,
      String lwM2mVersion,
      Long lifetime,
      String smsNumber,
      BindingMode binding,
      String[] objectLinks,
      Date registrationDate,
      InetSocketAddress registrationEndpoint) {

    Validate.notEmpty(endpoint);
    Validate.notNull(address);
    Validate.notNull(port);
    Validate.notNull(registrationEndpoint);

    this.registrationId = registrationId;
    this.endpoint = endpoint;
    this.address = address;
    this.port = port;
    this.objectLinks = objectLinks;
    this.registrationDate = registrationDate == null ? new Date() : registrationDate;
    lifeTimeInSec = lifetime == null ? DEFAULT_LIFETIME_IN_SEC : lifetime;
    this.lwM2mVersion = lwM2mVersion == null ? DEFAULT_LWM2M_VERSION : lwM2mVersion;
    bindingMode = binding == null ? BindingMode.U : binding;
    this.smsNumber = smsNumber;
    lastUpdate = new Date();
    registrationEndpointAddress = registrationEndpoint;
  }
예제 #16
0
  public void computeStatus(String errorMessage, String warnMessage) {
    Validate.notEmpty(errorMessage, "Error message must not be null.");

    // computeStatus sets a message if none is set,
    // therefore we need to check before calling computeStatus
    boolean noMessage = StringUtils.isEmpty(message);
    computeStatus();

    switch (status) {
      case FATAL_ERROR:
      case PARTIAL_ERROR:
        if (noMessage) {
          message = errorMessage;
        }
        break;
      case UNKNOWN:
      case WARNING:
      case NOT_APPLICABLE:
        if (noMessage) {
          if (StringUtils.isNotEmpty(warnMessage)) {
            message = warnMessage;
          } else {
            message = errorMessage;
          }
        }
        break;
    }
  }
 @Override
 public UploadPropositionFilter create(Account actor, UploadPropositionFilter dto)
     throws BusinessException {
   preChecks(actor);
   Validate.notNull(dto, "filter is required");
   Validate.notEmpty(dto.getUuid(), "filter uuid is required");
   return businessService.create(dto);
 }
예제 #18
0
 /** {@inheritDoc} */
 @Override
 public T integrate(final Function1D<U, T> f, final U[] lower, final U[] upper) {
   Validate.notNull(f, "function was null");
   Validate.notNull(lower, "lower bound array was null");
   Validate.notNull(upper, "upper bound array was null");
   Validate.notEmpty(lower, "lower bound array was empty");
   Validate.notEmpty(upper, "upper bound array was empty");
   Validate.notNull(lower[0], "lower bound was null");
   Validate.notNull(upper[0], "upper bound was null");
   if (lower.length > 1) {
     s_logger.info("Lower bound array had more than one element; only using the first");
   }
   if (upper.length > 1) {
     s_logger.info("Upper bound array had more than one element; only using the first");
   }
   return integrate(f, lower[0], upper[0]);
 }
예제 #19
0
 /** {@inheritDoc} */
 @Override
 public void deleteSnapshot(String snapshotId) {
   Validate.notEmpty(snapshotId);
   LOGGER.info(String.format("Deleting snapshot %s.", snapshotId));
   AmazonEC2 ec2Client = ec2Client();
   DeleteSnapshotRequest request = new DeleteSnapshotRequest().withSnapshotId(snapshotId);
   ec2Client.deleteSnapshot(request);
 }
  @Override
  public String setLayoutAttribute(String nodeId, String name, String value) {
    Validate.notEmpty(nodeId, "nodeId cannot be null");
    Validate.notEmpty(name, "name cannot be null");
    Validate.notEmpty(value, "value cannot be null");

    ConcurrentMap<String, String> nodeAttributes;
    synchronized (this.layoutAttributes) {
      nodeAttributes = this.layoutAttributes.get(nodeId);
      if (nodeAttributes == null) {
        nodeAttributes = new ConcurrentHashMap<String, String>();
        this.layoutAttributes.put(nodeId, nodeAttributes);
      }
    }

    return nodeAttributes.put(name, value);
  }
예제 #21
0
  public Collection<OralDefense> execute(
      List<TimeBox> timeboxes, List<Unavailability> unavailabilities) {

    // verify that a planning has been configure correctly
    Validate.notNull(planning);
    Validate.notNull(planning.getRooms());
    Validate.notEmpty(planning.getRooms());

    // verify that we have timeboxes
    Validate.notNull(timeboxes);
    Validate.notEmpty(timeboxes);

    // verify that we have participants
    Validate.notNull(planning.getParticipants());
    Validate.notEmpty(planning.getParticipants());

    // verify that we have enough timeboxes and rooms to create an oral defense for each participant
    Validate.isTrue(timeboxes.size() * rooms.size() >= planning.getParticipants().size());

    this.results = Lists.newArrayList();
    this.remainingTimeboxes = Lists.newArrayList(timeboxes);
    this.allocationsPerTimebox = Maps.newHashMap();
    this.unavailabilities = Lists.newArrayList();
    if (unavailabilities != null) {
      this.unavailabilities.addAll(unavailabilities);
    }
    this.buffer = Maps.newHashMap();
    this.remainingParticipants = Lists.newArrayList(planning.getParticipants());

    System.out.println("remaining participants: " + remainingParticipants.size());

    while (!remainingParticipants.isEmpty()) {

      // try to allocate a timebox to each participant
      // when considering their unavailabilities
      tryAllocation();

      // allocate a timebox to a participant from its list
      // of available timebox
      if (!remainingParticipants.isEmpty()) {
        forceAllocation();
      }
    } // loop until every participant is allocated to a timebox

    return results;
  }
예제 #22
0
 /** {@inheritDoc} */
 @Override
 public void deleteVolume(String volumeId) {
   Validate.notEmpty(volumeId);
   LOGGER.info(String.format("Deleting volume %s.", volumeId));
   AmazonEC2 ec2Client = ec2Client();
   DeleteVolumeRequest request = new DeleteVolumeRequest().withVolumeId(volumeId);
   ec2Client.deleteVolume(request);
 }
예제 #23
0
 /**
  * Get the UUID from the cache for the player named 'name'.
  *
  * <p>If the id does not exist in our database, then we will queue a fetch to get it, and return
  * null. A fetch at a later point will then be able to return this id.
  *
  * @param name the player name to lookup
  * @return the player's UUID
  */
 public UUID getIdOptimistic(String name) {
   Validate.notEmpty(name);
   UUID uuid = cache.get(name);
   if (uuid == null) {
     ensurePlayerUUID(name);
     return null;
   }
   return uuid;
 }
예제 #24
0
  public SimpleJdbcMapper(String tableName, ConnectionProvider connectionProvider) {
    Validate.notEmpty(tableName);
    Validate.notNull(connectionProvider);

    int queryTimeoutSecs = 30;
    connectionProvider.prepare();
    JdbcClient client = new JdbcClient(connectionProvider, queryTimeoutSecs);
    this.schemaColumns = client.getColumnSchema(tableName);
  }
예제 #25
0
 public static boolean isNoNullElements(Collection collection) {
   Validate.notEmpty(collection, "数组为空!");
   for (Iterator it = collection.iterator(); it.hasNext(); ) {
     if (it.next() == null) {
       return false;
     }
   }
   return true;
 }
예제 #26
0
 /** {@inheritDoc} */
 @Override
 public void deleteAutoScalingGroup(String asgName) {
   Validate.notEmpty(asgName);
   LOGGER.info(String.format("Deleting auto-scaling group with name %s.", asgName));
   AmazonAutoScalingClient asgClient = asgClient();
   DeleteAutoScalingGroupRequest request =
       new DeleteAutoScalingGroupRequest().withAutoScalingGroupName(asgName);
   asgClient.deleteAutoScalingGroup(request);
 }
예제 #27
0
파일: Utils.java 프로젝트: BoyCook/Parrot
 public static String readFile(String fileName) {
   Validate.notEmpty(fileName);
   String file = null;
   try {
     file = Utils.readFileToString(fileName);
   } catch (IOException e) {
     LOG.error("There was an error reading in file: " + fileName, e);
   }
   return file;
 }
  public SegmentAndComponentPath(Segment theSegment, List<Integer> theComponentPath) {
    super();

    Validate.notNull(theSegment);
    Validate.notNull(theComponentPath);
    Validate.notEmpty(theComponentPath);

    mySegment = theSegment;
    myComponentPath = theComponentPath;
  }
  private GisFeatureNames(
      String name, String asciiName, AlternateNamesProvider alternateNamesProvider) {
    super();

    Validate.notEmpty(name);

    this.name = name;
    this.asciiName = asciiName;
    this.alternateNamesProvider = alternateNamesProvider;
  }
  @Override
  public void generateReport(
      Map<String, String> parameters, ServletOutputStream outputStream, String fileType) {
    String reportName = parameters.get("reportName");
    Validate.notEmpty(reportName, "Missing parameter 'reportName'");

    ReportTemplate template = loadTemplate(reportName);

    template.generateAndExport(parameters, outputStream, fileType);
  }