Beispiel #1
0
 private static Authorship createAuthorship(Map<String, String> beanAttr)
     throws InternalErrorException {
   if (beanAttr == null) return null;
   Authorship authorship = new Authorship();
   authorship.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   authorship.setPublicationId(Integer.valueOf(beanAttr.get("publicationId")).intValue());
   authorship.setUserId(Integer.valueOf(beanAttr.get("userId")).intValue());
   authorship.setCreatedBy(BeansUtils.eraseEscaping(beanAttr.get("createdBy")));
   authorship.setCreatedByUid(
       (beanAttr.get("createdByUid").equals("\\0"))
           ? null
           : Integer.valueOf(beanAttr.get("createdByUid")).intValue());
   if (BeansUtils.eraseEscaping(beanAttr.get("createdDate")) == null)
     authorship.setCreatedDate(null);
   else {
     Date date;
     try {
       date =
           BeansUtils.DATE_FORMATTER.parse(BeansUtils.eraseEscaping(beanAttr.get("createdDate")));
     } catch (ParseException ex) {
       throw new InternalErrorException("Error when date was parsing from String to Date.", ex);
     }
     authorship.setCreatedDate(date);
   }
   return authorship;
 }
Beispiel #2
0
 private static Vo createVo(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Vo vo = new Vo();
   vo.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   vo.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   vo.setShortName(BeansUtils.eraseEscaping(beanAttr.get("shortName")));
   return vo;
 }
Beispiel #3
0
 private static Facility createFacility(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Facility facility = new Facility();
   facility.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   facility.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   facility.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return facility;
 }
Beispiel #4
0
 private static ExtSource createExtSource(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   ExtSource extSource = new ExtSource();
   extSource.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   extSource.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   extSource.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return extSource;
 }
Beispiel #5
0
 private static Destination createDestination(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Destination destination = new Destination();
   destination.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   destination.setDestination(BeansUtils.eraseEscaping(beanAttr.get("destination")));
   destination.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return destination;
 }
