Return a resource map for a generic resource type

@param kind the resource type name
@param meta the attributes about the resource type

@return the resource map describing a resource type
517878
public static Map<String, String> resourceType(String kind, Map<String, String> meta) {
        HashMap<String, String> authResource = new HashMap<String, String>();
        if (null != meta) {
            authResource.putAll(meta);
        }
        authResource.put(TYPE_FIELD, GENERIC_RESOURCE_TYPE_NAME);
        authResource.put(TYPE_KIND_FIELD, kind);
        return authResource;
    }
1286287
public static MappingColumn[] getMappingColumns(final Class<?> entityType, final SqlKind kind) {
		if (entityType == null) {
			return new MappingColumn[0];
		}

		Map<SqlKind, MappingColumn[]> cols;
		synchronized (CACHE) {
			cols = CACHE.get(entityType);
		}
		if (cols != null) {
			return cols.computeIfAbsent(kind, k -> cols.get(SqlKind.NONE));
		}

		Map<SqlKind, Map<String, MappingColumn>> fieldsMap = Stream.of(SqlKind.NONE, SqlKind.INSERT, SqlKind.UPDATE)
				.collect(Collectors.toMap(e -> e, e -> new LinkedHashMap<>()));

		JavaType.ImplementClass implementClass = new JavaType.ImplementClass(entityType);

		walkFields(entityType, implementClass, fieldsMap);

		final Map<SqlKind, MappingColumn[]> entityCols = fieldsMap.entrySet().stream()
				.collect(Collectors.toConcurrentMap(e -> e.getKey(),
						e -> e.getValue().values().toArray(new MappingColumn[e.getValue().size()])));

		synchronized (CACHE) {
			CACHE.put(entityType, entityCols);
		}
		return entityCols.computeIfAbsent(kind, k -> entityCols.get(SqlKind.NONE));
	}
80411
private void getAnchorLegacyMetadataFromRel(ValueMap resourceProps, Element element) {
    // Check href attribute - do not change elements with no href or links to anchor names
    String href = element.getAttributeValue("href");
    String linkWindowTarget = element.getAttributeValue("target");
    if (href == null || href.startsWith("#")) {
      return;
    }

    // get link metadata from rel element
    JSONObject metadata = null;
    String metadataString = element.getAttributeValue("rel");
    if (StringUtils.isNotEmpty(metadataString)) {
      try {
        metadata = new JSONObject(metadataString);
      }
      catch (JSONException ex) {
        log.debug("Invalid link metadata: " + metadataString, ex);
      }
    }
    if (metadata == null) {
      metadata = new JSONObject();
    }

    // transform link metadata to virtual JCR resource with JCR properties
    JSONArray metadataPropertyNames = metadata.names();
    if (metadataPropertyNames != null) {
      for (int i = 0; i < metadataPropertyNames.length(); i++) {
        String metadataPropertyName = metadataPropertyNames.optString(i);

        // check if value is array
        JSONArray valueArray = metadata.optJSONArray(metadataPropertyName);
        if (valueArray != null) {
          // store array values
          List<String> values = new ArrayList<String>();
          for (int j = 0; j < valueArray.length(); j++) {
            values.add(valueArray.optString(j));
          }
          resourceProps.put(metadataPropertyName, values.toArray(new String[values.size()]));
        }
        else {
          // store simple value
          Object value = metadata.opt(metadataPropertyName);
          if (value != null) {
            resourceProps.put(metadataPropertyName, value);
          }
        }
      }
    }

    // detect link type
    LinkType linkType = null;
    String linkTypeString = resourceProps.get(LinkNameConstants.PN_LINK_TYPE, String.class);
    for (Class<? extends LinkType> candidateClass : linkHandlerConfig.getLinkTypes()) {
      LinkType candidate = AdaptTo.notNull(adaptable, candidateClass);
      if (StringUtils.isNotEmpty(linkTypeString)) {
        if (StringUtils.equals(linkTypeString, candidate.getId())) {
          linkType = candidate;
          break;
        }
      }
      else if (candidate.accepts(href)) {
        linkType = candidate;
        break;
      }
    }
    if (linkType == null) {
      // skip further processing if link type was not detected
      return;
    }

    // workaround: strip off ".html" extension if it was added automatically by the RTE
    if (linkType instanceof InternalLinkType || linkType instanceof MediaLinkType) {
      String htmlSuffix = "." + FileExtension.HTML;
      if (StringUtils.endsWith(href, htmlSuffix)) {
        href = StringUtils.substringBeforeLast(href, htmlSuffix);
      }
    }

    // store link reference (property depending on link type)
    resourceProps.put(linkType.getPrimaryLinkRefProperty(), href);
    resourceProps.put(LinkNameConstants.PN_LINK_WINDOW_TARGET, linkWindowTarget);

  }
