Search in sources :

Example 1 with User

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;
}
Also used : User(com.xrtb.db.User)

Example 2 with User

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);
}
Also used : User(com.xrtb.db.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with User

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);
}
Also used : User(com.xrtb.db.User) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) Part(javax.servlet.http.Part) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with User

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);
}
Also used : User(com.xrtb.db.User) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with User

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");
}
Also used : Set(java.util.Set) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign)

Aggregations

User (com.xrtb.db.User)28 Campaign (com.xrtb.common.Campaign)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 Map (java.util.Map)9 List (java.util.List)7 RTBServer (com.xrtb.bidder.RTBServer)5 Configuration (com.xrtb.common.Configuration)5 DbTools (com.xrtb.tools.DbTools)5 Test (org.junit.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Node (com.xrtb.common.Node)3 BidRequest (com.xrtb.pojo.BidRequest)3 File (java.io.File)2 Set (java.util.Set)2 HttpSession (javax.servlet.http.HttpSession)2 BeforeClass (org.junit.BeforeClass)2 AddCampaign (com.xrtb.commands.AddCampaign)1 DeleteCampaign (com.xrtb.commands.DeleteCampaign)1 DataBaseObject (com.xrtb.db.DataBaseObject)1