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();
}
}
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()));
}
}
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()));
}
}
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);
}
}
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();
}
Aggregations