001package org.nuxeo.segment.io.web; 002 003import java.io.Serializable; 004 005import org.jboss.seam.ScopeType; 006import org.jboss.seam.annotations.In; 007import org.jboss.seam.annotations.Install; 008import org.jboss.seam.annotations.Name; 009import org.jboss.seam.annotations.Scope; 010import org.jboss.seam.contexts.Contexts; 011import org.nuxeo.ecm.core.api.NuxeoPrincipal; 012import org.nuxeo.runtime.api.Framework; 013import org.nuxeo.segment.io.SegmentIO; 014 015@Name("segmentIOActions") 016@Scope(ScopeType.EVENT) 017@Install(precedence = Install.FRAMEWORK) 018public class SegmentIOBean implements Serializable { 019 020 private static final long serialVersionUID = 1L; 021 022 @In(create=true) 023 NuxeoPrincipal currentNuxeoPrincipal; 024 025 protected static final String SEGMENTIO_FLAG = "segment.io.identify.flag"; 026 027 public String getWriteKey() { 028 return Framework.getLocalService(SegmentIO.class).getWriteKey(); 029 } 030 031 public boolean needsIdentify() { 032 if (currentNuxeoPrincipal==null) { 033 return false; 034 } 035 036 if (currentNuxeoPrincipal.isAnonymous()) { 037 return false; 038 } 039 040 Object flag = Contexts.getSessionContext().get(SEGMENTIO_FLAG); 041 if (flag == null) { 042 Contexts.getSessionContext().set(SEGMENTIO_FLAG, true); 043 return true; 044 } 045 return false; 046 } 047 048}