Search in sources :

Example 1 with RemoveRepositorySourceMirrorRequest

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

the class RepositoryApiIT method testRemoveRepositorySourceMirror.

@Test
public void testRemoveRepositorySourceMirror() {
    integrationTestSupportService.createStandardTestData();
    RemoveRepositorySourceMirrorRequest request = new RemoveRepositorySourceMirrorRequest();
    request.code = "testreposrc_xyz_m_notpri";
    {
        ObjectContext context = serverRuntime.newContext();
        Assertions.assertThat(RepositorySourceMirror.tryGetByCode(context, "testreposrc_xyz_m_notpri").isPresent()).isTrue();
    }
    // ------------------------------------
    repositoryApi.removeRepositorySourceMirror(request);
    // ------------------------------------
    {
        ObjectContext context = serverRuntime.newContext();
        Assertions.assertThat(RepositorySourceMirror.tryGetByCode(context, "testreposrc_xyz_m_notpri").isPresent()).isFalse();
    }
}
Also used : RemoveRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorRequest) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with RemoveRepositorySourceMirrorRequest

use of org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorRequest 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)2 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 RemoveRepositorySourceMirrorRequest (org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorRequest)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 Test (org.junit.jupiter.api.Test)1