@Override public int hashCode() { return EntityUtils.hashCode(this); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Entity)) return false; return EntityUtils.equals(this, (Entity) o); }
boolean isXrefOrCategorialDataType(Attribute attribute) { return isSingleReferenceType(attribute); }
private Boolean canValueBeUsedAsDate(Object value) { try { MolgenisDateFormat.parseLocalDate(value.toString()); } catch (Exception e) { return false; } return true; } }
private static boolean hasJunctionTable(Attribute attribute) { return isMultipleReferenceType(attribute) && attribute.getDataType() != AttributeType.ONE_TO_MANY; }
/** * Add attribute to entityType. * * @param entityType the {@link EntityType} to add attribute to * @param attr attribute to add */ private void addAttributeInternal(EntityType entityType, Attribute attr) { if (!isPersisted(attr)) { return; } if (isMultipleReferenceType(attr)) { createJunctionTable(entityType, attr); if (attr.getDefaultValue() != null && !attr.isNillable()) { @SuppressWarnings("unchecked") Iterable<Entity> defaultRefEntities = (Iterable<Entity>) AttributeUtils.getDefaultTypedValue(attr); if (!Iterables.isEmpty(defaultRefEntities)) { createJunctionTableRows(entityType, attr, defaultRefEntities); } } } else { createColumn(entityType, attr); } }
private static Instant convertDateTime(Attribute attr, String paramValue) { try { return parseInstant(paramValue); } catch (DateTimeParseException e) { throw new MolgenisDataException( format(FAILED_TO_PARSE_ATTRIBUTE_AS_DATETIME_MESSAGE, attr.getName(), paramValue)); } }
private Resource toResource(Package aPackage) { boolean isSystemPackage = PackageUtils.isSystemPackage(aPackage); return Resource.builder() .setType(ResourceType.PACKAGE) .setId(aPackage.getId()) .setLabel(aPackage.getLabel()) .setDescription(aPackage.getDescription()) .setHidden(isSystemPackage) .setReadonly(isSystemPackage) .build(); }
private void registerIndexAction(IndexAction action) { String entityTypeId = action.getEntityTypeId(); EntityType entityType = dataService.findOneById(ENTITY_TYPE_META_DATA, entityTypeId, EntityType.class); if (entityType != null) { Object typedEntityId = getTypedValue(action.getEntityId(), entityType.getIdAttribute()); indexActionRegisterService.register(entityType, typedEntityId); } } }
@Override public Iterable<String> getEntityTypeIds() { return dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .eq(BACKEND, POSTGRESQL) .fetch(getEntityTypeFetch()) .findAll() .map(EntityType::getId) ::iterator; }
private void validateNotContainsItself(Package pack, Package targetPackage) { if (PackageUtils.contains(pack, targetPackage)) { throw new RecursiveCopyException(); } }
public boolean hasSelfReferences() { return EntityTypeUtils.hasSelfReferences(getTarget()); } }
Stream<String> getEntityTypesDependentOn(String entityTypeId) { return genericDependencyResolver .getAllDependants( entityTypeId, id -> entityTypes.get(id).getIndexingDepth(), this::getReferencingEntities) .stream(); } }
private static LocalDate convertDate(Attribute attr, String paramValue) { try { return parseLocalDate(paramValue); } catch (DateTimeParseException e) { throw new MolgenisDataException( format(FAILED_TO_PARSE_ATTRIBUTE_AS_DATE_MESSAGE, attr.getName(), paramValue)); } } }
static boolean generateSqlColumnDefaultConstraint(Attribute attr) { return attr.getDefaultValue() != null && !EntityTypeUtils.isMultipleReferenceType(attr); }
private Resource toResource(EntityType entityType) { ResourceType type = entityType.isAbstract() ? ENTITY_TYPE_ABSTRACT : ENTITY_TYPE; boolean isSystemEntityType = PackageUtils.isSystemPackage(entityType.getPackage()); return Resource.builder() .setType(type) .setId(entityType.getId()) .setLabel(entityType.getLabel()) .setDescription(entityType.getDescription()) .setHidden(isSystemEntityType) .setReadonly(isSystemEntityType) .build(); }
@Override public Iterator<Repository<Entity>> iterator() { return dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .eq(BACKEND, POSTGRESQL) .and() .eq(IS_ABSTRACT, false) .fetch(getEntityTypeFetch()) .findAll() .map(this::getRepository) .iterator(); }
/** * Returns whether this attribute is stored in the entity table or another table such as a * junction table or referenced entity table. * * @param attr attribute * @return whether this attribute is stored in another table than the entity table */ private static boolean isPersistedInOtherTable(Attribute attr) { boolean bidirectionalOneToMany = attr.getDataType() == ONE_TO_MANY && attr.isMappedBy(); return isMultipleReferenceType(attr) || bidirectionalOneToMany; }
@Override public Repository<Entity> getRepository(String id) { EntityType entityType = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .eq(BACKEND, POSTGRESQL) .and() .eq(ID, id) .and() .eq(IS_ABSTRACT, false) .fetch(getEntityTypeFetch()) .findOne(); return getRepository(entityType); }
static boolean isTableAttribute(Attribute attr) { return !isMultipleReferenceType(attr) && !(attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()); }