Build metadata resolver aggregate. Loops through metadata resources
and attempts to resolve the metadata.

@param entityId the entity id
480151
@Synchronized
    @SneakyThrows
    public void buildMetadataResolverAggregate(final String entityId) {
        LOGGER.trace("Building metadata resolver aggregate");
        this.metadataResolver = new ChainingMetadataResolver();
        val resolvers = new ArrayList<MetadataResolver>();
        val entries = this.metadataResources.entrySet();
        entries.forEach(entry -> {
            val resource = entry.getKey();
            LOGGER.debug("Loading [{}]", resource.getFilename());
            resolvers.addAll(loadMetadataFromResource(entry.getValue(), resource, entityId));
        });
        this.metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
        this.metadataResolver.setResolvers(resolvers);
        LOGGER.debug("Collected metadata from [{}] resolvers(s). Initializing aggregate resolver...", resolvers.size());
        this.metadataResolver.initialize();
        LOGGER.info("Metadata aggregate initialized successfully.");
    }
1357093
public static void setId(Object entity, EntityMetadata metadata, Object rowKey)
    {
        try
        {
            Field idField = (Field) metadata.getIdAttribute().getJavaMember();
            set(entity, idField, rowKey);
        }
        catch (IllegalArgumentException iarg)
        {
            throw new PropertyAccessException(iarg);
        }
    }
1262400
private function validateIdStrategy(EntityMetadata $metadata)
    {
        $persistence = $metadata->persistence;
        $validIdStrategies = ['object'];
        if (!in_array($persistence->idStrategy, $validIdStrategies)) {
            throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies)));
        }
    }
156740
public long countInstallationOfEntityById(ModelId entityId) {
        final String field = String.format(Locale.ROOT, "%s.%s", ContentPackInstallation.FIELD_ENTITIES, NativeEntityDescriptor.FIELD_META_ID);

        return dbCollection.getCount(DBQuery.is(field, entityId));
    }
1231966
@SneakyThrows
    @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
    public static MetadataResolver getMetadataResolverForAllSamlServices(final ServicesManager servicesManager,
                                                                         final String entityID,
                                                                         final SamlRegisteredServiceCachingMetadataResolver resolver) {

        val registeredServices = servicesManager.findServiceBy(SamlRegisteredService.class::isInstance);
        val chainingMetadataResolver = new ChainingMetadataResolver();

        val resolvers = registeredServices.stream()
            .filter(SamlRegisteredService.class::isInstance)
            .map(SamlRegisteredService.class::cast)
            .map(s -> SamlRegisteredServiceServiceProviderMetadataFacade.get(resolver, s, entityID))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .map(SamlRegisteredServiceServiceProviderMetadataFacade::getMetadataResolver)
            .collect(Collectors.toList());

        LOGGER.debug("Located [{}] metadata resolvers to match against [{}]", resolvers, entityID);

        chainingMetadataResolver.setResolvers(resolvers);
        chainingMetadataResolver.setId(entityID);
        chainingMetadataResolver.initialize();
        return chainingMetadataResolver;
    }
931102
public InputSource resolveEntity(String publicId, String systemId) throws
      SAXException, IOException {
    if (systemId == null) {
      return null;
    }

    URL url = new URL(systemId);
    String file = url.getFile();

    if ( (file != null) && (file.indexOf('/') > -1)) {
      file = file.substring(file.lastIndexOf('/') + 1);
    }

    if ("www.jdon.com".equals(url.getHost())) {
      InputStream is = getClass().getResourceAsStream("/META-INF/" + file);

      if (is == null) {
        is = getClass().getResourceAsStream("/" + file);
      }

      if (is != null) {
        return new InputSource(is);
      }
    }

    return null;
  }
987742
protected void generateEntity(EntityDesc entityDesc) {
    File javaFile =
        FileUtil.createJavaFile(entityConfig.getDestDir(), entityDesc.getQualifiedName());
    GenerationContext context =
        new GenerationContext(
            entityDesc,
            javaFile,
            entityDesc.getTemplateName(),
            entityConfig.getEncoding(),
            entityConfig.isOverwrite());
    generator.generate(context);
  }
