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

Commit

Permalink
rhbz1211849 - enable version slug change
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed May 13, 2015
1 parent b304f74 commit 8e2d7f3
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 22 deletions.
8 changes: 6 additions & 2 deletions zanata-war/src/main/java/org/zanata/action/ProjectHome.java
Expand Up @@ -543,7 +543,8 @@ private boolean enableLocaleSilently(LocaleId localeId) {
*/
private boolean enableLocaleSilently(HLocale locale) {
ensureOverridingLocales();
final boolean localeWasDisabled = getInstance().getCustomizedLocales().add(locale);
final boolean localeWasDisabled = getInstance().getCustomizedLocales().add(
locale);
refreshDisabledLocales();
return localeWasDisabled;
}
Expand Down Expand Up @@ -696,9 +697,12 @@ private void updateProjectType() {
@Restrict("#{s:hasPermission(projectHome.instance, 'update')}")
public String update() {
String result = super.update();
if (result.equals("updated")) {
if (!slug.equals(getInstance().getSlug())) {
slug = getInstance().getSlug();
projectUpdateEvent.fire(new ProjectUpdate(getInstance()));
return "projectSlugUpdated";
}
projectUpdateEvent.fire(new ProjectUpdate(getInstance()));
return result;
}

Expand Down
22 changes: 18 additions & 4 deletions zanata-war/src/main/java/org/zanata/action/VersionHome.java
Expand Up @@ -92,6 +92,8 @@ public class VersionHome extends SlugHome<HProjectIteration> implements
@Setter
private String slug;

private Long versionId;

@Getter
@Setter
private String projectSlug;
Expand Down Expand Up @@ -230,9 +232,17 @@ public class VersionItem implements Serializable {
@Override
protected HProjectIteration loadInstance() {
Session session = (Session) getEntityManager().getDelegate();
return (HProjectIteration) session.byNaturalId(HProjectIteration.class)
.using("slug", getSlug())
.using("project", projectDAO.getBySlug(projectSlug)).load();
if (versionId == null) {
HProjectIteration iteration = (HProjectIteration) session
.byNaturalId(HProjectIteration.class)
.using("slug", getSlug())
.using("project", projectDAO.getBySlug(projectSlug)).load();
versionId = iteration.getId();
return iteration;
} else {
return (HProjectIteration) session.load(HProjectIteration.class,
versionId);
}
}

@Restrict("#{s:hasPermission(versionHome.instance, 'update')}")
Expand Down Expand Up @@ -261,7 +271,7 @@ private Map<ValidationId, ValidationAction> getValidations() {
if (availableValidations.isEmpty()) {
Collection<ValidationAction> validationList =
validationServiceImpl.getValidationActions(projectSlug,
slug);
getInstance().getSlug());

for (ValidationAction validationAction : validationList) {
availableValidations.put(validationAction.getId(),
Expand Down Expand Up @@ -419,6 +429,10 @@ public String update() {
String state = super.update();
projectIterationUpdateEvent.fire(
new ProjectIterationUpdate(getInstance()));
if (!slug.equals(getInstance().getSlug())) {
slug = getInstance().getSlug();
return "versionSlugUpdated";
}
return state;
}

Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.model.HProject;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HTextFlowTarget;

/**
Expand Down Expand Up @@ -104,4 +105,31 @@ public ScrollableResults getTargetsWithAllFieldsEagerlyFetchedForProject(
.setParameter("project", project)
.scroll(ScrollMode.FORWARD_ONLY);
}

/**
*
* @return scrollable result set of HTextFlowTarget under a project
* iteration, with all of its fields(locale, textflow, document,
* document locale, project iteration and project) eagerly fetched.
*/
public ScrollableResults
getTargetsWithAllFieldsEagerlyFetchedForProjectIteration(
HProjectIteration iteration) {
Query query =
getSession()
.createQuery(
"from HTextFlowTarget tft "
+ "join fetch tft.locale "
+ "join fetch tft.textFlow "
+ "join fetch tft.textFlow.document "
+
"join fetch tft.textFlow.document.locale "
+
"join fetch tft.textFlow.document.projectIteration iter "
+
"join fetch tft.textFlow.document.projectIteration.project where iter = :iteration");
return query.setFetchSize(Integer.MIN_VALUE)
.setParameter("iteration", iteration)
.scroll(ScrollMode.FORWARD_ONLY);
}
}
Expand Up @@ -115,7 +115,15 @@ private static void reindexScrollableResultSet(FullTextSession session,
session.clear(); // clear since the queue is processed
}

public void reindexForProjectVersion(HProjectIteration projectIteration) {

public void reindexForProjectVersion(HProjectIteration projectIteration,
FullTextSession session, AsyncTaskHandle<Void> handle) {
// it must use the same session in the DAO and to do the indexing
HTextFlowTargetStreamingDAO dao =
new HTextFlowTargetStreamingDAO(HTextFlowTarget.class, session);
ScrollableResults
scrollableResults =
dao.getTargetsWithAllFieldsEagerlyFetchedForProjectIteration(
projectIteration);
reindexScrollableResultSet(session, scrollableResults, handle);
}
}
Expand Up @@ -202,8 +202,10 @@ public Future<Void> reindexSlugEntity(SlugEntityBase slugEntity,
if (slugEntity instanceof HProject) {
indexingStrategy.reindexForProject((HProject) slugEntity,
session, handle);
} else if (slugEntity instanceof HProjectIteration) {
indexingStrategy.reindexForProjectVersion(
(HProjectIteration) slugEntity, session, handle);
}
// TODO pahuang handle HProjectIteration

if (handle.getCurrentProgress() != handle
.getMaxProgress()) {
Expand Down
Expand Up @@ -14,6 +14,9 @@
import org.zanata.model.HProjectIteration;
import org.zanata.model.SlugEntityBase;
import org.zanata.service.IndexingService;
import org.zanata.webtrans.server.TranslationWorkspaceManager;
import org.zanata.webtrans.shared.model.ProjectIterationId;
import org.zanata.webtrans.shared.model.WorkspaceId;
import com.google.common.base.Throwables;

/**
Expand All @@ -32,6 +35,9 @@ public class SlugUpdatedListener implements PostUpdateEventListener {
@In
private IndexingService indexingServiceImpl;

@In
private TranslationWorkspaceManager translationWorkspaceManager;

private Integer index;

@Override
Expand All @@ -52,7 +58,6 @@ public void onPostUpdate(PostUpdateEvent event) {
event.getEntity());
log.debug("Slug entity [{}] changed slug. old slug: {}, new slug: {}",
slugEntityBase, oldSlug, newSlug);
// TODO pahuang need to update lucene index for all text flow targets under this project or iteration

AsyncTaskHandle<Void> handle = new AsyncTaskHandle<>();
asyncTaskHandleManager.registerTaskHandle(handle);
Expand All @@ -63,6 +68,8 @@ public void onPostUpdate(PostUpdateEvent event) {
catch (Exception e) {
log.error("exception happen in async framework", e);
}
// TODO pahuang need to send workspace update event to all open workspace and let user redirect to new url
// translationWorkspaceManager.tryGetWorkspace(new WorkspaceId(new ProjectIterationId(oldSlug, null, )))
}

private Integer getSlugFieldIndex(PostUpdateEvent event) {
Expand Down
Expand Up @@ -37,7 +37,7 @@
*
*/
public interface TranslationWorkspace {
public Map<EditorClientId, PersonSessionDetails> getUsers();
Map<EditorClientId, PersonSessionDetails> getUsers();

void addEditorClient(String httpSessionId, EditorClientId editorClientId,
PersonId personId);
Expand All @@ -55,6 +55,6 @@ void updateUserSelection(EditorClientId editorClientId,

TransUnitId getUserSelection(EditorClientId editorClientId);

public void onEventServiceConnected(EditorClientId editorClientId,
void onEventServiceConnected(EditorClientId editorClientId,
String connectionId);
}
Expand Up @@ -210,9 +210,9 @@ void projectIterationUpdate(HProjectIteration projectIteration) {
ProjectType projectType = projectIteration.getProjectType();
log.info(
"Project {} iteration {} updated, status={}, isProjectActive={}, projectType={}",
new Object[] { projectSlug, iterSlug,
projectIteration.getStatus(), isProjectActive,
projectType });
projectSlug, iterSlug,
projectIteration.getStatus(), isProjectActive,
projectType);

ProjectIterationId iterId =
new ProjectIterationId(projectSlug, iterSlug,
Expand Down
Expand Up @@ -61,14 +61,9 @@
title="#{msgs['jsf.SlugExample']}"></i></span>
</h:outputLabel>
<s:decorate id="slugField" template="../field.xhtml" enclose="true">
<h:inputText rendered="#{versionHome.managed}" disabled="true"
value="#{versionHome.instance.slug}">
</h:inputText>

<h:inputText rendered="#{not versionHome.managed}" maxlength="40"
<h:inputText maxlength="40"
id="slug" required="true" value="#{versionHome.instance.slug}"
valueChangeListener="#{versionHome.verifySlugAvailable}">
<a4j:ajax event="blur" render="slugField" execute="@this"/>
<f:validateLength minimum="1"/>
</h:inputText>
</s:decorate>
Expand Down
12 changes: 11 additions & 1 deletion zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -333,7 +333,7 @@
</rule>
</navigation>
<navigation from-action="#{projectHome.update}">
<rule if-outcome="updated">
<rule if-outcome="projectSlugUpdated">
<redirect view-id="/project/project.xhtml">
<param name="slug" value="#{projectHome.slug}" />
</redirect>
Expand Down Expand Up @@ -420,6 +420,16 @@
value="#{versionHome.instance.slug}" />
</redirect>
</navigation>
<navigation from-action="#{versionHome.update}">
<rule if-outcome="versionSlugUpdated">
<redirect view-id="/iteration/view.xhtml">
<param name="projectSlug"
value="#{versionHome.projectSlug}" />
<param name="iterationSlug"
value="#{versionHome.instance.slug}" />
</redirect>
</rule>
</navigation>
</page>

<!-- Language -->
Expand Down

0 comments on commit 8e2d7f3

Please sign in to comment.