Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jan 3, 2012
1 parent d139370 commit 867dc84
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 179 deletions.
16 changes: 0 additions & 16 deletions server/zanata-model/src/main/java/org/zanata/model/HProject.java
Expand Up @@ -60,8 +60,6 @@ public abstract class HProject extends SlugEntityBase implements Serializable

private Set<HPerson> maintainers;

private boolean obsolete = false;

@Length(max = 80)
@NotEmpty
@Field(index = Index.TOKENIZED)
Expand Down Expand Up @@ -136,20 +134,6 @@ public void setCustomizedLocales(Set<HLocale> locales)
this.customizedLocales = locales;
}

public boolean isObsolete()
{
return obsolete;
}

/**
*
* @param obsolete
*/
public void setObsolete(boolean obsolete)
{
this.obsolete = obsolete;
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -54,8 +54,6 @@ public class HProjectIteration extends SlugEntityBase

private HIterationProject project;

private boolean active = true;

private HProjectIteration parent;
private List<HProjectIteration> children;

Expand All @@ -65,18 +63,6 @@ public class HProjectIteration extends SlugEntityBase
private boolean overrideLocales = false;
private Set<HLocale> customizedLocales;

private boolean obsolete = false;

public void setActive(boolean active)
{
this.active = active;
}

public boolean getActive()
{
return active;
}

public void setOverrideLocales(boolean var)
{
this.overrideLocales = var;
Expand Down Expand Up @@ -169,16 +155,6 @@ public void setDocuments(Map<String, HDocument> documents)
this.documents = documents;
}

public boolean isObsolete()
{
return obsolete;
}

public void setObsolete(boolean obsolete)
{
this.obsolete = obsolete;
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -20,19 +20,25 @@
*/
package org.zanata.model;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.NaturalId;
import org.hibernate.search.annotations.Field;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.zanata.model.type.StatusType;
import org.zanata.model.validator.Slug;

@MappedSuperclass
public class SlugEntityBase extends ModelEntityBase
{
private String slug;

@Enumerated(EnumType.STRING)
private StatusType status;

@NaturalId
@Length(min = 1, max = 40)
@Slug
Expand All @@ -48,6 +54,17 @@ public void setSlug(String slug)
this.slug = slug;
}

public StatusType getStatus()
{
return status;
}

public void setStatus(StatusType status)
{
this.status = status;
}


@Override
public String toString()
{
Expand Down
@@ -0,0 +1,34 @@
/*
* Copyright 2011, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata.model.type;

/**
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
**/
public enum StatusType
{
Current, Retired, Obsolete
}



Expand Up @@ -29,7 +29,6 @@
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
import org.zanata.dao.ProjectDAO;
Expand All @@ -41,8 +40,9 @@
public class ProjectAction extends BaseSecurityChecker implements Serializable
{
private static final long serialVersionUID = 1L;
private ProjectPagedListDataModel projectPagedListDataModel = new ProjectPagedListDataModel(false);

private ProjectPagedListDataModel filteredProjectPagedListDataModel = new ProjectPagedListDataModel(true);
private ProjectPagedListDataModel projectPagedListDataModel = new ProjectPagedListDataModel(false);

private int scrollerPage = 1;

Expand All @@ -55,32 +55,45 @@ public class ProjectAction extends BaseSecurityChecker implements Serializable
@In
Identity identity;

private boolean showObsolete = false;

private HProject securedEntity = null;

public boolean getEmpty()
{
if (checkViewObsoleteOption() && showObsolete)
if (checkViewObsolete())
{
return projectDAO.getProjectSize() == 0;

}
else
{
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("===========here3=========");
return projectDAO.getFilteredProjectSize() == 0;
}
}

public int getPageSize()
{
if (checkViewObsoleteOption() && showObsolete)
if (checkViewObsolete())
{
return filteredProjectPagedListDataModel.getPageSize();
return projectPagedListDataModel.getPageSize();
}
else
{
return projectPagedListDataModel.getPageSize();
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("===========here2=========");
return filteredProjectPagedListDataModel.getPageSize();
}
}

Expand All @@ -96,44 +109,14 @@ public void setScrollerPage(int scrollerPage)

public DataModel getProjectPagedListDataModel()
{
if (checkViewObsoleteOption() && showObsolete)
{
return filteredProjectPagedListDataModel;
}
else
if (checkViewObsolete())
{
return projectPagedListDataModel;
}
}

public void updateObsolete(HProject project)
{
securedEntity = project;
if (checkPermission("mark-obsolete"))
else
{
projectDAO.makePersistent(project);
projectDAO.flush();

if (project.isObsolete())
{
FacesMessages.instance().add("Marked {0} as obsolete", project.getName());
}
else
{
FacesMessages.instance().add("Marked {0} as current", project.getName());
}
return filteredProjectPagedListDataModel;
}
securedEntity = null;
}

public boolean isShowObsolete()
{
return showObsolete;
}

public void setShowObsolete(boolean showObsolete)
{
this.showObsolete = showObsolete;
}

@Override
Expand All @@ -148,9 +131,9 @@ public Object getSecuredEntity()
* @param operation
* @return
*/
public boolean checkViewObsoleteOption()
public boolean checkViewObsolete()
{
return identity != null && identity.hasPermission("HProject", "view-obsolete-option", null);
return identity != null && identity.hasPermission("HProject", "view-obsolete", null);
}

}
Expand Up @@ -51,42 +51,12 @@ public class ProjectIterationAction extends BaseSecurityChecker implements Seria

private HProjectIteration securedEntity = null;

public void markProjectIterationObsolete(HProjectIteration projectIteration)
{
securedEntity = projectIteration;
if (checkPermission("mark-obsolete"))
{
projectIteration.setObsolete(true);

projectIterationDAO.makePersistent(projectIteration);
projectIterationDAO.flush();
FacesMessages.instance().add("Marked iteration {0} as obsolete", projectIteration.getSlug());
}
}

public void markProjectIterationCurrent(HProjectIteration projectIteration)
{
securedEntity = projectIteration;
if (checkPermission("mark-obsolete"))
{
projectIteration.setObsolete(false);

projectIterationDAO.makePersistent(projectIteration);
projectIterationDAO.flush();
FacesMessages.instance().add("Marked iteration {0} as current", projectIteration.getSlug());
}
}

public boolean checkViewObsolete()
{
return Identity.instance() != null && Identity.instance().hasPermission("HProjectIteration", "view-obsolete", null);
}

public boolean checkViewObsoleteOption()
{
return Identity.instance() != null && Identity.instance().hasPermission("HProjectIteration", "view-obsolete-option", null);
}

@Override
public Object getSecuredEntity()
{
Expand Down
Expand Up @@ -30,11 +30,11 @@

public class ProjectPagedListDataModel extends PagedListDataModel<HProject>
{
boolean selectAll = false;
boolean filterList;

public ProjectPagedListDataModel(boolean selectAll)
public ProjectPagedListDataModel(boolean filterList)
{
this.selectAll = selectAll;
this.filterList = filterList;
}

@Override
Expand All @@ -43,13 +43,22 @@ public DataPage<HProject> fetchPage(int startRow, int pageSize)
ProjectDAO projectDAO = (ProjectDAO) Component.getInstance(ProjectDAO.class, ScopeType.STATELESS);
List<HProject> proj = null;

if (selectAll)
if (!filterList)
{
proj = projectDAO.getOffsetListByCreateDate(startRow, pageSize);
return new DataPage<HProject>(projectDAO.getProjectSize(), startRow, proj);
}
else
{
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("============================");
System.out.println("===========here5=========");

proj = projectDAO.getFilteredOffsetListByCreateDate(startRow, pageSize);
return new DataPage<HProject>(projectDAO.getFilteredProjectSize(), startRow, proj);
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.jboss.seam.annotations.Scope;
import org.zanata.model.HPerson;
import org.zanata.model.HProject;
import org.zanata.model.type.StatusType;

@Name("projectDAO")
@AutoCreate
Expand Down Expand Up @@ -51,12 +52,12 @@ public List<HProject> getOffsetListByCreateDate(int offset, int count)
@SuppressWarnings("unchecked")
public List<HProject> getFilteredOffsetListByCreateDate(int offset, int count)
{
return getSession().createCriteria(HProject.class).addOrder(Order.desc(ORDERBY_TIMESTAMP)).add(Restrictions.eq("obsolete", false)).setMaxResults(count).setFirstResult(offset).setComment("ProjectDAO.getOffsetListByCreateDate").list();
return getSession().createCriteria(HProject.class).addOrder(Order.desc(ORDERBY_TIMESTAMP)).add(Restrictions.eq("status", StatusType.Obsolete)).setMaxResults(count).setFirstResult(offset).setComment("ProjectDAO.getOffsetListByCreateDate").list();
}

public int getFilteredProjectSize()
{
Long totalCount = (Long) getSession().createQuery("select count(*) from HProject as p where p.obsolete = :obsolete").setParameter("obsolete", false).uniqueResult();
Long totalCount = (Long) getSession().createQuery("select count(*) from HProject as p where p.status <> :status").setParameter("status", StatusType.Obsolete).uniqueResult();
if (totalCount == null)
return 0;
return totalCount.intValue();
Expand Down

0 comments on commit 867dc84

Please sign in to comment.