@Override
  public MedicationHeadline transform(Map<String, Object> input) {

    MedicationHeadline medication = new MedicationHeadline();
    medication.setSource("EtherCIS");
    medication.setSourceId(MapUtils.getString(input, "uid"));
    medication.setName(MapUtils.getString(input, "name"));

    return medication;
  }
  @Override
  public boolean preHandle(
      HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o)
      throws Exception {
    HttpSession session = httpServletRequest.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null || user.getStatus() != UserConstant.Status.ACTIVE.value()) {
      return false;
    }

    Map<Privilege, Integer> map = PrivilegeHelper.getPrivilegeMap();

    Privilege privilege =
        new Privilege(
            httpServletRequest
                .getRequestURI()
                .substring(httpServletRequest.getContextPath().length()),
            httpServletRequest.getMethod());
    System.out.println("privilege = " + privilege);

    if (CollectionUtils.isEmpty(user.getPrivilegeIds())) {
      httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/error/low.html");
      return false;
    }

    if (MapUtils.isNotEmpty(map)
        && map.containsKey(privilege)
        && !user.getPrivilegeIds().contains(map.get(privilege))) {
      httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/error/low.html");
      return false;
    }

    return true;
  }
 private static void fillRequirementsMap(
     Map<String, Requirement> map,
     List<RequirementDefinition> elements,
     Collection<CSARDependency> dependencies,
     Map<String, Requirement> mapToMerge,
     IToscaElementFinder toscaElementFinder) {
   if (elements == null) {
     return;
   }
   for (RequirementDefinition requirement : elements) {
     Requirement toAddRequirement = MapUtils.getObject(mapToMerge, requirement.getId());
     if (toAddRequirement == null) {
       toAddRequirement = new Requirement();
       toAddRequirement.setType(requirement.getType());
       IndexedCapabilityType indexedReq =
           toscaElementFinder.getElementInDependencies(
               IndexedCapabilityType.class, requirement.getType(), dependencies);
       if (indexedReq != null && indexedReq.getProperties() != null) {
         toAddRequirement.setProperties(
             PropertyUtil.getDefaultPropertyValuesFromPropertyDefinitions(
                 indexedReq.getProperties()));
       }
     }
     map.put(requirement.getId(), toAddRequirement);
   }
 }
 private static void fillCapabilitiesMap(
     Map<String, Capability> map,
     List<CapabilityDefinition> elements,
     Collection<CSARDependency> dependencies,
     Map<String, Capability> mapToMerge,
     IToscaElementFinder toscaElementFinder) {
   if (elements == null) {
     return;
   }
   for (CapabilityDefinition capa : elements) {
     Capability toAddCapa = MapUtils.getObject(mapToMerge, capa.getId());
     if (toAddCapa == null) {
       toAddCapa = new Capability();
       toAddCapa.setType(capa.getType());
       IndexedCapabilityType indexedCapa =
           toscaElementFinder.getElementInDependencies(
               IndexedCapabilityType.class, capa.getType(), dependencies);
       if (indexedCapa != null && indexedCapa.getProperties() != null) {
         toAddCapa.setProperties(
             PropertyUtil.getDefaultPropertyValuesFromPropertyDefinitions(
                 indexedCapa.getProperties()));
       }
     }
     map.put(capa.getId(), toAddCapa);
   }
 }
示例#5
0
  static {
    // 获取所有的bean类与bean实例之间的映射关系(简称Bean Map)
    Map<Class<?>, Object> beanMap = BeanHelper.getBeanMap();
    if (MapUtils.isNotEmpty(beanMap)) {
      // 遍历 bean map
      for (Map.Entry<Class<?>, Object> beanEntry : beanMap.entrySet()) {
        // 从bean map中获取bean类和bean实例
        Class<?> beanClass = beanEntry.getKey();
        Object beanInstance = beanEntry.getValue();

        // 获取bean定义的所有成员变量
        Field[] beanFields = beanClass.getDeclaredFields();
        if (ArrayUtils.isNotEmpty(beanFields)) {
          // 遍历 bean field
          for (Field beanField : beanFields) {
            // 判断当前bean field是否带有Inject注解
            if (beanField.isAnnotationPresent(Inject.class)) {
              // 在bean map中获取bean field对应的实例
              Class<?> beanFieldClass = beanField.getType();
              Object beanFieldInstance = beanMap.get(beanFieldClass);
              if (null != beanFieldInstance) {
                // 通过反射初始化bean field的值
                ReflectionUtil.setField(beanInstance, beanField, beanFieldInstance);
              }
            }
          }
        }
      }
    }
  }
