Skip to content

Commit

Permalink
Merge pull request #12799 from chamilaadhi/org_visibility
Browse files Browse the repository at this point in the history
Add fixes
  • Loading branch information
chamilaadhi authored Jan 30, 2025
2 parents b5c2ae5 + ec339c3 commit 3a043b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,7 @@ public enum APITransportType {
* CustomIndexer property to indicate whether it is gone through API Custom Indexer.
*/
public static final String CUSTOM_API_INDEXER_PROPERTY = "registry.customIndexer";
public static final String VISIBLE_ORGANIZATION_PROPERTY = "visible_organizations";

/**
* Parameter related with accessControl support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
import org.wso2.carbon.apimgt.impl.utils.IndexerUtil;
import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
Expand All @@ -32,7 +33,9 @@
import org.wso2.carbon.registry.core.RegistryConstants;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.utils.RegistryUtils;
import org.wso2.carbon.registry.indexing.AsyncIndexer;
import org.wso2.carbon.registry.indexing.IndexingConstants;
import org.wso2.carbon.registry.indexing.IndexingManager;
import org.wso2.carbon.registry.indexing.solr.IndexDocument;

Expand All @@ -44,6 +47,8 @@

import static org.wso2.carbon.apimgt.impl.APIConstants.CUSTOM_API_INDEXER_PROPERTY;
import static org.wso2.carbon.apimgt.impl.APIConstants.OVERVIEW_PREFIX;
import static org.wso2.carbon.apimgt.impl.APIConstants.VISIBLE_ORGANIZATION_PROPERTY;


/**
* This is the custom indexer to add the API properties, to existing APIs.
Expand All @@ -68,25 +73,34 @@ public IndexDocument getIndexedDocument(AsyncIndexer.File2Index fileData) throws
if (log.isDebugEnabled()) {
log.debug("CustomAPIIndexer is currently indexing the api at path " + resourcePath);
}

// Here we are adding properties as fields, so that we can search the properties as we do for attributes.
IndexDocument indexDocument = super.getIndexedDocument(fileData);
Map<String, List<String>> fields = indexDocument.getFields();
if (resource != null) {
Properties properties = resource.getProperties();
Enumeration propertyNames = properties.propertyNames();
boolean hasOrganizationProperty = false;
while (propertyNames.hasMoreElements()) {
String property = (String) propertyNames.nextElement();
if (log.isDebugEnabled()) {
log.debug("API at " + resourcePath + " has " + property + " property");
}
if (VISIBLE_ORGANIZATION_PROPERTY.equals(property)) {
hasOrganizationProperty = true;
}
if (property.startsWith(APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX)) {
fields.put((OVERVIEW_PREFIX + property), getLowerCaseList(resource.getPropertyValues(property)));
if (log.isDebugEnabled()) {
log.debug(property + " is added as " + (OVERVIEW_PREFIX + property) + " field for indexing");
}
}
}
if (!hasOrganizationProperty) {
List<String> orgProperties = new ArrayList<>();
orgProperties.add(VISIBLE_ORGANIZATION_PROPERTY + ",all" );
fields.put(IndexingConstants.FIELD_PROPERTY_VALUES, orgProperties);
}
indexDocument.setFields(fields);
}
return indexDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ public OrganizationInfo getOrganizationInfo(String username) throws APIManagemen
organizationId =
manager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername(username), orgIdClaim, null);
// Get the internal organization id using externa id
//organizationId = APIUtil.getOrganizationIdFromExternalReference(organizationId, organization, tenantDomain); // TODO enable this after org add UI
/*
if (!StringUtils.isEmpty(organizationId)) {
organizationId = APIUtil.getOrganizationIdFromExternalReference(organizationId, organization,
tenantDomain); // TODO enable this after org add UI
}*/
}
orgInfo.setName(organization);
orgInfo.setOrganizationId(organizationId);
Expand Down

0 comments on commit 3a043b6

Please sign in to comment.