Example usage for com.amazonaws.services.simpledb.model DeleteAttributesRequest DeleteAttributesRequest

List of usage examples for com.amazonaws.services.simpledb.model DeleteAttributesRequest DeleteAttributesRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model DeleteAttributesRequest DeleteAttributesRequest.

Prototype

public DeleteAttributesRequest(String domainName, String itemName, java.util.List<Attribute> attributes) 

Source Link

Document

Constructs a new DeleteAttributesRequest object.

Usage

From source file:c3.ops.priam.aws.SDBInstanceData.java

License:Apache License

/**
 * Deregister instance (same as delete)//from ww  w  .  j a  v  a  2 s.  c o m
 *
 * @param instance
 * @throws AmazonServiceException
 */
public void deregisterInstance(PriamInstance instance) throws AmazonServiceException {
    AmazonSimpleDBClient simpleDBClient = getSimpleDBClient();
    DeleteAttributesRequest delReq = new DeleteAttributesRequest(DOMAIN, getKey(instance),
            createAttributesToDeRegister(instance));
    simpleDBClient.deleteAttributes(delReq);
}

From source file:com.brighttag.agathon.dao.sdb.SdbCassandraInstanceDao.java

License:Apache License

@Override
public void delete(String ring, CassandraInstance instance) {
    DeleteAttributesRequest request = new DeleteAttributesRequest(domain(ring),
            String.valueOf(instance.getId()), buildDeleteAttributes(instance));
    client.deleteAttributes(request);//  w ww.  j  a va2  s. co  m
}

From source file:com.tremolosecurity.provisioning.core.providers.AmazonSimpleDBProvider.java

License:Apache License

@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request)
        throws ProvisioningException {
    User amazonUser = this.findUser(user.getAttribs().get(this.uidAttrName).getValues().get(0), attributes,
            request);// w  w w. j av  a2 s  .  com
    if (amazonUser == null) {
        this.createUser(user, attributes, request);
        return;
    }

    int approvalID = 0;

    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }

    Workflow workflow = (Workflow) request.get("WORKFLOW");

    String userid = user.getAttribs().get(this.uidAttrName).getValues().get(0);

    Set<String> done = new HashSet<String>();

    Iterator<String> amazonAttrNames = amazonUser.getAttribs().keySet().iterator();
    while (amazonAttrNames.hasNext()) {
        String amznAttrName = amazonAttrNames.next();
        done.add(amznAttrName);
        Attribute userAttr = user.getAttribs().get(amznAttrName);
        if (userAttr == null) {
            if (addOnly) {
                //do nothing
            } else {
                ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                list.add(new com.amazonaws.services.simpledb.model.Attribute(amznAttrName.toLowerCase(), null));
                sdb.deleteAttributes(
                        new DeleteAttributesRequest(this.userDomain, amazonUser.getUserID(), list));
                boolean ok = false;
                while (!ok) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {

                    }

                    StringBuffer select = new StringBuffer();
                    select.append("SELECT uid FROM `").append(this.userDomain).append("` WHERE uid='")
                            .append(userid).append("' AND ").append(amznAttrName).append(" IS NOT NULL");

                    SelectResult res = this.sdb.select(new SelectRequest(select.toString()));

                    ok = res.getItems().size() == 0;
                }
            }
        } else {
            Set<String> vals = new HashSet<String>();
            vals.addAll(userAttr.getValues());

            List<String> amznVals = amazonUser.getAttribs().get(amznAttrName).getValues();

            for (String val : amznVals) {

                if (vals.contains(val)) {
                    vals.remove(val);
                } else {
                    if (!addOnly) {
                        ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                        list.add(new com.amazonaws.services.simpledb.model.Attribute(
                                userAttr.getName().toLowerCase(), val));
                        sdb.deleteAttributes(
                                new DeleteAttributesRequest(this.userDomain, amazonUser.getUserID(), list));
                        this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Delete,
                                approvalID, workflow, userAttr.getName().toLowerCase(), val);
                        boolean ok = false;
                        while (!ok) {
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {

                            }

                            StringBuffer select = new StringBuffer();
                            select.append("SELECT uid FROM `").append(this.userDomain).append("` WHERE uid='")
                                    .append(userid).append("' AND ").append(userAttr.getName().toLowerCase())
                                    .append("='").append(val).append("'");

                            SelectResult res = this.sdb.select(new SelectRequest(select.toString()));

                            ok = res.getItems().size() == 0;
                        }
                    }
                }
            }

            if (vals.size() > 0) {
                ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();

                Iterator<String> itv = vals.iterator();

                while (itv.hasNext()) {
                    String val = itv.next();
                    list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(
                            userAttr.getName().toLowerCase(), val, false));
                }

                sdb.putAttributes(new PutAttributesRequest(this.userDomain, amazonUser.getUserID(), list));

                itv = vals.iterator();

                while (itv.hasNext()) {
                    String val = itv.next();
                    this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Replace,
                            approvalID, workflow, userAttr.getName().toLowerCase(), val);
                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {

                }

            }

        }

        Iterator<String> itattr = user.getAttribs().keySet().iterator();
        while (itattr.hasNext()) {
            String name = itattr.next();
            if (attributes.contains(name) && !done.contains(name)) {
                ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();
                for (String val : user.getAttribs().get(name).getValues()) {
                    list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(name.toLowerCase(),
                            val, false));
                }

                sdb.putAttributes(new PutAttributesRequest(this.userDomain, amazonUser.getUserID(), list));

                for (String val : user.getAttribs().get(name).getValues()) {
                    this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID,
                            workflow, name, val);
                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {

                }
            }
        }

        String select = this.getGroupSelect(amazonUser.getUserID());

        SelectResult res = this.sdb.select(new SelectRequest(select));
        done.clear();
        for (Item group : res.getItems()) {
            String name = group.getName();
            if (!user.getGroups().contains(name) && !addOnly) {
                ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                list.add(new com.amazonaws.services.simpledb.model.Attribute(
                        GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(),
                        amazonUser.getUserID()));
                sdb.deleteAttributes(new DeleteAttributesRequest(this.groupDomain, name, list));

                this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Delete, approvalID,
                        workflow, "group", name);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {

                }
            }

            done.add(name);
        }

        for (String groupName : user.getGroups()) {
            if (done.contains(groupName)) {
                continue;
            }

            ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();
            list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(
                    GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(),
                    amazonUser.getUserID(), false));
            sdb.putAttributes(new PutAttributesRequest(this.groupDomain, groupName, list));
            this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID,
                    workflow, "group", groupName);
        }

    }

}

From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java

License:Apache License

private void deleteAttributesInternal(String domainName, String id, List<Attribute> attributes, int attempt)
        throws DataAccessException {
    if (!attributes.isEmpty()) {
        DeleteAttributesRequest request = new DeleteAttributesRequest(domainName, id, attributes);
        try {/*from w  ww  .  j  a v a2  s. c  om*/
            sdb.deleteAttributes(request);
        } catch (AmazonServiceException e) {
            if (SimpleDBUtil.AWS_ERR_CODE_NO_SUCH_DOMAIN.equals(e.getErrorCode())) {
                throw new IllegalArgumentException("no such domain: " + domainName, e);
            } else if (SimpleDBUtil.AWS_ERR_CODE_SERVICE_UNAVAILABLE.equals(e.getErrorCode())) {
                //retry after a small pause
                SimpleDBUtil.sleepBeforeRetry(attempt);
                attempt++;
                deleteAttributesInternal(domainName, id, attributes, attempt);
            } else {
                throw e;
            }
        }
    }
}