Search in sources :

Example 1 with ConnInstanceHistoryConf

use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.

the class JPAConnInstanceHistoryConfDAO method delete.

@Override
public void delete(final String key) {
    ConnInstanceHistoryConf conf = find(key);
    if (conf == null) {
        return;
    }
    entityManager().remove(conf);
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) JPAConnInstanceHistoryConf(org.apache.syncope.core.persistence.jpa.entity.JPAConnInstanceHistoryConf)

Example 2 with ConnInstanceHistoryConf

use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.

the class ConnectorHistoryLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_HISTORY_DELETE + "')")
public void delete(final String key) {
    ConnInstanceHistoryConf connInstanceHistoryConf = connInstanceHistoryConfDAO.find(key);
    if (connInstanceHistoryConf == null) {
        throw new NotFoundException("Connector History Conf '" + key + "'");
    }
    connInstanceHistoryConfDAO.delete(key);
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ConnInstanceHistoryConf

use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.

the class ConnInstanceHistoryConfTest method createDelete.

@Test
public void createDelete() {
    ConnInstance ldapConnector = connInstanceDAO.find("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
    assertNotNull(ldapConnector);
    ConnInstanceHistoryConf ldapHistory = entityFactory.newEntity(ConnInstanceHistoryConf.class);
    ldapHistory.setCreation(new Date());
    ldapHistory.setCreator("me");
    ldapHistory.setEntity(ldapConnector);
    ldapHistory.setConf(new ConnInstanceTO());
    ldapHistory = connInstanceHistoryConfDAO.save(ldapHistory);
    assertNotNull(ldapHistory.getKey());
    connInstanceHistoryConfDAO.flush();
    List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(ldapConnector);
    assertEquals(1, history.size());
    assertEquals(ldapHistory, history.get(0));
    connInstanceHistoryConfDAO.delete(ldapHistory.getKey());
    connInstanceHistoryConfDAO.flush();
    assertNull(connInstanceHistoryConfDAO.find(ldapHistory.getKey()));
    assertTrue(connInstanceHistoryConfDAO.findByEntity(ldapConnector).isEmpty());
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 4 with ConnInstanceHistoryConf

use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.

the class ConnInstanceDataBinderImpl method update.

@Override
public ConnInstance update(final ConnInstanceTO connInstanceTO) {
    ConnInstance connInstance = connInstanceDAO.authFind(connInstanceTO.getKey());
    if (connInstance == null) {
        throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
    }
    ConnInstanceTO current = getConnInstanceTO(connInstance);
    if (!current.equals(connInstanceTO)) {
        // 1. save the current configuration, before update
        ConnInstanceHistoryConf connInstanceHistoryConf = entityFactory.newEntity(ConnInstanceHistoryConf.class);
        connInstanceHistoryConf.setCreator(AuthContextUtils.getUsername());
        connInstanceHistoryConf.setCreation(new Date());
        connInstanceHistoryConf.setEntity(connInstance);
        connInstanceHistoryConf.setConf(current);
        connInstanceHistoryConfDAO.save(connInstanceHistoryConf);
        // 2. ensure the maximum history size is not exceeded
        List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(connInstance);
        long maxHistorySize = confDAO.find("connector.conf.history.size", 10L);
        if (maxHistorySize < history.size()) {
            // always remove the last item since history was obtained  by a query with ORDER BY creation DESC
            for (int i = 0; i < history.size() - maxHistorySize; i++) {
                connInstanceHistoryConfDAO.delete(history.get(history.size() - 1).getKey());
            }
        }
    }
    // 3. actual update
    connInstance.getCapabilities().clear();
    connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities());
    if (connInstanceTO.getAdminRealm() != null) {
        Realm realm = realmDAO.findByFullPath(connInstanceTO.getAdminRealm());
        if (realm == null) {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
            sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
            throw sce;
        }
        connInstance.setAdminRealm(realm);
    }
    if (connInstanceTO.getLocation() != null) {
        connInstance.setLocation(connInstanceTO.getLocation());
    }
    if (connInstanceTO.getBundleName() != null) {
        connInstance.setBundleName(connInstanceTO.getBundleName());
    }
    if (connInstanceTO.getVersion() != null) {
        connInstance.setVersion(connInstanceTO.getVersion());
    }
    if (connInstanceTO.getConnectorName() != null) {
        connInstance.setConnectorName(connInstanceTO.getConnectorName());
    }
    if (connInstanceTO.getConf() != null && !connInstanceTO.getConf().isEmpty()) {
        connInstance.setConf(connInstanceTO.getConf());
    }
    if (connInstanceTO.getDisplayName() != null) {
        connInstance.setDisplayName(connInstanceTO.getDisplayName());
    }
    if (connInstanceTO.getConnRequestTimeout() != null) {
        connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout());
    }
    if (connInstanceTO.getPoolConf() == null) {
        connInstance.setPoolConf(null);
    } else {
        connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
    }
    try {
        connInstance = connInstanceDAO.save(connInstance);
    } catch (Exception e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    return connInstance;
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Date(java.util.Date) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Example 5 with ConnInstanceHistoryConf

use of org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf in project syncope by apache.

the class ConnectorHistoryLogic method restore.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_HISTORY_RESTORE + "')")
public void restore(final String key) {
    ConnInstanceHistoryConf connInstanceHistoryConf = connInstanceHistoryConfDAO.find(key);
    if (connInstanceHistoryConf == null) {
        throw new NotFoundException("Connector History Conf '" + key + "'");
    }
    binder.update(connInstanceHistoryConf.getConf());
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ConnInstanceHistoryConf (org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf)5 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 Date (java.util.Date)2 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)2 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 Realm (org.apache.syncope.core.persistence.api.entity.Realm)1 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)1 JPAConnInstanceHistoryConf (org.apache.syncope.core.persistence.jpa.entity.JPAConnInstanceHistoryConf)1 Test (org.junit.jupiter.api.Test)1