Search in sources :

Example 1 with ExtensionJson

use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.

the class AdminAPITest method extensionJson.

private String extensionJson(Consumer<ExtensionJson> content) throws JsonProcessingException {
    var json = new ExtensionJson();
    content.accept(json);
    return new ObjectMapper().writeValueAsString(json);
}
Also used : ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ExtensionJson

use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.

the class RegistryAPITest method extensionJson.

private String extensionJson(Consumer<ExtensionJson> content) throws JsonProcessingException {
    var json = new ExtensionJson();
    content.accept(json);
    return new ObjectMapper().writeValueAsString(json);
}
Also used : ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ExtensionJson

use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.

the class AdminAPI method getExtension.

@GetMapping(path = "/admin/extension/{namespaceName}/{extensionName}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ExtensionJson> getExtension(@PathVariable String namespaceName, @PathVariable String extensionName) {
    try {
        admins.checkAdminUser();
        var extension = repositories.findExtension(extensionName, namespaceName);
        if (extension == null) {
            var json = ExtensionJson.error("Extension not found: " + namespaceName + "." + extensionName);
            return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
        }
        ExtensionJson json;
        // Don't rely on the 'latest' relationship here because the extension might be inactive
        var extVersion = getLatestVersion(extension);
        if (extVersion == null) {
            json = new ExtensionJson();
            json.namespace = extension.getNamespace().getName();
            json.name = extension.getName();
            json.allVersions = Collections.emptyMap();
        } else {
            json = local.toExtensionVersionJson(extVersion, false);
        }
        json.active = extension.isActive();
        return ResponseEntity.ok(json);
    } catch (ErrorResultException exc) {
        return exc.toResponseEntity(ExtensionJson.class);
    }
}
Also used : ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) ResponseEntity(org.springframework.http.ResponseEntity) ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with ExtensionJson

use of org.eclipse.openvsx.json.ExtensionJson in project openvsx by eclipse.

the class AdminAPITest method testGetUserPublishInfo.

@Test
public void testGetUserPublishInfo() throws Exception {
    mockAdminUser();
    var versions = mockExtension(1, 0, 0);
    var user = new UserData();
    user.setLoginName("test");
    user.setProvider("github");
    Mockito.when(repositories.findUserByLoginName("github", "test")).thenReturn(user);
    var token = new PersonalAccessToken();
    token.setUser(user);
    token.setActive(true);
    Mockito.when(repositories.findAccessTokens(user)).thenReturn(Streamable.of(token));
    versions.forEach(v -> v.setPublishedWith(token));
    Mockito.when(repositories.findVersionsByAccessToken(token)).thenReturn(Streamable.of(versions));
    mockMvc.perform(get("/admin/publisher/{provider}/{loginName}", "github", "test").with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN")))).with(csrf().asHeader())).andExpect(status().isOk()).andExpect(content().json(publishInfoJson(upi -> {
        upi.user = new UserJson();
        upi.user.loginName = "test";
        upi.activeAccessTokenNum = 1;
        var ext1 = new ExtensionJson();
        ext1.namespace = "foobar";
        ext1.name = "baz";
        ext1.version = "1";
        upi.extensions = Arrays.asList(ext1);
    })));
}
Also used : UserJson(org.eclipse.openvsx.json.UserJson) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

ExtensionJson (org.eclipse.openvsx.json.ExtensionJson)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 UserJson (org.eclipse.openvsx.json.UserJson)1 ErrorResultException (org.eclipse.openvsx.util.ErrorResultException)1 Test (org.junit.jupiter.api.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1 ResponseEntity (org.springframework.http.ResponseEntity)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1