@Test
  public void testUpdateTemplate() throws Exception {
    String structureId = generateId();

    addStructure(groupId, structureId, getDefultXsd());

    Map<Locale, String> nameMap = new HashMap<Locale, String>();

    nameMap.put(Locale.US, "New Test Structure");

    StringBundler sb = new StringBundler(5);

    sb.append("<root><dynamic-element name=\"abc\" index-type=\"\" ");
    sb.append("type=\"text\"><meta-data><entry name=\"label\">");
    sb.append("<![CDATA[abc]]></entry><entry name=\"required\">");
    sb.append("<![CDATA[false]]></entry></meta-data></dynamic-element>");
    sb.append("</root>");

    String xsd = sb.toString();

    JournalStructure structure =
        JournalStructureLocalServiceUtil.updateStructure(
            groupId, structureId, null, nameMap, null, xsd, getServiceContext());

    Assert.assertEquals("New Test Structure", structure.getName(Locale.US));
    Assert.assertEquals(
        JournalTestUtil.getXsdMap(xsd), JournalTestUtil.getXsdMap(structure.getXsd()));
  }
  public JournalStructure copyStructure(
      long userId,
      long groupId,
      String oldStructureId,
      String newStructureId,
      boolean autoStructureId)
      throws PortalException, SystemException {

    // Structure

    User user = userPersistence.findByPrimaryKey(userId);
    oldStructureId = oldStructureId.trim().toUpperCase();
    newStructureId = newStructureId.trim().toUpperCase();
    Date now = new Date();

    JournalStructure oldStructure = journalStructurePersistence.findByG_S(groupId, oldStructureId);

    if (autoStructureId) {
      newStructureId = String.valueOf(counterLocalService.increment());
    } else {
      validateStructureId(newStructureId);

      JournalStructure newStructure =
          journalStructurePersistence.fetchByG_S(groupId, newStructureId);

      if (newStructure != null) {
        throw new DuplicateStructureIdException();
      }
    }

    long id = counterLocalService.increment();

    JournalStructure newStructure = journalStructurePersistence.create(id);

    newStructure.setGroupId(groupId);
    newStructure.setCompanyId(user.getCompanyId());
    newStructure.setUserId(user.getUserId());
    newStructure.setUserName(user.getFullName());
    newStructure.setCreateDate(now);
    newStructure.setModifiedDate(now);
    newStructure.setStructureId(newStructureId);
    newStructure.setName(oldStructure.getName());
    newStructure.setDescription(oldStructure.getDescription());
    newStructure.setXsd(oldStructure.getXsd());

    journalStructurePersistence.update(newStructure, false);

    // Resources

    addStructureResources(newStructure, true, true);

    return newStructure;
  }