@Override protected void processQueryResults(Entity entity, Iterable<Entity> annotationSourceEntities, boolean updateMode) { if (updateMode) { throw new MolgenisDataException("This annotator/filter does not support updating of values"); } List<Entity> refMatches = determineRefMatches(entity, annotationSourceEntities); setGoNLFrequencies(entity, refMatches); } };
@ExceptionHandler(MolgenisDataException.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public ErrorMessageResponse handleMolgenisDataException(MolgenisDataException e) { LOG.error("", e); return new ErrorMessageResponse(Collections.singletonList(new ErrorMessage(e.getMessage()))); }
@Override public void deleteAll() { throw new MolgenisDataException( "Cannot delete all boostrap themes, at least one theme is needed for the application"); }
@ExceptionHandler(MolgenisDataException.class) @ResponseStatus(BAD_REQUEST) @ResponseBody public ErrorMessageResponse handleMolgenisDataException(MolgenisDataException e) { LOG.info("Operation failed.", e); return new ErrorMessageResponse(new ErrorMessage(e.getMessage())); }
static MolgenisDataException createMolgenisDataExceptionIdentifierAndValue() { return new MolgenisDataException( "Operation failed. Entities must provide only an identifier and a value"); }
@ExceptionHandler(MolgenisDataException.class) @ResponseStatus(BAD_REQUEST) public ErrorMessageResponse handleMolgenisDataException(MolgenisDataException e) { LOG.error("", e); return new ErrorMessageResponse(new ErrorMessage(e.getMessage())); }
static MolgenisDataException createMolgenisDataExceptionUnknownIdentifier(int count) { return new MolgenisDataException("Operation failed. Unknown identifier on index " + count); }
private static void validateName(Attribute attr) { // validate entity name (e.g. illegal characters, length) String name = attr.getName(); if (!name.equals(ATTRIBUTE_META_DATA) && !name.equals(ENTITY_TYPE_META_DATA) && !name.equals(PACKAGE)) { try { NameValidator.validateAttributeName(attr.getName()); } catch (MolgenisDataException e) { throw new MolgenisValidationException(new ConstraintViolation(e.getMessage())); } } }
private static void checkHyperlink(String value) { try { new URI(value); } catch (URISyntaxException e) { throw new MolgenisDataException("Default value [" + value + "] is not a valid hyperlink."); } }
/** * Validates the entity ID: - Validates that the entity ID does not contain illegal characters and * validates the name length * * @param entityType entity meta data * @throws MolgenisValidationException if the entity simple name content is invalid or the fully * qualified name, simple name and package name are not consistent */ static void validateEntityId(EntityType entityType) { // validate entity name (e.g. illegal characters, length) String id = entityType.getId(); if (!id.equals(ATTRIBUTE_META_DATA) && !id.equals(ENTITY_TYPE_META_DATA) && !id.equals(PACKAGE)) { try { NameValidator.validateEntityName(entityType.getId()); } catch (MolgenisDataException e) { throw new MolgenisValidationException(new ConstraintViolation(e.getMessage())); } } }
private static void checkForIllegalCharacters(String name) { if (!name.matches("[a-zA-Z0-9_#]+(-[a-z]{2,3})??$")) // FIXME too restrictive { throw new MolgenisDataException( "Invalid characters in: [" + name + "] Only letters (a-z, A-Z), digits (0-9), underscores(_) and hashes (#) are allowed."); } } }
private static void validateName(String name) { if (Character.isDigit(name.charAt(0))) { throw new MolgenisDataException( "Invalid name: [" + name + "] Names must start with a letter."); } }
private static Object throwExceptionUnexpectedQueryValueType( String attrName, Object actualType, String expectedType) { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s]", attrName, actualType.getClass().getSimpleName(), expectedType)); } }
/** Checks if a name is a reserved keyword. */ private static void checkForKeyword(String name) { if (KEYWORDS.contains(name) || KEYWORDS.contains(name.toUpperCase())) { throw new MolgenisDataException( "Name [" + name + "] is not allowed because it is a reserved keyword."); } }
@Override public Repository<Entity> getRepository(String name) { if (!repositories.containsKey(name)) { throw new MolgenisDataException(format("Unknown entity name [%s]", name)); } return repositories.get(name); }
@Override public Optional<Entity> filterResults(Iterable<Entity> results, Entity annotatedEntity, boolean updateMode) { if (updateMode == true) { throw new MolgenisDataException("This annotator/filter does not support updating of values"); } return FluentIterable.from(results).first(); }
private void checkEmail(String value) { if (!emailValidator.isValid(value, null)) { throw new MolgenisDataException("Default value [" + value + "] is not a valid email address"); } }
private void checkAndUpdateAppSettings(Object id) { if (appSettings.getBootstrapTheme().equals(id)) { throw new MolgenisDataException("Cannot delete the currently selected bootstrap theme"); } } }
@Override public void flush() { try { csvWriter.flush(); } catch (IOException e) { throw new MolgenisDataException("Error flushing csvwriter", e); } }
@Override public Repository addEntityMeta(EntityMetaData entityMeta) { String entityName = entityMeta.getName(); if (!entityName.equals(IdCardBiobank.ENTITY_NAME)) { throw new MolgenisDataException("Not a valid backend for entity [" + entityName + "]"); } else if (repositories.containsKey(IdCardBiobank.ENTITY_NAME)) { throw new MolgenisDataException( "ID-Card repository collection already contains repository [" + entityName + "]"); } else { repositories.put(IdCardBiobank.ENTITY_NAME, idCardBiobankRepository); } return idCardBiobankRepository; }