Search in sources :

Example 16 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class RevisionsManagerTest method commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem.

@Test
public void commitTwoDifferentFilesAndRetrieveChangelogForOneOfThem() throws Exception {
    lcEvents.fireStarted();
    final DataFile f1 = dfManager.getDataFile("test/foo.txt");
    f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first file."));
    final DataFile f2 = dfManager.getDataFile("test/bar.txt");
    f2.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for second file."));
    f2.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test (2) for second file."));
    final List<DataFileEvent> events = listener.waitForEvents(3);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    final List<ChangeSummary> changeLog = revManager.getDataChangeLog(f2.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(2));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) DataFileEvent(org.commonjava.indy.subsys.datafile.change.DataFileEvent) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 17 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class RevisionsManagerTest method commitOneFileTwice_ChangedBeforeServerStart_FirstChangelogAppearsOnServerStart.

@Test
public void commitOneFileTwice_ChangedBeforeServerStart_FirstChangelogAppearsOnServerStart() throws Exception {
    revManager.setup();
    final DataFile f1 = dfManager.getDataFile("test/foo.txt");
    f1.writeString("this is a test", "UTF-8", new ChangeSummary("test-user", "test for first write of file."));
    List<DataFileEvent> events = listener.waitForEvents(1);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    f1.writeString("this is another test", "UTF-8", new ChangeSummary("test-user", "test for second write of file."));
    events = listener.waitForEvents(1);
    System.out.println("Got events:\n  " + join(events, "\n  "));
    List<ChangeSummary> changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(0));
    lcEvents.fireStarted();
    changeLog = revManager.getDataChangeLog(f1.getPath(), 0, -1);
    assertThat(changeLog, notNullValue());
    assertThat(changeLog.size(), equalTo(1));
    assertThat(changeLog.get(0).getSummary().contains(RevisionsManager.CATCHUP_CHANGELOG), equalTo(true));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) DataFileEvent(org.commonjava.indy.subsys.datafile.change.DataFileEvent) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 18 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class RevisionsAdminResource method doGet.

@ApiOperation("Retrieve the changelog for the Indy data directory content with the specified path, start-index, and number of results")
@ApiResponse(code = 200, message = "JSON containing changelog entries", response = ChangeSummaryDTO.class)
@Path("/data/changelog{path: /.*}")
@GET
@Produces(ApplicationContent.application_json)
public Response doGet(@PathParam("path") final String path, @QueryParam("start") final int start, @QueryParam("count") final int count) {
    Response response;
    try {
        final List<ChangeSummary> listing = revisionsManager.getDataChangeLog(path, start, count);
        response = formatOkResponseWithJsonEntity(new ChangeSummaryDTO(listing), objectMapper);
    } catch (final GitSubsystemException e) {
        logger.error("Failed to read git changelog from data dir: " + e.getMessage(), e);
        response = formatResponse(e, "Failed to read git changelog from data dir.");
    }
    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) ChangeSummaryDTO(org.commonjava.indy.revisions.jaxrs.dto.ChangeSummaryDTO) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 19 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class SetBackSettingsManager method deleteStoreSettings.

public boolean deleteStoreSettings(final ArtifactStore store) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    final StoreKey key = store.getKey();
    if (StoreType.hosted == key.getType()) {
        return false;
    }
    final DataFile settingsXml = getSettingsXml(key);
    if (settingsXml.exists()) {
        try {
            settingsXml.delete(new ChangeSummary(ChangeSummary.SYSTEM_USER, "SETBACK: Deleting generated SetBack settings.xml for: " + store));
        } catch (final IOException e) {
            throw new SetBackDataException("Failed to delete SetBack settings.xml for: %s.\n  at: %s\n  Reason: %s", e, store, settingsXml, e.getMessage());
        }
        return true;
    }
    return false;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 20 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class SetBackSettingsManager method updateSettings.

private DataFile updateSettings(final ArtifactStore store, final List<ArtifactStore> allStores, final List<RemoteRepository> remotes) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    final StoreKey key = store.getKey();
    final DataFile settingsXml = getSettingsXml(key);
    final Map<String, Object> params = new HashMap<String, Object>();
    params.put("key", key);
    params.put("store", store);
    params.put("remotes", remotes);
    params.put("allStores", allStores);
    String rendered;
    try {
        rendered = templates.render(ApplicationContent.application_xml, TEMPLATE, params);
    } catch (final IndyGroovyException e) {
        throw new SetBackDataException("Failed to render template: %s for store: %s. Reason: %s", e, TEMPLATE, key, e.getMessage());
    }
    try {
        settingsXml.getParent().mkdirs();
        settingsXml.writeString(rendered, "UTF-8", new ChangeSummary(ChangeSummary.SYSTEM_USER, "SETBACK: Updating generated SetBack settings.xml for: " + key));
    } catch (final IOException e) {
        throw new SetBackDataException("Failed to write SetBack settings.xml for: %s\n  to: %s\n  Reason: %s", e, key, settingsXml, e.getMessage());
    }
    return settingsXml;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) HashMap(java.util.HashMap) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Aggregations

ChangeSummary (org.commonjava.indy.audit.ChangeSummary)68 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)37 Test (org.junit.Test)29 IndyDataException (org.commonjava.indy.data.IndyDataException)24 DataFile (org.commonjava.indy.subsys.datafile.DataFile)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17 StoreKey (org.commonjava.indy.model.core.StoreKey)14 IOException (java.io.IOException)11 HostedRepository (org.commonjava.indy.model.core.HostedRepository)11 Group (org.commonjava.indy.model.core.Group)10 File (java.io.File)8 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)8 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)8 Transfer (org.commonjava.maven.galley.model.Transfer)8 Logger (org.slf4j.Logger)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)7 ArrayList (java.util.ArrayList)6 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)5 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)5