Beispiel #6
0
 private static Owner createOwner(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Owner owner = new Owner();
   owner.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   owner.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   owner.setContact(BeansUtils.eraseEscaping(beanAttr.get("contact")));
   owner.setTypeByString(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return owner;
 }
Beispiel #7
0
 private static AttributeDefinition createAttributeDefinition(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   AttributeDefinition attributeDefinition = new AttributeDefinition();
   attributeDefinition.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   attributeDefinition.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName")));
   attributeDefinition.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace")));
   attributeDefinition.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return attributeDefinition;
 }
Beispiel #8
0
 private static Resource createResource(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Resource resource = new Resource();
   resource.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   resource.setVoId(Integer.valueOf(beanAttr.get("voId")).intValue());
   resource.setFacilityId(Integer.valueOf(beanAttr.get("facilityId")).intValue());
   resource.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   resource.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description")));
   return resource;
 }
Beispiel #9
0
 private static Member createMember(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Member member = new Member();
   member.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   member.setUserId(Integer.valueOf(beanAttr.get("userId")).intValue());
   member.setVoId(Integer.valueOf(beanAttr.get("voId")).intValue());
   member.setStatus(BeansUtils.eraseEscaping(beanAttr.get("status")));
   member.setMembershipType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   return member;
 }
Beispiel #10
0
 private static Group createGroup(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Group group = new Group();
   if (beanAttr.get("parentGroupId").equals("\\0")) group.setParentGroupId(null);
   else group.setParentGroupId(Integer.valueOf(beanAttr.get("parentGroupId")));
   group.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   group.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   group.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description")));
   group.setVoId(Integer.valueOf(beanAttr.get("voId")));
   return group;
 }
Beispiel #11
0
 // --------------------------------------------------------------------------
 // --------------------------BEANS CREATORS---------------------------------
 private static User createUser(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   User user = new User();
   user.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   user.setTitleBefore(BeansUtils.eraseEscaping(beanAttr.get("titleBefore")));
   user.setTitleAfter(BeansUtils.eraseEscaping(beanAttr.get("titleAfter")));
   user.setFirstName(BeansUtils.eraseEscaping(beanAttr.get("firstName")));
   user.setLastName(BeansUtils.eraseEscaping(beanAttr.get("lastName")));
   user.setMiddleName(BeansUtils.eraseEscaping(beanAttr.get("middleName")));
   user.setServiceUser(Boolean.valueOf(beanAttr.get("serviceAccount")).booleanValue());
   return user;
 }
Beispiel #12
0
 private static Attribute createAttribute(Map<String, String> beanAttr)
     throws InternalErrorException {
   if (beanAttr == null) return null;
   Attribute attribute = new Attribute();
   attribute.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   attribute.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName")));
   attribute.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace")));
   attribute.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   attribute.setValue(
       BeansUtils.stringToAttributeValue(
           BeansUtils.eraseEscaping(beanAttr.get("value")), attribute.getType()));
   return attribute;
 }
Beispiel #13
0
 @Override
 public String serializeToString() {
   return this.getClass().getSimpleName()
       + ":["
       + "id=<"
       + getId()
       + ">"
       + ", name=<"
       + (getName() == null ? "\\0" : BeansUtils.createEscaping(getName()))
       + ">"
       + ", shortName=<"
       + (getShortName() == null ? "\\0" : BeansUtils.createEscaping(getShortName()))
       + ">"
       + ']';
 }
Beispiel #14
0
 private static Service createService(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Service service = new Service();
   service.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   service.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   return service;
 }
Beispiel #15
0
 private static Candidate createCandidate(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Candidate candidate = new Candidate();
   candidate.setAttributes(BeansUtils.deserializeStringToMap(beanAttr.get("attributes")));
   // Parse and get ExtSource
   UserExtSource userExtSource;
   if (beanAttr.get("userExtSource").equals("\\0")) userExtSource = null;
   else {
     List<Pair<String, Map<String, String>>> userExtSourceMap =
         beansToMap(beanAttr.get("userExtSource"));
     userExtSource = createUserExtSource(userExtSourceMap.get(0).getRight());
   }
   candidate.setUserExtSource(userExtSource);
   // Parse and get list of UserExtSources
   List<UserExtSource> additionalUserExtSources = new ArrayList<UserExtSource>();
   if (beanAttr.get("additionalUserExtSources").equals("\\0")) additionalUserExtSources = null;
   else {
     List<Pair<String, Map<String, String>>> userExtSourcesList =
         beansToMap(beanAttr.get("additionalUserExtSources"));
     for (Pair<String, Map<String, String>> p : userExtSourcesList) {
       userExtSource = createUserExtSource(p.getRight());
       additionalUserExtSources.add(userExtSource);
     }
   }
   candidate.setAdditionalUserExtSources(additionalUserExtSources);
   return candidate;
 }
Beispiel #16
0
 private static Host createHost(Map<String, String> beanAttr) throws InternalErrorException {
   if (beanAttr == null) return null;
   Host host = new Host();
   host.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   host.setHostname(BeansUtils.eraseEscaping(beanAttr.get("hostname")));
   return host;
 }
Beispiel #17
0
 private static ResourceTag createResourceTag(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   ResourceTag resourceTag = new ResourceTag();
   resourceTag.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   resourceTag.setVoId(Integer.valueOf(beanAttr.get("voId")).intValue());
   resourceTag.setTagName(BeansUtils.eraseEscaping(beanAttr.get("tagName")));
   return resourceTag;
 }
Beispiel #18
0
  private static RichResource createRichResource(Map<String, String> beanAttr) {
    if (beanAttr == null) return null;
    RichResource richResource = new RichResource();
    richResource.setId(Integer.valueOf(beanAttr.get("id")).intValue());
    richResource.setVoId(Integer.valueOf(beanAttr.get("voId")).intValue());
    richResource.setFacilityId(Integer.valueOf(beanAttr.get("facilityId")).intValue());
    richResource.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
    richResource.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description")));
    // Parse and get Vo
    Vo vo;
    if (beanAttr.get("vo").equals("\\0")) vo = null;
    else {
      List<Pair<String, Map<String, String>>> voMap = beansToMap(beanAttr.get("vo"));
      vo = createVo(voMap.get(0).getRight());
    }
    richResource.setVo(vo);
    // Parse and get Facility
    Facility facility;
    if (beanAttr.get("facility").equals("\\0")) facility = null;
    else {
      List<Pair<String, Map<String, String>>> facilityMap = beansToMap(beanAttr.get("facility"));
      facility = createFacility(facilityMap.get(0).getRight());
    }
    richResource.setFacility(facility);
    // Parse and get List of ResourceTags
    List<ResourceTag> tags = new ArrayList<ResourceTag>();
    if (beanAttr.get("resourceTags").equals("\\0")) tags = null;
    else {
      List<Pair<String, Map<String, String>>> tagsList = beansToMap(beanAttr.get("resourceTags"));
      for (Pair<String, Map<String, String>> p : tagsList) {
        ResourceTag tag = createResourceTag(p.getRight());
        tags.add(tag);
      }
    }
    richResource.setResourceTags(tags);

    return richResource;
  }
Beispiel #19
0
  @Override
  public String serializeToString() {
    StringBuilder str = new StringBuilder();

    return str.append(this.getClass().getSimpleName())
        .append(":[")
        .append("id=<")
        .append(getId())
        .append(">")
        .append(", voId=<")
        .append(getVoId())
        .append(">")
        .append(", facilityId=<")
        .append(getFacilityId())
        .append(">")
        .append(", name=<")
        .append(getName() == null ? "\\0" : BeansUtils.createEscaping(getName()))
        .append(">")
        .append(", description=<")
        .append(getDescription() == null ? "\\0" : BeansUtils.createEscaping(getDescription()))
        .append(">")
        .append(']')
        .toString();
  }
Beispiel #20
0
 private static RichDestination createRichDestination(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   RichDestination richDestination = new RichDestination();
   richDestination.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   richDestination.setDestination(BeansUtils.eraseEscaping(beanAttr.get("destination")));
   richDestination.setType(BeansUtils.eraseEscaping(beanAttr.get("type")));
   // Parse and get service
   Service service;
   if (beanAttr.get("service").equals("\\0")) service = null;
   else {
     List<Pair<String, Map<String, String>>> serviceList = beansToMap(beanAttr.get("service"));
     service = createService(serviceList.get(0).getRight());
   }
   richDestination.setService(service);
   // Parse and get Facility
   Facility facility;
   if (beanAttr.get("facility").equals("\\0")) facility = null;
   else {
     List<Pair<String, Map<String, String>>> facilityList = beansToMap(beanAttr.get("facility"));
     facility = createFacility(facilityList.get(0).getRight());
   }
   richDestination.setFacility(facility);
   return richDestination;
 }
Beispiel #21
0
 private static UserExtSource createUserExtSource(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   UserExtSource userExtSource = new UserExtSource();
   userExtSource.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   userExtSource.setLoa(Integer.valueOf(beanAttr.get("loa")).intValue());
   userExtSource.setLogin(BeansUtils.eraseEscaping(beanAttr.get("login")));
   // Parse and get ExtSource
   ExtSource extSource;
   if (beanAttr.get("source").equals("\\0")) extSource = null;
   else {
     List<Pair<String, Map<String, String>>> extSourceList = beansToMap(beanAttr.get("source"));
     extSource = createExtSource(extSourceList.get(0).getRight());
   }
   userExtSource.setExtSource(extSource);
   return userExtSource;
 }
Beispiel #22
0
 public List<Group> getGroupsByAttribute(PerunSession sess, Attribute attribute)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups "
             + "join group_attr_values on groups.id=group_attr_values.group_id where group_attr_values.attr_id=? and "
             + "group_attr_values.attr_value=?",
         GROUP_MAPPER,
         attribute.getId(),
         BeansUtils.attributeValueToString(attribute));
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
Beispiel #23
0
 public List<Pair<Group, Resource>> getGroupResourcePairsByAttribute(
     PerunSession sess, Attribute attribute) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + ", "
             + ResourcesManagerImpl.resourceMappingSelectQuery
             + " from group_resource_attr_values "
             + "join groups on groups.id=group_resource_attr_values.group_id "
             + "join resources on resources.id=group_resource_attr_values.resource_id "
             + "where group_resource_attr_values.attr_id=? and group_resource_attr_values.attr_value=?",
         GROUP_RESOURCE_MAPPER,
         attribute.getId(),
         BeansUtils.attributeValueToString(attribute));
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Pair<Group, Resource>>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
Beispiel #24
0
 @Override
 public boolean isPerunReadOnly() {
   return BeansUtils.isPerunReadOnly();
 }