示例#6
0
文件: GCVote.java 项目: devykm/cgeo
  /**
   * Get user rating for a given guid or geocode. For a guid first the ratings cache is checked
   * before a request to gcvote.com is made.
   *
   * @param guid
   * @param geocode
   * @return
   */
  public static GCVoteRating getRating(final String guid, final String geocode) {
    if (StringUtils.isNotBlank(guid) && RATINGS_CACHE.containsKey(guid)) {
      return RATINGS_CACHE.get(guid);
    }

    final Map<String, GCVoteRating> ratings =
        getRating(singletonOrNull(guid), singletonOrNull(geocode));
    return MapUtils.isNotEmpty(ratings) ? ratings.values().iterator().next() : null;
  }
 /** TODO: should be removed ! */
 @Deprecated
 public static String getDefaultValueFromPropertyDefinitions(
     String propertyName, Map<String, PropertyDefinition> propertyDefinitions) {
   if (MapUtils.isNotEmpty(propertyDefinitions) && propertyDefinitions.containsKey(propertyName)) {
     return propertyDefinitions.get(propertyName).getDefault().toString();
   } else {
     return null;
   }
 }
示例#8
0
  /**
   * 获取请求参数 映射
   *
   * @return
   */
  public Map<String, Object> getFieldMap() {

    Map<String, Object> fieldMap = new HashMap<String, Object>(0);
    if (MapUtils.isNotEmpty(fieldMap)) {
      for (FormParam formParam : formParamList) {
        String fieldName = formParam.getFieldName();
        Object fieldValue = formParam.getFieldValue();
        if (fieldMap.containsKey(fieldName)) {
          fieldValue = fieldMap.get(fieldName) + StringUtil.SEPARATOR + fieldValue;
        }
        fieldMap.put(fieldName, fieldValue);
      }
    }
    return fieldMap;
  }
 /**
  * Builds the definitions MarkupDocument.
  *
  * @return the definitions MarkupDocument
  */
 @Override
 public MarkupDocument build() {
   if (MapUtils.isNotEmpty(globalContext.getSwagger().getDefinitions())) {
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
     buildDefinitionsTitle(DEFINITIONS);
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
     buildDefinitionsSection();
     applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
     applyDefinitionsDocumentExtension(
         new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
   }
   return new MarkupDocument(markupDocBuilder);
 }
 /**
  * Merge from map into 'into' map
  *
  * @param from from map
  * @param into into map
  * @param keysToConsider if defined only keys contained by this set are considered
  */
 public static void mergeProperties(
     Map<String, AbstractPropertyValue> from,
     Map<String, AbstractPropertyValue> into,
     Set<String> keysToConsider) {
   if (MapUtils.isNotEmpty(from)) {
     for (Map.Entry<String, AbstractPropertyValue> fromEntry : from.entrySet()) {
       if (keysToConsider != null && !keysToConsider.contains(fromEntry.getKey())) {
         // If the key filter do not contain the key then do not consider
         continue;
       }
       AbstractPropertyValue existingValue = into.get(fromEntry.getKey());
       if (fromEntry.getValue() != null || existingValue == null) {
         into.put(fromEntry.getKey(), fromEntry.getValue());
       }
     }
   }
 }
  @Override
  public Map<String, String> transform(Map<String, Object> rawData) {
    if (MapUtils.isEmpty(rawData)) {
      return new LinkedHashMap<>();
    }
    Map<String, String> navigationData = new HashMap<>();
    for (Map.Entry<String, Object> entry : rawData.entrySet()) {
      // todo currently we support only string navigation (no nested navigation)
      // - SUCCESS: some_task
      // the value of the navigation is the step to go to
      if (entry.getValue() instanceof String) {
        navigationData.put(entry.getKey(), (String) entry.getValue());
      }
    }

    return navigationData;
  }
示例#12
0
  /**
   * 获取 上传文件 映射
   *
   * @return
   */
  public Map<String, List<FileParam>> getFileMap() {

    Map<String, List<FileParam>> fileMap = new HashMap<String, List<FileParam>>(0);
    if (MapUtils.isNotEmpty(fileMap)) {
      for (FileParam fileParam : fileParamList) {
        String fieldName = fileParam.getFieldName();
        List<FileParam> fileParams;
        if (fileMap.containsKey(fieldName)) {
          fileParams = fileMap.get(fieldName);
        } else {
          fileParams = new ArrayList<FileParam>(0);
        }
        fileParams.add(fileParam);
        fileMap.put(fieldName, fileParams);
      }
    }
    return fileMap;
  }
 public static void fillProperties(
     Map<String, AbstractPropertyValue> properties,
     Map<String, PropertyDefinition> propertiesDefinitions,
     Map<String, AbstractPropertyValue> map) {
   if (propertiesDefinitions == null || properties == null) {
     return;
   }
   for (Map.Entry<String, PropertyDefinition> entry : propertiesDefinitions.entrySet()) {
     AbstractPropertyValue existingValue = MapUtils.getObject(map, entry.getKey());
     if (existingValue == null) {
       String defaultValue = entry.getValue().getDefault();
       if (defaultValue != null && !defaultValue.trim().isEmpty()) {
         properties.put(entry.getKey(), new ScalarPropertyValue(defaultValue));
       } else {
         properties.put(entry.getKey(), null);
       }
     } else {
       properties.put(entry.getKey(), existingValue);
     }
   }
 }
/** Example taken from https://groups.google.com/forum/#!topic/pact-support/-Kk_OxvcJQY */
public class ExampleServiceConsumerTest {

  String DATA_A_ID = "AAAAAAAA_ID";
  String DATA_B_ID = "BBBBBBBB_ID";

  Map<String, String> headers =
      MapUtils.putAll(
          new HashMap<String, String>(),
          new String[] {"Content-Type", "application/json;charset=UTF-8"});

  @Rule
  public PactProviderRule provider =
      new PactProviderRule("CarBookingProvider", "localhost", 1234, this);

  @Pact(provider = "CarBookingProvider", consumer = "CarBookingConsumer")
  public PactFragment configurationFragment(ConsumerPactBuilder.PactDslWithProvider builder) {
    return builder
        .given("john smith books a civic")
        .uponReceiving("retrieve data from Service-A")
        .path("/persons/" + DATA_A_ID)
        .method("GET")
        .willRespondWith()
        .headers(headers)
        .status(200)
        .body(
            new PactDslJsonBody()
                .stringValue("id", DATA_A_ID)
                .stringValue("firstName", "John")
                .stringValue("lastName", "Smith"))
        .uponReceiving("retrieving data from Service-B")
        .path("/cars/" + DATA_B_ID)
        .method("GET")
        .willRespondWith()
        .headers(headers)
        .status(200)
        .body(
            new PactDslJsonBody()
                .stringValue("id", DATA_B_ID)
                .stringValue("brand", "Honda")
                .stringValue("model", "Civic")
                .numberValue("year", 2012))
        .uponReceiving("book a car")
        .path("/orders/")
        .method("POST")
        .body(
            new PactDslJsonBody()
                .object("person")
                .stringValue("id", DATA_A_ID)
                .stringValue("firstName", "John")
                .stringValue("lastName", "Smith")
                .closeObject()
                .object("cars")
                .stringValue("id", DATA_B_ID)
                .stringValue("brand", "Honda")
                .stringValue("model", "Civic")
                .numberValue("year", 2012)
                .closeObject())
        .willRespondWith()
        .headers(headers)
        .status(201)
        .body(new PactDslJsonBody().stringMatcher("id", "ORDER_ID_\\d+", "ORDER_ID_123456"))
        .toFragment();
  }

  @PactVerification("CarBookingProvider")
  @Test
  public void testBookCar() throws IOException {
    ProviderCarBookingRestClient providerRestClient = new ProviderCarBookingRestClient();
    HttpResponse response =
        providerRestClient.placeOrder("http://localhost:1234", DATA_A_ID, DATA_B_ID, "2015-03-15");

    Assert.assertEquals(201, response.getStatusLine().getStatusCode());
    String orderDetails = EntityUtils.toString(response.getEntity());
    Assert.assertEquals("{\"id\":\"ORDER_ID_123456\"}", orderDetails);
  }
}
示例#15
0
 @Test
 public void isNotEmpty() {
   assertFalse(MapUtils.isNotEmpty(new HashMap<>()));
 }