{"id":2848,"date":"2013-05-20T13:20:11","date_gmt":"2013-05-20T18:20:11","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2848"},"modified":"2013-05-20T13:20:11","modified_gmt":"2013-05-20T18:20:11","slug":"deleting-profiles-and-all-associated-orders","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/05\/20\/deleting-profiles-and-all-associated-orders\/","title":{"rendered":"Deleting profiles and all associated orders"},"content":{"rendered":"<p>Nothing fancy, just a simple component to delete all profiles with no activity in the last 180 days.  We needed this in our development and QA environments to reclaim disk space.<\/p>\n<pre lang=\"java\" line=\"1\">\r\nimport javax.transaction.TransactionManager;\r\n\r\nimport atg.commerce.order.*;\r\nimport atg.commerce.pricing.*;\r\nimport atg.dtm.*;\r\nimport atg.userprofiling.ProfileTools;\r\n\r\nimport java.io.*;\r\nimport java.sql.*;\r\nimport java.util.*;\r\nimport javax.naming.*;\r\nimport javax.sql.*;\r\n\r\nimport atg.adapter.gsa.*;\r\n\r\nimport atg.core.util.*;\r\n\r\nimport atg.nucleus.*;\r\n\r\nimport atg.repository.*;\r\nimport atg.repository.rql.*;\r\n\r\npublic class deleteProfile extends GenericService {\r\n\r\n  public deleteProfile() {}\r\n\r\n  protected ProfileTools mProfileTools = null;\r\n\r\n  public void setProfileTools(ProfileTools pProfileTools){\r\n    mProfileTools = pProfileTools;\r\n  }\r\n\r\n  public ProfileTools getProfileTools(){\r\n    return mProfileTools;\r\n  }\r\n\r\n  protected OrderTools mOrderTools = null;\r\n\r\n  public void setOrderTools(OrderTools pOrderTools) {\r\n    mOrderTools = pOrderTools;\r\n  }\r\n\r\n  public OrderTools getOrderTools() {\r\n    return mOrderTools;\r\n  }\r\n\r\n  String profileId;\r\n\r\n  public void setProfileId(String profileId) {\r\n    this.profileId = profileId;\r\n  }\r\n\r\n  public String getProfileId() {\r\n    return profileId;\r\n  }\r\n\r\n  public void deleteProfiles () {\r\n    try {\r\n\r\n      InitialContext ic = new InitialContext();\r\n      DataSource ds = (DataSource)ic.lookup(\"java:\/atgcore_ds\");\r\n      Connection conn = ds.getConnection();\r\n      ResultSet rst = conn.createStatement().executeQuery(\"select id from dps_user where lastactivity_date < sysdate - 180\");\r\n      PreparedStatement pst = conn.prepareStatement(\"select order_id from dcspp_order where profile_id = ?\");\r\n      GSARepository r = (GSARepository)Nucleus.getGlobalNucleus().resolveName(\"\/atg\/userprofiling\/ProfileAdapterRepository\");\r\n      MutableRepository mr = (MutableRepository)r;\r\n      OrderManager om = getOrderTools().getProfileTools().getOrderManager();\r\n      RepositoryUtils ru = new RepositoryUtils();\r\n      while (rst.next()) {\r\n        pst.setString(1,rst.getString(1));\r\n        ResultSet rstOrders = pst.executeQuery();\r\n        while (rstOrders.next()) {\r\n          om.removeOrder(rstOrders.getString(1));\r\n        }\r\n        ru.removeReferencesToItem(ru.getMutableRepositoryItem(mr, rst.getString(1), \"user\"));\r\n        mr.removeItem(rst.getString(1),\"user\");\r\n      }\r\n    }\r\n    catch (Exception e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>...and the component properties file...<\/p>\n<pre lang=\"text\">\r\n$class=deleteProfile\r\n$scope=session\r\nprofileId=1\r\norderTools=\/atg\/commerce\/order\/OrderTools\/\r\nprofileTools=\/atg\/userprofiling\/ProfileTools\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Nothing fancy, just a simple component to delete all profiles with no activity in the last 180 days. We needed this in our development and QA environments to reclaim disk space. import javax.transaction.TransactionManager; import atg.commerce.order.*; import atg.commerce.pricing.*; import atg.dtm.*; import&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/05\/20\/deleting-profiles-and-all-associated-orders\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[37,38],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2848"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2848"}],"version-history":[{"count":7,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2848\/revisions"}],"predecessor-version":[{"id":2909,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2848\/revisions\/2909"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2848"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}