Search in sources :

Example 16 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class SettingsTemplate method formatSettings.

private void formatSettings() throws WebdavException {
    if (content != null) {
        return;
    }
    final String name = key.getName();
    final StoreType type = key.getType();
    final StringBuilder url = new StringBuilder();
    url.append(requestInfo.getBaseUrl());
    logger.debug("settings base-url is: '{}'", url);
    if (url.charAt(url.length() - 1) != '/') {
        url.append('/');
    }
    url.append("api/");
    url.append(type.singularEndpointName()).append('/').append(name);
    try {
        final Map<String, Object> params = new HashMap<String, Object>();
        params.put(TYPE_KEY, type.singularEndpointName());
        params.put(NAME_KEY, name);
        params.put(URL_KEY, url);
        params.put(RELEASES_KEY, advice.isReleasesAllowed());
        params.put(SNAPSHOTS_KEY, advice.isSnapshotsAllowed());
        params.put(DEPLOY_ENABLED_KEY, advice.isDeployable());
        final String rendered = templateEngine.render(TEMPLATE, params);
        content = rendered.getBytes("UTF-8");
    } catch (final UnsupportedEncodingException e) {
        throw new IllegalStateException("Cannot find encoding for UTF-8!", e);
    } catch (final IndyGroovyException e) {
        throw new WebdavException(String.format("Failed to render settings.xml template for: '%s'. Reason: %s", key, e.getMessage()), e);
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashMap(java.util.HashMap) WebdavException(net.sf.webdav.exceptions.WebdavException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Example 17 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class SettingsURIMatcher method getStoreType.

/* (non-Javadoc)
     * @see org.commonjava.indy.dotmaven.util.URIMatcher#getStoreType()
     */
@Override
public StoreType getStoreType() {
    if (!matches()) {
        return null;
    }
    final String typePart = matcher.group(TYPE_GRP);
    if (typePart == null) {
        return null;
    }
    final StoreType type = StoreType.get(typePart);
    return type;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType)

Example 18 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class StorageAdvisor method getStorageAdvice.

public StorageAdvice getStorageAdvice(final ArtifactStore store) throws DotMavenException {
    boolean deployable = false;
    boolean releases = true;
    boolean snapshots = false;
    HostedRepository hostedStore = null;
    final StoreType type = store.getKey().getType();
    all: switch(type) {
        case group:
            {
                List<ArtifactStore> constituents;
                try {
                    constituents = dataManager.query().packageType(MAVEN_PKG_KEY).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
                } catch (final IndyDataException e) {
                    throw new DotMavenException("Failed to retrieve constituent ArtifactStores for group: %s. Reason: %s", e, store.getName(), e.getMessage());
                }
                for (final ArtifactStore as : constituents) {
                    if (as.getKey().getType() == hosted) {
                        deployable = true;
                        hostedStore = (HostedRepository) as;
                        snapshots = hostedStore.isAllowSnapshots();
                        releases = hostedStore.isAllowReleases();
                        break all;
                    }
                }
                break;
            }
        case hosted:
            {
                deployable = true;
                hostedStore = (HostedRepository) store;
                snapshots = hostedStore.isAllowSnapshots();
                releases = hostedStore.isAllowReleases();
                break;
            }
        default:
    }
    return new StorageAdvice(store, hostedStore, deployable, releases, snapshots);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HostedRepository(org.commonjava.indy.model.core.HostedRepository) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 19 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class NfcResource method getStore.

@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@ApiOperation("Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response getStore(@ApiParam(name = "packageType", required = true, value = "The type of package (eg. maven, npm, generic-http)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    final StoreKey key = new StoreKey(packageType, type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer);
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class NfcResource method deprecatedClearStore.

@Path("/{type: (hosted|group|remote)}/{name}{path: (/.+)?}")
@ApiOperation("[Deprecated] Clear all not-found cache entries for a particular store (or optionally, a subpath within a store)")
@DELETE
@Deprecated
public Response deprecatedClearStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", required = true, value = "The name of the store") @PathParam("name") final String name, @ApiParam(name = "path", required = false, value = "The sub-path to clear") @PathParam("path") final String p) {
    Response response;
    final StoreType type = StoreType.get(t);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        if (isNotEmpty(p)) {
            controller.clear(key);
        } else {
            controller.clear(key, p);
        }
        response = markDeprecated(Response.ok(), altPath).build();
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)53 StoreKey (org.commonjava.indy.model.core.StoreKey)43 Response (javax.ws.rs.core.Response)25 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)25 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)22 ApiOperation (io.swagger.annotations.ApiOperation)21 ApiResponse (io.swagger.annotations.ApiResponse)21 Path (javax.ws.rs.Path)19 ApiResponses (io.swagger.annotations.ApiResponses)18 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)18 IOException (java.io.IOException)13 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 List (java.util.List)10 Inject (javax.inject.Inject)10 DELETE (javax.ws.rs.DELETE)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 ResponseUtils.markDeprecated (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated)9 IndyDataException (org.commonjava.indy.data.IndyDataException)8 Transfer (org.commonjava.maven.galley.model.Transfer)8