Search in sources :

Example 81 with StoreKey

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

the class ValidationRuleSetTest method matchesHostedRepoWithDotStarPattern.

@Test
public void matchesHostedRepoWithDotStarPattern() {
    ValidationRuleSet ruleSet = new ValidationRuleSet("test", ".*", Collections.emptyList(), Collections.emptyMap());
    assertThat(ruleSet.matchesKey(new StoreKey(StoreType.hosted, "repo").toString()), equalTo(true));
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 82 with StoreKey

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

the class RelateGenerationManager method generateRelationshipFile.

/**
     * Generate relationship file for pom transfer.
     * @param transfer
     * @param op
     * @return transfer pointing to the generated rel file.
     */
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Relate generation for {}", transfer);
    if (transfer == null) {
        logger.debug("No transfer. No .rel generation performed.");
        return null;
    }
    String txfrPath = transfer.getPath();
    if (!txfrPath.endsWith(".pom")) {
        logger.debug("This is not a pom transfer.");
        return null;
    }
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
        return null;
    }
    ConcreteResource pomResource = transfer.getResource();
    StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
    ArtifactStore store;
    try {
        store = storeManager.getArtifactStore(storeKey);
    } catch (final IndyDataException ex) {
        logger.error("Error retrieving artifactStore with key " + storeKey, ex);
        return null;
    }
    logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
    try {
        URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
        ProjectVersionRef ref = artPathInfo.getProjectId();
        // get all groups that this store is a member of
        Set<ArtifactStore> stores = new HashSet<>();
        stores.add(store);
        stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
        List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
        MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
        EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
        Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
        writeRelationships(rel, transferRel, op);
        return transferRel;
    } catch (Exception e) {
        logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Transfer(org.commonjava.maven.galley.model.Transfer) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) HashSet(java.util.HashSet)

Example 83 with StoreKey

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

the class ChangelogResource method getStoreChangelog.

@ApiOperation("Retrieve the changelog for the Indy group/repository definition with the start-index and number of results")
@ApiResponses({ @ApiResponse(code = 200, message = "JSON containing changelog entries", response = ChangeSummaryDTO.class), @ApiResponse(code = 400, message = "Requested group/repository type is not one of: {remote, hosted, group}") })
@Path("/store/{type}/{name}")
public Response getStoreChangelog(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String storeName, @QueryParam("start") int start, @QueryParam("count") int count) {
    final StoreType storeType = StoreType.get(t);
    if (storeType == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid store type: '" + t + "'").build();
    }
    final StoreKey key = new StoreKey(storeType, storeName);
    if (start < 0) {
        start = 0;
    }
    if (count < 1) {
        count = DEFAULT_CHANGELOG_COUNT;
    }
    Response response;
    try {
        final List<ChangeSummary> dataChangeLog = revisions.getDataChangeLog(key, start, count);
        response = formatOkResponseWithJsonEntity(new ChangeSummaryDTO(dataChangeLog), objectMapper);
        logger.info("\n\n\n\n\n\n{} Sent changelog for: {}\n\n{}\n\n\n\n\n\n\n", new Date(), key, dataChangeLog);
    } catch (final GitSubsystemException e) {
        final String message = String.format("Failed to lookup changelog for: %s. Reason: %s", key, e.getMessage());
        logger.error(message, e);
        response = formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ChangeSummaryDTO(org.commonjava.indy.revisions.jaxrs.dto.ChangeSummaryDTO) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 84 with StoreKey

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

the class PomUploadListenerTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    HostedRepository hosted1 = new HostedRepository(repo1);
    client.stores().create(hosted1, "adding hosted", HostedRepository.class);
    StoreKey key = new StoreKey(hosted, repo1);
    InputStream stream = new ByteArrayInputStream(content.getBytes());
    client.content().store(key, path, stream);
    waitForEventPropagation();
    boolean exists = client.content().exists(hosted, repo1, pathRel, true);
    assertThat(exists, equalTo(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 85 with StoreKey

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

the class AbstractValidationRuleTest method getRuleSet.

protected ValidationRuleSet getRuleSet() {
    ValidationRuleSet ruleSet = new ValidationRuleSet();
    ruleSet.setName("test");
    ruleSet.setStoreKeyPattern(new StoreKey(group, TARGET_NAME).toString());
    ruleSet.setRuleNames(Collections.singletonList(getRuleScriptFile()));
    return ruleSet;
}
Also used : ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18