use of org.commonjava.indy.httprox.handler.ProxyCreationResult in project indy by Commonjava.
the class ProxyResponseHelper method createRepo.
/**
* Create repositories (group, remote, hosted) when trackingId is present. Otherwise create normal remote
* repository with specified name.
*
* @param trackingId
* @param url
* @param name distinct remote repository name. null if trackingId is given
*/
private ProxyCreationResult createRepo(String trackingId, URL url, String name) throws IndyDataException {
UrlInfo info = new UrlInfo(url.toExternalForm());
UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
String baseUrl = getBaseUrl(url, false);
logger.debug(">>>> Create repo: trackingId=" + trackingId + ", name=" + name);
ProxyCreationResult result = repoCreator.create(trackingId, name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
RemoteRepository remote = result.getRemote();
if (remote != null) {
storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
}
HostedRepository hosted = result.getHosted();
if (hosted != null) {
storeManager.storeArtifactStore(hosted, changeSummary, false, true, new EventMetadata());
}
Group group = result.getGroup();
if (group != null) {
storeManager.storeArtifactStore(group, changeSummary, false, true, new EventMetadata());
}
return result;
}
use of org.commonjava.indy.httprox.handler.ProxyCreationResult in project indy by Commonjava.
the class ProxyResponseHelper method doGetArtifactStore.
private ArtifactStore doGetArtifactStore(String trackingId, final URL url) throws IndyDataException {
int port = getPort(url);
if (trackingId != null) {
String groupName = repoCreator.formatId(url.getHost(), port, 0, trackingId, StoreType.group);
ArtifactStoreQuery<Group> query = storeManager.query().storeType(Group.class);
Group group = query.getGroup(GENERIC_PKG_KEY, groupName);
logger.debug("Get httproxy group, group: {}", group);
if (group == null) {
logger.debug("Creating repositories (group, hosted, remote) for HTTProx request: {}, trackingId: {}", url, trackingId);
ProxyCreationResult result = createRepo(trackingId, url, null);
group = result.getGroup();
}
return group;
} else {
RemoteRepository remote;
final String baseUrl = getBaseUrl(url, false);
ArtifactStoreQuery<RemoteRepository> query = storeManager.query().storeType(RemoteRepository.class);
remote = query.getAllRemoteRepositories(GENERIC_PKG_KEY).stream().filter(store -> store.getUrl().equals(baseUrl) && store.getMetadata(TRACKING_ID) == null).findFirst().orElse(null);
logger.debug("Get httproxy remote, remote: {}", remote);
if (remote == null) {
logger.debug("Creating remote repository for HTTProx request: {}", url);
String name = getRemoteRepositoryName(url);
ProxyCreationResult result = createRepo(null, url, name);
remote = result.getRemote();
}
return remote;
}
}
Aggregations