Search in sources :

Example 81 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class DefaultEntityTest method shouldToStringDoNotMakeInfinityCycleWithTwoManyToManyFieldsWithoutId.

@Test
public final void shouldToStringDoNotMakeInfinityCycleWithTwoManyToManyFieldsWithoutId() {
    // given
    final Entity firstEntity = new DefaultEntity(dataDefinition);
    final Entity secondEntity = new DefaultEntity(dataDefinition);
    firstEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
    firstEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
    firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
    secondEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
    secondEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
    secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
    // when
    try {
        firstEntity.toString();
    } catch (StackOverflowError e) {
        Assert.fail();
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) Test(org.junit.Test)

Example 82 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class GroupDetailsCriteriaModifiers method criteriaForGroups.

public void criteriaForGroups(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
    Long groupId = filterValue.getLong(GroupDetailsConstants.GROUP_ID);
    Entity group = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_GROUP).find().add(SearchRestrictions.idEq(groupId)).uniqueResult();
    List<Entity> roles = group.getManyToManyField("roles");
    for (Entity role : roles) {
        scb.add(SearchRestrictions.idNe(role.getId()));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 83 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class UserCriteriaModifiers method criteriaForRole.

public void criteriaForRole(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
    Entity loggedUser = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(securityService.getCurrentUserId());
    Entity superAdminGroup = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_GROUP).find().add(SearchRestrictions.eq(GroupFields.IDENTIFIER, "SUPER_ADMIN")).setMaxResults(1).uniqueResult();
    if (securityService.hasRole(loggedUser, "ROLE_ADMIN")) {
        scb.createAlias(UserFields.GROUP, "gr", JoinType.INNER);
        scb.add(SearchRestrictions.ne("gr.id", superAdminGroup.getId()));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 84 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class UserService method disableFormForSuperadmin.

public void disableFormForSuperadmin(final ViewDefinitionState state) {
    FormComponent form = (FormComponent) state.getComponentByReference(QcadooViewConstants.L_FORM);
    Long viewedUserId = form.getEntityId();
    Entity viewedUser = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(viewedUserId);
    Entity loggedUser = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(securityService.getCurrentUserId());
    if (!securityService.hasRole(loggedUser, "ROLE_SUPERADMIN") && securityService.hasRole(viewedUser, "ROLE_SUPERADMIN")) {
        form.setFormEnabled(false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity)

Example 85 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class GlobalUnitConversionsAggregateServiceImpl method getAggregateId.

@Override
@Transactional
public Long getAggregateId() {
    Entity existingAggregate = getAggregateDataDefinition().find().setMaxResults(1).uniqueResult();
    if (existingAggregate == null) {
        existingAggregate = getAggregateDataDefinition().create();
        existingAggregate = existingAggregate.getDataDefinition().save(existingAggregate);
        Preconditions.checkState(existingAggregate.isValid());
    }
    return existingAggregate.getId();
}
Also used : Entity(com.qcadoo.model.api.Entity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Entity (com.qcadoo.model.api.Entity)2833 FormComponent (com.qcadoo.view.api.components.FormComponent)514 Test (org.junit.Test)491 BigDecimal (java.math.BigDecimal)376 DataDefinition (com.qcadoo.model.api.DataDefinition)337 FieldComponent (com.qcadoo.view.api.components.FieldComponent)210 LookupComponent (com.qcadoo.view.api.components.LookupComponent)188 Date (java.util.Date)185 List (java.util.List)149 GridComponent (com.qcadoo.view.api.components.GridComponent)141 Map (java.util.Map)124 Autowired (org.springframework.beans.factory.annotation.Autowired)114 Service (org.springframework.stereotype.Service)112 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)105 Transactional (org.springframework.transaction.annotation.Transactional)101 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)100 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)95 Collectors (java.util.stream.Collectors)87 Lists (com.google.common.collect.Lists)75 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)75