Category Systems create and list

ccm-docs
Jens Pelzetter 2020-11-11 14:59:52 +01:00
parent 99dfb7949c
commit 57f6e90c56
9 changed files with 138 additions and 48 deletions

View File

@ -89,6 +89,10 @@ public class CategorySystemDetailsModel {
return Collections.unmodifiableList(owners); return Collections.unmodifiableList(owners);
} }
public boolean isNew() {
return categorySystemId == 0;
}
public List<Message> getMessages() { public List<Message> getMessages() {
return Collections.unmodifiableList(messages); return Collections.unmodifiableList(messages);
} }

View File

@ -57,6 +57,9 @@ public class CategorySystemFormController {
@Inject @Inject
private CategorySystemDetailsModel categorySystemDetailsModel; private CategorySystemDetailsModel categorySystemDetailsModel;
@Inject
private DomainManager domainManager;
@Inject @Inject
private DomainRepository domainRepository; private DomainRepository domainRepository;
@ -75,17 +78,17 @@ public class CategorySystemFormController {
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public String createCategorySystem() { public String createCategorySystem() {
final Domain domain = new Domain();
domain.setDomainKey(domainKey);
domain.setUri(uri);
final Domain domain = domainManager.createDomain(domainKey, domainKey);
domain.setUri(uri);
domainRepository.save(domain); domainRepository.save(domain);
return "redirect:/categorymanager/categorysystems"; return "redirect:/categorymanager/categorysystems";
} }
@POST @POST
@Path("/{categorySystemIdentifier}/edit") @Path("{categorySystemIdentifier}/edit")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)

View File

@ -54,7 +54,7 @@ import javax.ws.rs.PathParam;
*/ */
@RequestScoped @RequestScoped
@Controller @Controller
@Path("/categorymanager") @Path("/categorymanager/categorysystems")
public class CategorySystemsController { public class CategorySystemsController {
@Inject @Inject
@ -78,16 +78,16 @@ public class CategorySystemsController {
@Inject @Inject
private Models models; private Models models;
@GET // @GET
@Path("/") // @Path("/")
@AuthorizationRequired // @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) // @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String getCategoryManager() { // public String getCategoryManager() {
return getCategorySystems(); // return getCategorySystems();
} // }
@GET @GET
@Path("/categorysystems") @Path("/")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String getCategorySystems() { public String getCategorySystems() {
@ -95,7 +95,7 @@ public class CategorySystemsController {
} }
@GET @GET
@Path("/categorysystems/{categorySystemIdentifier}/details") @Path("/{categorySystemIdentifier}/details")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -144,7 +144,7 @@ public class CategorySystemsController {
} }
@GET @GET
@Path("/categorysystems/new") @Path("/new")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String newCategorySystem() { public String newCategorySystem() {
@ -152,7 +152,7 @@ public class CategorySystemsController {
} }
@GET @GET
@Path("/categorysystems/{categorySystemIdentifier}/edit") @Path("/{categorySystemIdentifier}/edit")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -201,7 +201,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/delete") @Path("/{categorySystemIdentifier}/delete")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -253,7 +253,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/title/add") @Path("/{categorySystemIdentifier}/title/add")
@AuthorizationRequired @AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public String addTitle( public String addTitle(
@ -308,7 +308,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/title/${locale}/edit") @Path("/{categorySystemIdentifier}/title/${locale}/edit")
@AuthorizationRequired @AuthorizationRequired
public String editTitle( public String editTitle(
@PathParam("categorySystemIdentifier") @PathParam("categorySystemIdentifier")
@ -362,7 +362,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/title/${locale}/remove") @Path("/{categorySystemIdentifier}/title/${locale}/remove")
@AuthorizationRequired @AuthorizationRequired
public String removeTitle( public String removeTitle(
@PathParam("categorySystemIdentifier") @PathParam("categorySystemIdentifier")
@ -415,7 +415,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/description/add") @Path("/{categorySystemIdentifier}/description/add")
@AuthorizationRequired @AuthorizationRequired
public String addDescription( public String addDescription(
@PathParam("categorySystemIdentifier") @PathParam("categorySystemIdentifier")
@ -470,7 +470,7 @@ public class CategorySystemsController {
@POST @POST
@Path( @Path(
"/categorysystems/{categorySystemIdentifier}/description/${locale}/edit") "categorysystems/{categorySystemIdentifier}/description/${locale}/edit")
@AuthorizationRequired @AuthorizationRequired
public String editDescription( public String editDescription(
@PathParam("categorySystemIdentifier") @PathParam("categorySystemIdentifier")
@ -525,7 +525,7 @@ public class CategorySystemsController {
@POST @POST
@Path( @Path(
"/categorysystems/{categorySystemIdentifier}/description/${locale}/remove") "categorysystems/{categorySystemIdentifier}/description/${locale}/remove")
@AuthorizationRequired @AuthorizationRequired
public String removeDescription( public String removeDescription(
@PathParam("categorySystemIdentifier") @PathParam("categorySystemIdentifier")
@ -578,7 +578,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/owners/add") @Path("/{categorySystemIdentifier}/owners/add")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String addOwner( public String addOwner(
@ -650,7 +650,7 @@ public class CategorySystemsController {
} }
@POST @POST
@Path("/categorysystems/{categorySystemIdentifier}/owners/remove") @Path("/{categorySystemIdentifier}/owners/remove")
@AuthorizationRequired @AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public String removeOwner( public String removeOwner(

View File

@ -63,24 +63,27 @@ public class CategorySystemsTableModel {
row.setDomainKey(domain.getDomainKey()); row.setDomainKey(domain.getDomainKey());
row.setUri(domain.getUri()); row.setUri(domain.getUri());
row.setVersion(domain.getVersion()); row.setVersion(domain.getVersion());
row.setReleased( if (domain.getReleased() != null) {
DateTimeFormatter.ISO_DATE_TIME.format( row.setReleased(
domain.getReleased().toInstant() DateTimeFormatter.ISO_DATE_TIME.format(
) domain.getReleased().toInstant()
); )
);
}
row.setTitle( row.setTitle(
domain domain
.getTitle() .getTitle()
.getValues() .getValues()
.entrySet() .entrySet()
.stream() .stream()
.collect( .collect(
Collectors.toMap( Collectors.toMap(
entry -> entry.getKey().toString(), entry -> entry.getKey().toString(),
entry -> entry.getValue() entry -> entry.getValue()
)
) )
)
); );
return row; return row;
} }
} }

View File

@ -12,12 +12,74 @@
<li class="breadcrumb-item active"> <li class="breadcrumb-item active">
#{AdminMessages['categories.label']} #{AdminMessages['categories.label']}
</li> </li>
<li class="breadcrumb-item active">
<a href="#{mvc.uri('CategorySystemsController#getCategorySystems')}">
#{AdminMessages['categorysystems.label']}
</a>
</li>
<c:choose>
<c:when test="#{CategorySystemDetailsModel.new}">
<li class="breadcrumb-item active">
#{AdminMessages['categorysystems.new.label']}
</li>
</c:when>
<c:otherwise>
<li class="breadcrumb-item active">
#{CategorySystemDetailsModel.domainKey}
</li>
</c:otherwise>
</c:choose>
</ui:define> </ui:define>
<ui:define name="main"> <ui:define name="main">
<div class="container"> <div class="container">
<h1>#{AdminMessages['categories.label']}</h1> <h1>#{CategorySystemDetailsModel.new ? AdminMessages['categorysystems.new.label'] : AdminMessages.getMessage('categorysystems.edit.label', CategorySystemDetailsModel.domainKey)}</h1>
<p>ToDo</p>
<form action="#{CategorySystemDetailsModel.new ? mvc.uri('CategorySystemFormController#createCategorySystem') : mvc.uri('CategorySystemFormController#updateCategorySystem', {'categorySystemIdentifier': CategoryDetailsModel.domainKey })}"
method="post">
<div class="form-group">
<label for="domainKey">
#{AdminMessages['categorysystems.form.domainKey.label']}
</label>
<input aria-describedby="domainKey-help"
class="form-control"
name="domainKey"
type="text" />
<small class="form-text text-muted"
id="domainKey-help">
#{AdminMessages['categorysystems.form.domainKey.help']}
</small>
</div>
<div class="form-group">
<label for="uri">
#{AdminMessages['categorysystems.form.uri.label']}
</label>
<input aria-describedby="uri-help"
class="form-control"
name="domainKey"
type="text" />
<small class="form-text text-muted"
id="domainKey-help">
#{AdminMessages['categorysystems.form.uri.help']}
</small>
</div>
<a class="btn btn-warning"
href="#{mvc.uri('CategorySystemsController#getCategorySystems')}">
#{AdminMessages['categorysystems.form.buttons.cancel']}
</a>
<button class="btn btn-success" type="submit">
<c:choose>
<c:when test="#{UserDetailsModel.newUser}">
#{AdminMessages['categorysystems.form.buttons.create']}
</c:when>
<c:otherwise>
#{AdminMessages['categorysystems.form.buttons.save']}
</c:otherwise>
</c:choose>
</button>
</form>
</div> </div>
</ui:define> </ui:define>

View File

@ -25,7 +25,7 @@
<div class="container"> <div class="container">
<h1>#{AdminMessages['categorysystems.label']}</h1> <h1>#{AdminMessages['categorysystems.label']}</h1>
<div class="text-right m-b-2"> <div class="text-right mb-2">
<a class="btn btn-secondary" <a class="btn btn-secondary"
href="#{mvc.uri('CategorySystemsController#newCategorySystem')}"> href="#{mvc.uri('CategorySystemsController#newCategorySystem')}">
<svg class="bi" <svg class="bi"
@ -51,7 +51,7 @@
var="categorySystem"> var="categorySystem">
<tr> <tr>
<td> <td>
<a href="#{mvc.uri('CategorySystemsController#getCategorySystemDetails', categorySystem.identifier)}"> <a href="#{mvc.uri('CategorySystemsController#getCategorySystemDetails', { 'categorySystemIdentifier': categorySystem.identifier })}">
#{categorySystem.domainKey} #{categorySystem.domainKey}
</a> </a>
</td> </td>

View File

@ -43,7 +43,7 @@
<label for="username"> <label for="username">
#{AdminMessages['usersgroupsroles.users.form.username.label']} #{AdminMessages['usersgroupsroles.users.form.username.label']}
</label> </label>
<input aria-described-by="username-help" <input aria-describedby="username-help"
class="form-control" class="form-control"
id="username" id="username"
name="userName" name="userName"

View File

@ -248,3 +248,12 @@ categorysystems.table.headers.domainKey=Domain Key
categorysystems.table.headers.uri=URI categorysystems.table.headers.uri=URI
categorysystems.table.headers.version=Version categorysystems.table.headers.version=Version
categorysystems.table.headers.released=Released categorysystems.table.headers.released=Released
categorysystems.new.label=Create new categorysystem
categorysystems.edit.label=Edit Category System {0}
categorysystems.form.domainKey.label=Domain Key
categorysystems.form.domainKey.help=Unique key for category system
categorysystems.form.uri.label=URI
categorysystems.form.uri.help=URI stub of the categorysystem
categorysystems.form.buttons.create=Create new categorysystem
categorysystems.form.buttons.save=Apply changes
categorysystems.form.buttons.cancel=Cancel

View File

@ -248,3 +248,12 @@ categorysystems.table.headers.domainKey=Domain Key
categorysystems.table.headers.uri=URI categorysystems.table.headers.uri=URI
categorysystems.table.headers.version=Version categorysystems.table.headers.version=Version
categorysystems.table.headers.released=Freigegeben categorysystems.table.headers.released=Freigegeben
categorysystems.new.label=Neues Kategoriensystem erstellen
categorysystems.edit.label=Kategoriensystem {0} bearbeiten
categorysystems.form.domainKey.label=Domain Key
categorysystems.form.domainKey.help=Unique key for category system
categorysystems.form.uri.label=URI
categorysystems.form.uri.help=URI stub of the categorysystem
categorysystems.form.buttons.create=Neues Kategoriensystem anlegen
categorysystems.form.buttons.save=\u00c4nderungen anwenden
categorysystems.form.buttons.cancel=Abbrechen