List of usage examples for javax.persistence EntityManager find
public <T> T find(Class<T> entityClass, Object primaryKey);
From source file:org.apache.juddi.v3.auth.JUDDIAuthenticator.java
/** * @return the userId that came in on the request providing the user has * a publishing account in jUDDI.// ww w.j av a 2 s. c o m * @param authorizedName * @param credential * @return authorizedName * @throws AuthenticationException */ public String authenticate(String authorizedName, String credential) throws AuthenticationException { if (authorizedName == null || "".equals(authorizedName)) { throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } log.warn("DO NOT USE JUDDI AUTHENTICATOR FOR PRODUCTION SYSTEMS - DOES NOT VALIDATE PASSWORDS, AT ALL!"); int MaxBindingsPerService = -1; int MaxServicesPerBusiness = -1; int MaxTmodels = -1; int MaxBusinesses = -1; try { MaxBindingsPerService = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1); MaxServicesPerBusiness = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1); MaxTmodels = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1); MaxBusinesses = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER, -1); } catch (Exception ex) { MaxBindingsPerService = -1; MaxServicesPerBusiness = -1; MaxTmodels = -1; MaxBusinesses = -1; log.error("config exception! " + authorizedName, ex); } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) { log.warn("Publisher \"" + authorizedName + "\" was not found, adding the publisher in on the fly."); publisher = new Publisher(); publisher.setAuthorizedName(authorizedName); publisher.setIsAdmin("false"); publisher.setIsEnabled("true"); publisher.setMaxBindingsPerService(MaxBindingsPerService); publisher.setMaxBusinesses(MaxBusinesses); publisher.setMaxServicesPerBusiness(MaxServicesPerBusiness); publisher.setMaxTmodels(MaxTmodels); publisher.setPublisherName("Unknown"); em.persist(publisher); tx.commit(); } return authorizedName; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:com.enioka.jqm.api.ServiceSimple.java
public ServiceSimple(@Context ServletContext context) { if (context.getInitParameter("jqmnodeid") != null) { EntityManager em = null; try {/* ww w .j a va2s .com*/ em = Helpers.getEm(); n = em.find(Node.class, Integer.parseInt(context.getInitParameter("jqmnodeid"))); if (n == null) { throw new RuntimeException( "invalid configuration: no node of ID " + context.getInitParameter("jqmnodeid")); } } finally { Helpers.closeQuietly(em); } } }
From source file:nl.b3p.viewer.stripes.SearchActionBean.java
public Resolution source() throws Exception { EntityManager em = Stripersist.getEntityManager(); JSONArray jsonArray = new JSONArray(); String url = ""; if (appId != null) { Application app = em.find(Application.class, appId); Set components = app.getComponents(); for (Iterator it = components.iterator(); it.hasNext();) { ConfiguredComponent comp = (ConfiguredComponent) it.next(); if (comp.getName().equals(componentName)) { JSONObject config = new JSONObject(comp.getConfig()); if (config.has("searchconfigs")) { JSONArray searchConfig = config.getJSONArray("searchconfigs"); for (int i = 0; i < searchConfig.length(); i++) { JSONObject search = (JSONObject) searchConfig.get(i); if (search.get("id").equals(searchName)) { url = search.get("url").toString(); }//from w w w. j a v a 2 s. co m } } else if (config.has("searchUrl")) { url = config.getString("searchUrl"); } } } } if (url != null && !url.equals("")) { url = url.replace("[ZOEKWOORD]", searchText); JSONObject info = issueRequest(url); if (url.toLowerCase().contains("arcgis")) { jsonArray = (JSONArray) info.get("candidates"); } else { // not arcGis services } } return new StreamingResolution("application/json", new StringReader(jsonArray.toString())); }
From source file:com.intuit.tank.dao.ScriptDao.java
/** * @{inheritDoc/*w ww . j av a 2 s . c om*/ */ @Override public void delete(Integer id) throws HibernateException { EntityManager em = getEntityManager(); begin(); try { Script entity = em.find(Script.class, id); if (entity != null) { // check if it is used in scriptGroups List<ScriptGroupStep> scriptGroupsForScript = new ScriptGroupStepDao() .getScriptGroupsForScript(entity); if (!scriptGroupsForScript.isEmpty()) { StringBuilder sb = new StringBuilder(); for (ScriptGroupStep step : scriptGroupsForScript) { Project p = extractProject(step); if (sb.length() != 0) { sb.append(", "); } if (p != null) { sb.append(p.getName()).append(" (id=").append(p.getId()).append(")"); } else { sb.append("unknown project"); } } if (sb.length() > 0) { // throw exception throw new IllegalArgumentException("Cannot delete script " + entity.getName() + " because it is used in the following projects: " + sb.toString()); } } LOG.debug("deleting entity " + entity.toString()); em.remove(entity); commit(); } } finally { cleanup(); } }
From source file:nl.b3p.viewer.stripes.LayerListActionBean.java
public Resolution source() { EntityManager em = Stripersist.getEntityManager(); JSONArray jsonArray = new JSONArray(); if (appId != null) { Application app = em.find(Application.class, appId); // TODO filter layers according to readers // set writeable according to writers List<ApplicationLayer> filteredLayers = LayerListHelper.getLayers(app.getRoot(), filterable, bufferable, editable, influence, arc, wfs, attribute, hasConfiguredLayers, layers); for (ApplicationLayer layer : filteredLayers) { try { jsonArray.put(layer.toJSONObject()); } catch (JSONException je) { log.error("Error while getting JSONObject of Layer with id: " + layer.getId(), je); }/*from w w w. ja va 2 s .c o m*/ } } return new StreamingResolution("application/json", new StringReader(jsonArray.toString())); }
From source file:nl.b3p.kaartenbalie.struts.PricingAction.java
public LayerPricing getLayerPricing(DynaValidatorForm dynaForm, HttpServletRequest request, boolean createNew) throws Exception { log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(); LayerPricing lp = null;// ww w . ja v a 2s .c o m Integer id = getPricingID(dynaForm); if (null == id && createNew) { lp = new LayerPricing(); } else if (null != id) { lp = (LayerPricing) em.find(LayerPricing.class, id); } return lp; }
From source file:edu.csueb.cs6320.utils.UserService.java
public boolean delete(long userid) { EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager(); User u = em.find(User.class, userid); if (u == null) { return false; }// w w w . ja va 2 s .c o m em.getTransaction().begin(); em.remove(u); em.getTransaction().commit(); em.close(); return true; }
From source file:org.apache.juddi.v3.auth.XMLDocAuthenticator.java
public UddiEntityPublisher identify(String authInfo, String authorizedName) throws AuthenticationException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {//from ww w. ja v a 2 s . c o m tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); return publisher; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:de.zib.gndms.dspace.service.utils.DSpaceAspects.java
@Around(value = "inSliceServiceImpl() && args( subspaceId, sliceKindId, sliceId, .. )") public Object handleSlice(final ProceedingJoinPoint pjp, final String subspaceId, final String sliceKindId, final String sliceId) throws NoSuchElementException, Throwable { // check Rights {/* w w w.j av a 2 s . co m*/ final Slice slice = sliceProvider.getSlice(subspaceId, sliceId); final UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); final String dn = userDetails.getUsername(); final String owner = slice.getOwner(); // TODO: check for user / group rights here // ATTENTION: group can be null if (!owner.equals(dn)) { logger.debug("User " + dn + " tried to access slice " + sliceId + ", owned by " + slice.getOwner() + "."); throw new UnauthorizedException("User " + dn + " does not own slice " + sliceId + "."); } } Object returnvalue = pjp.proceed(); // extend termination time, if it had been published { EntityManager entityManager = emf.createEntityManager(); final TxFrame txf = new TxFrame(entityManager); try { final Slice slice = entityManager.find(Slice.class, sliceId); if (slice.getPublished()) { final DateTime now = new DateTime(DateTimeUtils.currentTimeMillis()); final DateTime month = now.plusMonths(1); if (slice.getTerminationTime().isBefore(month)) { slice.setTerminationTime(month); } } txf.commit(); } finally { txf.finish(); } } return returnvalue; }
From source file:edu.csueb.cs6320.utils.UserService.java
/** * doesnt set password!/*from w w w. ja v a 2 s. c o m*/ * @param alteredUser */ public boolean updateUser(long userid, User alteredUser) { EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager(); User u = em.find(User.class, userid); if (u == null) { return false; } em.getTransaction().begin(); u.setEmail(alteredUser.getEmail()); u.setFirstName(alteredUser.getFirstName()); u.setLastName(alteredUser.getLastName()); u.setRole(alteredUser.getRole()); em.getTransaction().commit(); em.close(); return true; }