use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class MaintenanceHandler method affectedBy.
@ApiOperation("Get groups affected by specified repo.")
@ApiResponse(code = 200, message = "Complete.")
@Produces("application/json")
@Path("/store/affected/{key}")
@GET
public Response affectedBy(@ApiParam("The store key") @PathParam("key") final String key) {
Response response;
try {
Set<StoreKey> storeKeys = new HashSet<>();
storeKeys.add(StoreKey.fromString(key));
Set<Group> groups = storeDataManager.affectedBy(storeKeys);
response = Response.ok(mapper.writeValueAsString(groups)).build();
} catch (final Exception e) {
logger.error(String.format("Failed to export: %s. Reason: %s", key, e.getMessage()), e);
response = responseHelper.formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupDataManagerTCK method createSameGroupTwiceAndRetrieveOne.
@Test
public void createSameGroupTwiceAndRetrieveOne() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final Group grp = new Group("test");
store(grp, grp);
final List<Group> result = manager.query().getAllGroups(MAVEN_PKG_KEY);
assertThat(result, notNullValue());
assertThat(result.size(), equalTo(1));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupDataManagerTCK method createTwoGroupsAndAffectedByForOneLevel.
@Test
public void createTwoGroupsAndAffectedByForOneLevel() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final StoreKey central = new StoreKey(remote, "central");
final StoreKey repo2 = new StoreKey(remote, "repo2");
Group g1 = new Group("g1", central);
Group g2 = new Group("g2", repo2);
store(g1, g2);
List<StoreKey> keys = asList(central, repo2);
Set<StoreKey> gKeys = manager.query().getGroupsAffectedBy(keys).stream().map(Group::getKey).collect(Collectors.toSet());
assertThat(gKeys.contains(g1.getKey()), equalTo(Boolean.TRUE));
assertThat(gKeys.contains(g2.getKey()), equalTo(Boolean.TRUE));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupDataManagerTCK method createTwoGroupsAndRetrieveBoth.
@Test
public void createTwoGroupsAndRetrieveBoth() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final Group grp = new Group("test");
final Group grp2 = new Group("test2");
store(grp, grp2);
final List<Group> result = manager.query().getAllGroups(MAVEN_PKG_KEY);
assertThat(result, notNullValue());
assertThat(result.size(), equalTo(2));
Collections.sort(result, new Comparator<Group>() {
@Override
public int compare(final Group g1, final Group g2) {
return g1.getName().compareTo(g2.getName());
}
});
Group g = result.get(0);
assertThat(g.getName(), equalTo(grp.getName()));
g = result.get(1);
assertThat(g.getName(), equalTo(grp2.getName()));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class ImpliedRepositoryDetector method updateExistingGroups.
private boolean updateExistingGroups(final ImplicationsJob job) {
final StoreKey key = job.store.getKey();
boolean anyChanged = false;
try {
final Set<Group> groups = storeManager.query().getGroupsContaining(key);
if (groups != null) {
logger.debug("{} groups contain: {}\n {}", groups.size(), key, new JoinString("\n ", groups));
final String message = String.format("Adding repositories implied by: %s\n\n %s", key, StringUtils.join(job.implied, "\n "));
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
for (final Group g : groups) {
if (config.isEnabledForGroup(g.getName())) {
Group group = g.copyOf();
boolean changed = false;
for (final ArtifactStore implied : job.implied) {
boolean groupChanged = group.addConstituent(implied);
changed = groupChanged || changed;
logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
}
if (changed) {
storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
}
anyChanged = changed || anyChanged;
}
}
}
} catch (final IndyDataException e) {
logger.error("Failed to lookup groups containing: " + key, e);
}
return anyChanged;
}
Aggregations