Method to get the given Entity from the underlying repository

@param root The incoming Root object.
348377
@Override
    public Root get(Root root) throws WIMException {
        final String METHODNAME = "get";
        Root outRoot = new Root();

        Map<String, Control> ctrlMap = ControlsHelper.getControlMap(root);
        PropertyControl propertyCtrl = (PropertyControl) ctrlMap.get(SchemaConstants.DO_PROPERTY_CONTROL);
        GroupMembershipControl grpMbrshipCtrl = (GroupMembershipControl) ctrlMap.get(SchemaConstants.DO_GROUP_MEMBERSHIP_CONTROL);
        GroupMemberControl grpMbrCtrl = (GroupMemberControl) ctrlMap.get(SchemaConstants.DO_GROUP_MEMBER_CONTROL);
        AncestorControl ancesCtrl = (AncestorControl) ctrlMap.get(SchemaConstants.DO_ANCESTOR_CONTROL);
        DescendantControl descCtrl = (DescendantControl) ctrlMap.get(SchemaConstants.DO_DESCENDANT_CONTROL);
        CheckGroupMembershipControl chkGrpMbrshipCtrl = (CheckGroupMembershipControl) ctrlMap.get(SchemaConstants.DO_CHECK_GROUP_MEMBERSHIP_CONTROL);
        CacheControl cacheCtrl = (CacheControl) ctrlMap.get(SchemaConstants.DO_CACHE_CONTROL);

        boolean clearCacheForMembership = false;

        // If a cache control is passed, the cache should be cleared
        if (cacheCtrl != null) {
            String cacheMode = cacheCtrl.getMode();
            if (tc.isDebugEnabled())
                Tr.debug(tc, METHODNAME + " Cache Control is passed with mode " + cacheMode);

            // If the mode is 'clearAll', then invalidate the caches
            if (cacheMode != null && SchemaConstants.CACHE_MODE_CLEARALL.equalsIgnoreCase(cacheMode)) {
                // Invalidate the attributes cache
                iLdapConn.invalidateAttributeCache();

                // Invalidate the search cache
                iLdapConn.invalidateSearchCache();

                // Log this clearAll call
                String uniqueName = getCallerUniqueName();
                if (tc.isWarningEnabled())
                    Tr.warning(tc, WIMMessageKey.CLEAR_ALL_CLEAR_CACHE_MODE, WIMMessageHelper.generateMsgParms(reposId, cacheMode, uniqueName));
            }

            // If the mode is 'clearEntity', then invalidate the attribute cache for the DN
            else if (cacheMode != null && SchemaConstants.CACHE_MODE_CLEAR_ENTITY.equalsIgnoreCase(cacheMode)) {
                // Get the entities
                List<Entity> entities = root.getEntities();

                // Iterate over the entities and remove each one from the cache.
                for (Entity inEntity : entities) {
                    // Get the identifier
                    IdentifierType id = inEntity.getIdentifier();
                    String externalName = id.getExternalName();
                    String extId = id.getExternalId();
                    String uniqueName = id.getUniqueName();

                    // Invalidate attibutes
                    iLdapConn.invalidateAttributes(externalName, extId, uniqueName);
                }

                // Set the flag that would be used to determine if the search
                // cache needs to be cleared later, depending on whether
                // the user has passed the Group Member and/or Group Membership controls.
                clearCacheForMembership = true;
            } else if (tc.isWarningEnabled())
                Tr.warning(tc, WIMMessageKey.UNKNOWN_CLEAR_CACHE_MODE, WIMMessageHelper.generateMsgParms(reposId, cacheMode));
        }

        List<String> propNames = null;
        if (propertyCtrl != null) {
            propNames = propertyCtrl.getProperties();
        }
        boolean needMbrAttr = false;

        if (grpMbrCtrl != null
            && (iLdapConfigMgr.getMembershipAttribute() == null || !iLdapConfigMgr.isDefaultMbrAttr())) {
            needMbrAttr = true;
        }

        for (Entity inEntity : root.getEntities()) {
            String inEntityType = inEntity.getTypeName();
            List<String> properties = iLdapConfigMgr.getSupportedProperties(inEntityType, propNames);

            List<String> EntityType = new ArrayList<String>(1);
            EntityType.add(inEntityType);

            IdentifierType inId = inEntity.getIdentifier();

            // Only retrieve member attr when there grpMbrCtrl is not null and no grpMbrship attr.
            LdapEntry ldapEntry = iLdapConn.getEntityByIdentifier(inId, EntityType, properties,
                                                                  (grpMbrshipCtrl != null || chkGrpMbrshipCtrl != null), needMbrAttr);

            // New:: Change to Input/Output property <<START>>
            if (ldapEntry != null && propNames != null) {
                if (propNames.contains(SchemaConstantsInternal.PROP_DISPLAY_BRIDGE_PRINCIPAL_NAME)) {
                    String type = ldapEntry.getType();
                    LdapEntity entity = iLdapConfigMgr.getLdapEntity(type);
                    String attrName = entity.getAttribute(SchemaConstants.PROP_PRINCIPAL_NAME);
                    String[] attrIds = new String[] { attrName };
                    ArrayList<String> entityTypes = new ArrayList<String>(1);
                    entityTypes.add(type);
                    Attributes attrs = iLdapConn.getAttributesByUniqueName(ldapEntry.getUniqueName(), attrIds, entityTypes);
                    if (attrs != null) {
                        NamingEnumeration<? extends Attribute> attEnum = attrs.getAll();
                        while (attEnum.hasMoreElements()) {
                            try {
                                ldapEntry.getAttributes().put(attEnum.next());
                            } catch (NamingException e) {
                                /* Ignore. */
                            }
                        }
                    }

                    if (properties != null)
                        properties.add(SchemaConstants.PROP_PRINCIPAL_NAME);
                    else {
                        properties = new ArrayList<String>();
                        properties.add(SchemaConstants.PROP_PRINCIPAL_NAME);
                    }
                } else if (propNames.contains(SchemaConstantsInternal.PROP_DISPLAY_BRIDGE_CN)) {
                    String type = ldapEntry.getType();
                    LdapEntity entity = iLdapConfigMgr.getLdapEntity(type);
                    String attrName = entity.getAttribute("cn");
                    String[] attrIds = new String[] { attrName };
                    ArrayList<String> entityTypes = new ArrayList<String>(1);
                    entityTypes.add(type);
                    Attributes attrs = iLdapConn.getAttributesByUniqueName(ldapEntry.getUniqueName(), attrIds, entityTypes);
                    if (attrs != null) {
                        NamingEnumeration<? extends Attribute> attEnum = attrs.getAll();
                        while (attEnum.hasMoreElements()) {
                            try {
                                ldapEntry.getAttributes().put(attEnum.next());
                            } catch (NamingException e) {
                                /* Ignore. */
                            }
                        }
                    }

                    if (properties != null)
                        properties.add("cn");
                    else {
                        properties = new ArrayList<String>();
                        properties.add("cn");
                    }
                }
            }
            // New:: Change to Input/Output property <<END>>

            Entity outEntity = createEntityFromLdapEntry(outRoot, SchemaConstants.DO_ENTITIES, ldapEntry, properties);

            // If Cache needs to be cleared
            if (clearCacheForMembership) {
                // If fetched entity is a group
                if (iLdapConfigMgr.isGroup(ldapEntry.getType())) {
                    // If group member control is passed, clear the search cache.
                    // This is done in order to correctly fetch members of dynamic groups.
                    if (grpMbrCtrl != null)
                        iLdapConn.invalidateSearchCache();
                    // If the membership control is passed, clear the search cache as the membership will be determined
                    // by a search
                    if ((grpMbrshipCtrl != null || chkGrpMbrshipCtrl != null))
                        iLdapConn.invalidateSearchCache();
                }
                // If fetched entity is a person or person account
                else if (iLdapConfigMgr.isPerson(ldapEntry.getType()) || iLdapConfigMgr.isPersonAccount(ldapEntry.getType())) {
                    // If the membership control is passed.
                    if ((grpMbrshipCtrl != null || chkGrpMbrshipCtrl != null)) {
                        // If membership attribute is not specified, clear the search cache.
                        if (iLdapConfigMgr.getMembershipAttribute() != null) {
                            String mbrshipAttrName = iLdapConfigMgr.getMembershipAttribute();
                            Attribute mbrshipAttr = ldapEntry.getAttributes().get(mbrshipAttrName);
                            try {
                                // If membership attr is not found
                                if (mbrshipAttr == null || (mbrshipAttr.size() == 1 && mbrshipAttr.get(0) == null)) {
                                    iLdapConn.invalidateSearchCache();
                                }

                                // If membership attr does not include dynamic groups i.e. the membership attribute is defined but its scope is not "All"
                                // or if the membership attribute does not support dynamic groups, then the search results cache need to be cleared.
                                if (iLdapConfigMgr.getMembershipAttributeScope() != LDAP_ALL_GROUP_MEMBERSHIP && iLdapConfigMgr.supportDynamicGroup()) {
                                    iLdapConn.invalidateSearchCache();
                                }
                            } catch (NamingException e) {
                                // If there was any exception in fetching the attributes, clear the search results cache.
                                iLdapConn.invalidateSearchCache();
                            }
                        } else {
                            // If membership attribute is not defined, then clear the search results cache.
                            iLdapConn.invalidateSearchCache();
                        }
                    }
                }
            }

            // Retrieve groups
            getGroups(outEntity, ldapEntry, grpMbrshipCtrl);

            // Retrieve members if this is a group
            if (iLdapConfigMgr.isGroup(ldapEntry.getType())) {
                getMembers(outEntity, ldapEntry, grpMbrCtrl);
            }

            // Retrieve descendants
            getDescendants(outEntity, ldapEntry, descCtrl);

            // Retrieve ancestors
            getAncestors(outEntity, ldapEntry, ancesCtrl);

            if (chkGrpMbrshipCtrl != null) {
                int level = chkGrpMbrshipCtrl.getLevel();
                CheckGroupMembershipControl reChkCtrl = new CheckGroupMembershipControl();
                reChkCtrl.setInGroup(isMemberInGroup(inEntity, ldapEntry, level));
            }
        }

        return outRoot;
    }
