use of com.xrtb.db.User in project XRTB by benmfaul.
the class Configuration method deleteUser.
/**
* Delete a user and all the campaigns. Causes a full reload
*
* @param owner
* String. The user deleting this user, the user itself or root.
* @param name
* String. The name of the user being deleted.
* @return boolean. Returns true if the user was deleted, else returns
* false.
* @throws Exception
* on database errors.
*/
public boolean deleteUser(String owner, String name) throws Exception {
User u = Database.getInstance().getUser(owner);
if (u == null)
return false;
Database.getInstance().deleteUser(name);
return true;
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method addUser.
/**
* Add a new user's information.
*
* @param m
* Map. The command parameters.
* @return JSON encoded string of the command return values.
* @throws Exception
* on JSON or cache errors.
*/
private String addUser(Map m) throws Exception {
Map response = new HashMap();
String name = (String) m.get("name");
String pass = (String) m.get("pass");
String directory = (String) m.get("dir");
String phone = (String) m.get("phone");
String email = (String) m.get("email");
String creditcard = (String) m.get("credit");
User u = db.getUser(name);
if (u != null) {
response.put("error", true);
response.put("message", "user already exists");
} else {
u = new User();
u.creditcard = creditcard;
u.password = pass;
u.email = email;
u.directory = directory;
u.phone = phone;
u.email = email;
u.name = name;
u.campaigns = new ArrayList();
db.addUser(u);
response.put("users", makeUsersResponseList());
}
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method multiPart.
public String multiPart(Request baseRequest, HttpServletRequest request, MultipartConfigElement config) throws Exception {
HttpSession session = request.getSession(false);
String user = (String) session.getAttribute("user");
User u = db.getUser(user);
if (u == null)
throw new Exception("No such user");
baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, config);
Collection<Part> parts = request.getParts();
for (Part part : parts) {
System.out.println("" + part.getName());
}
Part filePart = request.getPart("file");
InputStream imageStream = filePart.getInputStream();
byte[] resultBuff = new byte[0];
byte[] buff = new byte[1024];
int k = -1;
while ((k = imageStream.read(buff, 0, buff.length)) > -1) {
// temp buffer size
byte[] tbuff = new byte[resultBuff.length + k];
// = bytes already
// read + bytes last
// read
// copy
System.arraycopy(resultBuff, 0, tbuff, 0, resultBuff.length);
// previous
// bytes
// copy
System.arraycopy(buff, 0, tbuff, resultBuff.length, k);
// current
// lot
// call the temp buffer as your result buff
resultBuff = tbuff;
}
System.out.println(resultBuff.length + " bytes read.");
if (k == 0) {
// no file provided
throw new Exception("No file provided");
} else {
byte[] bytes = new byte[1024];
Part namePart = request.getPart("name");
InputStream nameStream = namePart.getInputStream();
int rc = nameStream.read(bytes);
String name = new String(bytes, 0, rc);
FileOutputStream fos = new FileOutputStream(u.directory + "/" + name);
fos.write(resultBuff);
fos.close();
}
Map response = new HashMap();
response.put("images", getFiles(u));
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method doDeleteCampaign.
/**
* Deletes a campaign from aerospike/cache.
*
* @param m
* Map. The command parameters.
* @return JSON. The JSON encoded return values of the command.
* @throws Exception
* on JSON or cache errors.
*/
private String doDeleteCampaign(Map m) throws Exception {
Map response = new HashMap();
String who = (String) m.get("username");
String id = (String) m.get("campaign");
User u = db.getUser(who);
if (u == null) {
response.put("message", "No user " + who);
return getString(response);
}
Controller.getInstance().sendLog(3, "WebAccess-Delete-Campaign", who + " deleted a campaign " + id);
// delete from bidder
Controller.getInstance().deleteCampaign(who, id);
// delete from
response.put("campaigns", db.deleteCampaign(u, id));
// database
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class DbTools method deleteCampaign.
/**
* Remove a campaign by ad id.
*
* @param adId
* String. The ad id.
* @throws Exception
* if the adid does not exist.
*/
public void deleteCampaign(String adId) throws Exception {
Set set = map.keySet();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String key = it.next();
User u = map.get(key);
for (int i = 0; i < u.campaigns.size(); i++) {
Campaign c = u.campaigns.get(i);
if (c.adId.equals(adId)) {
u.campaigns.remove(i);
dbo.put(u);
return;
}
}
}
throw new Exception("No such campaign");
}
Aggregations