Beispiel #25
0
  /**
   * This method take log message and return List of Pair where left is Name of object and right is
   * Map of object attributes and their values. For Example "Group - {id=21, voId=21,
   * description=Group containing VO members, name=members}"
   *
   * <p>This method using for function method parseOfLog to get listOfObjects in Strings from log
   * message
   *
   * @param log log message
   * @return list of pairs name of bean to map of his attributes and values
   */
  private static List<Pair<String, Map<String, String>>> beansToMap(String log) {
    if (log.equals("\\0")) return null;
    // First get list of beans from log message
    List<String> listOfNonparsedBeans = parseOfLog(log);
    List<Pair<String, Map<String, String>>> listOfBeans =
        new ArrayList<Pair<String, Map<String, String>>>();

    // For every object in list of nonparsed beans try to parse it
    for (String s : listOfNonparsedBeans) {
      // Prepare empty map and empty string for name of bean
      String nameOfBean = null;
      Map<String, String> map = new HashMap<String, String>();

      // Find, save and cut name of Bean from beanstring
      for (int i = 0; i < s.length(); i++) {
        // After correct bean name there is everytime char ":"
        if (s.charAt(i) == ':') {
          nameOfBean = s.substring(0, i);
          // Cut name of Bean + chars ":[" after it
          s = s.substring(i + 2);
          break;
        }
      }

      if (s.charAt(0) == '\\' && s.charAt(1) == '0') map = null;
      else {
        /*
        //Find name of Bean form beanString
        String nameOfBean = null;
        Matcher beanNameMatcher = beanName.matcher(s);
        beanNameMatcher.find();
        nameOfBean = s.substring(beanNameMatcher.start(), beanNameMatcher.end()-1);
        */

        // From the rest get pair attribute of object / value of attribute and put it to the MAP
        // Helping variables to find start of attribute name, end of attribute name and the same for
        // attribute value its always quaternion
        int startName = -1;
        int endName = -1;
        int startValue = -1;
        int endValue = -1;
        int pointyBrackets = 0;
        boolean isName = true;

        // For the rest of object String searching for attributes names and their values
        for (int i = 0; i < s.length(); i++) {
          // found first Letter when no start still exist and searching for name and save it
          if (Character.isLetter(s.charAt(i)) && startName == -1 && isName == true) {
            startName = i;
          } // found for last Letter symbol in beans attribute name
          else if (Character.isLetter(s.charAt(i)) && endName == -1 && isName == true) {
            // If there is still some symbol after this one and if it is not Letter, i save my end
            // name position
            if (i + 1 != s.length()) {
              if (!Character.isLetter(s.charAt(i + 1))) {
                endName = i;
                // when i found all name, i will be searching for value
                isName = false;
              }
            }
          } // If i found name already, trying to find nonescaped < and count it
          else if (s.charAt(i) == '<' && isName == false) {
            // if its first, its my start of value position and i save it
            if (pointyBrackets == 0) {
              if (!BeansUtils.isEscaped(s, i - 1)) {
                startValue = i;
              }
            }
            // if this bracket is nonescaped so count it
            if (!BeansUtils.isEscaped(s, i - 1)) {
              pointyBrackets++;
            }
          } // If i found name already, there are some open angle breackets and is nonescaped so
            // count this one off
          else if (pointyBrackets != 0 && s.charAt(i) == '>' && isName == false) {
            // if this bracket is nonescaped so count it off
            if (!BeansUtils.isEscaped(s, i - 1)) {
              pointyBrackets--;
            }
            // if there left no brackets after counting off, so its my end bracket and i save it
            if (pointyBrackets == 0) {
              if (!BeansUtils.isEscaped(s, i - 1)) {
                endValue = i;
                isName = true;
              }
            }
          }
          // If i have already all quaternion of position i will put this attribute to the map and
          // set helping variables to start
          if (startName != -1 && endName != -1 && startValue != -1 && endValue != -1) {
            map.put(s.substring(startName, endName + 1), s.substring(startValue + 1, endValue));
            startName = -1;
            endName = -1;
            startValue = -1;
            endValue = -1;
          }
        }
      }
      // Put name of object and map of attribute and values to the list of all objects
      Pair<String, Map<String, String>> pair = new Pair<String, Map<String, String>>();
      pair.put(nameOfBean, map);
      listOfBeans.add(pair);
    }
    return listOfBeans;
  }