1085254
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="REPOSITORY_ID")
    public Repository getRepository()
    {
        return this.repository;
    }
316812
public static RepositoryId getRepository(final MavenProject project,
			final String owner, final String name) {
		// Use owner and name if specified
		if (!StringUtils.isEmpty(owner, name))
			return RepositoryId.create(owner, name);

		if (project == null)
			return null;

		RepositoryId repo = null;
		// Extract repository from SCM URLs first if present
		final Scm scm = project.getScm();
		if (scm != null) {
			repo = RepositoryId.createFromUrl(scm.getUrl());
			if (repo == null)
				repo = extractRepositoryFromScmUrl(scm.getConnection());
			if (repo == null)
				repo = extractRepositoryFromScmUrl(scm.getDeveloperConnection());
		}

		// Check project URL last
		if (repo == null)
			repo = RepositoryId.createFromUrl(project.getUrl());

		return repo;
	}
1138919
public static Throwable getRootCause(Throwable exception) {
    Assert.notNull(exception);
    return exception.getCause() == null ? exception : getRootCause(exception.getCause());
  }
331159
public Object visit(QueryRootNode node, Object data) throws RepositoryException
   {
      BooleanQuery root = new BooleanQuery();

      Query wrapped = root;
      if (node.getLocationNode() != null)
      {
         wrapped = (Query)node.getLocationNode().accept(this, root);
      }

      return wrapped;
   }
