Skip to content

Commit 9caece4

Browse files
committed
Changes to ensure that the asset types are imported from the project-info db and that duplicates aren't created.
1 parent 359e396 commit 9caece4

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

src/main/java/com/quollwriter/Environment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,18 +4457,18 @@ public static void updateUserConfigurableObjectType (UserConfigurableObjectType
44574457
44584458
}
44594459
*/
4460-
/*
4460+
44614461
public static void addUserConfigurableObjectType (UserConfigurableObjectType type)
44624462
throws GeneralException
44634463
{
4464-
4464+
/*
44654465
if (type.getKey () == null)
44664466
{
44674467
44684468
Environment.projectInfoManager.saveObject (type);
44694469
44704470
}
4471-
4471+
*/
44724472
Environment.userConfigObjTypes.add (type);
44734473

44744474
// Need to now update the column/field state and save again since the field keys are now
@@ -4479,7 +4479,7 @@ public static void addUserConfigurableObjectType (UserConfigurableObjectType typ
44794479
// TODO type.addPropertyChangedListener (Environment.userConfigurableObjectTypeNameListener);
44804480

44814481
String id = type.getObjectTypeId ();
4482-
4482+
/*
44834483
if (!type.isLegacyObjectType ())
44844484
{
44854485
@@ -4496,9 +4496,9 @@ public static void addUserConfigurableObjectType (UserConfigurableObjectType typ
44964496
ProjectEvent.Type.userobjecttype,
44974497
ProjectEvent.Action._new,
44984498
type);
4499-
4500-
}
45014499
*/
4500+
}
4501+
45024502
/*
45034503
public static void removeUserConfigurableObjectTypeField (UserConfigurableObjectTypeField field)
45044504
throws GeneralException

src/main/java/com/quollwriter/db/ProjectDataHandler.java

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,19 @@ private void initUserConfigurableObjectTypes (Connection conn,
745745

746746
}
747747

748+
this.initUserConfigurableObjectTypesFromEnvironment (conn,
749+
project);
750+
748751
if (project.getUserConfigurableObjectType (Chapter.OBJECT_TYPE) == null)
749752
{
750753

754+
// Init the legacy object types.
755+
this.initLegacyObjectTypes (conn,
756+
project);
757+
758+
this.objectManager.saveObject (project,
759+
conn);
760+
/*
751761
// Can we init from the environment types?
752762
if (Environment.getUserConfigurableObjectType (Chapter.OBJECT_TYPE) != null)
753763
{
@@ -757,15 +767,8 @@ private void initUserConfigurableObjectTypes (Connection conn,
757767
758768
} else {
759769
760-
// Init the legacy object types.
761-
this.initLegacyObjectTypes (conn,
762-
project);
763-
764-
this.objectManager.saveObject (project,
765-
conn);
766-
767770
}
768-
771+
*/
769772
}
770773

771774
}
@@ -775,6 +778,28 @@ private void initUserConfigurableObjectTypesFromEnvironment (Connection conn,
775778
throws Exception
776779
{
777780

781+
Map<Long, Long> mappings = new HashMap<> ();
782+
783+
try
784+
{
785+
786+
mappings = (Map<Long, Long>) JSONDecoder.decode (project.getProperty ("userConfigObjTypesEnvToProjKeyMap"));
787+
System.out.println ("GOT MAPPINGS: " + mappings);
788+
} catch (Exception e) {
789+
790+
// Ignore
791+
792+
}
793+
794+
if (mappings == null)
795+
{
796+
797+
mappings = new HashMap<> ();
798+
799+
}
800+
801+
Map<Long, Long> tkmappings = mappings;
802+
778803
// This means we don't have the user config types set up.
779804
Map<UserConfigurableObjectType, UserConfigurableObjectType> tmappings = new HashMap<> ();
780805

@@ -788,6 +813,14 @@ private void initUserConfigurableObjectTypesFromEnvironment (Connection conn,
788813
for (UserConfigurableObjectType t : objTypes)
789814
{
790815

816+
if (tkmappings.containsKey (t.getKey () + ""))
817+
{
818+
819+
System.out.println ("ALREADY GOT: " + t.getKey () + ", " + t.getName ());
820+
continue;
821+
822+
}
823+
System.out.println ("ADDING: " + t.getKey () + ", " + t.getName ());
791824
UserConfigurableObjectType nt = new UserConfigurableObjectType (project);
792825
nt.setName (t.getName ());
793826
nt.setDescription (t.getDescription ());
@@ -933,7 +966,7 @@ private void initUserConfigurableObjectTypesFromEnvironment (Connection conn,
933966
}
934967

935968
// Map the type keys
936-
Map<Long, Long> tkmappings = new HashMap<> ();
969+
//Map<Long, Long> tkmappings = new HashMap<> ();
937970

938971
// k -> env key
939972
// v -> proj key

src/main/java/com/quollwriter/db/UserConfigurableObjectTypeDataHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private UserConfigurableObjectType getUserConfigurableObjectType (ResultSet rs,
102102
} else {
103103

104104
// Keep this around, needed so we can get the environment type.
105-
//Environment.addUserConfigurableObjectType (t);
105+
Environment.addUserConfigurableObjectType (t);
106106

107107
}
108108

0 commit comments

Comments
 (0)