/** PUT /users -> Updates an existing User. */ @RequestMapping( value = "/users", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed @Transactional @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<ManagedUserDTO> updateUser(@RequestBody ManagedUserDTO managedUserDTO) throws URISyntaxException { log.debug("REST request to update User : {}", managedUserDTO); return Optional.of(userRepository.findOne(managedUserDTO.getId())) .map( user -> { user.setLogin(managedUserDTO.getLogin()); user.setFirstName(managedUserDTO.getFirstName()); user.setLastName(managedUserDTO.getLastName()); user.setEmail(managedUserDTO.getEmail()); user.setActivated(managedUserDTO.isActivated()); user.setLangKey(managedUserDTO.getLangKey()); Set<Authority> authorities = user.getAuthorities(); authorities.clear(); managedUserDTO .getAuthorities() .stream() .forEach(authority -> authorities.add(authorityRepository.findOne(authority))); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert("user", managedUserDTO.getLogin())) .body(new ManagedUserDTO(userRepository.findOne(managedUserDTO.getId()))); }) .orElseGet(() -> new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); }
/** GET /account -> get the current user. */ @RequestMapping( value = "/account", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<UserDTO> getAccount() { User user = userService.getUserWithAuthorities(); if (user == null) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } List<String> roles = new ArrayList<>(); for (Authority authority : user.getAuthorities()) { roles.add(authority.getName()); } Set<ExternalAccount> externalAccounts = new HashSet<>(); for (ExternalAccount eAccount : user.getExternalAccounts()) { externalAccounts.add(eAccount); } return new ResponseEntity<>( new UserDTO( user.getLogin(), null, user.getFirstName(), user.getLastName(), user.getEmail(), user.getLangKey(), roles, externalAccounts), HttpStatus.OK); }
private void findAliases(Term primeTerm, String target, String prefix) { Morpher morpher = null; try { morpher = new Morpher(target); if (morpher.getData()) { Set<String> aliases = new HashSet<String>(); for (Morpher.Morph morph : morpher.getAllMorph()) { if (morph == null) { return; } String alias = prefix + morph.text; if (morph != null && !alias.isEmpty() && !alias.equals(primeTerm.getName())) { if (!aliases.contains(alias)) { TermMorph termMorph = commonDao.get(TermMorph.class, alias); if (termMorph == null) { commonDao.save(new TermMorph(alias, primeTerm.getUri())); log.info("Alias added: " + alias); } aliases.add(alias); } } } /* for (Map.Entry<String, Term> entry : aliases.entrySet()) { if (primeTerm.getUri().equals(entry.getValue().generateUri())) continue; commonDao.save(new Link(primeTerm, entry.getValue(), Link.ALIAS, Link.MORPHEME_WEIGHT)); }*/ } } catch (Exception e) { log.throwing(getClass().getName(), "findAliases", e); throw new RuntimeException(e); } }
public String getGenericNameByRxcui(Long rxcui) throws IOException { if (rxcui == null) { return ""; } UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.nlmRxnavUrl + "/" + rxcui + "/allProperties.json") .queryParam("prop", "names"); String result = rest.getForObject(builder.build().toUri(), String.class); FieldFinder finder = new FieldFinder("propValue"); Set<String> generics = finder.find(result); if (generics.isEmpty()) { return ""; } else { return generics.iterator().next(); } }
/** * PUT /users : Updates an existing User. * * @param managedUserDTO the user to update * @return the ResponseEntity with status 200 (OK) and with body the updated user, or with status * 400 (Bad Request) if the login or email is already in use, or with status 500 (Internal * Server Error) if the user couldnt be updated */ @RequestMapping( value = "/users", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed @Transactional @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<ManagedUserDTO> updateUser(@RequestBody ManagedUserDTO managedUserDTO) { log.debug("REST request to update User : {}", managedUserDTO); Optional<User> existingUser = userRepository.findOneByEmail(managedUserDTO.getEmail()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserDTO.getId()))) { return ResponseEntity.badRequest() .headers( HeaderUtil.createFailureAlert( "userManagement", "emailexists", "E-mail already in use")) .body(null); } existingUser = userRepository.findOneByLogin(managedUserDTO.getLogin().toLowerCase()); if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserDTO.getId()))) { return ResponseEntity.badRequest() .headers( HeaderUtil.createFailureAlert("userManagement", "userexists", "Login already in use")) .body(null); } return userRepository .findOneById(managedUserDTO.getId()) .map( user -> { user.setLogin(managedUserDTO.getLogin()); user.setFirstName(managedUserDTO.getFirstName()); user.setLastName(managedUserDTO.getLastName()); user.setEmail(managedUserDTO.getEmail()); user.setActivated(managedUserDTO.isActivated()); user.setLangKey(managedUserDTO.getLangKey()); Set<Authority> authorities = user.getAuthorities(); authorities.clear(); managedUserDTO .getAuthorities() .stream() .forEach(authority -> authorities.add(authorityRepository.findOne(authority))); return ResponseEntity.ok() .headers( HeaderUtil.createAlert("userManagement.updated", managedUserDTO.getLogin())) .body(new ManagedUserDTO(userRepository.findOne(managedUserDTO.getId()))); }) .orElseGet(() -> new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); }
@RequestMapping("related") @Model @ResponseBody public Collection<ModelMap> getRelated(@RequestParam String uri) { Set<UID> related = new LinkedHashSet<UID>(); for (Link link : linkDao.getRelated(uri)) { if (!ABBREVIATION.equals(link.getType()) && link.getQuote() == null) { if (link.getUid1().getUri().equals(uri)) { related.add(link.getUid2()); } else { related.add(link.getUid1()); } } } return convertToPlainObjects( related, new ValueObjectUtils.Modifier<UID>() { @Override public void modify(UID entity, ModelMap map) { map.remove("content"); } }); }
@ResponseBody @RequestMapping( value = "getIpAddressAllByGroupIdBYBBSA", method = RequestMethod.POST, produces = MediaTypes.JSON) public Set<String> getIpAddressAllByGroupIdBYBBSA( @RequestParam("id") Integer id, HttpServletRequest request) throws SQLException { Set<String> ipAddressList = new HashSet<String>(); List<GroupBean> groupBeanList = new ArrayList<GroupBean>(); // 选中的组 BLGroup groupNode = groupService.findByGroupId(id); // 子组 List<BLGroup> groupList = groupService.getAllChildrenGroup(id, new ArrayList<BLGroup>()); groupList.add(groupNode); List<Integer> ordinaryGroupList = new ArrayList<Integer>(); List<Integer> smartGroups = new ArrayList<Integer>(); for (BLGroup blGroup : groupList) { if (blGroup.getGROUP_TYPE_ID() == 1) { if (blGroup.getGROUP_TYPE_ID() instanceof Integer) ordinaryGroupList.add(blGroup.getGROUP_ID()); } else { smartGroups.add(blGroup.getGROUP_ID()); } } String ordinaryGroups = ""; for (Integer g : ordinaryGroupList) ordinaryGroups += "," + g; if (ordinaryGroupList.size() > 0) { String groupIDwhere = ordinaryGroups.substring(1, ordinaryGroups.length()); if (",".equals(groupIDwhere.substring(groupIDwhere.length() - 1, groupIDwhere.length()))) { groupIDwhere = groupIDwhere.substring(0, groupIDwhere.length() - 1); } SessionImplementor sessionImplementor = (SessionImplementor) entityManager.getDelegate(); Connection connection = sessionImplementor.connection(); Statement statement = connection.createStatement(); String sql = "select blgroup_device.device_id,blgroup_device.group_id,server.name IP_ADDRESS " + "from blgroup_device,device server,blgroup where server.agent_state_id=100 and server.device_state_id=50 " + "and blgroup_device.device_id=server.device_id and blgroup_device.group_id=blgroup.group_id " + "and blgroup.group_id in (" + groupIDwhere + ")"; System.out.println("SQL: " + sql); ResultSet resultSet = statement.executeQuery(sql); if (resultSet.next()) { ipAddressList.add(resultSet.getString("IP_ADDRESS")); } } if (smartGroups.size() > 0) { SessionImplementor sessionImplementor = (SessionImplementor) entityManager.getDelegate(); Connection connection = sessionImplementor.connection(); Statement statement = connection.createStatement(); for (Integer groupid : smartGroups) { SmartGroup smartGroup = smartGroupService.findWithGroupId(groupid); if (null != smartGroup) { String sql = smartGroup.getQUERY_STRING().substring(0, smartGroup.getQUERY_STRING().length() - 1); ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()) { ipAddressList.add(resultSet.getString("IP_ADDRESS")); } } } } return ipAddressList; // deviceFilter.deviceFilterRole(ipAddressList,UserNameUtil.getUserNameByRequest(request)); }
@RequestMapping(value = "/", method = RequestMethod.GET) @Model public ModelMap get( @RequestParam("name") String termName, @RequestParam(required = false) boolean mark) { termName = termName.replace("_", " "); TermsMap.TermProvider provider = termsMap.getTermProvider(termName); if (provider == null) { throw new QuietException(format("Термин `%s` отсутствует", termName)); } if (provider.hasMainTerm()) { provider = provider.getMainTermProvider(); } ModelMap modelMap = new ModelMap(); // (ModelMap) getModelMap(term); Term term = provider.getTerm(); modelMap.put("uri", term.getUri()); modelMap.put("name", term.getName()); if (mark) { if (term.getTaggedShortDescription() == null && term.getShortDescription() != null) { term.setTaggedShortDescription(termsMarker.mark(term.getShortDescription())); termDao.save(term); } if (term.getTaggedDescription() == null && term.getDescription() != null) { term.setTaggedDescription(termsMarker.mark(term.getDescription())); termDao.save(term); } modelMap.put("shortDescription", term.getTaggedShortDescription()); modelMap.put("description", term.getTaggedDescription()); } else { modelMap.put("shortDescription", term.getShortDescription()); modelMap.put("description", term.getDescription()); } // LINKS List<ModelMap> quotes = new ArrayList<ModelMap>(); Set<UID> related = new LinkedHashSet<UID>(); Set<UID> aliases = new LinkedHashSet<UID>(); UID code = null; List<Link> links = linkDao.getAllLinks(term.getUri()); for (Link link : links) { UID source = link.getUid1().getUri().equals(term.getUri()) ? link.getUid2() : link.getUid1(); if (link.getQuote() != null || source instanceof Item) { quotes.add(getQuote(link, source, mark)); } else if (ABBREVIATION.equals(link.getType()) || ALIAS.equals(link.getType())) { aliases.add(source); } else if (CODE.equals(link.getType())) { code = source; } else { related.add(source); } } // Нужно также включить цитаты всех синонимов и сокращений и кода Set<UID> aliasesQuoteSources = new HashSet<UID>(aliases); if (code != null) { aliasesQuoteSources.add(code); } for (UID uid : aliasesQuoteSources) { List<Link> aliasLinksWithQuote = linkDao.getAllLinks(uid.getUri()); for (Link link : aliasLinksWithQuote) { UID source = link.getUid1().getUri().equals(uid.getUri()) ? link.getUid2() : link.getUid1(); if (link.getQuote() != null || source instanceof Item) { quotes.add(getQuote(link, source, mark)); } else if (ABBREVIATION.equals(link.getType()) || ALIAS.equals(link.getType()) || CODE.equals(link.getType())) { // Синонимы синонимов :) по идее их не должно быть, но если вдруг... // как минимум один есть и этот наш основной термин if (!source.getUri().equals(term.getUri())) { aliases.add(source); } } else { related.add(source); } } } sort( quotes, new Comparator<ModelMap>() { @Override public int compare(ModelMap o1, ModelMap o2) { return ((String) o1.get("uri")).compareTo((String) o2.get("uri")); } }); modelMap.put("code", code); modelMap.put("quotes", quotes); modelMap.put("related", toPlainObjectWithoutContent(related)); modelMap.put("aliases", toPlainObjectWithoutContent(aliases)); modelMap.put("categories", searchController.inCategories(termName)); return modelMap; }