1113972
protected
  void parseRoot (Element rootElement) {
    Logger root = repository.getRootLogger();
    // category configuration needs to be atomic
    synchronized(root) {    
      parseChildrenOfLoggerElement(rootElement, root, true);
    }
  }
258275
public static Node getClosestExistingAncestor(final Session session, final String path)
            throws RepositoryException {

        String potentialPath = path.startsWith("/") ? path : "/" + path;
        while (!potentialPath.isEmpty()) {
            if (session.nodeExists(potentialPath)) {
                return session.getNode(potentialPath);
            }
            potentialPath = potentialPath.substring(0, potentialPath.lastIndexOf('/'));
        }
        return session.getRootNode();
    }
697766
@Override
    public InputSource resolveEntity(String publicId, String systemId) {
	for (int i = 0; i < Constants.DTDS_FLD.length; i++) {
	    if (publicId.equals(Constants.DTDS_FLD[i])) {
		return new InputSource(getClass().getResourceAsStream(DTD_1_0));
	    }
	}
	return null;
    }
349302
@Override
    public JsonEntityBean getEntity(IGroupMember member) {

        // get the type of this member entity
        EntityEnum entityEnum = getEntityType(member);

        // construct a new entity bean for this entity
        JsonEntityBean entity;
        if (entityEnum.isGroup()) {
            entity = new JsonEntityBean((IEntityGroup) member, entityEnum);
        } else {
            entity = new JsonEntityBean(member, entityEnum);
        }

        // if the name hasn't been set yet, look up the entity name
        if (entity.getName() == null) {
            entity.setName(lookupEntityName(entity));
        }

        if (EntityEnum.GROUP.equals(entity.getEntityType())
                || EntityEnum.PERSON.equals(entity.getEntityType())) {
            IAuthorizationPrincipal principal = getPrincipalForEntity(entity);
            entity.setPrincipalString(principal.getPrincipalString());
        }
        return entity;
    }
