mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	Add config links for git, hg and svn
This commit is contained in:
		| @@ -0,0 +1,45 @@ | ||||
| package sonia.scm.api.v2.resources; | ||||
|  | ||||
| import com.fasterxml.jackson.databind.JsonNode; | ||||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||||
| import sonia.scm.config.ConfigurationPermissions; | ||||
| import sonia.scm.plugin.Extension; | ||||
| import sonia.scm.web.JsonEnricher; | ||||
| import sonia.scm.web.JsonEnricherContext; | ||||
| import sonia.scm.web.VndMediaType; | ||||
|  | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Provider; | ||||
|  | ||||
| @Extension | ||||
| public class SvnConfigInIndexResource implements JsonEnricher { | ||||
|  | ||||
|   private final Provider<ScmPathInfoStore> scmPathInfoStore; | ||||
|   private final ObjectMapper objectMapper; | ||||
|  | ||||
|   @Inject | ||||
|   public SvnConfigInIndexResource(Provider<ScmPathInfoStore> scmPathInfoStore, ObjectMapper objectMapper) { | ||||
|     this.scmPathInfoStore = scmPathInfoStore; | ||||
|     this.objectMapper = objectMapper; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void enrich(JsonEnricherContext context) { | ||||
|     if (isIndexRequest(context) && ConfigurationPermissions.list().isPermitted()) { | ||||
|       String gitConfigUrl = new LinkBuilder(scmPathInfoStore.get().get(), SvnConfigResource.class) | ||||
|         .method("get") | ||||
|         .parameters() | ||||
|         .href(); | ||||
|  | ||||
|       ObjectNode gitConfigRefNode = objectMapper.createObjectNode(); | ||||
|       gitConfigRefNode.set("href", objectMapper.convertValue(gitConfigUrl, JsonNode.class)); | ||||
|  | ||||
|       ((ObjectNode) context.getResponseEntity().get("_links")).put("svnConfig", gitConfigRefNode); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private boolean isIndexRequest(JsonEnricherContext context) { | ||||
|     return VndMediaType.INDEX.equals(context.getResponseMediaType().toString()); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user