Search in sources :

Example 1 with NumbersInfo

use of org.apache.syncope.common.lib.info.NumbersInfo in project syncope by apache.

the class SyncopeLogic method numbers.

@PreAuthorize("isAuthenticated()")
public NumbersInfo numbers() {
    NumbersInfo numbersInfo = new NumbersInfo();
    numbersInfo.setTotalUsers(userDAO.count());
    numbersInfo.getUsersByRealm().putAll(userDAO.countByRealm());
    numbersInfo.getUsersByStatus().putAll(userDAO.countByStatus());
    numbersInfo.setTotalGroups(groupDAO.count());
    numbersInfo.getGroupsByRealm().putAll(groupDAO.countByRealm());
    Map<AnyType, Integer> anyObjectNumbers = anyObjectDAO.countByType();
    int i = 0;
    for (Iterator<Map.Entry<AnyType, Integer>> itor = anyObjectNumbers.entrySet().iterator(); i < 2 && itor.hasNext(); i++) {
        Map.Entry<AnyType, Integer> entry = itor.next();
        if (i == 0) {
            numbersInfo.setAnyType1(entry.getKey().getKey());
            numbersInfo.setTotalAny1(entry.getValue());
            numbersInfo.getAny1ByRealm().putAll(anyObjectDAO.countByRealm(entry.getKey()));
        } else if (i == 1) {
            numbersInfo.setAnyType2(entry.getKey().getKey());
            numbersInfo.setTotalAny2(entry.getValue());
            numbersInfo.getAny2ByRealm().putAll(anyObjectDAO.countByRealm(entry.getKey()));
        }
    }
    numbersInfo.setTotalResources(resourceDAO.count());
    numbersInfo.setTotalRoles(roleDAO.count());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.RESOURCE.name(), numbersInfo.getTotalResources() > 0);
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ACCOUNT_POLICY.name(), !policyDAO.find(AccountPolicy.class).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.PASSWORD_POLICY.name(), !policyDAO.find(PasswordPolicy.class).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.NOTIFICATION.name(), !notificationDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.PULL_TASK.name(), !taskDAO.findAll(TaskType.PULL).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.VIR_SCHEMA.name(), !virSchemaDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ANY_TYPE.name(), !anyObjectNumbers.isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.SECURITY_QUESTION.name(), !securityQuestionDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ROLE.name(), numbersInfo.getTotalRoles() > 0);
    return numbersInfo;
}
Also used : AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with NumbersInfo

use of org.apache.syncope.common.lib.info.NumbersInfo in project syncope by apache.

the class JAXBTest method numbersInfo.

@Test
public void numbersInfo() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(NumbersInfo.class);
    Marshaller marshaller = context.createMarshaller();
    Unmarshaller unmarshaller = context.createUnmarshaller();
    NumbersInfo original = new NumbersInfo();
    original.setTotalUsers(5);
    original.getUsersByRealm().put("/", 4);
    original.getUsersByRealm().put("/even", 1);
    original.getUsersByStatus().put("active", 5);
    original.setTotalGroups(16);
    original.getGroupsByRealm().put("/", 14);
    original.getGroupsByRealm().put("/even", 1);
    original.getGroupsByRealm().put("/odd", 1);
    original.setAnyType1("PRINTER");
    original.setTotalAny1(3);
    original.getAny1ByRealm().put("/", 2);
    original.getAny1ByRealm().put("/even/two", 1);
    original.setTotalResources(21);
    original.setTotalRoles(4);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.ANY_TYPE.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.PULL_TASK.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.ROLE.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.NOTIFICATION.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.PASSWORD_POLICY.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.ACCOUNT_POLICY.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.RESOURCE.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.VIR_SCHEMA.name(), Boolean.TRUE);
    original.getConfCompleteness().put(NumbersInfo.ConfItem.SECURITY_QUESTION.name(), Boolean.TRUE);
    StringWriter writer = new StringWriter();
    marshaller.marshal(original, writer);
    Object actual = unmarshaller.unmarshal(new StringReader(writer.toString()));
    assertEquals(original, actual);
}
Also used : Marshaller(javax.xml.bind.Marshaller) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.jupiter.api.Test)

Aggregations

NumbersInfo (org.apache.syncope.common.lib.info.NumbersInfo)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)1 AccountPolicy (org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy)1 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)1 Test (org.junit.jupiter.api.Test)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1