use of datawave.webservice.model.ModelList in project datawave by NationalSecurityAgency.
the class ModelBean method listModelNames.
/**
* Get the names of the models
*
* @param modelTableName
* name of the table that contains the model
* @return datawave.webservice.model.ModelList
* @RequestHeader X-ProxiedEntitiesChain use when proxying request for user
*
* @HTTP 200 success
* @HTTP 500 internal server error
*/
@GET
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff", "text/html" })
@Path("/list")
@GZIP
@Interceptors(ResponseInterceptor.class)
public ModelList listModelNames(@QueryParam("modelTableName") String modelTableName) {
if (modelTableName == null) {
modelTableName = defaultModelTableName;
}
ModelList response = new ModelList(jqueryUri, dataTablesUri, modelTableName);
// Find out who/what called this method
Principal p = ctx.getCallerPrincipal();
String user = p.getName();
Set<Authorizations> cbAuths = new HashSet<>();
if (p instanceof DatawavePrincipal) {
DatawavePrincipal cp = (DatawavePrincipal) p;
user = cp.getShortName();
for (Collection<String> auths : cp.getAuthorizations()) {
cbAuths.add(new Authorizations(auths.toArray(new String[auths.size()])));
}
}
log.trace(user + " has authorizations " + cbAuths);
Connector connector = null;
HashSet<String> modelNames = new HashSet<>();
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
connector = connectionFactory.getConnection(AccumuloConnectionFactory.Priority.LOW, trackingMap);
try (Scanner scanner = ScannerHelper.createScanner(connector, this.checkModelTableName(modelTableName), cbAuths)) {
for (Entry<Key, Value> entry : scanner) {
String colf = entry.getKey().getColumnFamily().toString();
if (!RESERVED_COLF_VALUES.contains(colf) && !modelNames.contains(colf)) {
String[] parts = colf.split(ModelKeyParser.NULL_BYTE);
if (parts.length == 1)
modelNames.add(colf);
else if (parts.length == 2)
modelNames.add(parts[0]);
}
}
}
} catch (Exception e) {
QueryException qe = new QueryException(DatawaveErrorCode.MODEL_NAME_LIST_ERROR, e);
log.error(qe);
response.addException(qe.getBottomQueryException());
throw new DatawaveWebApplicationException(qe, response);
} finally {
if (null != connector) {
try {
connectionFactory.returnConnection(connector);
} catch (Exception e) {
log.error("Error returning connection to factory", e);
}
}
}
response.setNames(modelNames);
return response;
}
use of datawave.webservice.model.ModelList in project datawave by NationalSecurityAgency.
the class ModelBeanTest method testListModels.
@Test
public void testListModels() throws Exception {
importModels();
PowerMock.resetAll();
EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal);
HashMap<String, String> trackingMap = new HashMap<>();
EasyMock.expect(connectionFactory.getTrackingMap((StackTraceElement[]) EasyMock.anyObject())).andReturn(trackingMap);
EasyMock.expect(connectionFactory.getConnection(EasyMock.eq(AccumuloConnectionFactory.Priority.LOW), EasyMock.eq(trackingMap))).andReturn(connector);
connectionFactory.returnConnection(connector);
PowerMock.replayAll();
ModelList list = bean.listModelNames((String) null);
PowerMock.verifyAll();
Assert.assertEquals(2, list.getNames().size());
Assert.assertTrue(list.getNames().contains(MODEL_ONE.getName()));
Assert.assertTrue(list.getNames().contains(MODEL_TWO.getName()));
}
use of datawave.webservice.model.ModelList in project datawave by NationalSecurityAgency.
the class ModelBean method importModel.
/**
* <strong>Administrator credentials required.</strong> Insert a new model
*
* @param model
* @param modelTableName
* name of the table that contains the model
* @return datawave.webservice.result.VoidResponse
* @RequestHeader X-ProxiedEntitiesChain use when proxying request for user
*
* @HTTP 200 success
* @HTTP 412 if model already exists with this name, delete it first
* @HTTP 500 internal server error
*/
@POST
@Consumes({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml" })
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/import")
@GZIP
@RolesAllowed({ "Administrator", "JBossAdministrator" })
@Interceptors(ResponseInterceptor.class)
public VoidResponse importModel(datawave.webservice.model.Model model, @QueryParam("modelTableName") String modelTableName) {
if (modelTableName == null) {
modelTableName = defaultModelTableName;
}
if (log.isDebugEnabled()) {
log.debug("modelTableName: " + (null == modelTableName ? "" : modelTableName));
}
VoidResponse response = new VoidResponse();
ModelList models = listModelNames(modelTableName);
if (models.getNames().contains(model.getName()))
throw new PreConditionFailedException(null, response);
insertMapping(model, modelTableName);
return response;
}
use of datawave.webservice.model.ModelList in project datawave by NationalSecurityAgency.
the class ModelBean method deleteModel.
private VoidResponse deleteModel(@Required("name") String name, String modelTableName, boolean reloadCache) {
if (log.isDebugEnabled()) {
log.debug("model name: " + name);
log.debug("modelTableName: " + (null == modelTableName ? "" : modelTableName));
}
VoidResponse response = new VoidResponse();
ModelList models = listModelNames(modelTableName);
if (!models.getNames().contains(name))
throw new NotFoundException(null, response);
datawave.webservice.model.Model model = getModel(name, modelTableName);
deleteMapping(model, modelTableName, reloadCache);
return response;
}
Aggregations