use of io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO in project hopsworks by logicalclocks.
the class SubjectsController method checkIfSchemaRegistered.
public SubjectDTO checkIfSchemaRegistered(Project project, String subject, String schemaContent) throws SchemaException {
if (!subjectsFacade.getListOfSubjects(project).contains(subject)) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SUBJECT_NOT_FOUND, Level.FINE, "subject=" + subject);
}
Schema schema;
try {
schema = new Schema.Parser().parse(schemaContent);
} catch (SchemaParseException e) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INVALID_AVRO_SCHEMA, Level.FINE, "schema=" + schemaContent);
}
Optional<Subjects> optional = subjectsFacade.findSubjectByNameAndSchema(project, subject, schema.toString());
if (!optional.isPresent()) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SCHEMA_NOT_FOUND, Level.FINE, "schema=" + schema.toString());
}
return new SubjectDTO(optional.get());
}
use of io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO in project hopsworks by logicalclocks.
the class SubjectsController method getSubjectDetails.
public SubjectDTO getSubjectDetails(Project project, String subject, String version) throws SchemaException {
validateVersion(version);
if (subjectsFacade.findSubjectByName(project, subject).isEmpty()) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SUBJECT_NOT_FOUND, Level.FINE, "subject=" + subject);
}
Optional<Subjects> optional;
if (version.equals("latest")) {
optional = subjectsFacade.findSubjectLatestVersion(project, subject);
} else {
optional = subjectsFacade.findSubjectByNameAndVersion(project, subject, Integer.valueOf(version));
}
if (optional.isPresent()) {
Subjects res = optional.get();
return new SubjectDTO(res.getSchema().getId(), res.getSubject(), res.getVersion(), res.getSchema().getSchema());
} else {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.VERSION_NOT_FOUND, Level.FINE, "subject=" + subject + ", version=" + version);
}
}
Aggregations