private static boolean hasUniqueSortAttribute(EntityType entityType, Sort sort) { for (Sort.Order order : sort) { String attributeName = order.getAttr(); Attribute attribute = entityType.getAttribute(attributeName); if (attribute.isUnique()) { return true; } } return false; }
/** * Updates unique constraint based on attribute unique changes. * * @param entityType entity meta data * @param attr current attribute * @param updatedAttr updated attribute */ private void updateUnique(EntityType entityType, Attribute attr, Attribute updatedAttr) { if (attr.isUnique() && !updatedAttr.isUnique()) { Attribute idAttr = entityType.getIdAttribute(); if (idAttr != null && idAttr.getName().equals(attr.getName())) { throw new MolgenisDataException( format( "ID attribute [%s] of entity [%s] must be unique", attr.getName(), entityType.getId())); } dropUniqueKey(entityType, updatedAttr); } else if (!attr.isUnique() && updatedAttr.isUnique()) { createUniqueKey(entityType, updatedAttr); } }
private static Map<String, Object> attributeToMap(Attribute attribute) { Map<String, Object> map = new HashMap<>(); map.put(AttributeMetadata.NAME, attribute.getName()); map.put(AttributeMetadata.LABEL, attribute.getLabel()); map.put(AttributeMetadata.DESCRIPTION, attribute.getDescription()); map.put(AttributeMetadata.TYPE, attribute.getDataType().toString()); map.put(AttributeMetadata.IS_NULLABLE, attribute.isNillable()); map.put(AttributeMetadata.IS_UNIQUE, attribute.isUnique()); if (attribute.getRefEntity() != null) { map.put(AttributeMetadata.REF_ENTITY_TYPE, attribute.getRefEntity().getId()); } return map; } }
private static Map<String, Object> attributeToMap(Attribute attribute) { Map<String, Object> map = new HashMap<String, Object>(); map.put(AttributeMetadata.NAME, attribute.getName()); map.put(AttributeMetadata.LABEL, attribute.getLabel()); map.put(AttributeMetadata.DESCRIPTION, attribute.getDescription()); map.put(AttributeMetadata.TYPE, attribute.getDataType().toString()); map.put(AttributeMetadata.IS_NULLABLE, attribute.isNillable()); map.put(AttributeMetadata.IS_UNIQUE, attribute.isUnique()); if (attribute.getRefEntity() != null) { map.put(AttributeMetadata.REF_ENTITY_TYPE, attribute.getRefEntity().getId()); } return map; } }
@Deprecated public static List<CategoricalOptionV2> getCategoricalOptionsForRefEntity( DataService dataService, EntityType refEntity, String language) { Sort sortOrder = stream(refEntity.getAttributes()) .filter(attribute -> attribute.isVisible() && attribute.isUnique()) .map(sortAttr -> new Sort(sortAttr.getName())) .findFirst() .orElse(null); Attribute labelAttribute = refEntity.getLabelAttribute(language); return dataService .findAll(refEntity.getId(), new QueryImpl<>().sort(sortOrder)) .map( entity -> new CategoricalOptionV2( entity.getIdValue(), entity.getString(labelAttribute.getName()))) .collect(Collectors.toList()); } }
private static List<String> getSqlTableConstraints(EntityType entityType, Attribute attr) { List<String> tableConstraints = Lists.newArrayList(); if (attr.getName().equals(entityType.getIdAttribute().getName())) { tableConstraints.add(getSqlConstraintPrimaryKey(entityType, attr)); } else { if (isSingleReferenceType(attr) && isPersistedInPostgreSql(attr.getRefEntity())) { tableConstraints.add(getSqlForeignKey(entityType, attr)); } if (attr.isUnique()) { tableConstraints.add(getSqlUniqueKey(entityType, attr)); } if (attr.getDataType() == ENUM) { tableConstraints.add(getSqlCheckConstraint(entityType, attr)); } } return tableConstraints; }
this.unique = attr.isUnique(); } else this.unique = null;
.filter(attr -> attr.isUnique() && attr.getExpression() == null) .collect(toList());
if (!ownIdAttr.isUnique()) { throw new MolgenisValidationException( new ConstraintViolation(
void validateDefaultValue(Attribute attr, boolean validateEntityReferences) { String value = attr.getDefaultValue(); if (value != null) { if (attr.isUnique()) { throw new MolgenisDataException( "Unique attribute " + attr.getName() + " cannot have default value");
this.defaultValue = attr.getDefaultValue(); this.labelAttribute = attr.equals(entityType.getLabelAttribute()); this.unique = attr.isUnique(); this.lookupAttribute = entityType.getLookupAttribute(attr.getName()) != null; this.isAggregatable = attr.isAggregatable();
Long rangeMax = attribute.getRangeMax(); boolean readonly = attribute.isReadOnly(); boolean unique = attribute.isUnique(); ImmutableList<EditorTagIdentifier> tags = tagMapper.toEditorTags(attribute.getTags()); String nullableExpression = attribute.getNullableExpression();