986521
def _get_resources_by_type(self, resource_type):
        
        resources = []
        for res in self.dsDoc['dataResources']:
            if res['resType'] == resource_type:
                resources.append(res)

        return resources
77201
public static HashMap<String, ResourceType> getDefaultMapping() {
        HashMap<String, ResourceType> map = new HashMap<>();
        for (ResourceType rt : getResourceTypes()) {
            for (String extension : rt.extensions) {
                map.put(extension, rt);
            }
        }
        return map;
    }
333797
protected <T extends BullhornEntity> MetaData<T> handleGetMetaData(Class<T> type, MetaParameter metaParameter, Set<String> fieldSet, Integer privateLabelId) {
        Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForMeta(BullhornEntityInfo.getTypesRestEntityName(type),
                metaParameter, fieldSet, privateLabelId);

        return handleGetMetaData(uriVariables, privateLabelId);
    }
1265767
protected Context getContext(ResourceType type) {
    Context c = typeToContext.get(type);
    if (c == null) {
      c = new Context();
      typeToContext.put(type, c);
    }
    return c;
  }
681715
public static ContextId fromMetaData(Map<String, String> metaData) {
        return new ContextId(metaData.get(META_KEY_ID));
    }
1325880
private Map<String, CmsGalleryTypeInfo> readGalleryInfosByTypeBeans(List<CmsResourceTypeBean> resourceTypes) {

        Map<String, CmsGalleryTypeInfo> galleryTypeInfos = new HashMap<String, CmsGalleryTypeInfo>();
        for (CmsResourceTypeBean typeBean : resourceTypes) {
            try {
                if (!typeBean.isDeactivated()) {
                    addGalleriesForType(galleryTypeInfos, typeBean.getType());
                }
            } catch (CmsLoaderException e1) {
                logError(e1);
            }
        }
        return galleryTypeInfos;
    }
325316
private static <L> Map<Name, TypeSet<ResourceType<L>>> buildTypeMapForConstructor(
            Collection<ResourceType<L>> allTypes) {
        TypeSetBuilder<ResourceType<L>> bldr = TypeSet.<ResourceType<L>> builder();
        bldr.enabled(true);
        bldr.name(new Name("all"));
        for (ResourceType<L> type : allTypes) {
            bldr.type(type);
        }
        TypeSet<ResourceType<L>> typeSet = bldr.build();

        return Collections.singletonMap(typeSet.getName(), typeSet);
    }
1009923
public static ResourceRequest getUnitResourceRequest(ResourceType type) {
    ResourceRequest req = unitResourceRequestMap.get(type);
    if (req == null) {
      req = new ResourceRequest(1, type);
      req.setSpecs(UNIT_COMPUTE_SPECS);

      // instead of using concurrent classes or locking - we clone and replace
      // the map with a new entry. this makes sense because this structure is
      // entirely read-only and will be populated quickly at bootstrap time

      HashMap<ResourceType, ResourceRequest> newMap =
          new HashMap<ResourceType, ResourceRequest>();
      for (Map.Entry<ResourceType, ResourceRequest> entry :
          unitResourceRequestMap.entrySet()) {
        newMap.put(entry.getKey(), entry.getValue());
      }
      newMap.put(type, req);
      unitResourceRequestMap = newMap;
    }
    return req;
  }
100406
public static ResourceMeta withStream(final HasInputStream stream, final Map<String, String> meta) {
        return new BaseStreamResource(meta,stream);
    }
1103979
public <T> T getResourceAsObject(final TypeToken<T> type)
    {
        try
        {
            //noinspection unchecked
            return (T) objectMapper.readValue(((ContentRepresentation) getUnderlyingRepresentation()).getContent(), objectMapper.constructType(type.getType()));
        }
        catch (IOException e)
        {
            LOGGER.warn("failed to parse resource as object: {}", e.getMessage());
            throw new RuntimeException(e);
        }
    }
959661
@SuppressWarnings("unchecked")
  public static Map<String, String> getLabels(ObjectMeta metadata) {
    if (metadata != null) {
      Map<String, String> labels = metadata.getLabels();
      if (labels != null) {
        return labels;
      }
    }
    return Collections.EMPTY_MAP;
  }
969058
private Map<ResourceType, MetricsTimeVaryingLong>
  createTypeToResourceCountMap(
      Collection<ResourceType> resourceTypes, String actionType) {
    Map<ResourceType, MetricsTimeVaryingLong> m =
        new HashMap<ResourceType, MetricsTimeVaryingLong>();
    for (ResourceType t : resourceTypes) {
      String name = (actionType + "_" + t).toLowerCase();
      MetricsTimeVaryingLong value = new MetricsTimeVaryingLong(name, registry);
      m.put(t, value);
    }
    return m;
  }