527518
protected void processMetadataInitialization(HttpServletRequest request) throws ServletException {

        // In case the hosted IdP metadata weren't initialized, let's do it now
        if (manager.getHostedIdpName() == null) {

            synchronized (IdpMetadataManager.class) {

                if (manager.getHostedIdpName() == null) {

                    try {

                        log.info(
                                "No default metadata configured, generating with default values, please pre-configure metadata for production use");

                        // Defaults
                        String alias = generator.getEntityAlias();
                        String baseURL = getDefaultBaseURL(request);

                        // Use default baseURL if not set
                        if (generator.getEntityBaseURL() == null) {
                            log.warn(
                                    "Generated default entity base URL {} based on values in the first server request. Please set property entityBaseURL on MetadataGenerator bean to fixate the value.",
                                    baseURL);
                            generator.setEntityBaseURL(baseURL);
                        } else {
                            baseURL = generator.getEntityBaseURL();
                        }

                        // Use default entityID if not set
                        if (generator.getEntityId() == null) {
                            generator.setEntityId(getDefaultEntityID(baseURL, alias));
                        }

                        // Ensure supported nameID formats in uaa are listed in the metadata
                        Collection<String> supportedNameID = Arrays.asList(NameIDType.EMAIL, NameIDType.PERSISTENT,
                                NameIDType.UNSPECIFIED);
                        generator.setNameID(supportedNameID);

                        EntityDescriptor descriptor = generator.generateMetadata();
                        ExtendedMetadata extendedMetadata = generator.generateExtendedMetadata();

                        log.info("Created default metadata for system with entityID: " + descriptor.getEntityID());
                        MetadataMemoryProvider memoryProvider = new MetadataMemoryProvider(descriptor);
                        memoryProvider.initialize();
                        MetadataProvider metadataProvider = new ExtendedMetadataDelegate(memoryProvider,
                                extendedMetadata);

                        manager.addMetadataProvider(metadataProvider);
                        manager.setHostedIdpName(descriptor.getEntityID());
                        manager.refreshMetadata();

                    } catch (MetadataProviderException e) {
                        log.error("Error generating system metadata", e);
                        throw new ServletException("Error generating system metadata", e);
                    }

                }

            }

        }

    }
910660
private void rebuildIndexOneEntity(String entityTypeId, String untypedEntityId) {
    LOG.trace("Indexing [{}].[{}]... ", entityTypeId, untypedEntityId);

    // convert entity id string to typed entity id
    EntityType entityType = dataService.getEntityType(entityTypeId);
    if (null != entityType) {
      Object entityId = getTypedValue(untypedEntityId, entityType.getIdAttribute());
      String entityFullName = entityType.getId();

      Entity actualEntity = dataService.findOneById(entityFullName, entityId);

      if (null == actualEntity) {
        // Delete
        LOG.debug("Index delete [{}].[{}].", entityFullName, entityId);
        indexService.deleteById(entityType, entityId);
        return;
      }

      boolean indexEntityExists = indexService.hasIndex(entityType);
      if (!indexEntityExists) {
        LOG.debug("Create mapping of repository [{}] because it was not exist yet", entityTypeId);
        indexService.createIndex(entityType);
      }

      LOG.debug("Index [{}].[{}].", entityTypeId, entityId);
      indexService.index(actualEntity.getEntityType(), actualEntity);
    } else {
      throw new MolgenisDataException("Unknown EntityType for entityTypeId: " + entityTypeId);
    }
  }
753054
private List<MetadataResolver> buildSingleMetadataResolver(final MetadataFilter metadataFilterChain, final Resource resource, final Document document) {
        try {
            val metadataRoot = document.getDocumentElement();
            val metadataProvider = new DOMMetadataResolver(metadataRoot);
            metadataProvider.setParserPool(this.configBean.getParserPool());
            metadataProvider.setFailFastInitialization(true);
            metadataProvider.setRequireValidMetadata(this.requireValidMetadata);
            metadataProvider.setId(metadataProvider.getClass().getCanonicalName());
            if (metadataFilterChain != null) {
                metadataProvider.setMetadataFilter(metadataFilterChain);
            }
            LOGGER.debug("Initializing metadata resolver for [{}]", resource);
            metadataProvider.initialize();
            val resolvers = new ArrayList<MetadataResolver>();
            resolvers.add(metadataProvider);
            return resolvers;
        } catch (final Exception ex) {
            LOGGER.warn("Could not initialize metadata resolver. Resource will be ignored", ex);
        }
        return new ArrayList<>(0);
    }
