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

Commit

Permalink
Merge pull request #194 from zanata/rhbz1010771
Browse files Browse the repository at this point in the history
Add slug check when persisting new TM : https://bugzilla.redhat.com/show_bug.cgi?id=1010771
  • Loading branch information
Patrick Huang committed Sep 23, 2013
2 parents 048189d + 2aa44ac commit 6f83d98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Expand Up @@ -46,8 +46,8 @@
import org.zanata.dao.TransMemoryDAO;
import org.zanata.exception.EntityMissingException;
import org.zanata.model.tm.TransMemory;
import org.zanata.service.AsyncTaskManagerService;
import org.zanata.rest.service.TranslationMemoryResourceService;
import org.zanata.service.AsyncTaskManagerService;
import org.zanata.service.SlugEntityService;

/**
Expand Down Expand Up @@ -77,8 +77,8 @@ public class TranslationMemoryAction extends EntityHome<TransMemory>
/**
* Stores the last process handle, in page scope (ie for this user).
*/
@In(scope=ScopeType.PAGE, required=false)
@Out(scope=ScopeType.PAGE, required=false)
@In(scope = ScopeType.PAGE, required = false)
@Out(scope = ScopeType.PAGE, required = false)
private AsyncTaskHandle myTaskHandle;

/**
Expand All @@ -88,7 +88,7 @@ public class TranslationMemoryAction extends EntityHome<TransMemory>

public List<TransMemory> getAllTranslationMemories()
{
if( transMemoryList == null )
if (transMemoryList == null)
{
transMemoryList = transMemoryDAO.findAll();
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public Void call() throws Exception
}
},
new ClearTransMemoryProcessKey(transMemorySlug)
);
);

transMemoryList = null; // Force refresh next time list is requested
}
Expand All @@ -148,7 +148,8 @@ public boolean isProcessErrorPollEnabled()
*/
public String getProcessError()
{
if (myProcessError != null) return myProcessError;
if (myProcessError != null)
return myProcessError;
if (myTaskHandle != null && myTaskHandle.isDone())
{
try
Expand Down Expand Up @@ -200,9 +201,9 @@ public boolean deleteTransMemoryDisabled(String transMemorySlug)
public boolean isTablePollEnabled()
{
// Poll is enabled only when there is something being cleared
for( TransMemory tm : transMemoryList )
for (TransMemory tm : transMemoryList)
{
if( isTransMemoryBeingCleared(tm.getSlug()) )
if (isTransMemoryBeingCleared(tm.getSlug()))
{
return true;
}
Expand All @@ -221,6 +222,18 @@ public String cancel()
return "cancel";
}

@Override
@Transactional
public String persist()
{
if (!validateSlug(getInstance().getSlug(), "slug"))
{
return null;
}

return super.persist();
}

/**
* Represents a key to index a translation memory clear process.
*
Expand Down
4 changes: 3 additions & 1 deletion zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -912,7 +912,9 @@
<action execute="#{breadcrumbs.addLocation('/tm/home.xhtml', messages['jsf.transmemory.Title'])}"/>
<action execute="#{breadcrumbs.addLocation('', messages['jsf.transmemory.title.New'])}"/>
<navigation from-action="#{translationMemoryAction.persist}">
<redirect view-id="/tm/home.xhtml"/>
<rule if="#{translationMemoryAction.managed}">
<redirect view-id="/tm/home.xhtml"/>
</rule>
</navigation>
<navigation from-action="#{translationMemoryAction.cancel}">
<redirect view-id="/tm/home.xhtml" />
Expand Down

0 comments on commit 6f83d98

Please sign in to comment.