713079
public Map<?, ?> getByType() {

        if (m_byType == null) {
            m_byType = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

                @SuppressWarnings("synthetic-access")
                public Object transform(Object arg0) {

                    String key = (String)arg0;
                    List<CmsContainerElementBean> result = Lists.newArrayList();
                    for (Map.Entry<String, CmsContainerBean> entry : getPage().getContainers().entrySet()) {
                        CmsContainerBean value = entry.getValue();
                        for (CmsContainerElementBean element : value.getElements()) {
                            try {
                                element.initResource(m_cms);
                                if (key.equals(element.getTypeName())) {
                                    result.add(element);
                                }
                            } catch (CmsException e) {
                                LOG.error(
                                    "Could not initialize resource with site path \""
                                        + element.getSitePath()
                                        + "\" to determine the container elements type.",
                                    e);
                            }
                        }
                    }
                    return result;
                }
            });
        }
        return m_byType;
    }
448576
private Map<String, Object> getEntityAsMap(
      Entity entity,
      EntityType meta,
      Set<String> attributesSet,
      Map<String, Set<String>> attributeExpandsSet) {
    if (null == entity) throw new IllegalArgumentException("entity is null");

    if (null == meta) throw new IllegalArgumentException("meta is null");

    Map<String, Object> entityMap = new LinkedHashMap<>();
    entityMap.put("href", UriUtils.createEntityUriPath(meta.getId(), entity.getIdValue()));

    for (Attribute attr : meta.getAtomicAttributes()) {
      // filter fields
      if (attributesSet != null && !attributesSet.contains(attr.getName().toLowerCase())) continue;

      String attrName = attr.getName();
      AttributeType attrType = attr.getDataType();

      if (attrType == COMPOUND) {
        if (attributeExpandsSet != null
            && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
          Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
          entityMap.put(
              attrName,
              new AttributeResponse(
                  meta.getId(),
                  meta,
                  attr,
                  subAttributesSet,
                  null,
                  permissionService,
                  dataService));
        } else {
          entityMap.put(
              attrName,
              Collections.singletonMap(
                  "href",
                  UriUtils.createEntityAttributeUriPath(
                      meta.getId(), entity.getIdValue(), attrName)));
        }
      } else if (attrType == DATE) {
        LocalDate date = entity.getLocalDate(attrName);
        entityMap.put(attrName, date != null ? date.toString() : null);
      } else if (attrType == DATE_TIME) {
        Instant date = entity.getInstant(attrName);
        entityMap.put(attrName, date != null ? date.toString() : null);
      } else if (attrType != XREF
          && attrType != CATEGORICAL
          && attrType != MREF
          && attrType != CATEGORICAL_MREF
          && attrType != ONE_TO_MANY
          && attrType != FILE) {
        entityMap.put(attrName, entity.get(attr.getName()));
      } else if ((attrType == XREF || attrType == CATEGORICAL || attrType == FILE)
          && attributeExpandsSet != null
          && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
        Entity refEntity = entity.getEntity(attr.getName());
        if (refEntity != null) {
          Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
          EntityType refEntityType = dataService.getEntityType(attr.getRefEntity().getId());
          Map<String, Object> refEntityMap =
              getEntityAsMap(refEntity, refEntityType, subAttributesSet, null);
          entityMap.put(attrName, refEntityMap);
        }
      } else if ((attrType == MREF || attrType == CATEGORICAL_MREF || attrType == ONE_TO_MANY)
          && attributeExpandsSet != null
          && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
        EntityType refEntityType = dataService.getEntityType(attr.getRefEntity().getId());
        Iterable<Entity> mrefEntities = entity.getEntities(attr.getName());

        Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
        List<Map<String, Object>> refEntityMaps = new ArrayList<>();
        for (Entity refEntity : mrefEntities) {
          Map<String, Object> refEntityMap =
              getEntityAsMap(refEntity, refEntityType, subAttributesSet, null);
          refEntityMaps.add(refEntityMap);
        }

        EntityPager pager =
            new EntityPager(
                0,
                new EntityCollectionRequest().getNum(),
                (long) refEntityMaps.size(),
                mrefEntities);

        EntityCollectionResponse ecr =
            new EntityCollectionResponse(
                pager,
                refEntityMaps,
                UriUtils.createEntityAttributeUriPath(meta.getId(), entity.getIdValue(), attrName),
                null,
                permissionService,
                dataService);

        entityMap.put(attrName, ecr);
      } else if ((attrType == XREF && entity.get(attr.getName()) != null)
          || (attrType == CATEGORICAL && entity.get(attr.getName()) != null)
          || (attrType == FILE && entity.get(attr.getName()) != null)
          || attrType == MREF
          || attrType == CATEGORICAL_MREF
          || attrType == ONE_TO_MANY) {
        // Add href to ref field
        Map<String, String> ref = new LinkedHashMap<>();
        ref.put(
            "href",
            UriUtils.createEntityAttributeUriPath(meta.getId(), entity.getIdValue(), attrName));
        entityMap.put(attrName, ref);
      }
    }

    return entityMap;
  }