936746
private void transform(JSONArray root) {
        for (int i = 0, size = root.size(); i < size; i++)
        {
            Object target = root.get(i);
            if (target instanceof JSONObject)
                this.transform((JSONObject)target);
        }
    }
338776
@Override
    public Long get(Entity entity) {
        Objects.requireNonNull(entity, "entity cannot be null");
        // return property value
        return entity.get(idFieldName).asLong();
    }
875521
public Entity getEntity(String id) {
        Entity e = getEntities().get(id);
        if (e == null) {
            return null;
        }
        return e;
    }
195843
protected RepositoryId getRepository(final MavenProject project,
			final String owner, final String name)
			throws MojoExecutionException {
		RepositoryId repository = RepositoryUtils.getRepository(project, owner,
				name);
		if (repository == null)
			throw new MojoExecutionException(
					"No GitHub repository (owner and name) configured");
		if (isDebug())
			debug(MessageFormat.format("Using GitHub repository {0}",
					repository.generateId()));
		return repository;
	}
268252
@Override
    @FFDCIgnore(InvalidNameException.class)
    public Root search(Root root) throws WIMException {
        final String METHODNAME = "search";
        boolean bFirstChangeSearchCall = false;

        String searchExpr = null;

        Map<String, Control> ctrlMap = ControlsHelper.getControlMap(root);

        // Extract the cache control
        CacheControl cacheCtrl = (CacheControl) ctrlMap.get(SchemaConstants.DO_CACHE_CONTROL);

        // If a cache control is passed, the cache should be cleared
        if (cacheCtrl != null) {
            String cacheMode = cacheCtrl.getMode();
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, METHODNAME + " Cache Control is passed with mode " + cacheMode);
            }

            // If the mode is 'clearAll', then invalidate the caches
            if (cacheMode != null && SchemaConstants.CACHE_MODE_CLEARALL.equalsIgnoreCase(cacheMode)) {
                // Invalidate the attributes cache
                iLdapConn.invalidateAttributeCache();

                // Invalidate the search cache
                iLdapConn.invalidateSearchCache();

                // Log this clearAll call
                String uniqueName = getCallerUniqueName();
                if (tc.isWarningEnabled())
                    Tr.warning(tc, WIMMessageKey.CLEAR_ALL_CLEAR_CACHE_MODE, WIMMessageHelper.generateMsgParms(reposId, cacheMode, uniqueName));
            }
            // If the mode is 'clearEntity', then log it as not supported
            else if (cacheMode != null && SchemaConstants.CACHE_MODE_CLEAR_ENTITY.equalsIgnoreCase(cacheMode)) {
                if (tc.isWarningEnabled())
                    Tr.warning(tc, WIMMessageKey.UNSUPPORTED_CLEAR_CACHE_MODE, WIMMessageHelper.generateMsgParms(reposId, cacheMode));
            } else if (tc.isWarningEnabled())
                Tr.warning(tc, WIMMessageKey.UNKNOWN_CLEAR_CACHE_MODE, WIMMessageHelper.generateMsgParms(reposId, cacheMode));
        }

        // Check whether this is a search for changed entities
        boolean bChangeSearch = true;
        SearchControl searchControl = (ChangeControl) ctrlMap.get(SchemaConstants.DO_CHANGE_CONTROL);
        if (searchControl == null) {
            bChangeSearch = false;
            searchControl = (SearchControl) ctrlMap.get(SchemaConstants.DO_SEARCH_CONTROL);
        } else {
            List<CheckPointType> checkpoint = ((ChangeControl) searchControl).getCheckPoint();
            if (checkpoint.size() == 0) {
                bFirstChangeSearchCall = true;
            }
        }
        if (searchControl != null) {
            searchExpr = searchControl.getExpression();
            if (!bFirstChangeSearchCall) {
                if (searchExpr == null || searchExpr.length() == 0) {
                    throw new SearchControlException(WIMMessageKey.MISSING_SEARCH_EXPRESSION, Tr.formatMessage(
                                                                                                               tc,
                                                                                                               WIMMessageKey.MISSING_SEARCH_EXPRESSION,
                                                                                                               null));
                }
            }
        }
        // Check if the base entries were specified by the client
        // If specified by client, then don't override them with entity search base
        Set<String> realms = getSpecifiedRealms(root);
        boolean isSearchBaseSetByClient = realms.contains("n/a"); // Indicates search bases were set by client

        // read the custom property allowDNPrincipalNameAsLiteral
        String customProperty = getContextProperty(root, SchemaConstants.ALLOW_DN_PRINCIPALNAME_AS_LITERAL);
        boolean ignoreDNBaseSearch = customProperty.equalsIgnoreCase("true");

        LdapSearchControl srchCtrl = getLdapSearchControl(searchControl, isSearchBaseSetByClient, ignoreDNBaseSearch);

        String[] searchBases = srchCtrl.getBases();
        String sFilter = srchCtrl.getFilter();
        int countLimit = srchCtrl.getCountLimit();
        int timeLimit = srchCtrl.getTimeLimit();
        List<String> entityTypes = srchCtrl.getEntityTypes();
        List<String> propNames = srchCtrl.getPropertyNames();
        int scope = srchCtrl.getScope();

        Root outRoot = new Root();

        if (bChangeSearch) {

            ChangeControl changeControl = (ChangeControl) searchControl;

            /*
             * It is possible that we retrieve changes since the specified checkpoint and
             * while we process them more changes occur in the repository. As a result if
             * current checkpoint is retrieved after processing the changed entries, we
             * may lose some changes. Hence, we need to first retrieve the current checkpoint
             * and then process changed entities.
             */

            // Get the current checkpoint
            String checkPoint = changeHandler.getCurrentCheckPoint();

            CheckPointType currCheckPointDO = new CheckPointType();
            currCheckPointDO.setRepositoryId(reposId);
            currCheckPointDO.setRepositoryCheckPoint(checkPoint);

            ChangeResponseControl changeResponseCtrl = new ChangeResponseControl();
            changeResponseCtrl.getCheckPoint().add(currCheckPointDO);

            // Get changed entities since the checkpoint specified in ChangeControl
            List<CheckPointType> checkPointList = changeControl.getCheckPoint();

            if ((checkPointList != null) && (checkPointList.size() > 0)) {
                /*
                 * At the adapter level, only the checkpoint corresponding to this
                 * repository is expected to be in the ChangeControl. Hence no need
                 * to check for repository ID
                 */
                CheckPointType checkPointDO = checkPointList.get(0);
                checkPoint = checkPointDO.getRepositoryCheckPoint();
                if (checkPoint == null) {
                    throw new ChangeControlException(WIMMessageKey.NULL_CHECKPOINT_VALUE, Tr.formatMessage(
                                                                                                           tc,
                                                                                                           WIMMessageKey.NULL_CHECKPOINT_VALUE,
                                                                                                           null));
                }

                boolean isAttrCacheNotEmpty = true;
                List<String> changeTypes = changeControl.getChangeTypes();
                for (int i = 0; i < searchBases.length; i++) {
                    List<LdapEntry> ldapEntriesList = changeHandler.searchChangedEntities(checkPoint, changeTypes, searchBases[i],
                                                                                          sFilter, scope, entityTypes, propNames, countLimit, timeLimit);

                    if (ldapEntriesList != null) {
                        for (int j = 0; j < ldapEntriesList.size(); j++) {
                            LdapEntry entry = ldapEntriesList.get(j);
                            // invalidating the attribute cache
                            // checking for active directory so as to check if it is a deleted change type the fetch the DN from the unique name
                            if (isActiveDirectory) {
                                if (SchemaConstants.CHANGETYPE_DELETE.equalsIgnoreCase(entry.getChangeType())) {
                                    iLdapConn.invalidateAttributes(iLdapConfigMgr.switchToLdapNode(entry.getUniqueName()), entry.getExtId(), entry.getUniqueName());
                                } else {
                                    iLdapConn.invalidateAttributes(entry.getDN(), entry.getExtId(), entry.getUniqueName());
                                }
                            } else {
                                if (isAttrCacheNotEmpty) {//checking if attribute cache is invalidated.
                                    if (entry.getExtId() == null && SchemaConstants.CHANGETYPE_DELETE.equalsIgnoreCase(entry.getChangeType())) {
                                        iLdapConn.invalidateAttributeCache();// clear the cache if extId of deleted entry is not known
                                        isAttrCacheNotEmpty = false;
                                    } else {
                                        iLdapConn.invalidateAttributes(entry.getDN(), entry.getExtId(), entry.getUniqueName());
                                    }
                                }
                            }
                            createEntityFromLdapEntry(outRoot, SchemaConstants.DO_ENTITIES, entry, propNames);
                        }
                        // invalidating the search cache
                        if (ldapEntriesList.size() > 0) {
                            iLdapConn.invalidateSearchCache();
                        }
                    }
                }
            }
        } else {
            if (root.isSetContexts()) {
                String inputPattern = getContextProperty(root, SchemaConstants.USE_USER_FILTER_FOR_SEARCH);
                if (inputPattern != null && inputPattern.length() > 0) {
                    String dn = null;
                    try {
                        dn = new LdapName(inputPattern).toString();
                    } catch (InvalidNameException e) {
                        e.getMessage();
                    }
                    if (dn == null) {
                        Filter f = iLdapConfigMgr.getUserFilter();
                        if (f != null)
                            sFilter = f.prepare(inputPattern);
                    }
                } else {
                    // Check if group filter pattern is specified
                    inputPattern = getContextProperty(root, SchemaConstants.USE_GROUP_FILTER_FOR_SEARCH);
                    if (inputPattern != null && inputPattern.length() > 0) {
                        String dn = null;
                        try {
                            dn = new LdapName(inputPattern).toString();
                        } catch (InvalidNameException e) {
                            e.getMessage();
                        }
                        if (dn == null) {
                            Filter f = iLdapConfigMgr.getGroupFilter();
                            if (f != null)
                                sFilter = f.prepare(inputPattern);
                        }
                    }
                }
            }

            for (int i = 0; i < searchBases.length; i++) {
                Set<LdapEntry> ldapEntriesSet = iLdapConn.searchEntities(searchBases[i], sFilter, null, scope, entityTypes, propNames,
                                                                         false, false, countLimit, timeLimit);
                for (LdapEntry entry : ldapEntriesSet) {
                    createEntityFromLdapEntry(outRoot, SchemaConstants.DO_ENTITIES, entry, propNames);
                }
            }
        }

        return outRoot;
    }
271433
public WebservicesMetaData loadFromVFSRoot(UnifiedVirtualFile root)
   {
      WebservicesMetaData webservices = null;

      UnifiedVirtualFile wsdd = root.findChildFailSafe("META-INF/webservices.xml");

      // Maybe a web application deployment?
      if (null == wsdd)
      {
         wsdd = root.findChildFailSafe("WEB-INF/webservices.xml");
      }

      // the descriptor is optional
      if (wsdd != null)
      {
         return load(wsdd.toURL());
      }

      return webservices;
   }
1221797
public R fetch(String properties) {
    ((TQRootBean) _root).query().fetch(_name, properties);
    return _root;
  }
913015
public static RepositoryQuery lookupFrom(EbeanQueryMethod method, EbeanServer ebeanServer) {
        final String queryName = method.getNamedQueryName();

        LOG.debug("Looking up named query {}", queryName);

        try {
            Query query = ebeanServer.createNamedQuery(method.getEntityInformation().getJavaType(), queryName);
            return new NamedEbeanQuery(method, ebeanServer, query);
        } catch (PersistenceException e) {
            LOG.debug("Did not find named query {}", queryName);
            return null;
        }
    }