Search in sources :

Example 1 with RemoveRepositorySourceMirrorResult

use of org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorResult in project haikudepotserver by haiku.

the class RepositoryApiImpl method removeRepositorySourceMirror.

@Override
public RemoveRepositorySourceMirrorResult removeRepositorySourceMirror(RemoveRepositorySourceMirrorRequest request) {
    Preconditions.checkArgument(null != request, "the request is required");
    Preconditions.checkArgument(StringUtils.isNotBlank(request.code), "the code is required on the request");
    final ObjectContext context = serverRuntime.newContext();
    RepositorySourceMirror repositorySourceMirror = RepositorySourceMirror.tryGetByCode(context, request.code).orElseThrow(() -> new ObjectNotFoundException(RepositorySourceMirror.class.getSimpleName(), request.code));
    if (repositorySourceMirror.getIsPrimary()) {
        throw new IllegalStateException("unable to remove the primary mirror");
    }
    repositorySourceMirror.getRepositorySource().getRepository().setModifyTimestamp();
    context.deleteObject(repositorySourceMirror);
    context.commitChanges();
    LOGGER.info("did remote the repository source mirror [{}]", request.code);
    return new RemoveRepositorySourceMirrorResult();
}
Also used : RemoveRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorResult) org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror) RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)1 RemoveRepositorySourceMirrorResult (org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorResult)1 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror)1 org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror)1