643514
public EntityContainer getEntityContainer(String id) {
        EntityContainer ec = (EntityContainer) getPmsession().getContainer(id);
        if (ec == null) {
            ec = getPresentationManager().newEntityContainer(id);
            getPmsession().setContainer(id, ec);
        }
        return ec;
    }
78758
public void prepareEmbeddedId(TopDocs docs, Map<String, Object> indexCol, IndexSearcher searcher,
            EntityMetadata metadata, MetamodelImpl metaModel)
    {
        try
        {
            for (ScoreDoc sc : docs.scoreDocs)
            {
                Document doc = searcher.doc(sc.doc);
                Map<String, Object> embeddedIdFields = new HashMap<String, Object>();
                EmbeddableType embeddableId = metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
                Set<Attribute> embeddedAttributes = embeddableId.getAttributes();

                prepareEmbeddedIdFields(embeddedAttributes, metaModel, embeddedIdFields, doc, metadata);

                String entityId = doc.get(IndexingConstants.ENTITY_ID_FIELD);
                indexCol.put(entityId, embeddedIdFields);
            }
        }
        catch (Exception e)
        {
            log.error("Error while parsing Lucene Query {} ", e);
            throw new LuceneIndexingException(e);
        }
    }
1192553
protected Issuer buildSamlResponseIssuer(final String entityId) {
        val issuer = newIssuer(entityId);
        issuer.setFormat(Issuer.ENTITY);
        return issuer;
    }
881454
public void addEntityId(long entityId)
    {
        if(this.entityIds == null)
            this.entityIds = new ArrayList<Long>();
        this.entityIds.add(entityId);
    }
1021117
private BasicDBObject createAggregation(EntityMetadata metadata)
    {
        if (kunderaQuery.getSelectStatement() != null)
        {
            Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
            EntityType entityType = metaModel.entity(metadata.getEntityClazz());
            AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz());
            boolean hasLob = managedType.hasLobAttribute();

            BasicDBObject aggregation = new BasicDBObject();

            SelectClause selectClause = (SelectClause) kunderaQuery.getSelectStatement().getSelectClause();
            Expression expression = selectClause.getSelectExpression();

            buildAggregation(aggregation, expression, metadata, entityType, hasLob);

            if (aggregation.size() == 0)
            {
                return null;
            }

            if (!aggregation.containsField("_id"))
            {
                aggregation.put("_id", null);
            }

            return aggregation;
        }

        return null;
    }
1342172
public function iGetEntityWithId($entityId)
    {
        $this->lastEntity = $this->entity;
        $this->entity = $this->repository->get($entityId);
    }
434355
private final Object find(Class<?> clazz, EntityMetadata metadata, Object rowId, List<String> relationNames) {

        List<Object> result = null;
        try {
            MetamodelImpl metaModel =
                (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());

            EntityType entityType = metaModel.entity(clazz);

            List<ManagedType> subTypes = ((AbstractManagedType) entityType).getSubManagedType();

            if (!subTypes.isEmpty()) {
                for (ManagedType subEntity : subTypes) {
                    EntityMetadata subEntityMetadata =
                        KunderaMetadataManager.getEntityMetadata(kunderaMetadata, subEntity.getJavaType());
                    result = populate(clazz, subEntityMetadata, rowId, subEntityMetadata.getRelationNames(), metaModel);
                    if (result != null && !result.isEmpty()) {
                        break;
                    }
                }
            } else {
                result = populate(clazz, metadata, rowId, relationNames, metaModel);
            }
        } catch (Exception e) {
            log.error("Error while retrieving records from database for entity {} and key {}, Caused by: .", clazz,
                rowId, e);

            throw new PersistenceException(e);
        }

        return result != null && !result.isEmpty() ? result.get(0) : null;
    }