List of usage examples for com.liferay.portal.kernel.util PropsUtil get
public static String get(String key)
From source file:de.fhg.fokus.odp.portal.datasets.searchresults.BrowseDataSetsSearchResults.java
/** * Constructor initializes our {@link CKANGateway} and * {@link #openLicensesId}.// w ww. j a v a 2 s . com */ public BrowseDataSetsSearchResults() { this.ckanGW = new CKANGateway(PropsUtil.get("cKANurl") + "/", PropsUtil.get("authenticationKey")); this.openLicensesId = new ArrayList<String>(); fillOpenLicensesId(); }
From source file:de.fhg.fokus.odp.portal.datasets.SelectedMetadata.java
License:Open Source License
/** * Send mail.//from w w w .ja v a2s. c o m * * @throws MessagingException * the messaging exception * @throws SystemException * @throws PortalException */ private void sendMail() throws MessagingException, PortalException, SystemException { // get some global objects LiferayFacesContext lfc = LiferayFacesContext.getInstance(); ThemeDisplay tD = lfc.getThemeDisplay(); PortletRequest request = (PortletRequest) lfc.getExternalContext().getRequest(); String metadataUrl = LiferayFacesContext.getInstance().getThemeDisplay().getLayout().getFriendlyURL(); metadataUrl += "/-/details/" + metadata.getName(); // get the email subject and body String subject = LanguageUtil.get(request.getLocale(), "od.datasets.comment.email.subject") + " " + metadata.getType().getDisplayName(); String body = LanguageUtil.get(request.getLocale(), "od.datasets.comment.email.body.comment") + "\t" + newComment; body += "\n\n" + LanguageUtil.get(request.getLocale(), "od.datasets.comment.email.body.metadata") + "\t" + metadata.getTitle() + "\n\t" + metadata.getName() + "\n\t" + portalUrl(metadataUrl); body += "\n\n" + LanguageUtil.get(request.getLocale(), "od.datasets.comment.email.body.user") + "\t" + UserLocalServiceUtil.getUser(tD.getUserId()).getLogin(); // get the from address String fromStr = PortalUtil.getPortalProperties().getProperty("admin.email.from.address"); if (fromStr == null || fromStr.matches("^\\s*$")) { try { fromStr = PrefsPropsUtil.getString(tD.getCompanyId(), "admin.email.from.address"); } catch (SystemException e) { logger.error("sendMail:SystemException:" + e.getMessage()); return; } } // check if an address can be send out if (fromStr == null || fromStr.matches("^\\s*%")) { logger.error("No from email address found"); return; } InternetAddress from = new InternetAddress(fromStr); // prepare the properties and session Properties props = new Properties(); String smtpHost = PropsUtil.get("mail.session.mail.smtp.host"); if (smtpHost == null || smtpHost.matches("^\\s*$")) { logger.error("No smtp host specified"); return; } props.put("mail.smtp.host", smtpHost); String port = PropsUtil.get("mail.session.mail.smtp.port"); if (port != null && !port.matches("^\\s*$")) { props.put("mail.smtp.port", port); } Session session = Session.getDefaultInstance(props); // start with building up the message Message msg = new MimeMessage(session); // get all the email addresses List<Contact> cLs = metadata.getContacts(); for (int i = 0; i < cLs.size(); i++) { try { logger.debug(cLs.get(i).getEmail()); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(cLs.get(i).getEmail())); } catch (AddressException e) { logger.warn(e.getMessage() + ": " + cLs.get(i).getEmail()); } catch (Exception e) { logger.error(e.getMessage()); } } // add BCC for observing comments msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(PropsUtil.get("mail.comment.cc.address"))); msg.setContent(body, "text/plain"); msg.setFrom(from); msg.setSubject(subject); Transport.send(msg); }
From source file:de.fhg.fokus.odp.portal.datasets.SelectedMetadata.java
License:Open Source License
/** * //from www. ja v a 2 s. c o m * @return The URL to CKAN API of this metadata */ public String getMetadataCKANUrl() { return PropsUtil.get("cKANurlFriendly") + "api/rest/dataset/" + metadata.getName(); }
From source file:de.fhg.fokus.odp.portal.managedatasets.controller.CurrentUser.java
License:Open Source License
/** * Inits the.//from w w w. j a v a2 s. com */ @PostConstruct public void init() { Properties props = new Properties(); props.setProperty("ckan.authorization.key", PropsUtil.get("authenticationKey")); props.setProperty("ckan.url", PropsUtil.get("cKANurl")); LOG.debug("odRClient props:" + props.toString()); odrClient = OpenDataRegistry.getClient(); odrClient.init(props); PortletRequest request = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); @SuppressWarnings("unchecked") Map<String, String> userInfo = (Map<String, String>) request.getAttribute(PortletRequest.USER_INFO); if (userInfo != null) { String loginid = userInfo.get("user.login.id"); if (loginid != null) { currentUser = odrClient.findUser(loginid); } } }
From source file:de.fhg.fokus.odp.portal.managedatasets.controller.ManageController.java
License:Open Source License
/** * Inits the.//from ww w . j a v a 2 s . c o m * */ @PostConstruct private void init() { LiferayFacesContext lfc = LiferayFacesContext.getInstance(); PortletRequest request = (PortletRequest) lfc.getExternalContext().getRequest(); ThemeDisplay td = lfc.getThemeDisplay(); Properties props = new Properties(); if (metadataController.getMetadata().getType().equals(MetadataEnumType.APPLICATION)) { props.setProperty("ckan.authorization.key", PropsUtil.get("authenticationKeyApps")); } else { props.setProperty("ckan.authorization.key", PropsUtil.get("authenticationKey")); } props.setProperty("ckan.url", PropsUtil.get("cKANurl")); LOG.debug("odRClient props:" + props.toString()); odrClient = OpenDataRegistry.getClient(); odrClient.init(props); redakteur = false; try { for (Role role : RoleLocalServiceUtil.getUserRoles(td.getUserId())) { if (role.getName().equals("Redakteur") && RoleLocalServiceUtil.hasUserRole(role.getRoleId(), td.getUserId())) { redakteur = true; } } } catch (SystemException e) { LOG.error(e.getMessage(), e); } selectedTags = new ArrayList<String>(); selectedCategories = new ArrayList<String>(); selectedManyCategories = new ArrayList<String>(); licences = new ArrayList<Licence>(); // resource2DeleteList = new ArrayList<String>(); /* * Sets caption according to create/edit metadata for * dataset/app/document */ if (metadataController.getMetadata().getTitle() == null || metadataController.getMetadata().getTitle().isEmpty()) { /* * Create */ author = metadataController.getMetadata().newContact(RoleEnumType.AUTHOR); maintainer = metadataController.getMetadata().newContact(RoleEnumType.MAINTAINER); distributor = metadataController.getMetadata().newContact(RoleEnumType.DISTRIBUTOR); editMode = false; LicenceBean lb = new LicenceBean(); Licence emptyLicence = new LicenceImpl(lb); metadataController.getMetadata().setLicence(emptyLicence); emptyLicence.setTitle(LanguageUtil.get(request.getLocale(), "od.licence.select")); licences.add(emptyLicence); if (metadataController.getMetadata().getType().equals(MetadataEnumType.DATASET) || metadataController.getMetadata().getType().equals(MetadataEnumType.UNKNOWN)) { metadataController.getMetadata().newResource(); caption = LanguageUtil.get(request.getLocale(), "od.create.metadata.data"); submitquestion = LanguageUtil.get(request.getLocale(), "od.create.metadata.data.submit"); metadataType = "dataset"; } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.APPLICATION)) { caption = LanguageUtil.get(request.getLocale(), "od.create.metadata.app"); submitquestion = LanguageUtil.get(request.getLocale(), "od.create.metadata.app.submit"); metadataType = "app"; usedDatasetUris = new ArrayList<String>(); } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.DOCUMENT)) { metadataController.getMetadata().newResource(); caption = LanguageUtil.get(request.getLocale(), "od.create.metadata.document"); submitquestion = LanguageUtil.get(request.getLocale(), "od.create.metadata.document.submit"); metadataType = "document"; } } else { /* * Edit */ try { // Handle contacts for (Contact contact : metadataController.getMetadata().getContacts()) { if (contact.getRole().equals(RoleEnumType.AUTHOR)) { author = contact; } else if (contact.getRole().equals(RoleEnumType.MAINTAINER)) { maintainer = contact; } else if (contact.getRole().equals(RoleEnumType.DISTRIBUTOR)) { distributor = contact; } else if (contact.getRole().equals(RoleEnumType.PUBLISHER)) { LOG.info("Handle metadata contact PUBLISHER [" + contact.getName() + "] now as AUTHOR"); /* msg 10.10.2014 begin */ author = contact; /* msg 10.10.2014 end */ } } } catch (UnknownRoleException une) { LOG.error("UnknownRoleException -> Contact role:", une.getMessage()); } finally { metadataController.getMetadata().getContacts().clear(); } if (author == null) { author = metadataController.getMetadata().newContact(RoleEnumType.AUTHOR); } if (maintainer == null) { maintainer = metadataController.getMetadata().newContact(RoleEnumType.MAINTAINER); } if (distributor == null) { distributor = metadataController.getMetadata().newContact(RoleEnumType.DISTRIBUTOR); } editMode = true; selectedLicence = metadataController.getMetadata().getLicence().getName(); unknownLicenceText = metadataController.getMetadata().getLicence().getTitle(); unknownLicenceUrl = metadataController.getMetadata().getLicence().getUrl(); for (Tag t : metadataController.getMetadata().getTags()) { selectedTags.add(t.getName()); } for (Category c : metadataController.getMetadata().getCategories()) { selectedCategories.add(c.getName()); selectedManyCategories.add(c.getName()); } submitquestion = LanguageUtil.get(request.getLocale(), "od.edit.any.data.save.changes"); if (metadataController.getMetadata().getType().equals(MetadataEnumType.DATASET) || metadataController.getMetadata().getType().equals(MetadataEnumType.UNKNOWN)) { caption = LanguageUtil.get(request.getLocale(), "od.edit.metadata.data"); metadataType = "dataset"; } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.APPLICATION)) { caption = LanguageUtil.get(request.getLocale(), "od.edit.metadata.app"); metadataType = "app"; usedDatasetUris = ((Application) metadataController.getMetadata()).getUsedDatasets(); if (((Application) metadataController.getMetadata()).getUsedDatasets().size() < 1) { } } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.DOCUMENT)) { caption = LanguageUtil.get(request.getLocale(), "od.edit.metadata.document"); metadataType = "document"; } unknownLicence = unknownLicence(metadataController.getMetadata().getLicence().getName()); } /* * Fill licences accordingly to the metadata type: dataset, app, * document */ List<Licence> tempDatenlizenzDeutschlandLicences = new ArrayList<Licence>(); List<Licence> tempEINGESCHRAENKTLicences = new ArrayList<Licence>(); if (metadataController.getMetadata().getType().equals(MetadataEnumType.DATASET) || metadataController.getMetadata().getType().equals(MetadataEnumType.UNKNOWN)) { for (Licence licence : odrClient.listLicenses()) { if (licence.isDomainData()) { add2licences(request, tempDatenlizenzDeutschlandLicences, tempEINGESCHRAENKTLicences, licence); } } } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.APPLICATION)) { for (Licence licence : odrClient.listLicenses()) { if (licence.isDomainSoftware()) { add2licences(request, tempDatenlizenzDeutschlandLicences, tempEINGESCHRAENKTLicences, licence); } } } else if (metadataController.getMetadata().getType().equals(MetadataEnumType.DOCUMENT)) { for (Licence licence : odrClient.listLicenses()) { if (licence.isDomainContent()) { add2licences(request, tempDatenlizenzDeutschlandLicences, tempEINGESCHRAENKTLicences, licence); } } } Collections.sort(tempDatenlizenzDeutschlandLicences, new Comparator<Licence>() { public int compare(Licence l1, Licence l2) { return -(l2.getTitle().compareTo(l1.getTitle())); } }); Collections.sort(tempEINGESCHRAENKTLicences, new Comparator<Licence>() { public int compare(Licence l1, Licence l2) { return -(l2.getTitle().compareTo(l1.getTitle())); } }); Collections.sort(licences, new Comparator<Licence>() { public int compare(Licence l1, Licence l2) { return -(l2.getTitle().compareTo(l1.getTitle())); } }); // Damit alle DatenlizenzDeutschland immer oben in der liste stehen if (!licences.get(0).getTitle().equals(LanguageUtil.get(request.getLocale(), "od.licence.select"))) { licences.addAll(0, tempDatenlizenzDeutschlandLicences); } else licences.addAll(1, tempDatenlizenzDeutschlandLicences); // Damit alle EINGESCHRAENKT immer ganz unten in der liste stehen licences.addAll(tempEINGESCHRAENKTLicences); categories = new ArrayList<Category>(); List<Category> cats = odrClient.listCategories(); for (Category c : cats) { if ("group".equals(c.getType())) { categories.add(c); } } sectors = new ArrayList<SectorEnumType>(); for (SectorEnumType sector : SectorEnumType.values()) { sectors.add(sector); } geoGranularities = new ArrayList<GeoGranularityEnumType>(); for (GeoGranularityEnumType geoType : GeoGranularityEnumType.values()) { geoGranularities.add(geoType); } temporalGranularityEnumTypes = new ArrayList<TemporalGranularityEnumType>(); for (TemporalGranularityEnumType t : TemporalGranularityEnumType.values()) { temporalGranularityEnumTypes.add(t); } }
From source file:de.fhg.fokus.odp.portal.managedatasets.controller.ManageController.java
License:Open Source License
/** * check if the titel already exist in ckan. * //from w w w . j a v a 2 s.c o m */ public void titelValidator(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (editMode) { return; } String titel = value.toString(); Properties props = new Properties(); props.setProperty("ckan.authorization.key", PropsUtil.get("authenticationKey")); props.setProperty("ckan.url", PropsUtil.get("cKANurl")); ODRClient oDRClient = OpenDataRegistry.getClient(); oDRClient.init(props); boolean nameExist = false; try { String mungeTitle = oDRClient.mungeTitleToName(titel); Metadata metadata = oDRClient.getMetadata(currentUser.getCurrentUser(), mungeTitle); if (metadata != null) { LOG.debug("titelValidator:Metadata Titel existiert:" + titel); nameExist = true; } else { LOG.debug("titelValidator:Metadata Titel existiert NICHT:" + titel); nameExist = false; } } catch (Exception e) { LOG.debug("titelValidator:Metadata Titel existiert NICHT:" + titel); nameExist = false; } if (nameExist) { // FacesMessage message = new // FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid titel","Titel existiert schon:" // + titel); // context.addMessage(component.getClientId(), message); throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, component.getClientId(), "Titel existiert schon:" + titel)); } }